OLD | NEW |
1 description('Tests if the spellchecker behavior change after the spellcheck attr
ibute changed by the script.'); | 1 description('Tests if the spellchecker behaves correctly when the spellcheck att
ribute ' |
| 2 + 'is being changed by the script.'); |
| 3 |
| 4 jsTestIsAsync = true; |
| 5 |
| 6 if (window.internals) { |
| 7 internals.settings.setUnifiedTextCheckerEnabled(true); |
| 8 internals.settings.setAsynchronousSpellCheckingEnabled(true); |
| 9 } |
2 | 10 |
3 var parent = document.createElement("div"); | 11 var parent = document.createElement("div"); |
4 document.body.appendChild(parent); | 12 document.body.appendChild(parent); |
5 var sel = document.getSelection(); | 13 var sel = document.getSelection(); |
6 | 14 |
7 function testSpellCheckingEnabled(target, enabled) | 15 function testSpellCheckingEnabled(target, enabled) |
8 { | 16 { |
9 target.spellcheck = enabled; | 17 target.spellcheck = enabled; |
10 | 18 |
11 if (target.tagName == "SPAN") { | 19 if (target.tagName == "SPAN") { |
12 target.appendChild(document.createTextNode("Hello,")); | 20 target.appendChild(document.createTextNode("Hello,")); |
13 sel.setBaseAndExtent(target, 6, target, 6); | 21 sel.setBaseAndExtent(target, 6, target, 6); |
14 } else if (target.tagName == "INPUT" || target.tagName == "TEXTAREA") { | 22 } else if (target.tagName == "INPUT" || target.tagName == "TEXTAREA") { |
15 target.focus(); | 23 target.focus(); |
16 document.execCommand("InsertText", false, "Hello,"); | 24 document.execCommand("InsertText", false, "Hello,"); |
17 } | 25 } |
18 | 26 |
19 document.execCommand("InsertText", false, 'z'); | 27 document.execCommand("InsertText", false, 'z'); |
20 document.execCommand("InsertText", false, 'z'); | 28 document.execCommand("InsertText", false, 'z'); |
21 document.execCommand("InsertText", false, ' '); | 29 document.execCommand("InsertText", false, ' '); |
22 | 30 |
23 window.target = target; | 31 window.target = target; |
24 shouldBe("target.spellcheck", enabled ? "true" : "false"); | 32 shouldBe("target.spellcheck", enabled ? "true" : "false"); |
25 shouldBe("internals.hasSpellingMarker(document, 6, 2)", enabled ? "true" : "
false"); | 33 if (window.internals) |
| 34 shouldBecomeEqual("internals.hasSpellingMarker(document, 6, 2)", enabled
? "true" : "false", done); |
| 35 else |
| 36 done(); |
26 } | 37 } |
27 | 38 |
28 function createElement(tagName, spellcheck) | 39 function createElement(tagName, spellcheck) |
29 { | 40 { |
30 var target = document.createElement(tagName); | 41 var target = document.createElement(tagName); |
31 if (tagName == "SPAN") | 42 if (tagName == "SPAN") |
32 target.setAttribute("contentEditable", "true"); | 43 target.setAttribute("contentEditable", "true"); |
33 if (spellcheck) | 44 if (spellcheck) |
34 target.setAttribute("spellcheck", spellcheck); | 45 target.setAttribute("spellcheck", spellcheck); |
35 return target; | 46 return target; |
36 } | 47 } |
37 | 48 |
38 function testFor(tagName, initialAttribute, expectation) | 49 function testFor(tagName, spellCheckAttribueValues) |
39 { | 50 { |
40 var target = createElement(tagName, initialAttribute); | 51 var target = createElement(tagName, spellCheckAttribueValues.initialValue); |
41 parent.appendChild(target); | 52 parent.appendChild(target); |
42 | 53 |
43 testSpellCheckingEnabled(target, expectation); | 54 testSpellCheckingEnabled(target, spellCheckAttribueValues.destinationValue); |
44 parent.innerHTML = ""; | |
45 } | 55 } |
46 | 56 |
47 // default -> true | 57 var testElements = [ |
48 testFor("SPAN", undefined, true); | 58 "SPAN", |
49 // default -> false | 59 "INPUT", |
50 testFor("SPAN", undefined, false); | 60 "TEXTAREA" |
51 // true -> true | 61 ]; |
52 testFor("SPAN", true, true); | |
53 // true -> false | |
54 testFor("SPAN", true, false); | |
55 // false -> true | |
56 testFor("SPAN", false, true); | |
57 // false -> false | |
58 testFor("SPAN", false, false); | |
59 | 62 |
60 // default -> true | 63 const spellcheckAttributeVariances = [ |
61 testFor("INPUT", undefined, true); | 64 { initialValue: undefined, destinationValue: true }, |
62 // default -> false | 65 { initialValue: undefined, destinationValue: false }, |
63 testFor("INPUT", undefined, false); | 66 { initialValue: true, destinationValue: true }, |
64 // true -> true | 67 { initialValue: true, destinationValue: false }, |
65 testFor("INPUT", true, true); | 68 { initialValue: false, destinationValue: true }, |
66 // true -> false | 69 { initialValue: false, destinationValue: false } |
67 testFor("INPUT", true, false); | 70 ]; |
68 // false -> true | |
69 testFor("INPUT", false, true); | |
70 // false -> false | |
71 testFor("INPUT", false, false); | |
72 | 71 |
73 // default -> true | 72 var iterator = 0; |
74 testFor("TEXTAREA", undefined, true); | 73 var currentElement = null; |
75 // default -> false | 74 |
76 testFor("TEXTAREA", undefined, false); | 75 function done() |
77 // true -> true | 76 { |
78 testFor("TEXTAREA", true, true); | 77 if (!currentElement) { |
79 // true -> false | 78 currentElement = testElements.shift(); |
80 testFor("TEXTAREA", true, false); | 79 // All elements have been already taken. |
81 // false -> true | 80 if (!currentElement) |
82 testFor("TEXTAREA", false, true); | 81 return finishJSTest(); |
83 // false -> false | 82 } |
84 testFor("TEXTAREA", false, false); | 83 |
| 84 if (iterator != spellcheckAttributeVariances.length) |
| 85 setTimeout(testFor(currentElement, spellcheckAttributeVariances[iterator
++]), 0); |
| 86 else { |
| 87 iterator = 0; |
| 88 currentElement = null; |
| 89 done(); |
| 90 } |
| 91 } |
| 92 done(); |
85 | 93 |
86 var successfullyParsed = true; | 94 var successfullyParsed = true; |
OLD | NEW |