Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / spelling / script-tests / spellcheck-paste.js
blob4d1c74e328bbb4758de3642022b46f543f2fde8e
2 description('For Bug 40092: Spell checking for pasted text.');
4 jsTestIsAsync = true;
6 var testRoot = document.createElement("div");
7 document.body.insertBefore(testRoot, document.body.firstChild);
9 var testTextArea = document.createElement("textarea");
10 testRoot.appendChild(testTextArea);
12 var testInput = document.createElement("input");
13 testInput.setAttribute("type", "text");
14 testRoot.appendChild(testInput);
16 var testEditable = document.createElement("div");
17 testEditable.setAttribute("contentEditable", "true");
18 testRoot.appendChild(testEditable);
20 var testSourcePlain = document.createElement("div");
21 testSourcePlain.innerHTML = "zz apple";
22 testRoot.appendChild(testSourcePlain);
24 var testSourceDecorated = document.createElement("div");
25 testSourceDecorated.innerHTML = "z<b>z appl</b>e";
26 testRoot.appendChild(testSourceDecorated);
28 var testSourceMulti = document.createElement("div");
29 testSourceMulti.innerHTML = "zz zz zz";
30 testRoot.appendChild(testSourceMulti);
32 var sel = window.getSelection();
34 var tests = [];
36 function done()
38 var next = tests.shift();
39 if (next)
40 return window.setTimeout(next, 0);
41 testRoot.style.display = "none";
42 finishJSTest();
45 function verifyMarker(node, expectedMarked)
47 if (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) {
48 node.focus();
49 } else {
50 sel.selectAllChildren(node);
53 var ok = true;
54 for (var i = 0; ok && i < expectedMarked.length; ++i)
55 ok = internals.hasSpellingMarker(document, expectedMarked[i][0], expectedMarked[i][1]);
57 if (ok) {
58 var nodeContent = node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement ? node.value : node.innerHTML;
59 testPassed(node.tagName + " has a marker on '" + nodeContent + "'");
62 return ok;
65 var destination = null;
66 var misspelledLocations = null;
67 function pasteAndVerify(source, dest, expectedMarked)
69 sel.selectAllChildren(source);
70 document.execCommand("Copy");
71 if (dest instanceof HTMLInputElement || dest instanceof HTMLTextAreaElement) {
72 dest.value = "";
73 dest.focus();
74 } else {
75 dest.innerHTML = "";
76 sel.selectAllChildren(dest);
78 document.execCommand("Paste");
80 if (window.internals) {
81 destination = dest;
82 misspelledLocations = expectedMarked;
83 shouldBecomeEqual('verifyMarker(destination, misspelledLocations)', 'true', done);
87 if (window.internals)
88 internals.settings.setAsynchronousSpellCheckingEnabled(true);
90 tests.push(function() { pasteAndVerify(testSourcePlain, testInput, [[0, 2]]); });
91 tests.push(function() { pasteAndVerify(testSourceDecorated, testInput, [[0, 2]]); });
92 tests.push(function() { pasteAndVerify(testSourceMulti, testInput, [[0, 2], [3, 2]]); });
94 tests.push(function() { pasteAndVerify(testSourcePlain, testTextArea, [[0, 2]]); });
95 tests.push(function() { pasteAndVerify(testSourceDecorated, testTextArea, [[0, 2]]); });
96 tests.push(function() { pasteAndVerify(testSourceMulti, testTextArea, [[0, 2], [3, 2]]); });
98 tests.push(function() { pasteAndVerify(testSourcePlain, testEditable, [[0, 2]]); });
99 tests.push(function() { pasteAndVerify(testSourceDecorated, testEditable, [[0, 1]]); }); // To check "fo" part of foo.
100 tests.push(function() { pasteAndVerify(testSourceMulti, testEditable, [[0, 2], [3, 2]]); });
101 done();
103 var successfullyParsed = true;