2 <script src=
"../../resources/testharness.js"></script>
3 <script src=
"../../resources/testharnessreport.js"></script>
5 async_test(function(t
) {
6 window
.onload
= t
.step_func(function() {
7 if (!window
.eventSender
) {
11 doSetSelectionRange('focus');
12 doSetSelectionRange('mousedown');
13 doSetSelectionRange('mouseup');
14 doSetSelectionRange('click');
18 function doSetSelectionRange(eventType
) {
19 var textfield
= document
.getElementById('textfield');
20 textfield
.setSelectionRange(0, 1);
21 var tx
= textfield
.offsetLeft
+ 4;
22 var ty
= textfield
.offsetTop
+ 4;
24 textfield
.addEventListener(eventType
, setSelectionRange
);
25 eventSender
.mouseMoveTo(tx
, ty
);
26 eventSender
.mouseDown();
27 eventSender
.mouseUp();
28 if (eventType
=== 'mousedown') {
29 assert_equals(textfield
.selectionStart
, 0);
30 assert_equals(textfield
.selectionEnd
, 0);
32 assert_equals(textfield
.selectionStart
, 0);
33 assert_equals(textfield
.selectionEnd
, 5);
36 eventSender
.leapForward(1000);
37 eventSender
.mouseMoveTo(textfield
.offsetLeft
, textfield
.offsetTop
);
38 eventSender
.mouseDown();
39 eventSender
.mouseUp();
42 assert_equals(textfield
.selectionStart
, 0);
43 assert_equals(textfield
.selectionEnd
, 0);
44 textfield
.removeEventListener(eventType
, setSelectionRange
);
47 function setSelectionRange(e
) {
48 var textfield
= document
.getElementById('textfield');
49 textfield
.setSelectionRange(0, textfield
.value
.length
);
51 }, "This tests the selection of the text field after setSelectionRange is called.");
53 <input type=
"text" value=
"value" id=
"textfield"></input>