tor-browser

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

bug968148_inner2.html (11289B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=968148
      5 -->
      6 <head>
      7  <title>Test for Bug 968148</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     10  <style>
     11  .test {
     12    width: 20px;
     13    height: 20px;
     14    border: 1px solid black;
     15    -moz-user-select: none;
     16  }
     17  </style>
     18 </head>
     19 <body>
     20 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=968148">Mozilla Bug 968148</a>
     21 <p id="display"></p>
     22 <div id="content" style="display: none">
     23 </div>
     24 <pre id="test">
     25 <script type="application/javascript">
     26 
     27 /**
     28 * Test for Bug 968148, test orignally copied from test_bug582771.html.
     29 * Mouse functionality converted to pointer and all steps duplicated in order to run them in parallel for two different pointer Id's
     30 */
     31 
     32 function ok(condition, msg) {
     33  parent.ok(condition, msg);
     34 }
     35 
     36 function is(a, b, msg) {
     37  parent.is(a, b, msg);
     38 }
     39 
     40 var test1d1;
     41 var test1d2;
     42 var test2d1;
     43 var test2d2;
     44 var test1d1pointermovecount = 0;
     45 var test1d2pointermovecount = 0;
     46 var test2d1pointermovecount = 0;
     47 var test2d2pointermovecount = 0;
     48 
     49 var test1d1pointerlostcapture = 0;
     50 var test1d2pointerlostcapture = 0;
     51 var test2d1pointerlostcapture = 0;
     52 var test2d2pointerlostcapture = 0;
     53 var test1d1pointergotcapture = 0;
     54 var test1d2pointergotcapture = 0;
     55 var test2d1pointergotcapture = 0;
     56 var test2d2pointergotcapture = 0;
     57 var test1PointerId = 1;
     58 var test2PointerId = 2;
     59 var rx = 1;
     60 var ry = 1;
     61 var angle = 0;
     62 var force = 1;
     63 var modifiers = 0;
     64 var utils = SpecialPowers.getDOMWindowUtils(window);
     65 
     66 function log(s) {
     67  document.getElementById("l").textContent += s + "\n";
     68 }
     69 
     70 function test1d1IncreasePointerMoveCount(e) {
     71  log(e.type + ", " + e.target.id);
     72  is(e.target, test1d1, "check target is 1d1.");
     73  ++test1d1pointermovecount;
     74 }
     75 
     76 function test1d2IncreasePointerMoveCount(e) {
     77  log(e.type + ", " + e.target.id);
     78  is(e.target, test1d2, "check target is 1d2.");
     79  ++test1d2pointermovecount;
     80 }
     81 
     82 function test2d1IncreasePointerMoveCount(e) {
     83  log(e.type + ", " + e.target.id);
     84  is(e.target, test2d1, "check target is 2d1.");
     85  ++test2d1pointermovecount;
     86 }
     87 
     88 function test2d2IncreasePointerMoveCount(e) {
     89  log(e.type + ", " + e.target.id);
     90  is(e.target, test2d2, "check target is 2d2.");
     91  ++test2d2pointermovecount;
     92 }
     93 
     94 function test1d1CapturePointer(e) {
     95  log(e.type + ", " + e.target.id);
     96  test1d1.setPointerCapture(e.pointerId);
     97 }
     98 
     99 function test1d2CapturePointer(e) {
    100  log(e.type + ", " + e.target.id);
    101  test1d2.setPointerCapture(e.pointerId);
    102 }
    103 
    104 function test2d1CapturePointer(e) {
    105  log(e.type + ", " + e.target.id);
    106  test2d1.setPointerCapture(e.pointerId);
    107 }
    108 
    109 function test2d2CapturePointer(e) {
    110  log(e.type + ", " + e.target.id);
    111  test2d2.setPointerCapture(e.pointerId);
    112 }
    113 
    114 function test1d1PointerGotCapture(e) {
    115  log(e.type + ", " + e.target.id);
    116  ++test1d1pointergotcapture;
    117 }
    118 
    119 function test1d1PointerLostCapture(e) {
    120  log(e.type + ", " + e.target.id);
    121  ++test1d1pointerlostcapture;
    122 }
    123 
    124 function test2d1PointerGotCapture(e) {
    125  log(e.type + ", " + e.target.id);
    126  ++test2d1pointergotcapture;
    127 }
    128 
    129 function test2d1PointerLostCapture(e) {
    130  log(e.type + ", " + e.target.id);
    131  ++test2d1pointerlostcapture;
    132 }
    133 
    134 function test1d2PointerGotCapture(e) {
    135  log(e.type + ", " + e.target.id);
    136  ++test1d2pointergotcapture;
    137 }
    138 
    139 function test1d2PointerLostCapture(e) {
    140  log(e.type + ", " + e.target.id);
    141  ++test1d2pointerlostcapture;
    142 }
    143 
    144 function test2d2PointerGotCapture(e) {
    145  log(e.type + ", " + e.target.id);
    146  ++test2d2pointergotcapture;
    147 }
    148 
    149 function test2d2PointerLostCapture(e) {
    150  log(e.type + ", " + e.target.id);
    151  ++test2d2pointerlostcapture;
    152 }
    153 
    154 function runTests() {
    155  test1d1 = document.getElementById("test1d1");
    156  test1d2 = document.getElementById("test1d2");
    157  test2d1 = document.getElementById("test2d1");
    158  test2d2 = document.getElementById("test2d2");
    159 
    160  var rect1d1 = test1d1.getBoundingClientRect();
    161  var rect1d2 = test1d2.getBoundingClientRect();
    162  var rect2d1 = test2d1.getBoundingClientRect();
    163  var rect2d2 = test2d2.getBoundingClientRect();
    164 
    165  var left1d1 = rect1d1.left + 5;
    166  var top1d1 = rect1d1.top + 5;
    167  var left1d2 = rect1d2.left + 5;
    168  var top1d2 = rect1d2.top + 5;
    169  var left2d1 = rect2d1.left + 5;
    170  var top2d1 = rect2d1.top + 5;
    171  var left2d2 = rect2d2.left + 5;
    172  var top2d2 = rect2d2.top + 5;
    173 
    174  test1d1.addEventListener("pointermove", test1d1IncreasePointerMoveCount, true);
    175  test1d2.addEventListener("pointermove", test1d2IncreasePointerMoveCount, true);
    176  test2d1.addEventListener("pointermove", test2d1IncreasePointerMoveCount, true);
    177  test2d2.addEventListener("pointermove", test2d2IncreasePointerMoveCount, true);
    178 
    179  test1d1.addEventListener("gotpointercapture", test1d1PointerGotCapture, true);
    180  test1d1.addEventListener("lostpointercapture", test1d1PointerLostCapture, true);
    181 
    182  test2d1.addEventListener("gotpointercapture", test2d1PointerGotCapture, true);
    183  test2d1.addEventListener("lostpointercapture", test2d1PointerLostCapture, true);
    184 
    185  test1d2.addEventListener("gotpointercapture", test1d2PointerGotCapture, true);
    186  test1d2.addEventListener("lostpointercapture", test1d2PointerLostCapture, true);
    187 
    188  test2d2.addEventListener("gotpointercapture", test2d2PointerGotCapture, true);
    189  test2d2.addEventListener("lostpointercapture", test2d2PointerLostCapture, true);
    190 
    191  document.body.offsetLeft;
    192 
    193  // This shouldn't enable capturing, since we're not in a right kind of
    194  // event listener.
    195  utils.sendTouchEvent('touchstart', [test1PointerId, test2PointerId],
    196                       [left1d1, left2d1], [top1d1, top2d1], [rx, rx], [ry, ry],
    197                       [angle, angle], [force, force], [0, 0], [0, 0],
    198                       [0, 0], modifiers);
    199 
    200  utils.sendTouchEvent('touchmove', [test1PointerId, test2PointerId],
    201                       [left1d2, left2d2], [top1d2, top2d2], [rx, rx], [ry, ry],
    202                       [angle, angle], [force, force], [0, 0], [0, 0],
    203                       [0, 0], modifiers);
    204 
    205  utils.sendTouchEvent('touchend', [test1PointerId, test2PointerId],
    206                       [left1d1, left2d1], [top1d1, top2d1], [rx, rx], [ry, ry],
    207                       [angle, angle], [force, force], [0, 0], [0, 0],
    208                       [0, 0], modifiers);
    209 
    210  // Implicitly pointer capture. pointermove should be dispatched to 1d1, 2d1
    211  is(test1d1pointermovecount, 1, "1d1 should have got pointermove");
    212  is(test2d1pointermovecount, 1, "2d1 should have got pointermove");
    213  is(test1d2pointermovecount, 0, "1d2 shouldn't have got pointermove");
    214  is(test2d2pointermovecount, 0, "2d2 shouldn't have got pointermove");
    215 
    216  // Explicitly capture pointer to 1d1, 2d1
    217  test1d1.addEventListener("pointerdown", test1d1CapturePointer, {capture: true, once: true});
    218  test2d1.addEventListener("pointerdown", test2d1CapturePointer, {capture: true, once: true});
    219 
    220  utils.sendTouchEvent('touchstart', [test1PointerId, test2PointerId],
    221                       [left1d1, left2d1], [top1d1, top2d1], [rx, rx], [ry, ry],
    222                       [angle, angle], [force, force], [0, 0], [0, 0],
    223                       [0, 0], modifiers);
    224 
    225  utils.sendTouchEvent('touchmove', [test1PointerId, test2PointerId],
    226                       [left1d2, left2d2], [top1d2, top2d2], [rx, rx], [ry, ry],
    227                       [angle, angle], [force, force], [0, 0], [0, 0],
    228                       [0, 0], modifiers);
    229 
    230  // Explicitly capture pointer to 1d1, 2d1. pointermove, gotpointercapture
    231  // should be dispatched to 1d1, 2d1
    232  is(test1d1pointermovecount, 2, "1d1 should have got pointermove");
    233  is(test1d1pointergotcapture, 2, "1d1 should have got pointergotcapture");
    234  is(test1d2pointermovecount, 0, "1d2 shouldn't have got pointermove");
    235  is(test1d2pointergotcapture, 0, "1d2 shouldn't have got pointergotcapture");
    236 
    237  is(test2d1pointermovecount, 2, "2d1 should have got pointermove");
    238  is(test2d1pointergotcapture, 2, "2d1 should have got pointergotcapture");
    239  is(test2d2pointermovecount, 0, "2d2 shouldn't have got pointermove");
    240  is(test2d2pointergotcapture, 0, "2d2 shouldn't have got pointergotcapture");
    241 
    242  utils.sendTouchEvent('touchend', [test1PointerId, test2PointerId],
    243                       [left1d1, left2d1], [top1d1, top2d1], [rx, rx], [ry, ry],
    244                       [angle, angle], [force, force], [0, 0], [0, 0],
    245                       [0, 0], modifiers);
    246 
    247  // Explicitly capture pointer to 1d1, 2d1 when pointerdown
    248  test1d1.addEventListener("pointerdown", test1d1CapturePointer, {capture: true, once: true});
    249  test2d1.addEventListener("pointerdown", test2d1CapturePointer, {capture: true, once: true});
    250 
    251  // Explicitly capture pointer to 1d2, 2d2 when pointermove
    252  test1d1.addEventListener("pointermove", test1d2CapturePointer, {capture: true, once: true});
    253  test2d1.addEventListener("pointermove", test2d2CapturePointer, {capture: true, once: true});
    254 
    255  utils.sendTouchEvent('touchstart', [test1PointerId, test2PointerId],
    256                       [left1d1, left2d1], [top1d1, top2d1], [rx, rx], [ry, ry],
    257                       [angle, angle], [force, force], [0, 0], [0, 0],
    258                       [0, 0], modifiers);
    259 
    260  // This should send pointer event to test1d1, test2d1.
    261  utils.sendTouchEvent('touchmove', [test1PointerId, test2PointerId],
    262                       [left1d1 + 5, left2d1 + 5], [top1d1, top2d1], [rx, rx], [ry, ry],
    263                       [angle, angle], [force, force], [0, 0], [0, 0],
    264                       [0, 0], modifiers);
    265 
    266  // This should send pointer event to test1d2, test2d2.
    267  utils.sendTouchEvent('touchmove', [test1PointerId, test2PointerId],
    268                       [left1d1 + 5, left2d1 + 5], [top1d1 + 5, top2d1 + 5], [rx, rx], [ry, ry],
    269                       [angle, angle], [force, force], [0, 0], [0, 0],
    270                       [0, 0], modifiers);
    271 
    272  is(test1d1pointermovecount, 3, "1d1 shouldn't have got pointermove");
    273  is(test1d1pointergotcapture, 3, "1d1 should have got pointergotcapture");
    274  is(test1d2pointermovecount, 1, "1d2 should have got pointermove");
    275  is(test1d2pointergotcapture, 1, "1d2 should have got pointergotcapture");
    276 
    277  is(test2d1pointermovecount, 3, "2d1 shouldn't have got pointermove");
    278  is(test2d1pointergotcapture, 3, "2d1 should have got pointergotcapture");
    279  is(test2d2pointermovecount, 1, "2d2 should have got pointermove");
    280  is(test2d2pointergotcapture, 1, "2d2 should have got pointergotcapture");
    281 
    282  utils.sendTouchEvent('touchend', [test1PointerId, test2PointerId],
    283                       [left1d1, left2d1], [top1d1, top2d1], [rx, rx], [ry, ry],
    284                       [angle, angle], [force, force], [0, 0], [0, 0],
    285                       [0, 0], modifiers);
    286 
    287  finishTest();
    288 }
    289 
    290 function finishTest() {
    291  // Let window.onerror have a chance to fire
    292  setTimeout(function() {
    293    setTimeout(function() {
    294      window.parent.postMessage("finishTest", "*");
    295    }, 0);
    296  }, 0);
    297 }
    298 
    299 window.onload = function () {
    300  SpecialPowers.pushPrefEnv({
    301    "set": [
    302      ["dom.w3c_pointer_events.implicit_capture", true]
    303    ]
    304  }, runTests);
    305 }
    306 
    307 SimpleTest.waitForExplicitFinish();
    308 
    309 </script>
    310 </pre>
    311 <div class="test" id="test1d1">&nbsp;</div><br><div class="test" id="test1d2">&nbsp;</div>
    312 <div class="test" id="test2d1">&nbsp;</div><br><div class="test" id="test2d2">&nbsp;</div>
    313 <pre id="l"></pre>
    314 </body>
    315 </html>