tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug993936.html (4450B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=993936
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 993936</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11  <script type="application/javascript">
     12 
     13  /** Test for Bug 993936 */
     14 
     15 var currentId = 0;
     16 var evictedTouchesCount = 0;
     17 
     18 function testtouch(aOptions) {
     19  if (!aOptions)
     20    aOptions = {};
     21  this.identifier = aOptions.identifier || 0;
     22  this.target = aOptions.target || 0;
     23  this.page = aOptions.page || {x: 0, y: 0};
     24  this.radius = aOptions.radius || {x: 0, y: 0};
     25  this.rotationAngle = aOptions.rotationAngle || 0;
     26  this.force = aOptions.force || 1;
     27 }
     28 
     29 function touchEvent(aOptions) {
     30  if (!aOptions) {
     31    aOptions = {};
     32  }
     33  this.ctrlKey = aOptions.ctrlKey || false;
     34  this.altKey = aOptions.altKey || false;
     35  this.shiftKey = aOptions.shiftKey || false;
     36  this.metaKey = aOptions.metaKey || false;
     37  this.touches = aOptions.touches || [];
     38  this.targetTouches = aOptions.targetTouches || [];
     39  this.changedTouches = aOptions.changedTouches || [];
     40 }
     41 
     42 function sendTouchEvent(windowUtils, aType, aEvent, aModifiers) {
     43  var ids = [], xs=[], ys=[], rxs = [], rys = [],
     44      rotations = [], forces = [], tiltXs = [], tiltYs = [], twists = [];
     45 
     46  for (var touchType of ["touches", "changedTouches", "targetTouches"]) {
     47    for (var i = 0; i < aEvent[touchType].length; i++) {
     48      if (!ids.includes(aEvent[touchType][i].identifier)) {
     49        ids.push(aEvent[touchType][i].identifier);
     50        xs.push(aEvent[touchType][i].page.x);
     51        ys.push(aEvent[touchType][i].page.y);
     52        rxs.push(aEvent[touchType][i].radius.x);
     53        rys.push(aEvent[touchType][i].radius.y);
     54        rotations.push(aEvent[touchType][i].rotationAngle);
     55        forces.push(aEvent[touchType][i].force);
     56        tiltXs.push(0);
     57        tiltYs.push(0);
     58        twists.push(0);
     59      }
     60    }
     61  }
     62  return windowUtils.sendTouchEvent(aType,
     63                                    ids, xs, ys, rxs, rys,
     64                                    rotations, forces, tiltXs, tiltYs, twists,
     65                                    aModifiers);
     66 }
     67 
     68 function getSingleTouchEventForTarget(target, cwu) {
     69  currentId++;
     70  var bcr = target.getBoundingClientRect();
     71  var touch = new testtouch({
     72    page: {x: Math.round(bcr.left + bcr.width/2),
     73           y: Math.round(bcr.top  + bcr.height/2)},
     74    target: target,
     75    identifier: currentId,
     76  });
     77  var event = new touchEvent({
     78    touches: [touch],
     79    targetTouches: [touch],
     80    changedTouches: [touch]
     81  });
     82  return event;
     83 }
     84 
     85 function getMultiTouchEventForTarget(target, cwu) {
     86  currentId++;
     87  var bcr = target.getBoundingClientRect();
     88  var touch1 = new testtouch({
     89    page: {x: Math.round(bcr.left + bcr.width/2),
     90           y: Math.round(bcr.top  + bcr.height/2)},
     91    target: target,
     92    identifier: currentId,
     93  });
     94  currentId++;
     95  var touch2 = new testtouch({
     96    page: {x: Math.round(bcr.left + bcr.width),
     97           y: Math.round(bcr.top  + bcr.height)},
     98    target: target,
     99    identifier: currentId,
    100  });
    101  var event = new touchEvent({
    102    touches: [touch1, touch2],
    103    targetTouches: [touch1, touch2],
    104    changedTouches: [touch1, touch2]
    105  });
    106  return event;
    107 }
    108 
    109 function runTests() {
    110  var cwu = SpecialPowers.getDOMWindowUtils(window);
    111 
    112  var event1 = getMultiTouchEventForTarget(d0, cwu);
    113  sendTouchEvent(cwu, "touchstart", event1, 0);
    114  sendTouchEvent(cwu, "touchmove", event1, 0);
    115  is(evictedTouchesCount, 0, "Still no evicted touches");
    116 
    117  var event2 = getSingleTouchEventForTarget(d0, cwu);
    118  sendTouchEvent(cwu, "touchstart", event2, 0);
    119 
    120  // By now we should get touchend event
    121  ok(evictedTouchesCount > 0, "Got evicted touch");
    122 
    123  finishTest();
    124 }
    125 
    126 function finishTest() {
    127  // Let window.onerror have a chance to fire
    128  setTimeout(function() {
    129    SimpleTest.finish();
    130  }, 0);
    131 }
    132 
    133 SimpleTest.waitForExplicitFinish();
    134 
    135  </script>
    136 </head>
    137 <body>
    138 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=993936">Mozilla Bug 993936</a>
    139 <p id="display"></p>
    140 <div id="content" style="display: none">
    141 
    142 </div>
    143 <pre id="test">
    144 </pre>
    145 <div id="d0">
    146    Test div
    147 </div>
    148 
    149 <script>
    150 var d0 = document.getElementById("d0");
    151 
    152 d0.addEventListener("touchend", function(ev) {
    153  evictedTouchesCount++;
    154 });
    155 
    156 window.onload = function () {
    157  setTimeout(function() {
    158    runTests();
    159  }, 0);
    160 }
    161 
    162 </script>
    163 </body>
    164 </html>