Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / spelling / resources / util.js
blobd2eed66c4fd1f1c31fb9f98c332aa44fad860916
1 function log(msg)
3     document.getElementById("console").innerHTML += (msg + "\n");
6 function verifySpellTest(nretry, opt_doNotFinishTest)
8     var node = window.destination;
9     if (window.destination.childNodes.length > 0)
10         node = window.destination.childNodes[0];
11     if (nretry && !internals.markerCountForNode(node, "spelling")) {
12         window.setTimeout(function() { verifySpellTest(nretry - 1, opt_doNotFinishTest); }, 0);
13         return;
14     }
15     testFunctionCallback(node);
16     if (!opt_doNotFinishTest)
17         finishJSTest();
20 function initSpellTest(testElementId, testText, testFunction, opt_doNotFinishTest)
22     if (!window.internals || !window.testRunner) {
23         log("FAIL Incomplete test environment");
24         return;
25     }
26     testFunctionCallback = testFunction;
27     jsTestIsAsync = true;
28     internals.settings.setAsynchronousSpellCheckingEnabled(true);
29     internals.settings.setSmartInsertDeleteEnabled(true);
30     internals.settings.setSelectTrailingWhitespaceEnabled(false);
31     internals.settings.setUnifiedTextCheckerEnabled(true);
32     internals.settings.setEditingBehavior("win");
33     window.destination = document.getElementById(testElementId);
34     window.destination.focus();
35     document.execCommand("InsertText", false, testText);
36     window.setTimeout(function() { verifySpellTest(10, opt_doNotFinishTest); }, 0);
39 function findFirstTextNode(node)
41     function iterToFindFirstTextNode(node)
42     {
43         if (node instanceof Text)
44             return node;
46         var childNodes = node.childNodes;
47         for (var i = 0; i < childNodes.length; ++i) {
48             var n = iterToFindFirstTextNode(childNodes[i]);
49             if (n)
50                 return n;
51         }
53         return null;
54     }
56     if (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) {
57         return iterToFindFirstTextNode(internals.shadowRoot(node));
58     } else {
59         return iterToFindFirstTextNode(node);
60     }
63 function typeText(elem, text)
65     elem.focus();
66     for (var i = 0; i < text.length; ++i) {
67         typeCharacterCommand(text[i]);
68     }