|
31 | 31 | import javafx.application.Application;
|
32 | 32 | import javafx.application.Platform;
|
33 | 33 | import javafx.event.Event;
|
| 34 | +import javafx.scene.control.ComboBox; |
34 | 35 | import javafx.scene.input.KeyCode;
|
35 | 36 | import javafx.scene.input.KeyEvent;
|
| 37 | +import javafx.scene.Node; |
36 | 38 | import javafx.scene.Scene;
|
| 39 | +import javafx.scene.text.Font; |
37 | 40 | import javafx.scene.web.HTMLEditor;
|
38 | 41 | import javafx.scene.web.WebView;
|
39 | 42 | import javafx.stage.Stage;
|
@@ -84,6 +87,12 @@ public static void setupOnce() {
|
84 | 87 | new Thread(() -> Application.launch(HTMLEditorTestApp.class,
|
85 | 88 | (String[]) null)).start();
|
86 | 89 |
|
| 90 | + // Used by selectFontFamilysWithSpace() for JDK-8230492 |
| 91 | + Font.loadFont( |
| 92 | + HTMLEditorTest.class.getResource("WebKit_Layout_Tests_2.ttf").toExternalForm(), |
| 93 | + 10 |
| 94 | + ); |
| 95 | + |
87 | 96 | assertTrue("Timeout waiting for FX runtime to start", Util.await(launchLatch));
|
88 | 97 | }
|
89 | 98 |
|
@@ -294,4 +303,55 @@ public void checkStyleProperty() throws Exception {
|
294 | 303 | assertNotNull("result must have a valid reference ", result.get());
|
295 | 304 | assertEquals("document.body.style.fontWeight must be bold ", "bold", result.get());
|
296 | 305 | }
|
| 306 | + |
| 307 | + /** |
| 308 | + * @test |
| 309 | + * @bug 8230492 |
| 310 | + * Summary Check font-family change on font name with numbers |
| 311 | + */ |
| 312 | + @Test |
| 313 | + public void selectFontFamilyWithSpace() { |
| 314 | + final CountDownLatch editorStateLatch = new CountDownLatch(1); |
| 315 | + final AtomicReference<String> result = new AtomicReference<>(); |
| 316 | + |
| 317 | + Util.runAndWait(() -> { |
| 318 | + webView.getEngine().getLoadWorker().stateProperty(). |
| 319 | + addListener((observable, oldValue, newValue) -> { |
| 320 | + if (newValue == SUCCEEDED) { |
| 321 | + htmlEditor.requestFocus(); |
| 322 | + } |
| 323 | + }); |
| 324 | + |
| 325 | + htmlEditor.setHtmlText("<body>Sample Text</body>"); |
| 326 | + |
| 327 | + webView.focusedProperty(). |
| 328 | + addListener((observable, oldValue, newValue) -> { |
| 329 | + if (newValue) { |
| 330 | + ComboBox<String> fontFamilyComboBox = null; |
| 331 | + int i = 0; |
| 332 | + for (Node comboBox : htmlEditor.lookupAll(".font-menu-button")) { |
| 333 | + // 0 - Format, 1 - Font Family, 2 - Font Size |
| 334 | + if (i == 1) { |
| 335 | + assertTrue("fontFamilyComboBox must be ComboBox", |
| 336 | + comboBox instanceof ComboBox); |
| 337 | + fontFamilyComboBox = (ComboBox<String>) comboBox; |
| 338 | + assertNotNull("fontFamilyComboBox must not be null", |
| 339 | + fontFamilyComboBox); |
| 340 | + } |
| 341 | + i++; |
| 342 | + } |
| 343 | + webView.getEngine(). |
| 344 | + executeScript("document.execCommand('selectAll', false, 'true');"); |
| 345 | + fontFamilyComboBox.getSelectionModel().select("WebKit Layout Tests 2"); |
| 346 | + result.set(htmlEditor.getHtmlText()); |
| 347 | + editorStateLatch.countDown(); |
| 348 | + } |
| 349 | + }); |
| 350 | + }); |
| 351 | + |
| 352 | + assertTrue("Timeout when waiting for focus change ", Util.await(editorStateLatch)); |
| 353 | + assertNotNull("result must have a valid reference ", result.get()); |
| 354 | + assertTrue("font-family must be 'WebKit Layout Test 2' ", result.get(). |
| 355 | + contains("font-family: "WebKit Layout Tests 2"")); |
| 356 | + } |
297 | 357 | }
|
0 commit comments