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 /widget/tests/test_mouse_event_with_control_on_mac.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'widget/tests/test_mouse_event_with_control_on_mac.html')
-rw-r--r-- | widget/tests/test_mouse_event_with_control_on_mac.html | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/widget/tests/test_mouse_event_with_control_on_mac.html b/widget/tests/test_mouse_event_with_control_on_mac.html new file mode 100644 index 0000000000..52ce206d35 --- /dev/null +++ b/widget/tests/test_mouse_event_with_control_on_mac.html @@ -0,0 +1,116 @@ +<html> +<head> + <title>Test control+click on Mac</title> + <script src="/tests/SimpleTest/EventUtils.js"></script> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <script src="/tests/SimpleTest/SpecialPowers.js"></script> + <script src="/tests/SimpleTest/paint_listener.js"></script> + <script src="/tests/gfx/layers/apz/test/mochitest/apz_test_utils.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> + <style> + #target { + width: 100px; + height: 100px; + background-color: lightgreen; + }; + </style> +</head> +<body> +<div id="target"></div> +<script type="application/javascript"> + +function waitAndCheckMouseEvents(aTarget, aExpectedEvents) { + return new Promise((aResolve, aReject) => { + let timer; + let cleanup = function() { + if (timer) { + clearTimeout(timer); + timer = null; + } + aTarget.removeEventListener("mousedown", listener); + aTarget.removeEventListener("mouseup", listener); + aTarget.removeEventListener("contextmenu", listener); + aTarget.removeEventListener("click", listener); + aTarget.removeEventListener("auxclick", listener); + }; + + let listener = function(aEvent) { + aEvent.preventDefault(); + let expectedEvent = aExpectedEvents.shift(); + if (!expectedEvent) { + cleanup(); + ok(false, `receive unexpected ${aEvent.type} event`); + aReject(new Error(`receive unexpected ${aEvent.type} event`)); + return; + } + + isDeeply([aEvent.type, aEvent.button, aEvent.ctrlKey], expectedEvent, + `check received ${aEvent.type} event`); + if (!aExpectedEvents.length) { + // Wait a bit to see if there is any unexpected event. + timer = setTimeout(function() { + cleanup(); + aResolve(); + }, 0); + } + }; + + aTarget.addEventListener("mousedown", listener); + aTarget.addEventListener("mouseup", listener); + aTarget.addEventListener("contextmenu", listener); + aTarget.addEventListener("click", listener); + aTarget.addEventListener("auxclick", listener); + }); +} + +add_task(async function Init() { + await SimpleTest.promiseFocus(); + await waitUntilApzStable(); + + let target = document.getElementById("target"); + target.addEventListener("click", function() { + ok(false, `should not receive click event`); + }); +}); + +add_task(async function TestMouseClickWithControl() { + await SpecialPowers.pushPrefEnv({ + set: [["dom.event.treat_ctrl_click_as_right_click.disabled", true]], + }); + + let target = document.getElementById("target"); + let promise = waitAndCheckMouseEvents(target, [["mousedown", 0, true], + ["contextmenu", 0, true], + ["mouseup", 0, true]]); + synthesizeNativeMouseEvent({ + type: "click", + target, + offsetX: 10, + offsetY: 10, + modifiers: { ctrlKey: true }, + }); + await promise; +}); + +add_task(async function TestOldBehavior() { + await SpecialPowers.pushPrefEnv({ + set: [["dom.event.treat_ctrl_click_as_right_click.disabled", false]], + }); + + let target = document.getElementById("target"); + let promise = waitAndCheckMouseEvents(target, [["mousedown", 2, true], + ["contextmenu", 2, true], + ["mouseup", 2, true], + ["auxclick", 2, true]]); + synthesizeNativeMouseEvent({ + type: "click", + target, + offsetX: 10, + offsetY: 10, + modifiers: { ctrlKey: true }, + }); + await promise; +}); +</script> +</body> +</html> |