layout/base/tests/test_bug993936.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/base/tests/test_bug993936.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,161 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=993936
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 993936</title>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +  <script type="application/javascript">
    1.15 +
    1.16 +  /** Test for Bug 993936 **/
    1.17 +
    1.18 +var currentId = 0;
    1.19 +var evictedTouchesCount = 0;
    1.20 +
    1.21 +function testtouch(aOptions) {
    1.22 +  if (!aOptions)
    1.23 +    aOptions = {};
    1.24 +  this.identifier = aOptions.identifier || 0;
    1.25 +  this.target = aOptions.target || 0;
    1.26 +  this.page = aOptions.page || {x: 0, y: 0};
    1.27 +  this.radius = aOptions.radius || {x: 0, y: 0};
    1.28 +  this.rotationAngle = aOptions.rotationAngle || 0;
    1.29 +  this.force = aOptions.force || 1;
    1.30 +}
    1.31 +
    1.32 +function touchEvent(aOptions) {
    1.33 +  if (!aOptions) {
    1.34 +    aOptions = {};
    1.35 +  }
    1.36 +  this.ctrlKey = aOptions.ctrlKey || false;
    1.37 +  this.altKey = aOptions.altKey || false;
    1.38 +  this.shiftKey = aOptions.shiftKey || false;
    1.39 +  this.metaKey = aOptions.metaKey || false;
    1.40 +  this.touches = aOptions.touches || [];
    1.41 +  this.targetTouches = aOptions.targetTouches || [];
    1.42 +  this.changedTouches = aOptions.changedTouches || [];
    1.43 +}
    1.44 +
    1.45 +function sendTouchEvent(windowUtils, aType, aEvent, aModifiers) {
    1.46 +  var ids = [], xs=[], ys=[], rxs = [], rys = [],
    1.47 +      rotations = [], forces = [];
    1.48 +
    1.49 +  for (var touchType of ["touches", "changedTouches", "targetTouches"]) {
    1.50 +    for (var i = 0; i < aEvent[touchType].length; i++) {
    1.51 +      if (ids.indexOf(aEvent[touchType][i].identifier) == -1) {
    1.52 +        ids.push(aEvent[touchType][i].identifier);
    1.53 +        xs.push(aEvent[touchType][i].page.x);
    1.54 +        ys.push(aEvent[touchType][i].page.y);
    1.55 +        rxs.push(aEvent[touchType][i].radius.x);
    1.56 +        rys.push(aEvent[touchType][i].radius.y);
    1.57 +        rotations.push(aEvent[touchType][i].rotationAngle);
    1.58 +        forces.push(aEvent[touchType][i].force);
    1.59 +      }
    1.60 +    }
    1.61 +  }
    1.62 +  return windowUtils.sendTouchEvent(aType,
    1.63 +                                    ids, xs, ys, rxs, rys,
    1.64 +                                    rotations, forces,
    1.65 +                                    ids.length, aModifiers, 0);
    1.66 +}
    1.67 +
    1.68 +function getSingleTouchEventForTarget(target, cwu) {
    1.69 +  currentId++;
    1.70 +  var bcr = target.getBoundingClientRect();
    1.71 +  var touch = new testtouch({
    1.72 +    page: {x: Math.round(bcr.left + bcr.width/2),
    1.73 +           y: Math.round(bcr.top  + bcr.height/2)},
    1.74 +    target: target,
    1.75 +    identifier: currentId,
    1.76 +  });
    1.77 +  var event = new touchEvent({
    1.78 +    touches: [touch],
    1.79 +    targetTouches: [touch],
    1.80 +    changedTouches: [touch]
    1.81 +  });
    1.82 +  return event;
    1.83 +}
    1.84 +
    1.85 +function getMultiTouchEventForTarget(target, cwu) {
    1.86 +  currentId++;
    1.87 +  var bcr = target.getBoundingClientRect();
    1.88 +  var touch1 = new testtouch({
    1.89 +    page: {x: Math.round(bcr.left + bcr.width/2),
    1.90 +           y: Math.round(bcr.top  + bcr.height/2)},
    1.91 +    target: target,
    1.92 +    identifier: currentId,
    1.93 +  });
    1.94 +  currentId++;
    1.95 +  var touch2 = new testtouch({
    1.96 +    page: {x: Math.round(bcr.left + bcr.width),
    1.97 +           y: Math.round(bcr.top  + bcr.height)},
    1.98 +    target: target,
    1.99 +    identifier: currentId,
   1.100 +  });
   1.101 +  var event = new touchEvent({
   1.102 +    touches: [touch1, touch2],
   1.103 +    targetTouches: [touch1, touch2],
   1.104 +    changedTouches: [touch1, touch2]
   1.105 +  });
   1.106 +  return event;
   1.107 +}
   1.108 +
   1.109 +function runTests() {
   1.110 +  var cwu = SpecialPowers.getDOMWindowUtils(window);
   1.111 +
   1.112 +  var event1 = getMultiTouchEventForTarget(d0, cwu);
   1.113 +  sendTouchEvent(cwu, "touchstart", event1, 0);
   1.114 +  sendTouchEvent(cwu, "touchmove", event1, 0);
   1.115 +  is(evictedTouchesCount, 0, "Still no evicted touches");
   1.116 +
   1.117 +  var event2 = getSingleTouchEventForTarget(d0, cwu);
   1.118 +  sendTouchEvent(cwu, "touchstart", event2, 0);
   1.119 +
   1.120 +  // By now we should get touchend event
   1.121 +  ok(evictedTouchesCount > 0, "Got evicted touch");
   1.122 +
   1.123 +  finishTest();
   1.124 +}
   1.125 +
   1.126 +function finishTest() {
   1.127 +  // Let window.onerror have a chance to fire
   1.128 +  setTimeout(function() {
   1.129 +    SimpleTest.finish();
   1.130 +  }, 0);
   1.131 +}
   1.132 +
   1.133 +SimpleTest.waitForExplicitFinish();
   1.134 +
   1.135 +  </script>
   1.136 +</head>
   1.137 +<body>
   1.138 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=993936">Mozilla Bug 993936</a>
   1.139 +<p id="display"></p>
   1.140 +<div id="content" style="display: none">
   1.141 +
   1.142 +</div>
   1.143 +<pre id="test">
   1.144 +</pre>
   1.145 +<div id="d0">
   1.146 +    Test div
   1.147 +</div>
   1.148 +
   1.149 +<script>
   1.150 +var d0 = document.getElementById("d0");
   1.151 +
   1.152 +d0.addEventListener("touchend", function(ev) {
   1.153 +  evictedTouchesCount++;
   1.154 +});
   1.155 +
   1.156 +window.onload = function () {
   1.157 +  setTimeout(function() {
   1.158 +    runTests();
   1.159 +  }, 0);
   1.160 +}
   1.161 +
   1.162 +</script>
   1.163 +</body>
   1.164 +</html>

mercurial