changeset 10916:da551ab4cec1

8200418: webPage.executeCommand("removeFormat", null) removes the style of the body element Reviewed-by: kcr, rkamath
author mbilla
date Thu, 03 May 2018 14:56:40 +0530
parents b7e3909a281c
children 1cf615e434d5
files modules/javafx.web/src/main/java/javafx/scene/web/HTMLEditorSkin.java tests/system/src/test/java/test/javafx/scene/web/HTMLEditorTest.java
diffstat 2 files changed, 67 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.web/src/main/java/javafx/scene/web/HTMLEditorSkin.java	Wed May 02 10:23:06 2018 +0000
+++ b/modules/javafx.web/src/main/java/javafx/scene/web/HTMLEditorSkin.java	Thu May 03 14:56:40 2018 +0530
@@ -69,7 +69,6 @@
 
 import com.sun.javafx.scene.control.skin.FXVK;
 import com.sun.javafx.scene.web.behavior.HTMLEditorBehavior;
-import com.sun.webkit.dom.HTMLDocumentImpl;
 import com.sun.webkit.WebPage;
 import com.sun.javafx.webkit.Accessor;
 
@@ -448,7 +447,6 @@
             if (newValue.doubleValue() == totalWork) {
                 cachedHTMLText = null;
                 Platform.runLater(() -> {
-                    setDesignMode("on");
                     setContentEditable(true);
                     updateToolbarState(true);
                     updateNodeOrientation();
@@ -1111,11 +1109,6 @@
         htmlBodyElement.setAttribute("contenteditable", Boolean.toString(b));
     }
 
-    private void setDesignMode(String mode) {
-        HTMLDocumentImpl htmlDocumentImpl = (HTMLDocumentImpl)webPage.getDocument(webPage.getMainFrame());
-        htmlDocumentImpl.setDesignMode(mode);
-    }
-
     private boolean getCommandState(String command) {
         return webPage.queryCommandState(command);
     }
--- a/tests/system/src/test/java/test/javafx/scene/web/HTMLEditorTest.java	Wed May 02 10:23:06 2018 +0000
+++ b/tests/system/src/test/java/test/javafx/scene/web/HTMLEditorTest.java	Thu May 03 14:56:40 2018 +0530
@@ -39,6 +39,7 @@
 import javafx.stage.Stage;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 import test.util.Util;
 
@@ -104,7 +105,10 @@
      * @bug 8090011
      * Summary Check document focus change behavior on tab key press
      */
-    @Test
+    // Currently ignoring this test case due to regression (JDK-8200418).
+    // The newly cloned issue (JDK-8202542) needs to be fixed before
+    // re-enabling this test case.
+    @Test @Ignore("JDK-8202542")
     public void checkFocusChange() throws Exception {
         final CountDownLatch editorStateLatch = new CountDownLatch(2);
         final AtomicBoolean result = new AtomicBoolean(false);
@@ -220,6 +224,7 @@
         }
 
         Util.runAndWait(() -> {
+            webView.getEngine().executeScript("document.body.focus();");
             webView.getEngine().executeScript(editorCommand1);
             assertEquals(expectedHTML, htmlEditor.getHtmlText());
             webView.getEngine().executeScript(editorCommand2);
@@ -261,4 +266,65 @@
         assertEquals(Double.parseDouble(actualValues[3].trim()),
                      Double.parseDouble(expectedValues[3].trim()), delta);
     }
+
+    /**
+     * @test
+     * @bug 8200418
+     * Summary Check Style property after removeformat
+     */
+    @Test
+    public void checkStyleProperty() throws Exception {
+        final CountDownLatch editorStateLatch = new CountDownLatch(2);
+        final AtomicBoolean result = new AtomicBoolean(false);
+        Platform.runLater(() -> {
+            HTMLEditor htmlEditor = new HTMLEditor();
+            Scene scene = new Scene(htmlEditor);
+            htmlEditorTestApp.primaryStage.setScene(scene);
+            htmlEditor.setHtmlText("<html>" +
+                "<head>" +
+                "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" +
+                "</head>" +
+                "<body style=\"font-weight: bold\">" +
+                "<p>Test</p>" +
+                "</body>" +
+                "</html>");
+
+            WebView webView = (WebView)htmlEditor.lookup(".web-view");
+            assertNotNull(webView);
+
+            webView.focusedProperty().
+                addListener((observable, oldValue, newValue) -> {
+                if (newValue) {
+                    webView.getEngine().
+                        executeScript("document.body.focus();");
+                    webView.getEngine().
+                        executeScript("document.execCommand('selectAll', false, 'true');");
+                    webView.getEngine().
+                        executeScript("document.execCommand('removeFormat', false, null);");
+                    result.set("bold".equals(webView.getEngine().
+                        executeScript("document.body.style.fontWeight").
+                        toString()));
+                    htmlEditorTestApp.primaryStage.hide();
+                    editorStateLatch.countDown();
+                }
+            });
+
+            webView.getEngine().getLoadWorker().stateProperty().
+                addListener((observable, oldValue, newValue) -> {
+                if (newValue == SUCCEEDED) {
+                    htmlEditor.requestFocus();
+                    editorStateLatch.countDown();
+                }
+            });
+            htmlEditorTestApp.primaryStage.show();
+        });
+
+        try {
+            editorStateLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
+        } catch (InterruptedException ex) {
+            throw new AssertionError(ex);
+        } finally {
+            assertTrue("check Style Property with removeFormat ", result.get());
+        }
+    }
 }