diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/base/test/useractivation/test_popup_blocker_pointer_event.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/test/useractivation/test_popup_blocker_pointer_event.html')
-rw-r--r-- | dom/base/test/useractivation/test_popup_blocker_pointer_event.html | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/dom/base/test/useractivation/test_popup_blocker_pointer_event.html b/dom/base/test/useractivation/test_popup_blocker_pointer_event.html new file mode 100644 index 0000000000..8d0b2c8cd1 --- /dev/null +++ b/dom/base/test/useractivation/test_popup_blocker_pointer_event.html @@ -0,0 +1,122 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title>Test for triggering popup by pointer events</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <script src="/tests/SimpleTest/EventUtils.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> + <div id="target" style="width: 50px; height: 50px; background: green"></div> + <script> + + function sendMouseEvent(element, eventName, button, listenEventName, handler) { + let needToCheckHandler = false; + let handlerIsCalled = false; + if (listenEventName && handler) { + needToCheckHandler = true; + element.addEventListener(listenEventName, (e) => { + handler(e); + handlerIsCalled = true; + }, {once: true}); + } + synthesizeMouseAtCenter(element, {type: eventName, button}); + if (needToCheckHandler) { + ok(handlerIsCalled, "Handler should be called"); + } + } + + function checkAllowOpenPopup(e) { + let w = window.open("about:blank"); + ok(w, `Should allow popup in the ${e.type} listener with button=${e.button}`); + if (w) { + w.close(); + } + } + + function checkBlockOpenPopup(e) { + let w = window.open("about:blank"); + ok(!w, `Should block popup in the ${e.type} listener with button=${e.button}`); + if (w) { + w.close(); + } + } + + add_setup(async function() { + const DENY_ACTION = SpecialPowers.Ci.nsIPermissionManager.DENY_ACTION; + let xorigin = SimpleTest.getTestFileURL("").replace(location.hostname, 'mochi.xorigin-test'); + await SpecialPowers.pushPermissions([ + {'type': 'popup', 'allow': DENY_ACTION, + 'context': document}, + {'type': 'popup', 'allow': DENY_ACTION, + 'context': xorigin} + ]); + await new Promise(resolve => SimpleTest.waitForFocus(resolve)); + }); + + const LEFT_BUTTON = 0; + const MIDDLE_BUTTON = 1; + const RIGHT_BUTTON = 2; + let target = document.getElementById("target"); + + add_task(function testPointerEventDefault() { + // By default, only allow opening popup in the pointerup listener. + // Left button + sendMouseEvent(target, "mousedown", LEFT_BUTTON, "pointerdown", checkAllowOpenPopup); + sendMouseEvent(target, "mousemove", LEFT_BUTTON, "pointermove", checkBlockOpenPopup); + sendMouseEvent(target, "mouseup", LEFT_BUTTON, "pointerup", checkAllowOpenPopup); + + // Middle button + sendMouseEvent(target, "mousedown", MIDDLE_BUTTON, "pointerdown", checkAllowOpenPopup); + sendMouseEvent(target, "mousemove", MIDDLE_BUTTON, "pointermove", checkBlockOpenPopup); + sendMouseEvent(target, "mouseup", MIDDLE_BUTTON, "pointerup", checkAllowOpenPopup); + + // Right button + sendMouseEvent(target, "mousedown", RIGHT_BUTTON, "pointerdown", checkBlockOpenPopup); + sendMouseEvent(target, "mousemove", RIGHT_BUTTON, "pointermove", checkBlockOpenPopup); + sendMouseEvent(target, "mouseup", RIGHT_BUTTON, "pointerup", checkBlockOpenPopup); + }); + + add_task(async function testPointerEventAddPointerDownToPref() { + // Adding pointerdown to preference + await SpecialPowers.pushPrefEnv({"set": [["dom.popup_allowed_events", + "pointerdown pointerup"]]}); + // Left button + sendMouseEvent(target, "mousedown", LEFT_BUTTON, "pointerdown", checkAllowOpenPopup); + sendMouseEvent(target, "mousemove", LEFT_BUTTON, "pointermove", checkBlockOpenPopup); + sendMouseEvent(target, "mouseup", LEFT_BUTTON, "pointerup", checkAllowOpenPopup); + + // Middle button + sendMouseEvent(target, "mousedown", MIDDLE_BUTTON, "pointerdown", checkAllowOpenPopup); + sendMouseEvent(target, "mousemove", MIDDLE_BUTTON, "pointermove", checkBlockOpenPopup); + sendMouseEvent(target, "mouseup", MIDDLE_BUTTON, "pointerup", checkAllowOpenPopup); + + // Right button + sendMouseEvent(target, "mousedown", RIGHT_BUTTON, "pointerdown", checkBlockOpenPopup); + sendMouseEvent(target, "mousemove", RIGHT_BUTTON, "pointermove", checkBlockOpenPopup); + sendMouseEvent(target, "mouseup", RIGHT_BUTTON, "pointerup", checkBlockOpenPopup); + }); + + add_task(async function testPointerEventAddPointerMoveToPref() { + // Adding pointermove to preference should have no effect. + await SpecialPowers.pushPrefEnv({"set": [["dom.popup_allowed_events", + "pointerdown pointerup pointermove"]]}); + // Left button + sendMouseEvent(target, "mousedown", LEFT_BUTTON, "pointerdown", checkAllowOpenPopup); + sendMouseEvent(target, "mousemove", LEFT_BUTTON, "pointermove", checkBlockOpenPopup); + sendMouseEvent(target, "mouseup", LEFT_BUTTON, "pointerup", checkAllowOpenPopup); + + // Middle button + sendMouseEvent(target, "mousedown", MIDDLE_BUTTON, "pointerdown", checkAllowOpenPopup); + sendMouseEvent(target, "mousemove", MIDDLE_BUTTON, "pointermove", checkBlockOpenPopup); + sendMouseEvent(target, "mouseup", MIDDLE_BUTTON, "pointerup", checkAllowOpenPopup); + + // Right button + sendMouseEvent(target, "mousedown", RIGHT_BUTTON, "pointerdown", checkBlockOpenPopup); + sendMouseEvent(target, "mousemove", RIGHT_BUTTON, "pointermove", checkBlockOpenPopup); + sendMouseEvent(target, "mouseup", RIGHT_BUTTON, "pointerup", checkBlockOpenPopup); + }); + </script> +</body> +</html> |