Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / spelling / markers.html
blob4b1659aaffaec7f9fbd2f7744838e231fa14b635
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <style>
5 .editing {
6 border: 2px solid red;
7 padding: 12px;
8 font-size: 24px;
10 </style>
11 <script src="../editing.js" language="JavaScript" type="text/JavaScript" ></script>
12 <script src="../../resources/js-test.js"></script>
13 </head>
14 <body>
15 <div id="container"></div>
16 <script>
17 description("Tests spelling and grammar markers for misspellings.");
19 jsTestIsAsync = true;
21 if (window.internals) {
22 internals.settings.setUnifiedTextCheckerEnabled(true);
23 internals.settings.setAsynchronousSpellCheckingEnabled(true);
26 function createEditableElement(parent) {
27 var e = document.createElement('div');
28 e.setAttribute("contentEditable", "true");
29 e.className = 'editing';
31 parent.appendChild(e);
32 return e;
35 function typeText(elem, text) {
36 elem.focus();
37 for (var i = 0; i < text.length; ++i)
38 typeCharacterCommand(text[i]);
41 var container = document.getElementById('container');
43 var elementWithGrammarIssue = createEditableElement(container);
44 typeText(elementWithGrammarIssue, 'I have a issue.');
46 var elementWithSpellingIssue = createEditableElement(container);
47 typeText(elementWithSpellingIssue, 'zz.');
49 var elementWithGrammarAndSpellingIssue = createEditableElement(container);
50 typeText(elementWithGrammarAndSpellingIssue, 'orange,zz,apple.');
52 var element;
53 var next;
55 function verifyMarkers(e, misspellings) {
56 if (!window.internals)
57 return done();
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();
72 var misspellings = [
73 { marker:'grammar', issue:'a' },
74 { marker:'spelling', issue:'zz' },
75 { marker:'grammar', issue:'orange,zz,apple.' }
78 var tests = [
79 function() { verifyMarkers(elementWithGrammarIssue, misspellings.slice(0, 1)) },
80 function() { verifyMarkers(elementWithSpellingIssue, misspellings.slice(1, 2)) },
81 function() { verifyMarkers(elementWithGrammarAndSpellingIssue, misspellings.slice(1, 3)) },
84 function done()
86 var next = tests.shift();
87 if (next)
88 return window.setTimeout(next, 0);
90 finishJSTest();
92 done();
93 </script>
94 </body>
95 </html>