Index: third_party/WebKit/LayoutTests/editing/spelling/grammar-paste.html |
diff --git a/third_party/WebKit/LayoutTests/editing/spelling/script-tests/spellcheck-paste.js b/third_party/WebKit/LayoutTests/editing/spelling/grammar-paste.html |
similarity index 52% |
copy from third_party/WebKit/LayoutTests/editing/spelling/script-tests/spellcheck-paste.js |
copy to third_party/WebKit/LayoutTests/editing/spelling/grammar-paste.html |
index 1b14370d8d73b9cfad51388806f62dbf2d7c469f..73f2f1af72187f6302f0500b19dd1fda8baa6750 100644 |
--- a/third_party/WebKit/LayoutTests/editing/spelling/script-tests/spellcheck-paste.js |
+++ b/third_party/WebKit/LayoutTests/editing/spelling/grammar-paste.html |
@@ -1,5 +1,13 @@ |
- |
-description('For Bug 40092: Spell checking for pasted text.'); |
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
+<html> |
+<head> |
+<script src="../../resources/js-test.js"></script> |
+</head> |
+<body> |
+<p id="description"></p> |
+<div id="console"></div> |
+<script> |
+description('Grammar checking for pasted text.'); |
jsTestIsAsync = true; |
@@ -18,15 +26,15 @@ testEditable.setAttribute("contentEditable", "true"); |
testRoot.appendChild(testEditable); |
var testSourcePlain = document.createElement("div"); |
-testSourcePlain.innerHTML = "zz apple"; |
+testSourcePlain.innerHTML = "You has the right."; |
testRoot.appendChild(testSourcePlain); |
var testSourceDecorated = document.createElement("div"); |
-testSourceDecorated.innerHTML = "z<b>z appl</b>e"; |
+testSourceDecorated.innerHTML = "I have a<b>n ki</b>wi. I have no idea."; |
testRoot.appendChild(testSourceDecorated); |
var testSourceMulti = document.createElement("div"); |
-testSourceMulti.innerHTML = "zz zz zz"; |
+testSourceMulti.innerHTML = "I have an grape. I have an muscat. I don't know."; |
testRoot.appendChild(testSourceMulti); |
var sel = window.getSelection(); |
@@ -42,28 +50,55 @@ function done() |
finishJSTest(); |
} |
+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) |
{ |
- if (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) { |
+ if (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) |
node.focus(); |
- } else { |
+ else |
sel.selectAllChildren(node); |
- } |
- var ok = true; |
- for (var i = 0; ok && i < expectedMarked.length; ++i) |
- ok = internals.hasSpellingMarker(document, expectedMarked[i][0], expectedMarked[i][1]); |
- |
- if (ok) { |
- var nodeContent = node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement ? node.value : node.innerHTML; |
- testPassed(node.tagName + " has a marker on '" + nodeContent + "'"); |
+ 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 ok; |
+ var nodeContent = node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement ? node.value : node.innerHTML; |
+ testPassed(node.tagName + " ungrammatical phrase '" + expectedMarked + "' on '" + nodeContent + "'"); |
+ |
+ return true; |
} |
var destination = null; |
-var misspelledLocations = null; |
+var expectedMarked = null; |
function pasteAndVerify(source, dest, expectedMarked) |
{ |
sel.selectAllChildren(source); |
@@ -79,22 +114,26 @@ function pasteAndVerify(source, dest, expectedMarked) |
if (window.internals) { |
destination = dest; |
- misspelledLocations = expectedMarked; |
- shouldBecomeEqual('verifyMarker(destination, misspelledLocations)', 'true', done); |
+ ungrammaticalPhrase = expectedMarked; |
+ shouldBecomeEqual('verifyMarker(destination, ungrammaticalPhrase)', 'true', done); |
} |
}; |
-tests.push(function() { pasteAndVerify(testSourcePlain, testInput, [[0, 2]]); }); |
-tests.push(function() { pasteAndVerify(testSourceDecorated, testInput, [[0, 2]]); }); |
-tests.push(function() { pasteAndVerify(testSourceMulti, testInput, [[0, 2], [3, 2]]); }); |
+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, [[0, 2]]); }); |
-tests.push(function() { pasteAndVerify(testSourceDecorated, testTextArea, [[0, 2]]); }); |
-tests.push(function() { pasteAndVerify(testSourceMulti, testTextArea, [[0, 2], [3, 2]]); }); |
+tests.push(function() { pasteAndVerify(testSourcePlain, testTextArea, ["has"]); }); |
+tests.push(function() { pasteAndVerify(testSourceDecorated, testTextArea, ["an"]); }); |
+tests.push(function() { pasteAndVerify(testSourceMulti, testTextArea, ["an", "an"]); }); |
-tests.push(function() { pasteAndVerify(testSourcePlain, testEditable, [[0, 2]]); }); |
-tests.push(function() { pasteAndVerify(testSourceDecorated, testEditable, [[0, 1]]); }); // To check "fo" part of foo. |
-tests.push(function() { pasteAndVerify(testSourceMulti, testEditable, [[0, 2], [3, 2]]); }); |
done(); |
var successfullyParsed = true; |
+</script> |
+</body> |
+</html> |