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.

     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");
    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 }
    22 function test()
    23 {
    24   var selection = window.getSelection();
    25   selection.removeAllRanges();
    26   var rect = div1.getBoundingClientRect();
    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);
    40   selectionController.wordMove(false, false);
    41   selectionController.wordMove(true, true);
    42   isnot(selection.rangeCount, 0, "Something should be selected");
    43   var string = selection.toString();
    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");
    50   SimpleTest.finish();
    51 }
    52 window.onload = function() { setTimeout(test, 0); };
    53 SimpleTest.waitForExplicitFinish();
    54 </script>
    55 </pre>
    56 </body>
    57 </html>

mercurial