test_selection_touchevents.html (2069B)
1 <!DOCTYPE> 2 <html> 3 <head> 4 <title>selection expanding test</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <script src="/tests/SimpleTest/EventUtils.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 8 </head> 9 <body> 10 <div id="div1" class="testingDiv"> 11 aaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaa 12 </div> 13 <pre id="test"> 14 <script class="testbody" type="text/javascript"> 15 var div1 = document.getElementById("div1"); 16 17 function sendTouch(aType, aX, aY) { 18 var cwu = SpecialPowers.getDOMWindowUtils(window); 19 cwu.sendTouchEvent(aType, [0], [aX], [aY], [1], [1], [0], [1], [0], [0], [0], 0); 20 } 21 22 function test() 23 { 24 var selection = window.getSelection(); 25 selection.removeAllRanges(); 26 var rect = div1.getBoundingClientRect(); 27 28 // Position the caret using a fake mouse click 29 var Ci = SpecialPowers.Ci; 30 var wrappedWindow = SpecialPowers.wrap(window); 31 wrappedWindow.synthesizeMouseEvent("mousedown", rect.left + rect.width/2, rect.top + rect.height/2, {}, { toWindow: true }); 32 wrappedWindow.synthesizeMouseEvent("mouseup", rect.left + rect.width/2, rect.top + rect.height/2, {}, { toWindow: true }); 33 var selectionController = SpecialPowers.wrap(window).docShell. 34 QueryInterface(Ci.nsIInterfaceRequestor). 35 getInterface(Ci.nsISelectionDisplay). 36 QueryInterface(Ci.nsISelectionController); 37 38 selectionController.wordMove(false, false); 39 selectionController.wordMove(true, true); 40 isnot(selection.rangeCount, 0, "Something should be selected"); 41 var string = selection.toString(); 42 43 sendTouch("touchstart", rect.right, rect.top + rect.height/2); 44 sendTouch("touchmove", rect.left, rect.top + rect.height/2); 45 sendTouch("touchend", rect.left, rect.top + rect.height/2); 46 is(selection.toString(), string, "touch events should not affect the selection"); 47 48 SimpleTest.finish(); 49 } 50 window.onload = function() { setTimeout(test, 0); }; 51 SimpleTest.waitForExplicitFinish(); 52 </script> 53 </pre> 54 </body> 55 </html>