3 <script type=
"text/javascript">
4 function print(message
)
6 var paragraph
= document
.createElement("div");
8 paragraph
.appendChild(document
.createElement("br"));
10 paragraph
.appendChild(document
.createTextNode(message
));
12 document
.getElementById("console").appendChild(paragraph
);
16 if (window
.testRunner
) {
17 testRunner
.dumpAsText();
19 var elt
= document
.getElementById("text");
20 print("===textarea===");
23 elt
= document
.getElementById("input");
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)");
47 // make sure that setSelectionRange is defined
48 if (elt
.setSelectionRange
== undefined) {
49 print("Failed: no setSelectionRange");
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);
57 elt
.setSelectionRange(-2,5);
59 elt
.setSelectionRange(42,54);
61 elt
.setSelectionRange(5,2);
65 print("selectionStart:");
66 elt
.selectionStart
= 3;
68 elt
.selectionStart
= 7;
70 elt
.selectionStart
= -1;
72 elt
.selectionStart
= 54;
74 elt
.selectionStart
= 3;
78 print("selectionEnd:");
83 elt
.selectionEnd
= -1;
85 elt
.selectionEnd
= 54;
87 elt
.selectionStart
= 7;
93 function testButtonSelectionAccess(button
, access
)
95 var source
= "button" + access
;
98 print(source
+ " did not throw exception");
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();
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>
117 <textarea id=
"text"></textarea>
118 <input type=
"text" id=
"input" />
119 <input type=
"button" id=
"button" />