1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"../../resources/js-test.js"></script>
7 <p id=
"description"></p>
8 <div id=
"console"></div>
10 description('Grammar checking for pasted text.');
14 var testRoot
= document
.createElement("div");
15 document
.body
.insertBefore(testRoot
, document
.body
.firstChild
);
17 var testTextArea
= document
.createElement("textarea");
18 testRoot
.appendChild(testTextArea
);
20 var testInput
= document
.createElement("input");
21 testInput
.setAttribute("type", "text");
22 testRoot
.appendChild(testInput
);
24 var testEditable
= document
.createElement("div");
25 testEditable
.setAttribute("contentEditable", "true");
26 testRoot
.appendChild(testEditable
);
28 var testSourcePlain
= document
.createElement("div");
29 testSourcePlain
.innerHTML
= "You has the right.";
30 testRoot
.appendChild(testSourcePlain
);
32 var testSourceDecorated
= document
.createElement("div");
33 testSourceDecorated
.innerHTML
= "I have a<b>n ki</b>wi. I have no idea.";
34 testRoot
.appendChild(testSourceDecorated
);
36 var testSourceMulti
= document
.createElement("div");
37 testSourceMulti
.innerHTML
= "I have an grape. I have an muscat. I don't know.";
38 testRoot
.appendChild(testSourceMulti
);
40 var sel
= window
.getSelection();
46 var next
= tests
.shift();
48 return window
.setTimeout(next
, 0);
49 testRoot
.style
.display
= "none";
53 function findFirstTextNode(node
)
55 function iterToFindFirstTextNode(node
)
57 if (node
instanceof Text
)
60 var childNodes
= node
.childNodes
;
61 for (var i
= 0; i
< childNodes
.length
; ++i
) {
62 var n
= iterToFindFirstTextNode(childNodes
[i
]);
71 if (node
instanceof HTMLInputElement
|| node
instanceof HTMLTextAreaElement
)
72 return iterToFindFirstTextNode(internals
.shadowRoot(node
));
74 return iterToFindFirstTextNode(node
);
77 function verifyMarker(node
, expectedMarked
)
79 if (node
instanceof HTMLInputElement
|| node
instanceof HTMLTextAreaElement
)
82 sel
.selectAllChildren(node
);
84 var textNode
= findFirstTextNode(node
);
85 var num
= internals
.markerCountForNode(textNode
, "grammar");
86 if (num
!= expectedMarked
.length
)
88 for (var i
= 0; i
< num
; ++i
) {
89 var range
= internals
.markerRangeForNode(textNode
, "grammar", i
);
90 if (range
.toString() != expectedMarked
[i
])
94 var nodeContent
= node
instanceof HTMLInputElement
|| node
instanceof HTMLTextAreaElement
? node
.value
: node
.innerHTML
;
95 testPassed(node
.tagName
+ " ungrammatical phrase '" + expectedMarked
+ "' on '" + nodeContent
+ "'");
100 var destination
= null;
101 var expectedMarked
= null;
102 function pasteAndVerify(source
, dest
, expectedMarked
)
104 sel
.selectAllChildren(source
);
105 document
.execCommand("Copy");
106 if (dest
instanceof HTMLInputElement
|| dest
instanceof HTMLTextAreaElement
) {
111 sel
.selectAllChildren(dest
);
113 document
.execCommand("Paste");
115 if (window
.internals
) {
117 ungrammaticalPhrase
= expectedMarked
;
118 shouldBecomeEqual('verifyMarker(destination, ungrammaticalPhrase)', 'true', done
);
122 if (window
.internals
)
123 internals
.settings
.setAsynchronousSpellCheckingEnabled(true);
125 tests
.push(function() { pasteAndVerify(testSourcePlain
, testEditable
, ["has"]); });
126 tests
.push(function() { pasteAndVerify(testSourceDecorated
, testEditable
, ["a"]); }); // Checks only 'a'.
127 tests
.push(function() { pasteAndVerify(testSourceMulti
, testEditable
, ["an", "an"]); });
129 tests
.push(function() { pasteAndVerify(testSourcePlain
, testInput
, ["has"]); });
130 tests
.push(function() { pasteAndVerify(testSourceDecorated
, testInput
, ["an"]); });
131 tests
.push(function() { pasteAndVerify(testSourceMulti
, testInput
, ["an", "an"]); });
133 tests
.push(function() { pasteAndVerify(testSourcePlain
, testTextArea
, ["has"]); });
134 tests
.push(function() { pasteAndVerify(testSourceDecorated
, testTextArea
, ["an"]); });
135 tests
.push(function() { pasteAndVerify(testSourceMulti
, testTextArea
, ["an", "an"]); });
139 var successfullyParsed
= true;