Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=822898 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 822898</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=822898">Mozilla Bug 822898</a> |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | <div id="content" style="display: none"> |
michael@0 | 15 | <iframe id="subFrame"></iframe> |
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 822898 - Pointer* Events **/ |
michael@0 | 21 | |
michael@0 | 22 | let tests = [], testTarget, parent, iframeBody, gOnPointerPropHandled; |
michael@0 | 23 | |
michael@0 | 24 | function nextTest() { |
michael@0 | 25 | if (tests.length) |
michael@0 | 26 | SimpleTest.executeSoon(tests.shift()); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function random() { |
michael@0 | 30 | return Math.floor(Math.random() * 100); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function createTestEventValue(name) { |
michael@0 | 34 | |
michael@0 | 35 | let detail = random(); |
michael@0 | 36 | let screenX = random(); |
michael@0 | 37 | let screenY = random(); |
michael@0 | 38 | let clientX = random(); |
michael@0 | 39 | let clientY = random(); |
michael@0 | 40 | let ctrlKey = random() % 2 ? true : false; |
michael@0 | 41 | let altKey = random() % 2 ? true : false; |
michael@0 | 42 | let shiftKey = random() % 2 ? true : false; |
michael@0 | 43 | let metaKey = random() % 2 ? true : false; |
michael@0 | 44 | let button = random(); |
michael@0 | 45 | let pointerId = random(); |
michael@0 | 46 | |
michael@0 | 47 | return function() { |
michael@0 | 48 | let event = new PointerEvent("pointerdown", { |
michael@0 | 49 | bubbles: true, cancelable: true, view: window, |
michael@0 | 50 | detail: detail, screenX: screenX, screenY: screenY, clientX: clientX, clientY: clientY, |
michael@0 | 51 | ctrlKey: ctrlKey, altKey: altKey, shiftKey: shiftKey, metaKey: metaKey, |
michael@0 | 52 | button: button, relatedTarget: null, pointerId: pointerId |
michael@0 | 53 | }); |
michael@0 | 54 | |
michael@0 | 55 | |
michael@0 | 56 | function check(ev) { |
michael@0 | 57 | is(ev.detail, detail, "Correct detail"); |
michael@0 | 58 | is(ev.screenX, screenX, "Correct screenX"); |
michael@0 | 59 | is(ev.screenY, screenY, "Correct screenY"); |
michael@0 | 60 | is(ev.clientX, clientX, "Correct clientX"); |
michael@0 | 61 | is(ev.clientY, clientY, "Correct clientY"); |
michael@0 | 62 | is(ev.ctrlKey, ctrlKey, "Correct ctrlKey"); |
michael@0 | 63 | is(ev.altKey, altKey, "Correct altKey"); |
michael@0 | 64 | is(ev.shiftKey, shiftKey, "Correct shiftKey"); |
michael@0 | 65 | is(ev.metaKey, metaKey, "Correct metaKey"); |
michael@0 | 66 | is(ev.button, button, "Correct buttonArg"); |
michael@0 | 67 | is(ev.pointerId, pointerId, "Correct pointerId"); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | for each (let target in [document, window, testTarget, parent]) |
michael@0 | 71 | target.addEventListener(name, check, false); |
michael@0 | 72 | |
michael@0 | 73 | testTarget.dispatchEvent(event); |
michael@0 | 74 | |
michael@0 | 75 | for each (let target in [document, window, testTarget, parent]) |
michael@0 | 76 | target.removeEventListener(name, check, false); |
michael@0 | 77 | |
michael@0 | 78 | |
michael@0 | 79 | nextTest(); |
michael@0 | 80 | } |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | function getDefaultArgEvent(eventname) { |
michael@0 | 84 | return new PointerEvent(eventname, { |
michael@0 | 85 | bubbles: true, cancelable: true, view: window, |
michael@0 | 86 | detail: 0, screenX: 0, screenY: 0, clientX: 0, clientY: 0, |
michael@0 | 87 | ctrlKey: false, altKey: false, shiftKey: false, metaKey: false, |
michael@0 | 88 | button: 0, relatedTarget: null, pointerId: 0 |
michael@0 | 89 | }); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | function testDefaultArg() { |
michael@0 | 93 | let event = getDefaultArgEvent("pointerdown"); |
michael@0 | 94 | |
michael@0 | 95 | testTarget.addEventListener("pointerdown", function(ev) { |
michael@0 | 96 | testTarget.removeEventListener("pointerdown", arguments.callee, false); |
michael@0 | 97 | is(ev.pointerId, 0, "Correct default pointerId"); |
michael@0 | 98 | }, false); |
michael@0 | 99 | testTarget.dispatchEvent(event); |
michael@0 | 100 | |
michael@0 | 101 | nextTest(); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | function testStopPropagation() { |
michael@0 | 105 | let event = getDefaultArgEvent("pointerdown"); |
michael@0 | 106 | |
michael@0 | 107 | let unreachableListener = function () { |
michael@0 | 108 | ok(false, "Event should have been stopped"); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | // Capturing phase |
michael@0 | 112 | let captured = false; |
michael@0 | 113 | parent.addEventListener("pointerdown", function() { |
michael@0 | 114 | parent.removeEventListener("pointerdown", arguments.callee, true); |
michael@0 | 115 | captured = true; |
michael@0 | 116 | }, true); // Capturing phase |
michael@0 | 117 | |
michael@0 | 118 | // Bubbling phase |
michael@0 | 119 | parent.addEventListener("pointerdown", unreachableListener, false); |
michael@0 | 120 | |
michael@0 | 121 | testTarget.addEventListener("pointerdown", function(ev) { |
michael@0 | 122 | testTarget.removeEventListener("pointerdown", arguments.callee, false); |
michael@0 | 123 | is(captured, true, "Event should have been captured"); |
michael@0 | 124 | ev.stopPropagation(); |
michael@0 | 125 | }, false); |
michael@0 | 126 | |
michael@0 | 127 | testTarget.dispatchEvent(event); |
michael@0 | 128 | |
michael@0 | 129 | parent.removeEventListener("pointerdown", unreachableListener, false); |
michael@0 | 130 | |
michael@0 | 131 | nextTest(); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | function testPreventDefault() { |
michael@0 | 135 | let event = getDefaultArgEvent("pointerdown"); |
michael@0 | 136 | |
michael@0 | 137 | parent.addEventListener("pointerdown", function(ev) { |
michael@0 | 138 | parent.removeEventListener("pointerdown", arguments.callee, false); |
michael@0 | 139 | is(ev.defaultPrevented, true, "preventDefault can be called"); |
michael@0 | 140 | nextTest(); |
michael@0 | 141 | }, false); |
michael@0 | 142 | |
michael@0 | 143 | testTarget.addEventListener("pointerdown", function(ev) { |
michael@0 | 144 | testTarget.removeEventListener("pointerdown", arguments.callee, false); |
michael@0 | 145 | ev.preventDefault(); |
michael@0 | 146 | }, false); |
michael@0 | 147 | |
michael@0 | 148 | testTarget.dispatchEvent(event); |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | function testBlockPreventDefault() { |
michael@0 | 152 | let event = new PointerEvent("pointerdown", { |
michael@0 | 153 | bubbles: true, cancelable: false, view: window, |
michael@0 | 154 | detail: 0, screenX: 0, screenY: 0, clientX: 0, clientY: 0, |
michael@0 | 155 | ctrlKey: false, altKey: false, shiftKey: false, metaKey: false, |
michael@0 | 156 | button: 0, relatedTarget: null, pointerId: 0, pointerType: "pen" |
michael@0 | 157 | }); |
michael@0 | 158 | |
michael@0 | 159 | parent.addEventListener("pointerdown", function(ev) { |
michael@0 | 160 | parent.removeEventListener("pointerdown", arguments.callee, false); |
michael@0 | 161 | is(ev.defaultPrevented, false, "aCancelableArg works"); |
michael@0 | 162 | nextTest(); |
michael@0 | 163 | }, false); |
michael@0 | 164 | |
michael@0 | 165 | testTarget.addEventListener("pointerdown", function(ev) { |
michael@0 | 166 | testTarget.removeEventListener("pointerdown", arguments.callee, false); |
michael@0 | 167 | ev.preventDefault(); |
michael@0 | 168 | }, false); |
michael@0 | 169 | |
michael@0 | 170 | testTarget.dispatchEvent(event); |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | function testBlockBubbling() { |
michael@0 | 174 | let unreachableListener = function () { |
michael@0 | 175 | ok(false, "aCanBubble doesn't work"); |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | let event = new PointerEvent("pointerdown", { |
michael@0 | 179 | bubbles: false, cancelable: true, view: window, |
michael@0 | 180 | detail: 0, screenX: 0, screenY: 0, clientX: 0, clientY: 0, |
michael@0 | 181 | ctrlKey: false, altKey: false, shiftKey: false, metaKey: false, |
michael@0 | 182 | button: 0, relatedTarget: null, pointerId: 0 |
michael@0 | 183 | }); |
michael@0 | 184 | |
michael@0 | 185 | parent.addEventListener("pointerdown", unreachableListener, false); |
michael@0 | 186 | testTarget.dispatchEvent(event); |
michael@0 | 187 | parent.removeEventListener("pointerdown", unreachableListener, false); |
michael@0 | 188 | |
michael@0 | 189 | nextTest(); |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | function testOnPointerProperty() |
michael@0 | 193 | { |
michael@0 | 194 | iframeBody.onpointerdown = function (e) { gOnPointerPropHandled["pointerdown"] = true; } |
michael@0 | 195 | iframeBody.onpointerup = function (e) { gOnPointerPropHandled["pointerup"] = true; } |
michael@0 | 196 | iframeBody.onpointermove = function (e) { gOnPointerPropHandled["pointermove"] = true; } |
michael@0 | 197 | iframeBody.onpointerout = function (e) { gOnPointerPropHandled["pointerout"] = true; } |
michael@0 | 198 | iframeBody.onpointerover = function (e) { gOnPointerPropHandled["pointerover"] = true; } |
michael@0 | 199 | iframeBody.onpointerenter = function (e) { gOnPointerPropHandled["pointerenter"] = true; } |
michael@0 | 200 | iframeBody.onpointerleave = function (e) { gOnPointerPropHandled["pointerleave"] = true; } |
michael@0 | 201 | iframeBody.onpointercancel = function (e) { gOnPointerPropHandled["pointercancel"] = true; } |
michael@0 | 202 | |
michael@0 | 203 | iframeBody.dispatchEvent(getDefaultArgEvent("pointerdown")); |
michael@0 | 204 | is(gOnPointerPropHandled['pointerdown'], true, "pointerdown property is performed"); |
michael@0 | 205 | |
michael@0 | 206 | iframeBody.dispatchEvent(getDefaultArgEvent("pointerup")); |
michael@0 | 207 | is(gOnPointerPropHandled['pointerup'], true, "pointerup property is performed"); |
michael@0 | 208 | |
michael@0 | 209 | iframeBody.dispatchEvent(getDefaultArgEvent("pointermove")); |
michael@0 | 210 | is(gOnPointerPropHandled['pointermove'], true, "pointermove property is performed"); |
michael@0 | 211 | |
michael@0 | 212 | iframeBody.dispatchEvent(getDefaultArgEvent("pointerout")); |
michael@0 | 213 | is(gOnPointerPropHandled['pointerout'], true, "pointerout property is performed"); |
michael@0 | 214 | |
michael@0 | 215 | iframeBody.dispatchEvent(getDefaultArgEvent("pointerover")); |
michael@0 | 216 | is(gOnPointerPropHandled['pointerover'], true, "pointerover property is performed"); |
michael@0 | 217 | |
michael@0 | 218 | iframeBody.dispatchEvent(getDefaultArgEvent("pointerenter")); |
michael@0 | 219 | is(gOnPointerPropHandled['pointerenter'], true, "pointerenter property is performed"); |
michael@0 | 220 | |
michael@0 | 221 | iframeBody.dispatchEvent(getDefaultArgEvent("pointerleave")); |
michael@0 | 222 | is(gOnPointerPropHandled['pointerleave'], true, "pointerleave property is performed"); |
michael@0 | 223 | |
michael@0 | 224 | iframeBody.dispatchEvent(getDefaultArgEvent("pointercancel")); |
michael@0 | 225 | is(gOnPointerPropHandled['pointercancel'], true, "pointercancel property is performed"); |
michael@0 | 226 | |
michael@0 | 227 | nextTest(); |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | function testPointerEventCTORS() |
michael@0 | 231 | { |
michael@0 | 232 | // TODO: This should go to test_eventctors.html, when PointerEvents enabled by default |
michael@0 | 233 | var receivedEvent; |
michael@0 | 234 | iframeBody.addEventListener("hello", function(e) { receivedEvent = e; }, true); |
michael@0 | 235 | |
michael@0 | 236 | var e; |
michael@0 | 237 | var ex = false; |
michael@0 | 238 | |
michael@0 | 239 | try { |
michael@0 | 240 | e = new PointerEvent(); |
michael@0 | 241 | } catch(exp) { |
michael@0 | 242 | ex = true; |
michael@0 | 243 | } |
michael@0 | 244 | ok(ex, "PointerEvent: First parameter is required!"); |
michael@0 | 245 | ex = false; |
michael@0 | 246 | |
michael@0 | 247 | e = new PointerEvent("hello"); |
michael@0 | 248 | ok(e.type, "hello", "PointerEvent: Wrong event type!"); |
michael@0 | 249 | ok(!e.isTrusted, "PointerEvent: Event shouldn't be trusted!"); |
michael@0 | 250 | ok(!e.bubbles, "PointerEvent: Event shouldn't bubble!"); |
michael@0 | 251 | ok(!e.cancelable, "PointerEvent: Event shouldn't be cancelable!"); |
michael@0 | 252 | iframeBody.dispatchEvent(e); |
michael@0 | 253 | is(receivedEvent, e, "PointerEvent: Wrong event!"); |
michael@0 | 254 | |
michael@0 | 255 | var PointerEventProps = |
michael@0 | 256 | [ { screenX: 0 }, |
michael@0 | 257 | { screenY: 0 }, |
michael@0 | 258 | { clientX: 0 }, |
michael@0 | 259 | { clientY: 0 }, |
michael@0 | 260 | { ctrlKey: false }, |
michael@0 | 261 | { shiftKey: false }, |
michael@0 | 262 | { altKey: false }, |
michael@0 | 263 | { metaKey: false }, |
michael@0 | 264 | { button: 0 }, |
michael@0 | 265 | { buttons: 0 }, |
michael@0 | 266 | { relatedTarget: null }, |
michael@0 | 267 | { pointerId: 0 }, |
michael@0 | 268 | { pointerType: "" } |
michael@0 | 269 | ]; |
michael@0 | 270 | |
michael@0 | 271 | var testPointerProps = |
michael@0 | 272 | [ |
michael@0 | 273 | { screenX: 1 }, |
michael@0 | 274 | { screenY: 2 }, |
michael@0 | 275 | { clientX: 3 }, |
michael@0 | 276 | { clientY: 4 }, |
michael@0 | 277 | { ctrlKey: true }, |
michael@0 | 278 | { shiftKey: true }, |
michael@0 | 279 | { altKey: true }, |
michael@0 | 280 | { metaKey: true }, |
michael@0 | 281 | { button: 5 }, |
michael@0 | 282 | { buttons: 6 }, |
michael@0 | 283 | { relatedTarget: window }, |
michael@0 | 284 | { pointerId: 5 }, |
michael@0 | 285 | { pointerType: "mouse" } |
michael@0 | 286 | ]; |
michael@0 | 287 | |
michael@0 | 288 | var defaultPointerEventValues = {}; |
michael@0 | 289 | for (var i = 0; i < PointerEventProps.length; ++i) { |
michael@0 | 290 | for (prop in PointerEventProps[i]) { |
michael@0 | 291 | ok(prop in e, "PointerEvent: PointerEvent doesn't have property " + prop + "!"); |
michael@0 | 292 | defaultPointerEventValues[prop] = PointerEventProps[i][prop]; |
michael@0 | 293 | } |
michael@0 | 294 | } |
michael@0 | 295 | |
michael@0 | 296 | while (testPointerProps.length) { |
michael@0 | 297 | var p = testPointerProps.shift(); |
michael@0 | 298 | e = new PointerEvent("foo", p); |
michael@0 | 299 | for (var def in defaultPointerEventValues) { |
michael@0 | 300 | if (!(def in p)) { |
michael@0 | 301 | is(e[def], defaultPointerEventValues[def], |
michael@0 | 302 | "PointerEvent: Wrong default value for " + def + "!"); |
michael@0 | 303 | } else { |
michael@0 | 304 | is(e[def], p[def], "PointerEvent: Wrong event init value for " + def + "!"); |
michael@0 | 305 | } |
michael@0 | 306 | } |
michael@0 | 307 | } |
michael@0 | 308 | nextTest(); |
michael@0 | 309 | } |
michael@0 | 310 | |
michael@0 | 311 | function runTests() { |
michael@0 | 312 | SpecialPowers.setBoolPref("dom.w3c_pointer_events.enabled", true); // Enable Pointer Events |
michael@0 | 313 | testTarget = document.getElementById("testTarget"); |
michael@0 | 314 | parent = testTarget.parentNode; |
michael@0 | 315 | gOnPointerPropHandled = new Array; |
michael@0 | 316 | iframeBody = document.getElementById("subFrame").contentWindow.document.body; |
michael@0 | 317 | |
michael@0 | 318 | tests.push(createTestEventValue("pointerdown")); |
michael@0 | 319 | tests.push(createTestEventValue("pointermove")); |
michael@0 | 320 | tests.push(createTestEventValue("pointerup")); |
michael@0 | 321 | |
michael@0 | 322 | tests.push(testDefaultArg); |
michael@0 | 323 | tests.push(testStopPropagation); |
michael@0 | 324 | |
michael@0 | 325 | tests.push(testPreventDefault); |
michael@0 | 326 | tests.push(testBlockPreventDefault); |
michael@0 | 327 | |
michael@0 | 328 | tests.push(testBlockBubbling); |
michael@0 | 329 | tests.push(testOnPointerProperty()); |
michael@0 | 330 | tests.push(testPointerEventCTORS()); |
michael@0 | 331 | |
michael@0 | 332 | tests.push(function() { |
michael@0 | 333 | clearPrefs(); |
michael@0 | 334 | SimpleTest.finish(); |
michael@0 | 335 | }); |
michael@0 | 336 | |
michael@0 | 337 | nextTest(); |
michael@0 | 338 | } |
michael@0 | 339 | |
michael@0 | 340 | function initPrefs() |
michael@0 | 341 | { |
michael@0 | 342 | SpecialPowers.setBoolPref("dom.w3c_pointer_events.enabled", true); // Enable Pointer Events |
michael@0 | 343 | } |
michael@0 | 344 | |
michael@0 | 345 | function clearPrefs() |
michael@0 | 346 | { |
michael@0 | 347 | SpecialPowers.clearUserPref("dom.w3c_pointer_events.enabled"); // Disable Pointer Events |
michael@0 | 348 | } |
michael@0 | 349 | |
michael@0 | 350 | window.onload = function () { |
michael@0 | 351 | initPrefs(); |
michael@0 | 352 | SimpleTest.executeSoon(runTests); |
michael@0 | 353 | } |
michael@0 | 354 | |
michael@0 | 355 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 356 | |
michael@0 | 357 | </script> |
michael@0 | 358 | </pre> |
michael@0 | 359 | <div id="parent"> |
michael@0 | 360 | <span id="testTarget" style="border: 1px solid black;">testTarget</span> |
michael@0 | 361 | </div> |
michael@0 | 362 | </body> |
michael@0 | 363 | </html> |