Title: [102662] trunk/LayoutTests
Revision
102662
Author
[email protected]
Date
2011-12-13 01:33:57 -0800 (Tue, 13 Dec 2011)

Log Message

Asynchronous text checking should check the grammar.
https://bugs.webkit.org/show_bug.cgi?id=56368

Patch by Shinya Kawanaka <[email protected]> on 2011-12-13
Reviewed by Hajime Morita.

>From r102553, we had capability of grammar checking for asynchronous text checking.
This patch adds a test for it.

* editing/spelling/grammar-paste-expected.txt: Added.
* editing/spelling/grammar-paste.html: Added.
* platform/chromium/test_expectations.txt:
* platform/gtk/Skipped:
* platform/mac-leopard/Skipped:
* platform/qt/Skipped:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (102661 => 102662)


--- trunk/LayoutTests/ChangeLog	2011-12-13 08:17:53 UTC (rev 102661)
+++ trunk/LayoutTests/ChangeLog	2011-12-13 09:33:57 UTC (rev 102662)
@@ -1,3 +1,20 @@
+2011-12-13  Shinya Kawanaka  <[email protected]>
+
+        Asynchronous text checking should check the grammar.
+        https://bugs.webkit.org/show_bug.cgi?id=56368
+
+        Reviewed by Hajime Morita.
+
+        From r102553, we had capability of grammar checking for asynchronous text checking.
+        This patch adds a test for it.
+
+        * editing/spelling/grammar-paste-expected.txt: Added.
+        * editing/spelling/grammar-paste.html: Added.
+        * platform/chromium/test_expectations.txt:
+        * platform/gtk/Skipped:
+        * platform/mac-leopard/Skipped:
+        * platform/qt/Skipped:
+
 2011-12-12  Kenichi Ishibashi  <[email protected]>
 
         Unreviewed Chromium test expectations update.

Added: trunk/LayoutTests/editing/spelling/grammar-paste-expected.txt (0 => 102662)


--- trunk/LayoutTests/editing/spelling/grammar-paste-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/spelling/grammar-paste-expected.txt	2011-12-13 09:33:57 UTC (rev 102662)
@@ -0,0 +1,18 @@
+Grammar checking for pasted text.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS DIV has a marker on 'You has the right.'
+PASS DIV has a marker on 'I have a<b>n ki</b>wi. I have no idea.'
+PASS DIV has a marker on 'I have an grape. I have an muscat. I don't know.'
+PASS INPUT has a marker on 'You has the right.'
+PASS INPUT has a marker on 'I have a<b>n ki</b>wi. I have no idea.'
+PASS INPUT has a marker on 'I have an grape. I have an muscat. I don't know.'
+PASS TEXTAREA has a marker on 'You has the right.'
+PASS TEXTAREA has a marker on 'I have a<b>n ki</b>wi. I have no idea.'
+PASS TEXTAREA has a marker on 'I have an grape. I have an muscat. I don't know.'
+

Added: trunk/LayoutTests/editing/spelling/grammar-paste.html (0 => 102662)


--- trunk/LayoutTests/editing/spelling/grammar-paste.html	                        (rev 0)
+++ trunk/LayoutTests/editing/spelling/grammar-paste.html	2011-12-13 09:33:57 UTC (rev 102662)
@@ -0,0 +1,161 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description('Grammar checking for pasted text.');
+
+layoutTestController.waitUntilDone();
+
+var testRoot = document.createElement("div");
+document.body.insertBefore(testRoot, document.body.firstChild);
+
+var testTextArea = document.createElement("textarea");
+testRoot.appendChild(testTextArea);
+
+var testInput = document.createElement("input");
+testInput.setAttribute("type", "text");
+testRoot.appendChild(testInput);
+
+var testEditable = document.createElement("div");
+testEditable.setAttribute("contentEditable", "true");
+testRoot.appendChild(testEditable);
+
+var testSourcePlain = document.createElement("div");
+testSourcePlain.innerHTML = "You has the right.";
+testRoot.appendChild(testSourcePlain);
+
+var testSourceDecorated = document.createElement("div");
+testSourceDecorated.innerHTML = "I have a<b>n ki</b>wi. I have no idea.";
+testRoot.appendChild(testSourceDecorated);
+
+var testSourceMulti = document.createElement("div");
+testSourceMulti.innerHTML = "I have an grape. I have an muscat. I don't know.";
+testRoot.appendChild(testSourceMulti);
+
+var sel = window.getSelection();
+
+var tests = [];
+
+function done()
+{
+    var next = tests.shift();
+    if (next)
+        return window.setTimeout(next, 0);
+    testRoot.style.display = "none";
+
+    layoutTestController.setAsynchronousSpellCheckingEnabled(false);
+    layoutTestController.notifyDone();
+}
+
+function findFirstTextNode(node)
+{
+    function iterToFindFirstTextNode(node)
+    {
+        if (node instanceof Text)
+            return node;
+
+        var childNodes = node.childNodes;
+        for (var i = 0; i < childNodes.length; ++i) {
+            var n = iterToFindFirstTextNode(childNodes[i]);
+            if (n)
+                return n;
+        }
+
+        return null;
+    }
+
+
+    if (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement)
+        return iterToFindFirstTextNode(internals.shadowRoot(node));
+    else
+        return iterToFindFirstTextNode(node);
+}
+
+function verifyMarker(node, expectedMarked, needsFocus)
+{
+    if (true) {
+        if (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) {
+            node.focus();
+        } else {
+            sel.selectAllChildren(node);
+        }
+    }
+
+    var textNode = findFirstTextNode(node);
+    var num = internals.markerCountForNode(textNode, "grammar");
+    if (num != expectedMarked.length)
+        return false;
+    for (var i = 0; i < num; ++i) {
+        var range = internals.markerRangeForNode(textNode, "grammar", i);
+        if (range.toString() != expectedMarked[i])
+            return false;
+    }
+
+    return true;
+}
+
+function pasteAndVerify(source, dest, expectedMarked)
+{
+    sel.selectAllChildren(source);
+    document.execCommand("Copy");
+    if (dest instanceof HTMLInputElement || dest instanceof HTMLTextAreaElement) {
+        dest.value = "";
+        dest.focus();
+    } else {
+        dest.innerHTML = "";
+        sel.selectAllChildren(dest);
+    }
+    document.execCommand("Paste");
+
+    var nretry = 10;
+    var nsleep = 4;
+    function trial() { 
+        var verified = verifyMarker(dest, expectedMarked);
+        if (verified) {
+            testPassed(dest.tagName + " has a marker on '" + source.innerHTML + "'");
+            done();
+            return;
+        }
+
+        nretry--;
+        if (0 == nretry) {
+            testFailed(dest.tagName + " should have a marker on for '" + source.innerHTML + "'");
+            done();
+            return;
+        }
+        
+        nsleep *= 2;
+        window.setTimeout(trial, nsleep);
+    };
+    trial();
+};
+
+if (window.layoutTestController) {
+    layoutTestController.setAsynchronousSpellCheckingEnabled(true);
+}
+
+tests.push(function() { pasteAndVerify(testSourcePlain, testEditable, ["has"]); });
+tests.push(function() { pasteAndVerify(testSourceDecorated, testEditable, ["a"]); }); // Checks only 'a'.
+tests.push(function() { pasteAndVerify(testSourceMulti, testEditable, ["an", "an"]); });
+
+tests.push(function() { pasteAndVerify(testSourcePlain, testInput, ["has"]); });
+tests.push(function() { pasteAndVerify(testSourceDecorated, testInput, ["an"]); });
+tests.push(function() { pasteAndVerify(testSourceMulti, testInput, ["an", "an"]); });
+
+tests.push(function() { pasteAndVerify(testSourcePlain, testTextArea, ["has"]); });
+tests.push(function() { pasteAndVerify(testSourceDecorated, testTextArea, ["an"]); });
+tests.push(function() { pasteAndVerify(testSourceMulti, testTextArea, ["an", "an"]); });
+
+done();
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/platform/chromium/test_expectations.txt (102661 => 102662)


--- trunk/LayoutTests/platform/chromium/test_expectations.txt	2011-12-13 08:17:53 UTC (rev 102661)
+++ trunk/LayoutTests/platform/chromium/test_expectations.txt	2011-12-13 09:33:57 UTC (rev 102662)
@@ -668,6 +668,8 @@
 
 // New test added in r82159
 BUGCR77706 : editing/spelling/grammar.html = FAIL
+// Chromium does not have a grammar checker.
+BUGWK56368 : editing/spelling/grammar-paste.html = FAIL
 
 // Needs grammar checking.
 BUGWK71792 : editing/spelling/markers.html = FAIL MISSING

Modified: trunk/LayoutTests/platform/gtk/Skipped (102661 => 102662)


--- trunk/LayoutTests/platform/gtk/Skipped	2011-12-13 08:17:53 UTC (rev 102661)
+++ trunk/LayoutTests/platform/gtk/Skipped	2011-12-13 09:33:57 UTC (rev 102662)
@@ -1281,6 +1281,7 @@
 
 # textInputController.hasGrammarMarker() is not implemented.
 editing/spelling/grammar.html
+editing/spelling/grammar-paste.html
 
 # layoutTestController::setTextDirection() is not implemented.
 fast/html/set-text-direction.html

Modified: trunk/LayoutTests/platform/mac-leopard/Skipped (102661 => 102662)


--- trunk/LayoutTests/platform/mac-leopard/Skipped	2011-12-13 08:17:53 UTC (rev 102661)
+++ trunk/LayoutTests/platform/mac-leopard/Skipped	2011-12-13 09:33:57 UTC (rev 102662)
@@ -96,6 +96,7 @@
 
 # Available 10.6 or later
 editing/spelling/spellcheck-paste.html
+editing/spelling/grammar-paste.html
 fast/html/set-text-direction.html
 
 # Disable tests which started failing after r66961

Modified: trunk/LayoutTests/platform/qt/Skipped (102661 => 102662)


--- trunk/LayoutTests/platform/qt/Skipped	2011-12-13 08:17:53 UTC (rev 102661)
+++ trunk/LayoutTests/platform/qt/Skipped	2011-12-13 09:33:57 UTC (rev 102662)
@@ -994,6 +994,7 @@
 
 # textInputController.hasGrammarMarkers() is not implemented.
 editing/spelling/grammar.html
+editing/spelling/grammar-paste.html
 
 # Needs grammar checking.
 editing/spelling/markers.html
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to