OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <script src="../../resources/js-test.js"></script> | |
3 <script> | |
4 description("This tests the selection of the text field after setSelectionRa
nge is called"); | |
5 window.onload = function() { | |
6 if (window.eventSender) { | |
7 doSetSelectionRange('focus'); | |
8 doSetSelectionRange('mousedown'); | |
9 doSetSelectionRange('mouseup'); | |
10 doSetSelectionRange('click'); | |
11 } | |
12 } | |
13 | |
14 function doSetSelectionRange(event) { | |
15 debug(event + ' test :'); | |
16 var textfield = document.getElementById('textfield'); | |
17 textfield.setSelectionRange(0, 1); | |
18 var tx = textfield.offsetLeft + 4; | |
19 var ty = textfield.offsetTop + 4; | |
20 | |
21 textfield.addEventListener(event, setSelectionRange); | |
22 eventSender.mouseMoveTo(tx, ty); | |
23 eventSender.mouseDown(); | |
24 eventSender.mouseUp(); | |
25 if (event == 'mousedown') { | |
26 shouldBe('textfield.selectionStart', '0'); | |
27 shouldBe('textfield.selectionEnd', '0'); | |
28 } else { | |
29 shouldBe('textfield.selectionStart', '0'); | |
30 shouldBe('textfield.selectionEnd', '5'); | |
31 } | |
32 eventSender.mouseMoveTo(tx, ty + 30); | |
33 eventSender.mouseDown(); | |
34 eventSender.mouseUp(); | |
35 debug('the selection should be cleared'); | |
36 shouldBe('textfield.selectionStart', '0'); | |
37 shouldBe('textfield.selectionEnd', '0'); | |
38 textfield.removeEventListener(event, setSelectionRange); | |
39 } | |
40 | |
41 function setSelectionRange(e) { | |
42 var textfield = document.getElementById('textfield'); | |
43 textfield.setSelectionRange(0, textfield.value.length); | |
44 } | |
45 </script> | |
46 <input type="text" value="value" id="textfield"></input> | |
OLD | NEW |