dom/events/test/test_bug603008.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_bug603008.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,553 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=508906
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 603008</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=508906">Mozilla Bug 603008</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none">
    1.18 +  
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script class="testbody" type="application/javascript;version=1.8">
    1.22 +
    1.23 +/** Test for Bug 306008 - Touch* Events **/
    1.24 +
    1.25 +let tests = [], testTarget, parent;
    1.26 +
    1.27 +let touch = {
    1.28 +  id: 0,
    1.29 +  point: {x: 0, y: 0},
    1.30 +  radius: {x: 0, y: 0},
    1.31 +  rotation: 0,
    1.32 +  force: 0.5,
    1.33 +  target: null
    1.34 +}
    1.35 +
    1.36 +function nextTest() {
    1.37 +  if (tests.length)
    1.38 +    SimpleTest.executeSoon(tests.shift());
    1.39 +}
    1.40 +
    1.41 +function random() {
    1.42 +  return Math.floor(Math.random() * 100);
    1.43 +}
    1.44 +
    1.45 +function checkEvent(aFakeEvent) {
    1.46 +  return function(aEvent) {
    1.47 +    is(aFakeEvent.ctrlKey, aEvent.ctrlKey, "Correct ctrlKey");
    1.48 +    is(aFakeEvent.altKey, aEvent.altKey, "Correct altKey");
    1.49 +    is(aFakeEvent.shiftKey, aEvent.shiftKey, "Correct shiftKey");
    1.50 +    is(aFakeEvent.metaKey, aEvent.metaKey, "Correct metaKey");
    1.51 +    checkTouches(aFakeEvent.touches, aEvent.touches);
    1.52 +    checkTouches(aFakeEvent.targetTouches, aEvent.targetTouches);
    1.53 +    checkTouches(aFakeEvent.changedTouches, aEvent.changedTouches);
    1.54 +  }
    1.55 +}
    1.56 +
    1.57 +function checkTouches(aTouches1, aTouches2) {
    1.58 +  is(aTouches1.length, aTouches2.length, "Correct touches length");
    1.59 +  for (var i = 0; i < aTouches1.length; i++) {
    1.60 +    checkTouch(aTouches1[i], aTouches2[i]);
    1.61 +  }
    1.62 +}
    1.63 +
    1.64 +function checkTouch(aFakeTouch, aTouch) {
    1.65 +  is(aFakeTouch.identifier, aTouch.identifier, "Touch has correct identifier");
    1.66 +  is(aFakeTouch.target, aTouch.target, "Touch has correct target");
    1.67 +  is(aFakeTouch.page.x, aTouch.pageX, "Touch has correct pageX");
    1.68 +  is(aFakeTouch.page.y, aTouch.pageY, "Touch has correct pageY");
    1.69 +  is(aFakeTouch.page.x + Math.round(window.mozInnerScreenX), aTouch.screenX, "Touch has correct screenX");
    1.70 +  is(aFakeTouch.page.y + Math.round(window.mozInnerScreenY), aTouch.screenY, "Touch has correct screenY");
    1.71 +  is(aFakeTouch.page.x, aTouch.clientX, "Touch has correct clientX");
    1.72 +  is(aFakeTouch.page.y, aTouch.clientY, "Touch has correct clientY");
    1.73 +  is(aFakeTouch.radius.x, aTouch.radiusX, "Touch has correct radiusX");
    1.74 +  is(aFakeTouch.radius.y, aTouch.radiusY, "Touch has correct radiusY");
    1.75 +  is(aFakeTouch.rotationAngle, aTouch.rotationAngle, "Touch has correct rotationAngle");
    1.76 +  is(aFakeTouch.force, aTouch.force, "Touch has correct force");
    1.77 +}
    1.78 +
    1.79 +function sendTouchEvent(windowUtils, aType, aEvent, aModifiers) {
    1.80 +  var ids = [], xs=[], ys=[], rxs = [], rys = [],
    1.81 +      rotations = [], forces = [];
    1.82 +
    1.83 +  for (var touchType of ["touches", "changedTouches", "targetTouches"]) {
    1.84 +    for (var i = 0; i < aEvent[touchType].length; i++) {
    1.85 +      if (ids.indexOf(aEvent[touchType][i].identifier) == -1) {
    1.86 +        ids.push(aEvent[touchType][i].identifier);
    1.87 +        xs.push(aEvent[touchType][i].page.x);
    1.88 +        ys.push(aEvent[touchType][i].page.y);
    1.89 +        rxs.push(aEvent[touchType][i].radius.x);
    1.90 +        rys.push(aEvent[touchType][i].radius.y);
    1.91 +        rotations.push(aEvent[touchType][i].rotationAngle);
    1.92 +        forces.push(aEvent[touchType][i].force);
    1.93 +      }
    1.94 +    }
    1.95 +  }
    1.96 +  return windowUtils.sendTouchEvent(aType,
    1.97 +                                    ids, xs, ys, rxs, rys,
    1.98 +                                    rotations, forces,
    1.99 +                                    ids.length, aModifiers, 0);
   1.100 +}
   1.101 +
   1.102 +function touchEvent(aOptions) {
   1.103 +  if (!aOptions) {
   1.104 +    aOptions = {};
   1.105 +  }
   1.106 +  this.ctrlKey = aOptions.ctrlKey || false;
   1.107 +  this.altKey = aOptions.altKey || false;
   1.108 +  this.shiftKey = aOptions.shiftKey || false;
   1.109 +  this.metaKey = aOptions.metaKey || false;
   1.110 +  this.touches = aOptions.touches || [];
   1.111 +  this.targetTouches = aOptions.targetTouches || [];
   1.112 +  this.changedTouches = aOptions.changedTouches || [];
   1.113 +}
   1.114 +
   1.115 +function testtouch(aOptions) {
   1.116 +  if (!aOptions)
   1.117 +    aOptions = {};
   1.118 +  this.identifier = aOptions.identifier || 0;
   1.119 +  this.target = aOptions.target || 0;
   1.120 +  this.page = aOptions.page || {x: 0, y: 0};
   1.121 +  this.radius = aOptions.radius || {x: 0, y: 0};
   1.122 +  this.rotationAngle = aOptions.rotationAngle || 0;
   1.123 +  this.force = aOptions.force || 1;
   1.124 +}
   1.125 +
   1.126 +function testSingleTouch(name) {
   1.127 +  let cwu = SpecialPowers.getDOMWindowUtils(window);
   1.128 +  let target = document.getElementById("testTarget");
   1.129 +  let target2 = document.getElementById("testTarget2");
   1.130 +  let bcr = target.getBoundingClientRect();
   1.131 +  let bcr2 = target2.getBoundingClientRect();
   1.132 +
   1.133 +  let touch1 = new testtouch({
   1.134 +    page: {x: Math.round(bcr.left + bcr.width/2),
   1.135 +           y: Math.round(bcr.top  + bcr.height/2)},
   1.136 +    target: target
   1.137 +  });
   1.138 +  let event = new touchEvent({
   1.139 +    touches: [touch1],
   1.140 +    targetTouches: [touch1],
   1.141 +    changedTouches: [touch1]
   1.142 +  });
   1.143 +
   1.144 +  // test touchstart event fires correctly
   1.145 +  var checkFunction = checkEvent(event);
   1.146 +  window.addEventListener("touchstart", checkFunction, false);
   1.147 +  sendTouchEvent(cwu, "touchstart", event, 0);
   1.148 +  window.removeEventListener("touchstart", checkFunction, false);
   1.149 +
   1.150 +  // test touchmove event fires correctly
   1.151 +  event.touches[0].page.x -= 1;
   1.152 +  event.targetTouches[0].page.x -= 1;
   1.153 +  event.changedTouches[0].page.x -= 1;
   1.154 +  checkFunction = checkEvent(event);
   1.155 +  window.addEventListener("touchmove", checkFunction, false);
   1.156 +  sendTouchEvent(cwu, "touchmove", event, 0);
   1.157 +  window.removeEventListener("touchmove", checkFunction, false);
   1.158 +
   1.159 +  // test touchend event fires correctly
   1.160 +  event.touches = [];
   1.161 +  event.targetTouches = [];
   1.162 +  checkFunction = checkEvent(event);
   1.163 +  window.addEventListener("touchend", checkFunction, false);
   1.164 +  sendTouchEvent(cwu, "touchend", event, 0);
   1.165 +  window.removeEventListener("touchend", checkFunction, false);
   1.166 +
   1.167 +  nextTest();
   1.168 +}
   1.169 +
   1.170 +function testSingleTouch2(name) {
   1.171 +  // firing a touchstart that includes only one touch will evict any touches in the queue with touchend messages
   1.172 +  let cwu = SpecialPowers.getDOMWindowUtils(window);
   1.173 +  let target = document.getElementById("testTarget");
   1.174 +  let target2 = document.getElementById("testTarget2");
   1.175 +  let bcr = target.getBoundingClientRect();
   1.176 +  let bcr2 = target2.getBoundingClientRect();
   1.177 +
   1.178 +  let touch1 = new testtouch({
   1.179 +    identifier: 0,
   1.180 +    page: {x: Math.round(bcr.left + bcr.width/2),
   1.181 +           y: Math.round(bcr.top  + bcr.height/2)},
   1.182 +    target: target
   1.183 +  });
   1.184 +  let event1 = new touchEvent({
   1.185 +    touches: [touch1],
   1.186 +    targetTouches: [touch1],
   1.187 +    changedTouches: [touch1]
   1.188 +  });
   1.189 +  let touch2 = new testtouch({
   1.190 +    identifier: 1,
   1.191 +    page: {x: Math.round(bcr2.left + bcr2.width/2),
   1.192 +           y: Math.round(bcr2.top  + bcr2.height/2)},
   1.193 +    target: target2
   1.194 +  });
   1.195 +  let event2 = new touchEvent({
   1.196 +    touches: [touch2],
   1.197 +    targetTouches: [touch2],
   1.198 +    changedTouches: [touch2]
   1.199 +  });
   1.200 +
   1.201 +  // test touchstart event fires correctly
   1.202 +  var checkFunction1 = checkEvent(event1);
   1.203 +  window.addEventListener("touchstart", checkFunction1, false);
   1.204 +  sendTouchEvent(cwu, "touchstart", event1, 0);
   1.205 +  window.removeEventListener("touchstart", checkFunction1, false);
   1.206 +
   1.207 +  event1.touches = [];
   1.208 +  event1.targetTouches = [];
   1.209 +  checkFunction1 = checkEvent(event1);
   1.210 +  var checkFunction2 = checkEvent(event2);
   1.211 +
   1.212 +  window.addEventListener("touchend", checkFunction1, false);
   1.213 +  window.addEventListener("touchstart", checkFunction2, false);
   1.214 +  sendTouchEvent(cwu, "touchstart", event2, 0);
   1.215 +  window.removeEventListener("touchend", checkFunction1, false);
   1.216 +  window.removeEventListener("touchstart", checkFunction2, false);
   1.217 +
   1.218 +  sendTouchEvent(cwu, "touchstart", event1, 0);
   1.219 +
   1.220 +  nextTest();
   1.221 +}
   1.222 +
   1.223 +
   1.224 +function testMultiTouch(name) {
   1.225 +  let cwu = SpecialPowers.getDOMWindowUtils(window);
   1.226 +  let target1 = document.getElementById("testTarget");
   1.227 +  let target2 = document.getElementById("testTarget2");
   1.228 +  let bcr = target1.getBoundingClientRect();
   1.229 +  let bcr2 = target2.getBoundingClientRect();
   1.230 +
   1.231 +  let touch1 = new testtouch({
   1.232 +    identifier: 0,
   1.233 +    page: {x: Math.round(bcr.left + bcr.width/2),
   1.234 +           y: Math.round(bcr.top  + bcr.height/2)},
   1.235 +    target: target1
   1.236 +  });
   1.237 +  let touch2 = new testtouch({
   1.238 +    identifier: 1,
   1.239 +    page: {x: Math.round(bcr2.left + bcr2.width/2),
   1.240 +           y: Math.round(bcr2.top  + bcr2.height/2)},
   1.241 +    target: target2
   1.242 +  });
   1.243 +  let event = new touchEvent({
   1.244 +    touches: [touch1],
   1.245 +    targetTouches: [touch1],
   1.246 +    changedTouches: [touch1]
   1.247 +  });
   1.248 +
   1.249 +  // test touchstart event fires correctly
   1.250 +  var checkFunction = checkEvent(event);
   1.251 +  window.addEventListener("touchstart", checkFunction, false);
   1.252 +  sendTouchEvent(cwu, "touchstart", event, 0);
   1.253 +  window.removeEventListener("touchstart", checkFunction, false);
   1.254 +
   1.255 +  event.touches.push(touch2);
   1.256 +  event.targetTouches = [touch2];
   1.257 +  event.changedTouches = [touch2];
   1.258 +  window.addEventListener("touchstart", checkFunction, false);
   1.259 +  sendTouchEvent(cwu, "touchstart", event, 0);
   1.260 +  window.removeEventListener("touchstart", checkFunction, false);
   1.261 +
   1.262 +  // test moving one touch point
   1.263 +  event.touches[0].page.x -= 1;
   1.264 +  event.targetTouches = [event.touches[0]];
   1.265 +  event.changedTouches = [event.touches[0]];
   1.266 +  window.addEventListener("touchmove", checkFunction, false);
   1.267 +  sendTouchEvent(cwu, "touchmove", event, 0);
   1.268 +  window.removeEventListener("touchmove", checkFunction, false);
   1.269 +
   1.270 +  // test moving both touch points -- two touchmove events should fire, one on each target
   1.271 +  event.touches[0].page.x -= 1;
   1.272 +  event.touches[1].page.x -= 1;
   1.273 +  event.targetTouches = event.touches;
   1.274 +  event.changedTouches = event.touches;
   1.275 +  var touchMoveEvents = 0;
   1.276 +  var checkFunction2 = function(aEvent) {
   1.277 +    is(event.ctrlKey, aEvent.ctrlKey, "Correct ctrlKey");
   1.278 +    is(event.altKey, aEvent.altKey, "Correct altKey");
   1.279 +    is(event.shiftKey, aEvent.shiftKey, "Correct shiftKey");
   1.280 +    is(event.metaKey, aEvent.metaKey, "Correct metaKey");
   1.281 +    checkTouches(event.touches, aEvent.touches);
   1.282 +    checkTouches(event.changedTouches, aEvent.changedTouches);
   1.283 +    if (aEvent.targetTouches[0].target == target1) {
   1.284 +      checkTouches([event.touches[0]], aEvent.targetTouches);
   1.285 +    } else if (aEvent.targetTouches[0].target == target2) {
   1.286 +      checkTouches([event.touches[1]], aEvent.targetTouches);
   1.287 +    } else
   1.288 +      ok(false, "Event target is incorrect: " + event.targetTouches[0].target.nodeName + "#" + event.targetTouches[0].target.id);
   1.289 +    touchMoveEvents++;
   1.290 +  };
   1.291 +  window.addEventListener("touchmove", checkFunction2, false);
   1.292 +  sendTouchEvent(cwu, "touchmove", event, 0);
   1.293 +  ok(touchMoveEvents, 2, "Correct number of touchmove events fired");
   1.294 +  window.removeEventListener("touchmove", checkFunction2, false);
   1.295 +
   1.296 +  // test removing just one finger
   1.297 +  var expected = new touchEvent({
   1.298 +    touches: [touch2],
   1.299 +    targetTouches: [],
   1.300 +    changedTouches: [touch1]
   1.301 +  });
   1.302 +  checkFunction = checkEvent(expected);
   1.303 +
   1.304 +  event.touches = [];
   1.305 +  event.targetTouches = [];
   1.306 +  event.changedTouches = [touch1];
   1.307 +
   1.308 +  // test removing the other finger
   1.309 +  window.addEventListener("touchend", checkFunction, false);
   1.310 +  sendTouchEvent(cwu, "touchend", event, 0);
   1.311 +  window.removeEventListener("touchend", checkFunction, false);
   1.312 +
   1.313 +  event.touches = [];
   1.314 +  event.targetTouches = [];
   1.315 +  event.changedTouches = [touch2];
   1.316 +  checkFunction = checkEvent(event);
   1.317 +  window.addEventListener("touchend", checkFunction, false);
   1.318 +  sendTouchEvent(cwu, "touchend", event, 0);
   1.319 +  window.removeEventListener("touchend", checkFunction, false);
   1.320 +
   1.321 +  nextTest();
   1.322 +}
   1.323 +
   1.324 +function testTouchChanged() {
   1.325 +  let cwu = SpecialPowers.getDOMWindowUtils(window);
   1.326 +  let target1 = document.getElementById("testTarget");
   1.327 +  let bcr = target1.getBoundingClientRect();
   1.328 +
   1.329 +  let touch1 = new testtouch({
   1.330 +    identifier: 0,
   1.331 +    page: {x: Math.round(bcr.left + bcr.width/2),
   1.332 +           y: Math.round(bcr.top  + bcr.height/2)},
   1.333 +    target: target1
   1.334 +  });
   1.335 +  let event = new touchEvent({
   1.336 +    touches: [touch1],
   1.337 +    targetTouches: [touch1],
   1.338 +    changedTouches: [touch1]
   1.339 +  });
   1.340 +
   1.341 +  var checkFunction = checkEvent(event);
   1.342 +  sendTouchEvent(cwu, "touchstart", event, 0);
   1.343 +
   1.344 +  var moveEvents = 0;
   1.345 +  function onMove(aEvent) {
   1.346 +    moveEvents++;
   1.347 +  }
   1.348 +
   1.349 +  window.addEventListener("touchmove", onMove, false);
   1.350 +
   1.351 +  // changing nothing should not fire a touchmove event
   1.352 +  sendTouchEvent(cwu, "touchmove", event, 0);
   1.353 +
   1.354 +  // test moving x
   1.355 +  event.touches[0].page.x -= 1;
   1.356 +  sendTouchEvent(cwu, "touchmove", event, 0);
   1.357 +
   1.358 +  // test moving y
   1.359 +  event.touches[0].page.y -= 1;
   1.360 +  sendTouchEvent(cwu, "touchmove", event, 0);
   1.361 +
   1.362 +  // test changing y radius
   1.363 +  event.touches[0].radius.y += 1;
   1.364 +  sendTouchEvent(cwu, "touchmove", event, 0);
   1.365 +  
   1.366 +  // test changing x radius
   1.367 +  event.touches[0].radius.x += 1;
   1.368 +  sendTouchEvent(cwu, "touchmove", event, 0);
   1.369 +
   1.370 +  // test changing rotationAngle
   1.371 +  event.touches[0].rotationAngle += 1;
   1.372 +  sendTouchEvent(cwu, "touchmove", event, 0);
   1.373 +
   1.374 +  // test changing force
   1.375 +  event.touches[0].force += 1;
   1.376 +  sendTouchEvent(cwu, "touchmove", event, 0);
   1.377 +
   1.378 +  // changing nothing again
   1.379 +  sendTouchEvent(cwu, "touchmove", event, 0);
   1.380 +  
   1.381 +  is(moveEvents, 6, "Six move events fired");
   1.382 +
   1.383 +  window.removeEventListener("touchmove", onMove, false);
   1.384 +  sendTouchEvent(cwu, "touchend", event, 0);
   1.385 +  nextTest();
   1.386 +}
   1.387 +
   1.388 +function testPreventDefault() {
   1.389 +  let cwu = SpecialPowers.getDOMWindowUtils(window);
   1.390 +  let target = document.getElementById("testTarget");
   1.391 +  let target2 = document.getElementById("testTarget2");
   1.392 +  let bcr = target.getBoundingClientRect();
   1.393 +  let bcr2 = target2.getBoundingClientRect();
   1.394 +
   1.395 +  let touch1 = new testtouch({
   1.396 +    page: {x: bcr.left + bcr.width/2,
   1.397 +           y: bcr.top + bcr.height/2},
   1.398 +    target: target
   1.399 +  });
   1.400 +  let event = new touchEvent({
   1.401 +    touches: [touch1],
   1.402 +    targetTouches: [touch1],
   1.403 +    changedTouches: [touch1]
   1.404 +  });
   1.405 +
   1.406 +  let preventFunction = function(aEvent) {
   1.407 +    aEvent.preventDefault();
   1.408 +  }
   1.409 +  
   1.410 +  let tests = [
   1.411 +    [{ name: "touchstart", prevent: false },
   1.412 +     { name: "touchmove", prevent: false },
   1.413 +     { name: "touchmove", prevent: false },
   1.414 +     { name: "touchend", prevent: false }],
   1.415 +    [{ name: "touchstart", prevent: true, doPrevent: true },
   1.416 +     { name: "touchmove", prevent: true },
   1.417 +     { name: "touchmove", prevent: true },
   1.418 +     { name: "touchend", prevent: true }],
   1.419 +    [{ name: "touchstart", prevent: false },
   1.420 +     { name: "touchmove", prevent: true, doPrevent: true },
   1.421 +     { name: "touchmove", prevent: true },
   1.422 +     { name: "touchend", prevent: true }],
   1.423 +    [{ name: "touchstart", prevent: false },
   1.424 +     { name: "touchmove", prevent: false },
   1.425 +     { name: "touchmove", prevent: false, doPrevent: true },
   1.426 +     { name: "touchend", prevent: false }],
   1.427 +    [{ name: "touchstart", prevent: false },
   1.428 +     { name: "touchmove", prevent: false },
   1.429 +     { name: "touchmove", prevent: false },
   1.430 +     { name: "touchend", prevent: false, doPrevent: true }]
   1.431 +  ];
   1.432 +
   1.433 +  var dotest = function(aTest) {
   1.434 +    if (aTest.doPrevent) {
   1.435 +      target.addEventListener(aTest.name, preventFunction, false);
   1.436 +    }
   1.437 +
   1.438 +    if (aTest.name == "touchmove") {
   1.439 +      touch1.page.x++;
   1.440 +      event.touches[0] = touch1;
   1.441 +    }
   1.442 +
   1.443 +    is(sendTouchEvent(cwu, aTest.name, event, 0), aTest.prevent, "Got correct status");
   1.444 +
   1.445 +    if (aTest.doPrevent)
   1.446 +      target.removeEventListener(aTest.name, preventFunction, false);
   1.447 +  }
   1.448 +
   1.449 +  for (var i = 0; i < tests.length; i++) {
   1.450 +    for (var j = 0; j < tests[i].length; j++) {
   1.451 +      dotest(tests[i][j]);
   1.452 +    }
   1.453 +  } 
   1.454 +
   1.455 +  nextTest();
   1.456 +}
   1.457 +
   1.458 +function testRemovingElement() {
   1.459 +  let cwu = SpecialPowers.getDOMWindowUtils(window);
   1.460 +  let target = document.getElementById("testTarget");
   1.461 +  let bcr = document.getElementById("testTarget").getBoundingClientRect();
   1.462 +
   1.463 +  let touch1 = new testtouch({
   1.464 +    page: {x: bcr.left + bcr.width/2,
   1.465 +           y: bcr.top + bcr.height/2},
   1.466 +  });
   1.467 +  let e = new touchEvent({
   1.468 +    touches: [touch1],
   1.469 +    targetTouches: [touch1],
   1.470 +    changedTouches: [touch1]
   1.471 +  });
   1.472 +
   1.473 +  var touchEvents = 0;  
   1.474 +  var removeTarget = function(aEvent) {
   1.475 +    aEvent.target.parentNode.removeChild(aEvent.target);
   1.476 +  };
   1.477 +
   1.478 +  var checkTarget = function(aEvent) {
   1.479 +    is(aEvent.target, target, "Event has correct target");
   1.480 +    touchEvents++;
   1.481 +  };
   1.482 +
   1.483 +  target.addEventListener("touchstart", removeTarget, false);
   1.484 +  target.addEventListener("touchmove", checkTarget, false);
   1.485 +  target.addEventListener("touchend", checkTarget, false);
   1.486 +
   1.487 +  sendTouchEvent(cwu, "touchstart", e, 0);
   1.488 +
   1.489 +  e.touches[0].page.x++;
   1.490 +  sendTouchEvent(cwu, "touchmove", e, 0);
   1.491 +  sendTouchEvent(cwu, "touchend", e, 0);
   1.492 +
   1.493 +  target.removeEventListener("touchstart", removeTarget, false);
   1.494 +  target.removeEventListener("touchmove", checkTarget, false);
   1.495 +  target.removeEventListener("touchend", checkTarget, false);
   1.496 +
   1.497 +  is(touchEvents, 2, "Check target was called twice");
   1.498 +
   1.499 +  nextTest();
   1.500 +}
   1.501 +
   1.502 +function testNAC() {
   1.503 +  let cwu = SpecialPowers.getDOMWindowUtils(window);
   1.504 +  let target = document.getElementById("testTarget3");
   1.505 +  let bcr = target.getBoundingClientRect();
   1.506 +
   1.507 +  let touch1 = new testtouch({
   1.508 +    page: {x: Math.round(bcr.left + bcr.width/2),
   1.509 +           y: Math.round(bcr.top  + bcr.height/2)},
   1.510 +    target: target
   1.511 +  });
   1.512 +  let event = new touchEvent({
   1.513 +    touches: [touch1],
   1.514 +    targetTouches: [touch1],
   1.515 +    changedTouches: [touch1]
   1.516 +  });
   1.517 +
   1.518 +  // test touchstart event fires correctly
   1.519 +  var checkFunction = checkEvent(event);
   1.520 +  window.addEventListener("touchstart", checkFunction, false);
   1.521 +  sendTouchEvent(cwu, "touchstart", event, 0);
   1.522 +  window.removeEventListener("touchstart", checkFunction, false);
   1.523 +
   1.524 +  sendTouchEvent(cwu, "touchend", event, 0);
   1.525 +
   1.526 +  nextTest();
   1.527 +}
   1.528 +
   1.529 +function doTest() {
   1.530 +  tests.push(testSingleTouch);
   1.531 +  tests.push(testSingleTouch2);
   1.532 +  tests.push(testMultiTouch);
   1.533 +  tests.push(testPreventDefault);
   1.534 +  tests.push(testTouchChanged);
   1.535 +  tests.push(testRemovingElement);
   1.536 +  tests.push(testNAC);
   1.537 +
   1.538 +  tests.push(function() {
   1.539 +    SimpleTest.finish();
   1.540 +  });
   1.541 +
   1.542 +  nextTest();
   1.543 +}
   1.544 +
   1.545 +SimpleTest.waitForExplicitFinish();
   1.546 +addLoadEvent(doTest);
   1.547 +
   1.548 +</script>
   1.549 +</pre>
   1.550 +<div id="parent">
   1.551 +  <span id="testTarget" style="padding: 5px; border: 1px solid black;">testTarget</span>
   1.552 +  <span id="testTarget2" style="padding: 5px; border: 1px solid blue;">testTarget</span>
   1.553 +  <input type="text" id="testTarget3">
   1.554 +</div>
   1.555 +</body>
   1.556 +</html>

mercurial