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