|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=392746 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 392746</title> |
|
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
10 <style> |
|
11 </style> |
|
12 </head> |
|
13 <body> |
|
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=392746">Mozilla Bug 392746</a> |
|
15 <div id="content"> |
|
16 text text text text text <span id="d">ddd text text </span>text text text <br> |
|
17 text <span id="c">ccc text</span> text text <span id="e">eee text</span> text text text <span id="b">bbb text</span><br> |
|
18 text text text text text text <span id="a">aaa text</span> text text text <br> |
|
19 </div> |
|
20 <pre id="test"> |
|
21 <script class="testbody" type="text/javascript"> |
|
22 var wu = SpecialPowers.getDOMWindowUtils(window); |
|
23 |
|
24 function ctrlselect(aX,aY, aX2, aY2) { |
|
25 var modifyers = (navigator.platform.indexOf("Mac") >= 0) ? 8 : 2; |
|
26 wu.sendMouseEvent('mousedown', aX, aY, 0, 1, modifyers); |
|
27 wu.sendMouseEvent('mousemove', aX2, aY2, 0, 0, modifyers); |
|
28 wu.sendMouseEvent('mouseup', aX2, aY2, 0, 1, modifyers); |
|
29 } |
|
30 |
|
31 function test() { |
|
32 var sel = window.getSelection(); |
|
33 sel.removeAllRanges(); |
|
34 |
|
35 var a=document.getElementById('a').getBoundingClientRect(); |
|
36 ctrlselect(a.left+1, a.top+1, a.right-1, a.top+1); |
|
37 var b=document.getElementById('b').getBoundingClientRect(); |
|
38 ctrlselect(b.left+1, b.top+1, b.right-1, b.top+1); |
|
39 var c=document.getElementById('c').getBoundingClientRect(); |
|
40 ctrlselect(c.left+1, c.top+1, c.right-1, c.top+1); |
|
41 var d=document.getElementById('d').getBoundingClientRect(); |
|
42 ctrlselect(d.left+1, d.top+1, d.right-1, d.top+1); |
|
43 var e=document.getElementById('e').getBoundingClientRect(); |
|
44 ctrlselect(e.right-1, e.top+1, e.left+1, e.top+1); |
|
45 |
|
46 ok(sel.getRangeAt(0).toString() == 'ddd text text ', 'First selection range should be "ddd text text "'); |
|
47 ok(sel.getRangeAt(1).toString() == 'ccc text', 'First selection range should be "ccc text"'); |
|
48 ok(sel.getRangeAt(2).toString() == 'eee text', 'First selection range should be "eee text"'); |
|
49 ok(sel.getRangeAt(3).toString() == 'bbb text', 'First selection range should be "bbb text"'); |
|
50 ok(sel.getRangeAt(4).toString() == 'aaa text', 'First selection range should be "aaa text"'); |
|
51 |
|
52 ok(sel.focusNode == sel.anchorNode, 'focusNode and anchorNode should be the same'); |
|
53 ok(sel.focusNode.parentNode == document.getElementById('e'), 'focusNode.parentNode should be the same as the node with id=e'); |
|
54 ok(sel.focusOffset == 0, 'focusOffset should be 0'); |
|
55 ok(sel.anchorOffset == 8, 'anchorOffset should be 8'); |
|
56 |
|
57 wu.sendMouseEvent('mousedown', 0, 0, 0, 1, 0); |
|
58 wu.sendMouseEvent('mousemove', 0, 0, 0, 0, 0); |
|
59 wu.sendMouseEvent('mouseup', 0, 0, 0, 1, 0); |
|
60 |
|
61 SimpleTest.finish(); |
|
62 } |
|
63 |
|
64 window.onload=function() { |
|
65 SimpleTest.waitForExplicitFinish(); |
|
66 setTimeout(test, 0); |
|
67 }; |
|
68 </script> |
|
69 </pre> |
|
70 </body> |
|
71 </html> |