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 behavior change after the spellcheck attr ibute changed by the script.'); |
2 | 2 |
3 jsTestIsAsync = true; | |
4 | |
5 if (window.internals) { | |
6 internals.settings.setUnifiedTextCheckerEnabled(true); | |
7 internals.settings.setAsynchronousSpellCheckingEnabled(true); | |
8 } | |
9 | |
3 var parent = document.createElement("div"); | 10 var parent = document.createElement("div"); |
4 document.body.appendChild(parent); | 11 document.body.appendChild(parent); |
5 var sel = document.getSelection(); | 12 var sel = document.getSelection(); |
6 | 13 |
7 function testSpellCheckingEnabled(target, enabled) | 14 function testSpellCheckingEnabled(target, enabled) |
8 { | 15 { |
9 target.spellcheck = enabled; | 16 target.spellcheck = enabled; |
10 | 17 |
11 if (target.tagName == "SPAN") { | 18 if (target.tagName == "SPAN") { |
12 target.appendChild(document.createTextNode("Hello,")); | 19 target.appendChild(document.createTextNode("Hello,")); |
13 sel.setBaseAndExtent(target, 6, target, 6); | 20 sel.setBaseAndExtent(target, 6, target, 6); |
14 } else if (target.tagName == "INPUT" || target.tagName == "TEXTAREA") { | 21 } else if (target.tagName == "INPUT" || target.tagName == "TEXTAREA") { |
15 target.focus(); | 22 target.focus(); |
16 document.execCommand("InsertText", false, "Hello,"); | 23 document.execCommand("InsertText", false, "Hello,"); |
17 } | 24 } |
18 | 25 |
19 document.execCommand("InsertText", false, 'z'); | 26 document.execCommand("InsertText", false, 'z'); |
20 document.execCommand("InsertText", false, 'z'); | 27 document.execCommand("InsertText", false, 'z'); |
21 document.execCommand("InsertText", false, ' '); | 28 document.execCommand("InsertText", false, ' '); |
22 | 29 |
23 window.target = target; | 30 window.target = target; |
24 shouldBe("target.spellcheck", enabled ? "true" : "false"); | 31 shouldBe("target.spellcheck", enabled ? "true" : "false"); |
25 shouldBe("internals.hasSpellingMarker(document, 6, 2)", enabled ? "true" : " false"); | 32 if (window.internals) |
33 shouldBecomeEqual("internals.hasSpellingMarker(document, 6, 2)", enabled ? "true" : "false", done); | |
34 else | |
35 done(); | |
26 } | 36 } |
27 | 37 |
28 function createElement(tagName, spellcheck) | 38 function createElement(tagName, spellcheck) |
29 { | 39 { |
30 var target = document.createElement(tagName); | 40 var target = document.createElement(tagName); |
31 if (tagName == "SPAN") | 41 if (tagName == "SPAN") |
32 target.setAttribute("contentEditable", "true"); | 42 target.setAttribute("contentEditable", "true"); |
33 if (spellcheck) | 43 if (spellcheck) |
34 target.setAttribute("spellcheck", spellcheck); | 44 target.setAttribute("spellcheck", spellcheck); |
35 return target; | 45 return target; |
36 } | 46 } |
37 | 47 |
38 function testFor(tagName, initialAttribute, expectation) | 48 function testFor(tagName, initialAttribute, expectation) |
39 { | 49 { |
40 var target = createElement(tagName, initialAttribute); | 50 var target = createElement(tagName, initialAttribute); |
41 parent.appendChild(target); | 51 parent.appendChild(target); |
42 | 52 |
43 testSpellCheckingEnabled(target, expectation); | 53 testSpellCheckingEnabled(target, expectation); |
44 parent.innerHTML = ""; | |
45 } | 54 } |
46 | 55 |
47 // default -> true | 56 var tests = [ |
48 testFor("SPAN", undefined, true); | 57 function() { testFor("SPAN", undefined, true); }, // default -> true |
49 // default -> false | 58 function() { testFor("SPAN", undefined, false); }, // default -> false |
50 testFor("SPAN", undefined, false); | 59 function() { testFor("SPAN", true, true); }, // true -> true |
tony
2014/03/10 17:07:56
I'm not sure there's a lot of value to these comme
groby-ooo-7-16
2014/03/10 20:14:09
And while you're simplifying: The testFor function
grzegorz
2014/03/11 13:24:32
Thanks. Please have a look at patch #2 if I proper
| |
51 // true -> true | 60 function() { testFor("SPAN", true, false); }, // true -> false |
52 testFor("SPAN", true, true); | 61 function() { testFor("SPAN", false, true); }, // false -> true |
53 // true -> false | 62 function() { testFor("SPAN", false, false); }, // false -> false |
54 testFor("SPAN", true, false); | |
55 // false -> true | |
56 testFor("SPAN", false, true); | |
57 // false -> false | |
58 testFor("SPAN", false, false); | |
59 | 63 |
60 // default -> true | 64 function() { testFor("INPUT", undefined, true); }, // default -> true |
61 testFor("INPUT", undefined, true); | 65 function() { testFor("INPUT", undefined, false); }, // default -> false |
62 // default -> false | 66 function() { testFor("INPUT", true, true); }, // true -> true |
63 testFor("INPUT", undefined, false); | 67 function() { testFor("INPUT", true, false); }, // true -> false |
64 // true -> true | 68 function() { testFor("INPUT", false, true); }, // false -> true |
65 testFor("INPUT", true, true); | 69 function() { testFor("INPUT", false, false); }, // false -> false |
66 // true -> false | |
67 testFor("INPUT", true, false); | |
68 // false -> true | |
69 testFor("INPUT", false, true); | |
70 // false -> false | |
71 testFor("INPUT", false, false); | |
72 | 70 |
73 // default -> true | 71 function() { testFor("TEXTAREA", undefined, true); }, // default -> true |
74 testFor("TEXTAREA", undefined, true); | 72 function() { testFor("TEXTAREA", undefined, false); }, // default -> false |
75 // default -> false | 73 function() { testFor("TEXTAREA", true, true); }, // true -> true |
76 testFor("TEXTAREA", undefined, false); | 74 function() { testFor("TEXTAREA", true, false); }, // true -> false |
77 // true -> true | 75 function() { testFor("TEXTAREA", false, true); }, // false -> true |
78 testFor("TEXTAREA", true, true); | 76 function() { testFor("TEXTAREA", false, false); }, // false -> false |
79 // true -> false | 77 ]; |
80 testFor("TEXTAREA", true, false); | 78 |
81 // false -> true | 79 function done() |
82 testFor("TEXTAREA", false, true); | 80 { |
83 // false -> false | 81 var next = tests.shift(); |
84 testFor("TEXTAREA", false, false); | 82 if (next) |
83 return setTimeout(next, 0); | |
84 | |
85 finishJSTest(); | |
86 } | |
87 done(); | |
85 | 88 |
86 var successfullyParsed = true; | 89 var successfullyParsed = true; |
OLD | NEW |