2 description('For Bug 40092: Spell checking for pasted text.');
6 var testRoot
= document
.createElement("div");
7 document
.body
.insertBefore(testRoot
, document
.body
.firstChild
);
9 var testTextArea
= document
.createElement("textarea");
10 testRoot
.appendChild(testTextArea
);
12 var testInput
= document
.createElement("input");
13 testInput
.setAttribute("type", "text");
14 testRoot
.appendChild(testInput
);
16 var testEditable
= document
.createElement("div");
17 testEditable
.setAttribute("contentEditable", "true");
18 testRoot
.appendChild(testEditable
);
20 var testSourcePlain
= document
.createElement("div");
21 testSourcePlain
.innerHTML
= "zz apple";
22 testRoot
.appendChild(testSourcePlain
);
24 var testSourceDecorated
= document
.createElement("div");
25 testSourceDecorated
.innerHTML
= "z<b>z appl</b>e";
26 testRoot
.appendChild(testSourceDecorated
);
28 var testSourceMulti
= document
.createElement("div");
29 testSourceMulti
.innerHTML
= "zz zz zz";
30 testRoot
.appendChild(testSourceMulti
);
32 var sel
= window
.getSelection();
38 var next
= tests
.shift();
40 return window
.setTimeout(next
, 0);
41 testRoot
.style
.display
= "none";
45 function verifyMarker(node
, expectedMarked
)
47 if (node
instanceof HTMLInputElement
|| node
instanceof HTMLTextAreaElement
) {
50 sel
.selectAllChildren(node
);
54 for (var i
= 0; ok
&& i
< expectedMarked
.length
; ++i
)
55 ok
= internals
.hasSpellingMarker(document
, expectedMarked
[i
][0], expectedMarked
[i
][1]);
58 var nodeContent
= node
instanceof HTMLInputElement
|| node
instanceof HTMLTextAreaElement
? node
.value
: node
.innerHTML
;
59 testPassed(node
.tagName
+ " has a marker on '" + nodeContent
+ "'");
65 var destination
= null;
66 var misspelledLocations
= null;
67 function pasteAndVerify(source
, dest
, expectedMarked
)
69 sel
.selectAllChildren(source
);
70 document
.execCommand("Copy");
71 if (dest
instanceof HTMLInputElement
|| dest
instanceof HTMLTextAreaElement
) {
76 sel
.selectAllChildren(dest
);
78 document
.execCommand("Paste");
80 if (window
.internals
) {
82 misspelledLocations
= expectedMarked
;
83 shouldBecomeEqual('verifyMarker(destination, misspelledLocations)', 'true', done
);
88 internals
.settings
.setAsynchronousSpellCheckingEnabled(true);
90 tests
.push(function() { pasteAndVerify(testSourcePlain
, testInput
, [[0, 2]]); });
91 tests
.push(function() { pasteAndVerify(testSourceDecorated
, testInput
, [[0, 2]]); });
92 tests
.push(function() { pasteAndVerify(testSourceMulti
, testInput
, [[0, 2], [3, 2]]); });
94 tests
.push(function() { pasteAndVerify(testSourcePlain
, testTextArea
, [[0, 2]]); });
95 tests
.push(function() { pasteAndVerify(testSourceDecorated
, testTextArea
, [[0, 2]]); });
96 tests
.push(function() { pasteAndVerify(testSourceMulti
, testTextArea
, [[0, 2], [3, 2]]); });
98 tests
.push(function() { pasteAndVerify(testSourcePlain
, testEditable
, [[0, 2]]); });
99 tests
.push(function() { pasteAndVerify(testSourceDecorated
, testEditable
, [[0, 1]]); }); // To check "fo" part of foo.
100 tests
.push(function() { pasteAndVerify(testSourceMulti
, testEditable
, [[0, 2], [3, 2]]); });
103 var successfullyParsed
= true;