Skip to content

Commit 470c7d0

Browse files
committed
8230809: HTMLEditor formatting lost when selecting all (CTRL-A)
Reviewed-by: ajoseph, kcr
1 parent fda015c commit 470c7d0

File tree

2 files changed

+115
-3
lines changed

2 files changed

+115
-3
lines changed

modules/javafx.web/src/main/java/javafx/scene/web/HTMLEditorSkin.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -353,10 +353,14 @@ public HTMLEditorSkin(HTMLEditor control) {
353353
(event.getCode() == KeyCode.UP || event.getCode() == KeyCode.DOWN ||
354354
event.getCode() == KeyCode.LEFT || event.getCode() == KeyCode.RIGHT ||
355355
event.getCode() == KeyCode.HOME || event.getCode() == KeyCode.END)) {
356+
enableAtomicityCheck = true;
356357
updateToolbarState(true);
358+
enableAtomicityCheck = false;
357359
} else if ((event.isControlDown() || event.isMetaDown()) &&
358360
event.getCode() == KeyCode.A) {
361+
enableAtomicityCheck = true;
359362
updateToolbarState(true);
363+
enableAtomicityCheck = false;
360364
}
361365
});
362366
});

tests/system/src/test/java/test/javafx/scene/web/HTMLEditorTest.java

Lines changed: 110 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525

2626
package test.javafx.scene.web;
2727

28+
import com.sun.javafx.PlatformUtil;
2829
import java.util.concurrent.atomic.AtomicReference;
2930
import java.util.concurrent.CountDownLatch;
3031
import java.util.concurrent.TimeUnit;
@@ -45,6 +46,8 @@
4546
import org.junit.BeforeClass;
4647
import org.junit.Ignore;
4748
import org.junit.Test;
49+
import test.com.sun.javafx.scene.control.infrastructure.KeyEventFirer;
50+
import test.com.sun.javafx.scene.control.infrastructure.KeyModifier;
4851
import test.util.Util;
4952

5053
import static javafx.concurrent.Worker.State.SUCCEEDED;
@@ -60,6 +63,7 @@ public class HTMLEditorTest {
6063

6164
private HTMLEditor htmlEditor;
6265
private WebView webView;
66+
private Scene scene;
6367

6468
public static class HTMLEditorTestApp extends Application {
6569
Stage primaryStage = null;
@@ -105,7 +109,7 @@ public static void tearDownOnce() {
105109
public void setupTestObjects() {
106110
Platform.runLater(() -> {
107111
htmlEditor = new HTMLEditor();
108-
Scene scene = new Scene(htmlEditor);
112+
scene = new Scene(htmlEditor);
109113
htmlEditorTestApp.primaryStage.setScene(scene);
110114
htmlEditorTestApp.primaryStage.show();
111115

@@ -354,4 +358,108 @@ public void selectFontFamilyWithSpace() {
354358
assertTrue("font-family must be 'WebKit Layout Test 2' ", result.get().
355359
contains("font-family: "WebKit Layout Tests 2""));
356360
}
361+
362+
/**
363+
* @test
364+
* @bug 8230809
365+
* Summary HTMLEditor formatting lost when selecting all (CTRL-A)
366+
*/
367+
@Test
368+
public void checkFontSizeOnSelectAll_ctrl_A() throws Exception {
369+
final CountDownLatch editorStateLatch = new CountDownLatch(1);
370+
371+
final String editorCommand1 =
372+
"document.execCommand('fontSize', false, '7');" +
373+
"document.execCommand('insertText', false, 'First_word ');";
374+
final String editorCommand2 =
375+
"document.execCommand('fontSize', false, '1');" +
376+
"document.execCommand('insertText', false, 'Second_word');";
377+
378+
Util.runAndWait(() -> {
379+
webView.getEngine().getLoadWorker().stateProperty().
380+
addListener((observable, oldValue, newValue) -> {
381+
if (newValue == SUCCEEDED) {
382+
htmlEditor.requestFocus();
383+
}
384+
});
385+
386+
htmlEditor.setHtmlText(htmlEditor.getHtmlText());
387+
388+
webView.focusedProperty().addListener((observable, oldValue, newValue) -> {
389+
if (newValue) {
390+
webView.getEngine().executeScript("document.body.focus();");
391+
webView.getEngine().executeScript(editorCommand1);
392+
webView.getEngine().executeScript(editorCommand2);
393+
394+
editorStateLatch.countDown();
395+
}
396+
});
397+
});
398+
399+
assertTrue("Timeout while waiting for test html text setup", Util.await(editorStateLatch));
400+
401+
String expectedHtmlText = htmlEditor.getHtmlText();
402+
403+
// Select entire text using Ctrl+A (on mac Cmd + A)
404+
Util.runAndWait(() -> {
405+
KeyEventFirer keyboard = new KeyEventFirer(htmlEditor, scene);
406+
407+
keyboard.doKeyPress(KeyCode.A,
408+
PlatformUtil.isMac()? KeyModifier.META : KeyModifier.CTRL);
409+
});
410+
411+
String actualHtmlText = htmlEditor.getHtmlText();
412+
413+
assertEquals("Expected and Actual HTML text does not match. ", expectedHtmlText, actualHtmlText);
414+
}
415+
416+
417+
@Test
418+
public void checkFontSizeOnSelectAll_Shift_LeftArrowKey() throws Exception {
419+
final CountDownLatch editorStateLatch = new CountDownLatch(1);
420+
421+
final String editorCommand1 =
422+
"document.execCommand('fontSize', false, '7');" +
423+
"document.execCommand('insertText', false, 'Hello');";
424+
final String editorCommand2 =
425+
"document.execCommand('fontSize', false, '1');" +
426+
"document.execCommand('insertText', false, 'World');";
427+
428+
Util.runAndWait(() -> {
429+
webView.getEngine().getLoadWorker().stateProperty().
430+
addListener((observable, oldValue, newValue) -> {
431+
if (newValue == SUCCEEDED) {
432+
htmlEditor.requestFocus();
433+
}
434+
});
435+
436+
htmlEditor.setHtmlText(htmlEditor.getHtmlText());
437+
438+
webView.focusedProperty().addListener((observable, oldValue, newValue) -> {
439+
if (newValue) {
440+
webView.getEngine().executeScript("document.body.focus();");
441+
webView.getEngine().executeScript(editorCommand1);
442+
webView.getEngine().executeScript(editorCommand2);
443+
444+
editorStateLatch.countDown();
445+
}
446+
});
447+
});
448+
449+
assertTrue("Timeout while waiting for test html text setup", Util.await(editorStateLatch));
450+
451+
String expectedHtmlText = htmlEditor.getHtmlText();
452+
453+
// Select entire text using SHIFT + series of Left arrows
454+
Util.runAndWait(() -> {
455+
KeyEventFirer keyboard = new KeyEventFirer(htmlEditor, scene);
456+
for (int i = 0; i < 10; i++) {
457+
keyboard.doLeftArrowPress(KeyModifier.SHIFT);
458+
}
459+
});
460+
461+
String actualHtmlText = htmlEditor.getHtmlText();
462+
463+
assertEquals("Expected and Actual HTML text does not match. ", expectedHtmlText, actualHtmlText);
464+
}
357465
}

0 commit comments

Comments
 (0)