OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../editing.js"></script> | 4 <script src="../editing.js"></script> |
5 <script src="resources/util.js"></script> | 5 <script src="resources/util.js"></script> |
6 <script src="../../resources/js-test.js"></script> | 6 <script src="../../resources/js-test.js"></script> |
7 </head> | 7 </head> |
8 <body onload="test();"> | 8 <body> |
9 <div id="container"> | 9 <div id="container"> |
10 <div id="test_editable" contentEditable>zz zz zz.</div> | 10 <div id="test_editable" contentEditable>zz zz zz.</div> |
11 <textarea id="test_textarea">zz zz zz.</textarea> | 11 <textarea id="test_textarea">zz zz zz.</textarea> |
12 <input type="text" id="test_textfield" value="zz zz zz."></input> | 12 <input type="text" id="test_textfield" value="zz zz zz."></input> |
13 </div> | 13 </div> |
14 <script> | 14 <script> |
15 description("Spell checking should be triggered on focus of an editable. " | 15 description("Spell checking should be triggered on focus of an editable. " |
16 + "To test manually, set focus on above elements. The test succeed if " | 16 + "To test manually, set focus on above elements. The test succeed if " |
17 + "misspellings are marked."); | 17 + "misspellings are marked."); |
18 | 18 |
19 jsTestIsAsync = true; | 19 jsTestIsAsync = true; |
20 | 20 |
21 var testEditable = document.getElementById('test_editable'); | 21 function findFirstTextNodeOf(id) { |
22 var testTextArea = document.getElementById('test_textarea'); | 22 return findFirstTextNode(document.getElementById(id)); |
23 var testTextField = document.getElementById('test_textfield'); | |
24 | |
25 function triggerSpellingForEditables() { | |
26 testEditable.focus(); | |
27 testTextArea.focus(); | |
28 testTextField.focus(); | |
29 } | 23 } |
30 | 24 |
31 var expectedNumberOfMarkers; | 25 var expectedNumberOfMarkers = "0"; |
32 var textNode; | 26 function checkMarkersFor(elementID, doFocus, continuation) { |
33 function verifySpellingMarkers(expectation, doneCallback) { | 27 var element = document.getElementById(elementID); |
34 expectedNumberOfMarkers = expectation; | 28 if (doFocus) |
35 shouldBecomeEqual('internals.markerCountForNode(findFirstTextNode(testEditab
le), "spelling")', 'expectedNumberOfMarkers', function() { | 29 element.focus(); |
36 shouldBecomeEqual('internals.markerCountForNode(findFirstTextNode(testTe
xtArea), "spelling")', 'expectedNumberOfMarkers', function() { | 30 shouldBecomeEqual('internals.markerCountForNode(findFirstTextNodeOf("' + ele
mentID + '"), "spelling")', expectedNumberOfMarkers, continuation); |
37 shouldBecomeEqual('internals.markerCountForNode(findFirstTextNode(te
stTextField), "spelling")', 'expectedNumberOfMarkers', function() { | 31 } |
38 doneCallback(); | 32 |
| 33 function verifySpellingMarkers(doFocus, doneCallback) { |
| 34 checkMarkersFor('test_editable', doFocus, function () { |
| 35 checkMarkersFor('test_textarea', doFocus, function () { |
| 36 checkMarkersFor('test_textfield', doFocus, function () { |
| 37 doneCallback && doneCallback(); |
39 // After focusing the editable elements, check whether they have
spelling markers. | 38 // After focusing the editable elements, check whether they have
spelling markers. |
40 verifySpellingMarkers(3, finishJSTest); | 39 expectedNumberOfMarkers = "3"; |
41 }); | 40 verifySpellingMarkers(true, finishJSTest); |
| 41 }); |
42 }); | 42 }); |
43 }); | 43 }); |
44 } | 44 } |
45 | 45 |
46 function test() { | 46 function test() { |
47 if (!window.internals) { | 47 if (!window.internals) { |
48 debug("Automatic testing impossible. Test manually."); | 48 debug("Automatic testing impossible. Test manually."); |
49 return; | 49 return; |
50 } | 50 } |
51 | 51 |
52 internals.settings.setUnifiedTextCheckerEnabled(true); | 52 internals.settings.setUnifiedTextCheckerEnabled(true); |
53 | 53 |
54 // Check whether non-focused elements do not have spelling markers, then | 54 // Check whether non-focused elements do not have spelling markers, then |
55 // verify them when they get focused. | 55 // verify them when they get focused. |
56 verifySpellingMarkers(0, triggerSpellingForEditables); | 56 verifySpellingMarkers(false); |
57 } | 57 } |
58 | 58 test(); |
59 </script> | 59 </script> |
60 </body> | 60 </body> |
61 </html> | 61 </html> |
OLD | NEW |