4 <script src=
"../../resources/js-test.js"></script>
5 <script src=
"../editing.js"></script>
15 <pre id=
"description"></pre>
16 <pre id=
"console"></pre>
17 <div id=
"container"></div>
20 description("Test for Unified Spell Checker & Async Spell Checker.");
24 if (window
.internals
) {
25 internals
.settings
.setAsynchronousSpellCheckingEnabled(true);
26 internals
.settings
.setUnifiedTextCheckerEnabled(true);
29 var container
= document
.getElementById('container');
30 function removeChildren(node
) {
31 while (node
.firstChild
)
32 node
.removeChild(node
.firstChild
);
36 { text
: 'zz', marked
: ['zz'] },
37 { text
: 'apple,zz,orange', marked
: ['zz'] },
38 { text
: 'zz,zz', marked
: ['zz','zz'] },
39 { text
: 'zz zz zz', marked
: ['zz', 'zz', 'zz'] },
40 { text
: ' zz zz zz ', marked
: ['zz', 'zz', 'zz'] },
41 { text
: 'zz apple orange', marked
: ['zz'] },
42 { text
: 'apple zz orange', marked
: ['zz'] },
43 { text
: 'apple orange zz', marked
: ['zz'] },
44 { text
: 'zzz', marked
: [] },
45 { text
: 'I would like to sleep, zzz', marked
: [] }
49 function doTestIfAny() {
50 var next
= testData
.shift();
52 return window
.setTimeout(function(){ doTest(++testNo
, next
.text
, next
.marked
); }, 0);
55 removeChildren(container
);
59 function createEditableElement(id
) {
60 var e
= document
.createElement('div');
61 e
.setAttribute("contentEditable", "true");
62 e
.className
= 'editing';
68 function typeText(e
, text
) {
70 for (var i
= 0; i
< text
.length
; ++i
) {
71 typeCharacterCommand(text
[i
]);
73 typeCharacterCommand('.');
76 function doTest(testNo
, text
, marked
) {
77 removeChildren(container
);
78 var id
= "spelling" + testNo
;
79 var e
= createEditableElement(id
);
80 container
.appendChild(e
);
84 if (!window
.internals
)
87 tryVerify(10, id
, text
, marked
, 1);
90 function tryVerify(restTry
, id
, text
, marked
, nsleep
) {
93 testFailed('text : "' + text
+ '" should have markers: [' + marked
+ ']');
94 setTimeout(doTestIfAny
, 0);
99 var e
= document
.getElementById(id
);
100 var numMarked
= internals
.markerCountForNode(e
.firstChild
, "spelling");
101 var success
= numMarked
== marked
.length
;
104 for (var i
= 0; i
< numMarked
; ++i
) {
105 var range
= internals
.markerRangeForNode(e
.firstChild
, "spelling", i
);
106 if (range
.toString() != marked
[i
])
112 testPassed('text : "' + text
+ '" has markers: [' + marked
+ ']');
113 setTimeout(doTestIfAny
, 0);
115 // Type '.' to invoke asynchronouse spell checking again.
116 typeCharacterCommand('.');
117 setTimeout(function() { tryVerify(restTry
- 1, id
, text
, marked
, nsleep
* 2); }, nsleep
);
123 var successfullyParsed
= true;