Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / spelling / script-tests / spelling-attribute-change.js
blobfe25f6a04cd29a2a79cc85a62b8914bdc445c723
1 description('Tests if the spellchecker behaves correctly when the spellcheck attribute '
2 + 'is being changed by the script.');
4 jsTestIsAsync = true;
6 if (window.internals) {
7 internals.settings.setUnifiedTextCheckerEnabled(true);
8 internals.settings.setAsynchronousSpellCheckingEnabled(true);
11 var parent = document.createElement("div");
12 document.body.appendChild(parent);
13 var sel = document.getSelection();
15 function testSpellCheckingEnabled(target, enabled)
17 target.spellcheck = enabled;
19 if (target.tagName == "SPAN") {
20 target.appendChild(document.createTextNode("Hello,"));
21 sel.setBaseAndExtent(target, 6, target, 6);
22 } else if (target.tagName == "INPUT" || target.tagName == "TEXTAREA") {
23 target.focus();
24 document.execCommand("InsertText", false, "Hello,");
27 document.execCommand("InsertText", false, 'z');
28 document.execCommand("InsertText", false, 'z');
29 document.execCommand("InsertText", false, ' ');
31 window.target = target;
32 shouldBe("target.spellcheck", enabled ? "true" : "false");
33 if (window.internals)
34 shouldBecomeEqual("internals.hasSpellingMarker(document, 6, 2)", enabled ? "true" : "false", done);
35 else
36 done();
39 function createElement(tagName, spellcheck)
41 var target = document.createElement(tagName);
42 if (tagName == "SPAN")
43 target.setAttribute("contentEditable", "true");
44 if (spellcheck)
45 target.setAttribute("spellcheck", spellcheck);
46 return target;
49 function testFor(tagName, spellCheckAttribueValues)
51 var target = createElement(tagName, spellCheckAttribueValues.initialValue);
52 parent.appendChild(target);
54 testSpellCheckingEnabled(target, spellCheckAttribueValues.destinationValue);
57 var testElements = [
58 "SPAN",
59 "INPUT",
60 "TEXTAREA"
63 const spellcheckAttributeVariances = [
64 { initialValue: undefined, destinationValue: true },
65 { initialValue: undefined, destinationValue: false },
66 { initialValue: true, destinationValue: true },
67 { initialValue: true, destinationValue: false },
68 { initialValue: false, destinationValue: true },
69 { initialValue: false, destinationValue: false }
72 var iterator = 0;
73 var currentElement = null;
75 function done()
77 if (!currentElement) {
78 currentElement = testElements.shift();
79 // All elements have been already taken.
80 if (!currentElement)
81 return finishJSTest();
84 if (iterator != spellcheckAttributeVariances.length)
85 setTimeout(testFor(currentElement, spellcheckAttributeVariances[iterator++]), 0);
86 else {
87 iterator = 0;
88 currentElement = null;
89 done();
92 done();
94 var successfullyParsed = true;