Skip to content
Permalink
Browse files

8230492: font-family not set in HTMLEditor if font name has a number …

…in it

Reviewed-by: kcr, shadzic
  • Loading branch information
arun-Joseph authored and kevinrushforth committed Nov 6, 2019
1 parent f74f3af commit 286d1b5427a2b9724cb400335741ed99295c5141
@@ -689,7 +689,7 @@ private void populateToolbars() {
});

fontFamilyComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
executeCommand(FONT_FAMILY.getCommand(), ("".equals(newValue)) ? "''" : newValue);
executeCommand(FONT_FAMILY.getCommand(), "'" + newValue + "'");
});

fontSizeComboBox = new ComboBox<String>();
@@ -1139,7 +1139,7 @@ private void applyTextFormatting() {
String font = fontFamilyComboBox.getValue().toString();

executeCommand(FORMAT.getCommand(), format);
executeCommand(FONT_FAMILY.getCommand(), font);
executeCommand(FONT_FAMILY.getCommand(), "'" + font + "'");
}
}

@@ -31,9 +31,12 @@
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.Event;
import javafx.scene.control.ComboBox;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.scene.web.HTMLEditor;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
@@ -84,6 +87,12 @@ public static void setupOnce() {
new Thread(() -> Application.launch(HTMLEditorTestApp.class,
(String[]) null)).start();

// Used by selectFontFamilysWithSpace() for JDK-8230492
Font.loadFont(
HTMLEditorTest.class.getResource("WebKit_Layout_Tests_2.ttf").toExternalForm(),
10
);

assertTrue("Timeout waiting for FX runtime to start", Util.await(launchLatch));
}

@@ -294,4 +303,55 @@ public void checkStyleProperty() throws Exception {
assertNotNull("result must have a valid reference ", result.get());
assertEquals("document.body.style.fontWeight must be bold ", "bold", result.get());
}

/**
* @test
* @bug 8230492
* Summary Check font-family change on font name with numbers
*/
@Test
public void selectFontFamilyWithSpace() {
final CountDownLatch editorStateLatch = new CountDownLatch(1);
final AtomicReference<String> result = new AtomicReference<>();

Util.runAndWait(() -> {
webView.getEngine().getLoadWorker().stateProperty().
addListener((observable, oldValue, newValue) -> {
if (newValue == SUCCEEDED) {
htmlEditor.requestFocus();
}
});

htmlEditor.setHtmlText("<body>Sample Text</body>");

webView.focusedProperty().
addListener((observable, oldValue, newValue) -> {
if (newValue) {
ComboBox<String> fontFamilyComboBox = null;
int i = 0;
for (Node comboBox : htmlEditor.lookupAll(".font-menu-button")) {
// 0 - Format, 1 - Font Family, 2 - Font Size
if (i == 1) {
assertTrue("fontFamilyComboBox must be ComboBox",
comboBox instanceof ComboBox);
fontFamilyComboBox = (ComboBox<String>) comboBox;
assertNotNull("fontFamilyComboBox must not be null",
fontFamilyComboBox);
}
i++;
}
webView.getEngine().
executeScript("document.execCommand('selectAll', false, 'true');");
fontFamilyComboBox.getSelectionModel().select("WebKit Layout Tests 2");
result.set(htmlEditor.getHtmlText());
editorStateLatch.countDown();
}
});
});

assertTrue("Timeout when waiting for focus change ", Util.await(editorStateLatch));
assertNotNull("result must have a valid reference ", result.get());
assertTrue("font-family must be 'WebKit Layout Test 2' ", result.get().
contains("font-family: &quot;WebKit Layout Tests 2&quot;"));
}
}
Binary file not shown.

0 comments on commit 286d1b5

Please sign in to comment.
You can’t perform that action at this time.