layout/generic/test/test_selection_touchevents.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/generic/test/test_selection_touchevents.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,57 @@
     1.4 +<!DOCTYPE>
     1.5 +<html>
     1.6 +<head>
     1.7 +<title>selection expanding test</title>
     1.8 +<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.10 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +</head>
    1.12 +<body>
    1.13 +<div id="div1" class="testingDiv">
    1.14 +  aaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaa
    1.15 +</div>
    1.16 +<pre id="test">
    1.17 +<script class="testbody" type="text/javascript">
    1.18 +var div1 = document.getElementById("div1");
    1.19 +
    1.20 +function sendTouch(aType, aX, aY) {
    1.21 +  var cwu = SpecialPowers.getDOMWindowUtils(window);
    1.22 +  cwu.sendTouchEvent(aType, [0], [aX], [aY], [1], [1], [0], [1], 1, 0, true);
    1.23 +}
    1.24 +
    1.25 +function test()
    1.26 +{
    1.27 +  var selection = window.getSelection();
    1.28 +  selection.removeAllRanges();
    1.29 +  var rect = div1.getBoundingClientRect();
    1.30 +
    1.31 +  // Position the caret using a fake mouse click
    1.32 +  var Ci = SpecialPowers.Ci;
    1.33 +  var cwu = SpecialPowers.getDOMWindowUtils(window);
    1.34 +  cwu.sendMouseEventToWindow("mousedown", rect.left + rect.width/2, rect.top + rect.height/2, 0, 0, 0, true);
    1.35 +  cwu.sendMouseEventToWindow("mouseup",   rect.left + rect.width/2, rect.top + rect.height/2, 0, 0, 0, true);
    1.36 +  var selectionController = SpecialPowers.wrap(window).
    1.37 +                              QueryInterface(Ci.nsIInterfaceRequestor).
    1.38 +                              getInterface(Ci.nsIWebNavigation).
    1.39 +                              QueryInterface(Ci.nsIInterfaceRequestor).
    1.40 +                              getInterface(Ci.nsISelectionDisplay).
    1.41 +                              QueryInterface(Ci.nsISelectionController);
    1.42 +
    1.43 +  selectionController.wordMove(false, false);
    1.44 +  selectionController.wordMove(true, true);
    1.45 +  isnot(selection.rangeCount, 0, "Something should be selected");
    1.46 +  var string = selection.toString();
    1.47 +
    1.48 +  sendTouch("touchstart", rect.right, rect.top + rect.height/2);
    1.49 +  sendTouch("touchmove",  rect.left, rect.top + rect.height/2);
    1.50 +  sendTouch("touchend",   rect.left, rect.top + rect.height/2);
    1.51 +  is(selection.toString(), string, "touch events should not affect the selection");
    1.52 +
    1.53 +  SimpleTest.finish();
    1.54 +}
    1.55 +window.onload = function() { setTimeout(test, 0); };
    1.56 +SimpleTest.waitForExplicitFinish();
    1.57 +</script>
    1.58 +</pre>
    1.59 +</body>
    1.60 +</html>
    1.61 \ No newline at end of file

mercurial