layout/base/tests/test_bug993936.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    11   <script type="application/javascript">
    13   /** Test for Bug 993936 **/
    15 var currentId = 0;
    16 var evictedTouchesCount = 0;
    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 }
    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 }
    42 function sendTouchEvent(windowUtils, aType, aEvent, aModifiers) {
    43   var ids = [], xs=[], ys=[], rxs = [], rys = [],
    44       rotations = [], forces = [];
    46   for (var touchType of ["touches", "changedTouches", "targetTouches"]) {
    47     for (var i = 0; i < aEvent[touchType].length; i++) {
    48       if (ids.indexOf(aEvent[touchType][i].identifier) == -1) {
    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       }
    57     }
    58   }
    59   return windowUtils.sendTouchEvent(aType,
    60                                     ids, xs, ys, rxs, rys,
    61                                     rotations, forces,
    62                                     ids.length, aModifiers, 0);
    63 }
    65 function getSingleTouchEventForTarget(target, cwu) {
    66   currentId++;
    67   var bcr = target.getBoundingClientRect();
    68   var touch = new testtouch({
    69     page: {x: Math.round(bcr.left + bcr.width/2),
    70            y: Math.round(bcr.top  + bcr.height/2)},
    71     target: target,
    72     identifier: currentId,
    73   });
    74   var event = new touchEvent({
    75     touches: [touch],
    76     targetTouches: [touch],
    77     changedTouches: [touch]
    78   });
    79   return event;
    80 }
    82 function getMultiTouchEventForTarget(target, cwu) {
    83   currentId++;
    84   var bcr = target.getBoundingClientRect();
    85   var touch1 = new testtouch({
    86     page: {x: Math.round(bcr.left + bcr.width/2),
    87            y: Math.round(bcr.top  + bcr.height/2)},
    88     target: target,
    89     identifier: currentId,
    90   });
    91   currentId++;
    92   var touch2 = new testtouch({
    93     page: {x: Math.round(bcr.left + bcr.width),
    94            y: Math.round(bcr.top  + bcr.height)},
    95     target: target,
    96     identifier: currentId,
    97   });
    98   var event = new touchEvent({
    99     touches: [touch1, touch2],
   100     targetTouches: [touch1, touch2],
   101     changedTouches: [touch1, touch2]
   102   });
   103   return event;
   104 }
   106 function runTests() {
   107   var cwu = SpecialPowers.getDOMWindowUtils(window);
   109   var event1 = getMultiTouchEventForTarget(d0, cwu);
   110   sendTouchEvent(cwu, "touchstart", event1, 0);
   111   sendTouchEvent(cwu, "touchmove", event1, 0);
   112   is(evictedTouchesCount, 0, "Still no evicted touches");
   114   var event2 = getSingleTouchEventForTarget(d0, cwu);
   115   sendTouchEvent(cwu, "touchstart", event2, 0);
   117   // By now we should get touchend event
   118   ok(evictedTouchesCount > 0, "Got evicted touch");
   120   finishTest();
   121 }
   123 function finishTest() {
   124   // Let window.onerror have a chance to fire
   125   setTimeout(function() {
   126     SimpleTest.finish();
   127   }, 0);
   128 }
   130 SimpleTest.waitForExplicitFinish();
   132   </script>
   133 </head>
   134 <body>
   135 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=993936">Mozilla Bug 993936</a>
   136 <p id="display"></p>
   137 <div id="content" style="display: none">
   139 </div>
   140 <pre id="test">
   141 </pre>
   142 <div id="d0">
   143     Test div
   144 </div>
   146 <script>
   147 var d0 = document.getElementById("d0");
   149 d0.addEventListener("touchend", function(ev) {
   150   evictedTouchesCount++;
   151 });
   153 window.onload = function () {
   154   setTimeout(function() {
   155     runTests();
   156   }, 0);
   157 }
   159 </script>
   160 </body>
   161 </html>

mercurial