Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / selection / find-in-text-control.html
bloba46ab1354ae47051c5538a112d3b5d8893fd9329
1 <p id="description" style="display: none;">
2 Test for <i><a href="https://bugs.webkit.org/show_bug.cgi?id=7023">https://bugs.webkit.org/show_bug.cgi?id=7023</a> Searching in text areas</i>.
3 </p>
4 <div id="div">
5 Lorem ip<textarea id="textarea">sum dolor si</textarea>t amet
6 Lorem ip<input id="input: text" type="text" value="sum dolor si">t amet
7 Lorem ip<input id="input: search" type="search" value="sum dolor si">t amet
8 Lorem ip<input id="input: password" type="password" value="sum dolor si">t amet
9 </div>
10 <script>
11 if (window.testRunner)
12 testRunner.dumpAsText();
14 var result = "";
16 function textNodeIndex(node)
18 var index = 1;
19 while (node = node.previousSibling) {
20 if (node.nodeType == Node.TEXT_NODE)
21 ++index;
23 return index;
26 function clearSelection()
28 getSelection().selectAllChildren(document.body);
29 getSelection().empty();
32 function selectionLocationAsString()
34 if (document.activeElement.selectionStart != document.activeElement.selectionEnd)
35 return document.activeElement.id + ", at offset " + document.activeElement.selectionStart;
36 if (getSelection().rangeCount == 0)
37 return "";
38 var range = getSelection().getRangeAt(0);
39 return "outer text node " + textNodeIndex(range.startContainer) + ", at offset " + range.startOffset;
42 function findAll(target)
44 var sel = getSelection();
45 var ranges = [];
47 clearSelection();
48 document.execCommand("FindString", false, target);
50 var firstMatch = selectionLocationAsString();
51 if (firstMatch == "") {
52 result += "Target " + target + " not matched\n";
53 return;
56 result += "Target " + target + " matched at:\n " + firstMatch + "\n";
58 document.execCommand("FindString", false, target);
59 var match = selectionLocationAsString();
60 while (match !== firstMatch) {
61 result += " " + match + "\n";
62 document.execCommand("FindString", false, target);
63 match = selectionLocationAsString();
66 clearSelection();
69 findAll("m");
70 findAll("s");
71 findAll("si");
72 findAll("rem");
73 findAll("ipsum");
74 findAll("sit");
75 findAll("amet");
77 document.body.appendChild(document.createElement("pre")).appendChild(document.createTextNode(result));
78 document.getElementById("description").style.display = "";
79 </script>