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('For Bug 72939: Asynchronous SpellChecker should consider multiple requests.');
15 internals
.settings
.setAsynchronousSpellCheckingEnabled(true);
17 var testRoot
= document
.createElement("div");
18 document
.body
.insertBefore(testRoot
, document
.body
.firstChild
);
20 var source1
= document
.createElement("div");
21 source1
.innerHTML
= "foo bar";
22 testRoot
.appendChild(source1
);
24 var source2
= document
.createElement("div");
25 source2
.innerHTML
= "zz apple orange";
26 testRoot
.appendChild(source2
);
28 function createInput(testRoot
) {
29 var e
= document
.createElement('input');
30 e
.setAttribute("type", "text");
31 testRoot
.appendChild(e
);
36 function createTextArea(testRoot
) {
37 var e
= document
.createElement("textarea");
38 testRoot
.appendChild(e
);
43 function createContentEditable(testRoot
) {
44 var e
= document
.createElement("div");
45 e
.setAttribute("contentEditable", "true");
46 testRoot
.appendChild(e
);
52 createInput(testRoot
),
53 createTextArea(testRoot
),
54 createContentEditable(testRoot
),
55 createInput(testRoot
),
56 createTextArea(testRoot
),
57 createContentEditable(testRoot
),
58 createInput(testRoot
),
59 createTextArea(testRoot
),
60 createContentEditable(testRoot
),
63 var sel
= window
.getSelection();
66 for (var i
= 0; i
< destinations
.length
; ++i
) {
68 return function() { verify(source2
, destinations
[i
], ["zz"]); }
73 function verifyIfAny()
75 var next
= tests
.shift();
81 testRoot
.style
.display
= "none";
85 function findFirstTextNode(node
)
87 function iterToFindFirstTextNode(node
)
89 if (node
instanceof Text
)
92 var childNodes
= node
.childNodes
;
93 for (var i
= 0; i
< childNodes
.length
; ++i
) {
94 var n
= iterToFindFirstTextNode(childNodes
[i
]);
103 if (node
instanceof HTMLInputElement
|| node
instanceof HTMLTextAreaElement
)
104 return iterToFindFirstTextNode(internals
.shadowRoot(node
));
106 return iterToFindFirstTextNode(node
);
109 function verifyMarker(node
, expectedMarked
)
111 if (!window
.testRunner
|| !window
.internals
)
114 var textNode
= findFirstTextNode(node
);
116 var num
= internals
.markerCountForNode(textNode
, "spelling");
117 if (num
!= expectedMarked
.length
)
119 for (var i
= 0; i
< num
; ++i
) {
120 var range
= internals
.markerRangeForNode(textNode
, "spelling", i
);
121 if (range
.toString() != expectedMarked
[i
])
128 function copyAndPaste(source
, dest
)
130 sel
.selectAllChildren(source
);
131 document
.execCommand("Copy");
133 if (dest
instanceof HTMLInputElement
|| dest
instanceof HTMLTextAreaElement
) {
138 sel
.selectAllChildren(dest
);
140 document
.execCommand("Paste");
143 function verify(source
, dest
, expectedMarked
)
148 var verified
= verifyMarker(dest
, expectedMarked
);
150 testPassed(dest
.tagName
+ " has a marker on '" + source
.innerHTML
+ "'");
157 testFailed(dest
.tagName
+ " should have a marker on for '" + source
.innerHTML
+ "'");
163 window
.setTimeout(trial
, nsleep
);
170 for (var i
= 0; i
< destinations
.length
; ++i
)
171 copyAndPaste(source1
, destinations
[i
]);
173 // paste "zz apple orange"
174 for (var i
= 0; i
< destinations
.length
; ++i
)
175 copyAndPaste(source2
, destinations
[i
]);
179 var successfullyParsed
= true;