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