2013-11-22 19:12:01 +04:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=822898
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 822898</title>
|
2019-04-16 06:53:28 +03:00
|
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
2013-11-22 19:12:01 +04:00
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=822898">Mozilla Bug 822898</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
<iframe id="subFrame"></iframe>
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
2017-02-23 00:10:07 +03:00
|
|
|
<script class="testbody" type="application/javascript">
|
2013-11-22 19:12:01 +04:00
|
|
|
|
|
|
|
/** Test for Bug 822898 - Pointer* Events **/
|
|
|
|
|
|
|
|
let tests = [], testTarget, parent, iframeBody, gOnPointerPropHandled;
|
|
|
|
|
|
|
|
function nextTest() {
|
|
|
|
if (tests.length)
|
|
|
|
SimpleTest.executeSoon(tests.shift());
|
|
|
|
}
|
|
|
|
|
|
|
|
function random() {
|
|
|
|
return Math.floor(Math.random() * 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createTestEventValue(name) {
|
|
|
|
|
|
|
|
let detail = random();
|
|
|
|
let screenX = random();
|
|
|
|
let screenY = random();
|
|
|
|
let clientX = random();
|
|
|
|
let clientY = random();
|
2019-09-02 14:23:26 +03:00
|
|
|
let ctrlKey = !!(random() % 2);
|
|
|
|
let altKey = !!(random() % 2);
|
|
|
|
let shiftKey = !!(random() % 2);
|
|
|
|
let metaKey = !!(random() % 2);
|
2013-11-22 19:12:01 +04:00
|
|
|
let button = random();
|
|
|
|
let pointerId = random();
|
|
|
|
|
|
|
|
return function() {
|
|
|
|
let event = new PointerEvent("pointerdown", {
|
|
|
|
bubbles: true, cancelable: true, view: window,
|
2019-09-02 14:22:27 +03:00
|
|
|
detail, screenX, screenY, clientX, clientY,
|
|
|
|
ctrlKey, altKey, shiftKey, metaKey,
|
|
|
|
button, relatedTarget: null, pointerId
|
2013-11-22 19:12:01 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function check(ev) {
|
|
|
|
is(ev.detail, detail, "Correct detail");
|
|
|
|
is(ev.screenX, screenX, "Correct screenX");
|
|
|
|
is(ev.screenY, screenY, "Correct screenY");
|
|
|
|
is(ev.clientX, clientX, "Correct clientX");
|
|
|
|
is(ev.clientY, clientY, "Correct clientY");
|
|
|
|
is(ev.ctrlKey, ctrlKey, "Correct ctrlKey");
|
|
|
|
is(ev.altKey, altKey, "Correct altKey");
|
|
|
|
is(ev.shiftKey, shiftKey, "Correct shiftKey");
|
|
|
|
is(ev.metaKey, metaKey, "Correct metaKey");
|
|
|
|
is(ev.button, button, "Correct buttonArg");
|
|
|
|
is(ev.pointerId, pointerId, "Correct pointerId");
|
|
|
|
}
|
|
|
|
|
2015-10-18 20:00:50 +03:00
|
|
|
for (let target of [document, window, testTarget, parent])
|
2013-11-22 19:12:01 +04:00
|
|
|
target.addEventListener(name, check);
|
|
|
|
|
|
|
|
testTarget.dispatchEvent(event);
|
|
|
|
|
2015-10-18 20:00:50 +03:00
|
|
|
for (let target of [document, window, testTarget, parent])
|
2013-11-22 19:12:01 +04:00
|
|
|
target.removeEventListener(name, check);
|
|
|
|
|
|
|
|
|
|
|
|
nextTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDefaultArgEvent(eventname) {
|
|
|
|
return new PointerEvent(eventname, {
|
|
|
|
bubbles: true, cancelable: true, view: window,
|
|
|
|
detail: 0, screenX: 0, screenY: 0, clientX: 0, clientY: 0,
|
|
|
|
ctrlKey: false, altKey: false, shiftKey: false, metaKey: false,
|
|
|
|
button: 0, relatedTarget: null, pointerId: 0
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDefaultArg() {
|
|
|
|
let event = getDefaultArgEvent("pointerdown");
|
|
|
|
|
|
|
|
testTarget.addEventListener("pointerdown", function(ev) {
|
|
|
|
is(ev.pointerId, 0, "Correct default pointerId");
|
|
|
|
}, {once: true});
|
|
|
|
testTarget.dispatchEvent(event);
|
|
|
|
|
|
|
|
nextTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testStopPropagation() {
|
|
|
|
let event = getDefaultArgEvent("pointerdown");
|
|
|
|
|
|
|
|
let unreachableListener = function () {
|
|
|
|
ok(false, "Event should have been stopped");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Capturing phase
|
|
|
|
let captured = false;
|
|
|
|
parent.addEventListener("pointerdown", function() {
|
|
|
|
captured = true;
|
|
|
|
}, {capture: true, once: true}); // Capturing phase
|
|
|
|
|
|
|
|
// Bubbling phase
|
|
|
|
parent.addEventListener("pointerdown", unreachableListener);
|
|
|
|
|
|
|
|
testTarget.addEventListener("pointerdown", function(ev) {
|
|
|
|
is(captured, true, "Event should have been captured");
|
|
|
|
ev.stopPropagation();
|
|
|
|
}, {once: true});
|
|
|
|
|
|
|
|
testTarget.dispatchEvent(event);
|
|
|
|
|
|
|
|
parent.removeEventListener("pointerdown", unreachableListener);
|
|
|
|
|
|
|
|
nextTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testPreventDefault() {
|
|
|
|
let event = getDefaultArgEvent("pointerdown");
|
|
|
|
|
|
|
|
parent.addEventListener("pointerdown", function(ev) {
|
|
|
|
is(ev.defaultPrevented, true, "preventDefault can be called");
|
|
|
|
nextTest();
|
|
|
|
}, {once: true});
|
|
|
|
|
|
|
|
testTarget.addEventListener("pointerdown", function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
}, {once: true});
|
|
|
|
|
|
|
|
testTarget.dispatchEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testBlockPreventDefault() {
|
|
|
|
let event = new PointerEvent("pointerdown", {
|
|
|
|
bubbles: true, cancelable: false, view: window,
|
|
|
|
detail: 0, screenX: 0, screenY: 0, clientX: 0, clientY: 0,
|
|
|
|
ctrlKey: false, altKey: false, shiftKey: false, metaKey: false,
|
|
|
|
button: 0, relatedTarget: null, pointerId: 0, pointerType: "pen"
|
|
|
|
});
|
|
|
|
|
|
|
|
parent.addEventListener("pointerdown", function(ev) {
|
|
|
|
is(ev.defaultPrevented, false, "aCancelableArg works");
|
|
|
|
nextTest();
|
|
|
|
}, {once: true});
|
|
|
|
|
|
|
|
testTarget.addEventListener("pointerdown", function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
}, {once: true});
|
|
|
|
|
|
|
|
testTarget.dispatchEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testBlockBubbling() {
|
|
|
|
let unreachableListener = function () {
|
|
|
|
ok(false, "aCanBubble doesn't work");
|
|
|
|
}
|
|
|
|
|
|
|
|
let event = new PointerEvent("pointerdown", {
|
|
|
|
bubbles: false, cancelable: true, view: window,
|
|
|
|
detail: 0, screenX: 0, screenY: 0, clientX: 0, clientY: 0,
|
|
|
|
ctrlKey: false, altKey: false, shiftKey: false, metaKey: false,
|
|
|
|
button: 0, relatedTarget: null, pointerId: 0
|
|
|
|
});
|
|
|
|
|
|
|
|
parent.addEventListener("pointerdown", unreachableListener);
|
|
|
|
testTarget.dispatchEvent(event);
|
|
|
|
parent.removeEventListener("pointerdown", unreachableListener);
|
|
|
|
|
|
|
|
nextTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testOnPointerProperty()
|
|
|
|
{
|
2019-09-02 14:23:05 +03:00
|
|
|
iframeBody.onpointerdown = function (e) { gOnPointerPropHandled.pointerdown = true; }
|
|
|
|
iframeBody.onpointerup = function (e) { gOnPointerPropHandled.pointerup = true; }
|
|
|
|
iframeBody.onpointermove = function (e) { gOnPointerPropHandled.pointermove = true; }
|
|
|
|
iframeBody.onpointerout = function (e) { gOnPointerPropHandled.pointerout = true; }
|
|
|
|
iframeBody.onpointerover = function (e) { gOnPointerPropHandled.pointerover = true; }
|
|
|
|
iframeBody.onpointerenter = function (e) { gOnPointerPropHandled.pointerenter = true; }
|
|
|
|
iframeBody.onpointerleave = function (e) { gOnPointerPropHandled.pointerleave = true; }
|
|
|
|
iframeBody.onpointercancel = function (e) { gOnPointerPropHandled.pointercancel = true; }
|
2013-11-22 19:12:01 +04:00
|
|
|
|
|
|
|
iframeBody.dispatchEvent(getDefaultArgEvent("pointerdown"));
|
2019-09-02 14:23:05 +03:00
|
|
|
is(gOnPointerPropHandled.pointerdown, true, "pointerdown property is performed");
|
2013-11-22 19:12:01 +04:00
|
|
|
|
|
|
|
iframeBody.dispatchEvent(getDefaultArgEvent("pointerup"));
|
2019-09-02 14:23:05 +03:00
|
|
|
is(gOnPointerPropHandled.pointerup, true, "pointerup property is performed");
|
2013-11-22 19:12:01 +04:00
|
|
|
|
|
|
|
iframeBody.dispatchEvent(getDefaultArgEvent("pointermove"));
|
2019-09-02 14:23:05 +03:00
|
|
|
is(gOnPointerPropHandled.pointermove, true, "pointermove property is performed");
|
2013-11-22 19:12:01 +04:00
|
|
|
|
|
|
|
iframeBody.dispatchEvent(getDefaultArgEvent("pointerout"));
|
2019-09-02 14:23:05 +03:00
|
|
|
is(gOnPointerPropHandled.pointerout, true, "pointerout property is performed");
|
2013-11-22 19:12:01 +04:00
|
|
|
|
|
|
|
iframeBody.dispatchEvent(getDefaultArgEvent("pointerover"));
|
2019-09-02 14:23:05 +03:00
|
|
|
is(gOnPointerPropHandled.pointerover, true, "pointerover property is performed");
|
2013-11-22 19:12:01 +04:00
|
|
|
|
|
|
|
iframeBody.dispatchEvent(getDefaultArgEvent("pointerenter"));
|
2019-09-02 14:23:05 +03:00
|
|
|
is(gOnPointerPropHandled.pointerenter, true, "pointerenter property is performed");
|
2013-11-22 19:12:01 +04:00
|
|
|
|
|
|
|
iframeBody.dispatchEvent(getDefaultArgEvent("pointerleave"));
|
2019-09-02 14:23:05 +03:00
|
|
|
is(gOnPointerPropHandled.pointerleave, true, "pointerleave property is performed");
|
2013-11-22 19:12:01 +04:00
|
|
|
|
2014-02-28 04:13:05 +04:00
|
|
|
iframeBody.dispatchEvent(getDefaultArgEvent("pointercancel"));
|
2019-09-02 14:23:05 +03:00
|
|
|
is(gOnPointerPropHandled.pointercancel, true, "pointercancel property is performed");
|
2014-02-28 04:13:05 +04:00
|
|
|
|
2013-11-22 19:12:01 +04:00
|
|
|
nextTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testPointerEventCTORS()
|
|
|
|
{
|
|
|
|
// TODO: This should go to test_eventctors.html, when PointerEvents enabled by default
|
|
|
|
var receivedEvent;
|
|
|
|
iframeBody.addEventListener("hello", function(e) { receivedEvent = e; }, true);
|
|
|
|
|
|
|
|
var e;
|
|
|
|
var ex = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
e = new PointerEvent();
|
|
|
|
} catch(exp) {
|
|
|
|
ex = true;
|
|
|
|
}
|
|
|
|
ok(ex, "PointerEvent: First parameter is required!");
|
|
|
|
ex = false;
|
|
|
|
|
|
|
|
e = new PointerEvent("hello");
|
2018-10-23 10:12:23 +03:00
|
|
|
is(e.type, "hello", "PointerEvent: Wrong event type!");
|
2013-11-22 19:12:01 +04:00
|
|
|
ok(!e.isTrusted, "PointerEvent: Event shouldn't be trusted!");
|
|
|
|
ok(!e.bubbles, "PointerEvent: Event shouldn't bubble!");
|
|
|
|
ok(!e.cancelable, "PointerEvent: Event shouldn't be cancelable!");
|
|
|
|
iframeBody.dispatchEvent(e);
|
|
|
|
is(receivedEvent, e, "PointerEvent: Wrong event!");
|
|
|
|
|
|
|
|
var PointerEventProps =
|
|
|
|
[ { screenX: 0 },
|
|
|
|
{ screenY: 0 },
|
|
|
|
{ clientX: 0 },
|
|
|
|
{ clientY: 0 },
|
|
|
|
{ ctrlKey: false },
|
|
|
|
{ shiftKey: false },
|
|
|
|
{ altKey: false },
|
|
|
|
{ metaKey: false },
|
|
|
|
{ button: 0 },
|
|
|
|
{ buttons: 0 },
|
|
|
|
{ relatedTarget: null },
|
|
|
|
{ pointerId: 0 },
|
|
|
|
{ pointerType: "" }
|
|
|
|
];
|
|
|
|
|
|
|
|
var testPointerProps =
|
|
|
|
[
|
|
|
|
{ screenX: 1 },
|
|
|
|
{ screenY: 2 },
|
|
|
|
{ clientX: 3 },
|
|
|
|
{ clientY: 4 },
|
|
|
|
{ ctrlKey: true },
|
|
|
|
{ shiftKey: true },
|
|
|
|
{ altKey: true },
|
|
|
|
{ metaKey: true },
|
|
|
|
{ button: 5 },
|
|
|
|
{ buttons: 6 },
|
|
|
|
{ relatedTarget: window },
|
|
|
|
{ pointerId: 5 },
|
|
|
|
{ pointerType: "mouse" }
|
|
|
|
];
|
|
|
|
|
|
|
|
var defaultPointerEventValues = {};
|
|
|
|
for (var i = 0; i < PointerEventProps.length; ++i) {
|
|
|
|
for (prop in PointerEventProps[i]) {
|
|
|
|
ok(prop in e, "PointerEvent: PointerEvent doesn't have property " + prop + "!");
|
|
|
|
defaultPointerEventValues[prop] = PointerEventProps[i][prop];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (testPointerProps.length) {
|
|
|
|
var p = testPointerProps.shift();
|
|
|
|
e = new PointerEvent("foo", p);
|
|
|
|
for (var def in defaultPointerEventValues) {
|
|
|
|
if (!(def in p)) {
|
|
|
|
is(e[def], defaultPointerEventValues[def],
|
|
|
|
"PointerEvent: Wrong default value for " + def + "!");
|
|
|
|
} else {
|
|
|
|
is(e[def], p[def], "PointerEvent: Wrong event init value for " + def + "!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nextTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function runTests() {
|
|
|
|
testTarget = document.getElementById("testTarget");
|
|
|
|
parent = testTarget.parentNode;
|
|
|
|
gOnPointerPropHandled = new Array;
|
|
|
|
iframeBody = document.getElementById("subFrame").contentWindow.document.body;
|
|
|
|
|
|
|
|
tests.push(createTestEventValue("pointerdown"));
|
|
|
|
tests.push(createTestEventValue("pointermove"));
|
|
|
|
tests.push(createTestEventValue("pointerup"));
|
|
|
|
|
|
|
|
tests.push(testDefaultArg);
|
|
|
|
tests.push(testStopPropagation);
|
|
|
|
|
|
|
|
tests.push(testPreventDefault);
|
|
|
|
tests.push(testBlockPreventDefault);
|
|
|
|
|
|
|
|
tests.push(testBlockBubbling);
|
|
|
|
tests.push(testOnPointerProperty());
|
|
|
|
tests.push(testPointerEventCTORS());
|
|
|
|
|
|
|
|
tests.push(function() {
|
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
|
|
|
|
|
|
|
nextTest();
|
|
|
|
}
|
|
|
|
|
2015-02-19 19:53:01 +03:00
|
|
|
window.onload = function() {
|
|
|
|
SpecialPowers.pushPrefEnv({"set":[["dom.w3c_pointer_events.enabled", true]]}, runTests);
|
2013-11-22 19:12:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
<div id="parent">
|
|
|
|
<span id="testTarget" style="border: 1px solid black;">testTarget</span>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|