layout/generic/test/test_selection_touchevents.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:2cfdf2891015
1 <!DOCTYPE>
2 <html>
3 <head>
4 <title>selection expanding test</title>
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6 <script type="text/javascript" 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], 1, 0, true);
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 cwu = SpecialPowers.getDOMWindowUtils(window);
31 cwu.sendMouseEventToWindow("mousedown", rect.left + rect.width/2, rect.top + rect.height/2, 0, 0, 0, true);
32 cwu.sendMouseEventToWindow("mouseup", rect.left + rect.width/2, rect.top + rect.height/2, 0, 0, 0, true);
33 var selectionController = SpecialPowers.wrap(window).
34 QueryInterface(Ci.nsIInterfaceRequestor).
35 getInterface(Ci.nsIWebNavigation).
36 QueryInterface(Ci.nsIInterfaceRequestor).
37 getInterface(Ci.nsISelectionDisplay).
38 QueryInterface(Ci.nsISelectionController);
39
40 selectionController.wordMove(false, false);
41 selectionController.wordMove(true, true);
42 isnot(selection.rangeCount, 0, "Something should be selected");
43 var string = selection.toString();
44
45 sendTouch("touchstart", rect.right, rect.top + rect.height/2);
46 sendTouch("touchmove", rect.left, rect.top + rect.height/2);
47 sendTouch("touchend", rect.left, rect.top + rect.height/2);
48 is(selection.toString(), string, "touch events should not affect the selection");
49
50 SimpleTest.finish();
51 }
52 window.onload = function() { setTimeout(test, 0); };
53 SimpleTest.waitForExplicitFinish();
54 </script>
55 </pre>
56 </body>
57 </html>

mercurial