dom/events/test/test_bug741666.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.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=741666
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 741666</title>
michael@0 8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=741666">Mozilla Bug 741666</a>
michael@0 13 <p id="display"></p>
michael@0 14 <div id="content" style="display: none">
michael@0 15
michael@0 16 </div>
michael@0 17 <pre id="test">
michael@0 18 <script class="testbody" type="application/javascript;version=1.8">
michael@0 19
michael@0 20 /** Test for Bug 306008 - Touch events with a reference held should retain their touch lists **/
michael@0 21
michael@0 22 let tests = [], testTarget, parent;
michael@0 23
michael@0 24 let touch = {
michael@0 25 id: 0,
michael@0 26 point: {x: 0, y: 0},
michael@0 27 radius: {x: 0, y: 0},
michael@0 28 rotation: 0,
michael@0 29 force: 0.5,
michael@0 30 target: null
michael@0 31 }
michael@0 32
michael@0 33 function nextTest() {
michael@0 34 if (tests.length)
michael@0 35 SimpleTest.executeSoon(tests.shift());
michael@0 36 }
michael@0 37
michael@0 38 function checkEvent(aFakeEvent, aTouches) {
michael@0 39 return function(aEvent, aTrusted) {
michael@0 40 is(aFakeEvent.ctrlKey, aEvent.ctrlKey, "Correct ctrlKey");
michael@0 41 is(aFakeEvent.altKey, aEvent.altKey, "Correct altKey");
michael@0 42 is(aFakeEvent.shiftKey, aEvent.shiftKey, "Correct shiftKey");
michael@0 43 is(aFakeEvent.metaKey, aEvent.metaKey, "Correct metaKey");
michael@0 44 is(aEvent.isTrusted, aTrusted, "Event is trusted");
michael@0 45 checkTouches(aFakeEvent[aTouches], aEvent[aTouches]);
michael@0 46 }
michael@0 47 }
michael@0 48
michael@0 49 function checkTouches(aTouches1, aTouches2) {
michael@0 50 is(aTouches1.length, aTouches2.length, "Correct touches length");
michael@0 51 for (var i = 0; i < aTouches1.length; i++) {
michael@0 52 checkTouch(aTouches1[i], aTouches2[i]);
michael@0 53 }
michael@0 54 }
michael@0 55
michael@0 56 function checkTouch(aFakeTouch, aTouch) {
michael@0 57 is(aFakeTouch.identifier, aTouch.identifier, "Touch has correct identifier");
michael@0 58 is(aFakeTouch.target, aTouch.target, "Touch has correct target");
michael@0 59 is(aFakeTouch.page.x, aTouch.pageX, "Touch has correct pageX");
michael@0 60 is(aFakeTouch.page.y, aTouch.pageY, "Touch has correct pageY");
michael@0 61 is(aFakeTouch.page.x + Math.round(window.mozInnerScreenX), aTouch.screenX, "Touch has correct screenX");
michael@0 62 is(aFakeTouch.page.y + Math.round(window.mozInnerScreenY), aTouch.screenY, "Touch has correct screenY");
michael@0 63 is(aFakeTouch.page.x, aTouch.clientX, "Touch has correct clientX");
michael@0 64 is(aFakeTouch.page.y, aTouch.clientY, "Touch has correct clientY");
michael@0 65 is(aFakeTouch.radius.x, aTouch.radiusX, "Touch has correct radiusX");
michael@0 66 is(aFakeTouch.radius.y, aTouch.radiusY, "Touch has correct radiusY");
michael@0 67 is(aFakeTouch.rotationAngle, aTouch.rotationAngle, "Touch has correct rotationAngle");
michael@0 68 is(aFakeTouch.force, aTouch.force, "Touch has correct force");
michael@0 69 }
michael@0 70
michael@0 71 function sendTouchEvent(windowUtils, aType, aEvent, aModifiers) {
michael@0 72 var ids = [], xs=[], ys=[], rxs = [], rys = [],
michael@0 73 rotations = [], forces = [];
michael@0 74
michael@0 75 for (var touchType of ["touches", "changedTouches", "targetTouches"]) {
michael@0 76 for (var i = 0; i < aEvent[touchType].length; i++) {
michael@0 77 if (ids.indexOf(aEvent[touchType][i].identifier) == -1) {
michael@0 78 ids.push(aEvent[touchType][i].identifier);
michael@0 79 xs.push(aEvent[touchType][i].page.x);
michael@0 80 ys.push(aEvent[touchType][i].page.y);
michael@0 81 rxs.push(aEvent[touchType][i].radius.x);
michael@0 82 rys.push(aEvent[touchType][i].radius.y);
michael@0 83 rotations.push(aEvent[touchType][i].rotationAngle);
michael@0 84 forces.push(aEvent[touchType][i].force);
michael@0 85 }
michael@0 86 }
michael@0 87 }
michael@0 88 return windowUtils.sendTouchEvent(aType,
michael@0 89 ids, xs, ys, rxs, rys,
michael@0 90 rotations, forces,
michael@0 91 ids.length, aModifiers, 0);
michael@0 92 }
michael@0 93
michael@0 94 function touchEvent(aOptions) {
michael@0 95 if (!aOptions) {
michael@0 96 aOptions = {};
michael@0 97 }
michael@0 98 this.ctrlKey = aOptions.ctrlKey || false;
michael@0 99 this.altKey = aOptions.altKey || false;
michael@0 100 this.shiftKey = aOptions.shiftKey || false;
michael@0 101 this.metaKey = aOptions.metaKey || false;
michael@0 102 this.touches = aOptions.touches || [];
michael@0 103 this.targetTouches = aOptions.targetTouches || [];
michael@0 104 this.changedTouches = aOptions.changedTouches || [];
michael@0 105 }
michael@0 106
michael@0 107 function testtouch(aOptions) {
michael@0 108 if (!aOptions)
michael@0 109 aOptions = {};
michael@0 110 this.identifier = aOptions.identifier || 0;
michael@0 111 this.target = aOptions.target || 0;
michael@0 112 this.page = aOptions.page || {x: 0, y: 0};
michael@0 113 this.radius = aOptions.radius || {x: 0, y: 0};
michael@0 114 this.rotationAngle = aOptions.rotationAngle || 0;
michael@0 115 this.force = aOptions.force || 1;
michael@0 116 }
michael@0 117
michael@0 118 function testPreventDefault(name) {
michael@0 119 let cwu = SpecialPowers.getDOMWindowUtils(window);
michael@0 120 let target = document.getElementById("testTarget");
michael@0 121 let bcr = target.getBoundingClientRect();
michael@0 122
michael@0 123 let touch1 = new testtouch({
michael@0 124 page: {x: Math.round(bcr.left + bcr.width/2),
michael@0 125 y: Math.round(bcr.top + bcr.height/2)},
michael@0 126 target: target
michael@0 127 });
michael@0 128
michael@0 129 let event = new touchEvent({
michael@0 130 touches: [touch1],
michael@0 131 targetTouches: [touch1],
michael@0 132 changedTouches: [touch1]
michael@0 133 });
michael@0 134
michael@0 135 // test touchstart event fires correctly
michael@0 136 var checkTouches = checkEvent(event, "touches");
michael@0 137 var checkTargetTouches = checkEvent(event, "targetTouches");
michael@0 138
michael@0 139 /* This is the heart of the test. Verify that the touch event
michael@0 140 looks correct both in and outside of a setTimeout */
michael@0 141 window.addEventListener("touchstart", function(firedEvent) {
michael@0 142 checkTouches(firedEvent, true);
michael@0 143 setTimeout(function() {
michael@0 144 checkTouches(firedEvent, true);
michael@0 145 checkTargetTouches(firedEvent, true);
michael@0 146
michael@0 147 event.touches = [];
michael@0 148 event.targetTouches = [];
michael@0 149 sendTouchEvent(cwu, "touchend", event, 0);
michael@0 150
michael@0 151 nextTest();
michael@0 152 }, 0);
michael@0 153 }, false);
michael@0 154 sendTouchEvent(cwu, "touchstart", event, 0);
michael@0 155 }
michael@0 156
michael@0 157 function doTest() {
michael@0 158 tests.push(testPreventDefault);
michael@0 159
michael@0 160 tests.push(function() {
michael@0 161 SimpleTest.finish();
michael@0 162 });
michael@0 163
michael@0 164 nextTest();
michael@0 165 }
michael@0 166
michael@0 167 SimpleTest.waitForExplicitFinish();
michael@0 168 addLoadEvent(doTest);
michael@0 169
michael@0 170 </script>
michael@0 171 </pre>
michael@0 172 <div id="parent">
michael@0 173 <span id="testTarget" style="padding: 5px; border: 1px solid black;">testTarget</span>
michael@0 174 </div>
michael@0 175 </body>
michael@0 176 </html>

mercurial