OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <style> | 4 <style> |
5 .editing { | 5 .editing { |
6 border: 2px solid red; | 6 border: 2px solid red; |
7 padding: 12px; | 7 padding: 12px; |
8 font-size: 24px; | 8 font-size: 24px; |
9 } | 9 } |
10 </style> | 10 </style> |
11 <script src="../editing.js" language="JavaScript" type="text/JavaScript" ></scri
pt> | 11 <script src="../editing.js" language="JavaScript" type="text/JavaScript" ></scri
pt> |
12 <script src="../../resources/js-test.js"></script> | 12 <script src="../../resources/js-test.js"></script> |
13 </head> | 13 </head> |
14 <body> | 14 <body> |
15 <pre id="description"></pre> | 15 <div id="container"></div> |
16 <pre id="console"></pre> | 16 <script> |
17 <div id="container"> | 17 description("Tests spelling and grammar markers for misspellings."); |
18 </div> | |
19 | 18 |
20 <script> | 19 jsTestIsAsync = true; |
21 function createEditableElement(id, parent) { | 20 |
| 21 if (window.internals) { |
| 22 internals.settings.setUnifiedTextCheckerEnabled(true); |
| 23 internals.settings.setAsynchronousSpellCheckingEnabled(true); |
| 24 } |
| 25 |
| 26 function createEditableElement(parent) { |
22 var e = document.createElement('div'); | 27 var e = document.createElement('div'); |
23 e.setAttribute("contentEditable", "true"); | 28 e.setAttribute("contentEditable", "true"); |
24 e.className = 'editing'; | 29 e.className = 'editing'; |
25 e.id = id; | |
26 | 30 |
27 parent.appendChild(e); | 31 parent.appendChild(e); |
28 return e; | 32 return e; |
29 } | 33 } |
30 | 34 |
31 function typeText(elem, text) { | 35 function typeText(elem, text) { |
32 elem.focus(); | 36 elem.focus(); |
33 for (var i = 0; i < text.length; ++i) { | 37 for (var i = 0; i < text.length; ++i) |
34 typeCharacterCommand(text[i]); | 38 typeCharacterCommand(text[i]); |
35 } | |
36 } | 39 } |
37 | 40 |
38 var container = document.getElementById('container'); | 41 var container = document.getElementById('container'); |
39 var range; | |
40 | 42 |
41 debug("Grammar Error Only"); | 43 var elementWithGrammarIssue = createEditableElement(container); |
42 var id = 'id1' | 44 typeText(elementWithGrammarIssue, 'I have a issue.'); |
43 var e = createEditableElement(id, container); | 45 |
44 typeText(e, 'I have a issue.'); | 46 var elementWithSpellingIssue = createEditableElement(container); |
45 if (window.internals) { | 47 typeText(elementWithSpellingIssue, 'zz.'); |
46 shouldBe('internals.markerCountForNode(e.firstChild, "spelling")', '0'); | 48 |
47 shouldBe('internals.markerCountForNode(e.firstChild, "grammar")', '1'); | 49 var elementWithGrammarAndSpellingIssue = createEditableElement(container); |
48 range = internals.markerRangeForNode(e.firstChild, "grammar", 0); | 50 typeText(elementWithGrammarAndSpellingIssue, 'orange,zz,apple.'); |
49 shouldBe("range.toString()", '"a"'); | 51 |
| 52 var element; |
| 53 var next; |
| 54 |
| 55 function verifyMarkers(e, misspellings) { |
| 56 if (!window.internals) |
| 57 return done(); |
| 58 |
| 59 var n = misspellings.shift(); |
| 60 element = e; |
| 61 next = n; |
| 62 if (next) { |
| 63 shouldBecomeEqual('internals.markerCountForNode(element.firstChild, next
.marker)', '1', function() { |
| 64 range = internals.markerRangeForNode(element.firstChild, next.marker
, 0); |
| 65 shouldBe('range.toString()', 'next.issue'); |
| 66 verifyMarkers(element, misspellings); |
| 67 }); |
| 68 } else |
| 69 done(); |
50 } | 70 } |
51 | 71 |
52 debug("Spelling Error Only"); | 72 var misspellings = [ |
53 var id = 'id2' | 73 { marker:'grammar', issue:'a' }, |
54 var e = createEditableElement(id, container); | 74 { marker:'spelling', issue:'zz' }, |
55 typeText(e, 'zz.'); | 75 { marker:'grammar', issue:'orange,zz,apple.' } |
56 if (window.internals) { | 76 ]; |
57 shouldBe('internals.markerCountForNode(e.firstChild, "spelling")', '1'); | 77 |
58 range = internals.markerRangeForNode(e.firstChild, "spelling", 0); | 78 var tests = [ |
59 shouldBe('range.toString()', '"zz"'); | 79 function() { verifyMarkers(elementWithGrammarIssue, misspellings.slice(0, 1)
) }, |
60 shouldBe('internals.markerCountForNode(e.firstChild, "grammar")', '0'); | 80 function() { verifyMarkers(elementWithSpellingIssue, misspellings.slice(1, 2
)) }, |
| 81 function() { verifyMarkers(elementWithGrammarAndSpellingIssue, misspellings.
slice(1, 3)) }, |
| 82 ]; |
| 83 |
| 84 function done() |
| 85 { |
| 86 var next = tests.shift(); |
| 87 if (next) |
| 88 return window.setTimeout(next, 0); |
| 89 |
| 90 finishJSTest(); |
61 } | 91 } |
62 | 92 done(); |
63 debug("Grammar and Spelling Error"); | |
64 var id = 'id3' | |
65 var e = createEditableElement(id, container); | |
66 typeText(e, 'orange,zz,apple.'); | |
67 if (window.internals) { | |
68 shouldBe('internals.markerCountForNode(e.firstChild, "spelling")', '1'); | |
69 range = internals.markerRangeForNode(e.firstChild, "spelling", 0); | |
70 shouldBe('range.toString()', '"zz"'); | |
71 shouldBe('internals.markerCountForNode(e.firstChild, "grammar")', '1'); | |
72 range = internals.markerRangeForNode(e.firstChild, "grammar", 0); | |
73 shouldBe('range.toString()', '"orange,zz,apple."'); | |
74 } | |
75 | |
76 var successfullyParsed = true; | |
77 </script> | 93 </script> |
78 </body> | 94 </body> |
79 </html> | 95 </html> |
OLD | NEW |