Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / selection-functions.html
blobe256af5e84b268fbe17fb4e2ac44d27f78542e1c
1 <html>
2 <head>
3 <script type="text/javascript">
4 function print(message)
6 var paragraph = document.createElement("div");
7 if (message == "") {
8 paragraph.appendChild(document.createElement("br"));
9 } else {
10 paragraph.appendChild(document.createTextNode(message));
12 document.getElementById("console").appendChild(paragraph);
14 function test()
16 if (window.testRunner) {
17 testRunner.dumpAsText();
19 var elt = document.getElementById("text");
20 print("===textarea===");
21 testElt(elt);
23 elt = document.getElementById("input");
24 print("");
25 print("===input===");
26 testElt(elt);
28 print("");
29 print("===button===");
31 // Make sure that accessing selectionStart and selectionEnd on
32 // the button throws exceptions.
33 elt = document.getElementById("button");
34 testButtonSelectionAccess(elt, ".selectionStart");
35 testButtonSelectionAccess(elt, ".selectionStart = 0");
36 testButtonSelectionAccess(elt, ".selectionEnd");
37 testButtonSelectionAccess(elt, ".selectionEnd = 0");
38 // Make sure that setSelectionRange is defined on the button element,
39 // but throws an exception if called.
40 if (elt.setSelectionRange != undefined) {
41 print("button.setSelectionRange defined");
42 testButtonSelectionAccess(elt, ".setSelectionRange(0,0)");
45 function testElt(elt)
47 // make sure that setSelectionRange is defined
48 if (elt.setSelectionRange == undefined) {
49 print("Failed: no setSelectionRange");
50 return;
52 elt.value = "This is a test value. Just filling in some text.";
53 // the value is 48 characters long
54 print("setSelectionRange():");
55 elt.setSelectionRange(3,7);
56 display(elt);
57 elt.setSelectionRange(-2,5);
58 display(elt);
59 elt.setSelectionRange(42,54);
60 display(elt);
61 elt.setSelectionRange(5,2);
62 display(elt);
64 print("");
65 print("selectionStart:");
66 elt.selectionStart = 3;
67 display(elt);
68 elt.selectionStart = 7;
69 display(elt);
70 elt.selectionStart = -1;
71 display(elt);
72 elt.selectionStart = 54;
73 display(elt);
74 elt.selectionStart = 3;
75 display(elt);
77 print("");
78 print("selectionEnd:");
79 elt.selectionEnd = 5;
80 display(elt);
81 elt.selectionEnd = 2;
82 display(elt);
83 elt.selectionEnd = -1;
84 display(elt);
85 elt.selectionEnd = 54;
86 display(elt);
87 elt.selectionStart = 7;
88 elt.selectionEnd = 7;
89 display(elt);
91 elt.value = "";
93 function testButtonSelectionAccess(button, access)
95 var source = "button" + access;
96 try {
97 eval(source);
98 print(source + " did not throw exception");
99 } catch(e) {
100 print(source + " threw exception");
103 function display(elt)
105 var actStart = elt.selectionStart;
106 var actEnd = elt.selectionEnd;
107 var txt = actStart.toString() + ", " + actEnd.toString();
108 print(txt);
110 </script>
111 </head>
112 <body onload="test();">
113 <p>This test checks if setSelectionRange(), selectionStart, and selectionEnd on a textarea and input work as expected. This includes checking edge cases such as out-of-bound values.</p>
114 <p>If this test passed you'll see a bunch of correct selection ranges below. Check the expected file for the correct ranges.</p>
115 <hr />
116 <form>
117 <textarea id="text"></textarea>
118 <input type="text" id="input" />
119 <input type="button" id="button" />
120 </form>
121 <hr />
122 <p id="console"></p>
123 </body>
124 </html>