layout/generic/test/test_selection_touchevents.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial