From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../browser/input/browser_dispatchMouseEvent.js | 136 +++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 remote/cdp/test/browser/input/browser_dispatchMouseEvent.js (limited to 'remote/cdp/test/browser/input/browser_dispatchMouseEvent.js') diff --git a/remote/cdp/test/browser/input/browser_dispatchMouseEvent.js b/remote/cdp/test/browser/input/browser_dispatchMouseEvent.js new file mode 100644 index 0000000000..9ab2b74a67 --- /dev/null +++ b/remote/cdp/test/browser/input/browser_dispatchMouseEvent.js @@ -0,0 +1,136 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const PAGE_URL = + "https://example.com/browser/remote/cdp/test/browser/input/doc_events.html"; + +add_task(async function testPressedReleasedAndClick({ client }) { + const { Input } = client; + + await loadURL(PAGE_URL); + await resetEvents(); + + info("Click the 'pointers' div."); + await Input.dispatchMouseEvent({ + type: "mousePressed", + x: 80, + y: 180, + }); + await Input.dispatchMouseEvent({ + type: "mouseReleased", + x: 80, + y: 180, + }); + + const events = await getEvents(); + ["mousedown", "mouseup", "click"].forEach((type, index) => { + info(`Checking properties for event ${type}`); + checkProperties({ type, button: 0 }, events[index]); + }); +}); + +add_task(async function testModifiers({ client }) { + const { Input } = client; + + await loadURL(PAGE_URL); + + const testable_modifiers = [ + [alt], + [ctrl], + [meta], + [shift], + [alt, meta], + [ctrl, shift], + [alt, ctrl, meta, shift], + ]; + + for (let modifiers of testable_modifiers) { + info(`MousePressed with modifier ${modifiers} on the 'pointers' div.`); + + await resetEvents(); + await Input.dispatchMouseEvent({ + type: "mousePressed", + x: 80, + y: 180, + modifiers: modifiers.reduce((previous, current) => previous | current), + }); + + const events = await getEvents(); + const expectedEvent = { + type: "mousedown", + button: 0, + altKey: modifiers.includes(alt), + ctrlKey: modifiers.includes(ctrl), + metaKey: modifiers.includes(meta), + shiftKey: modifiers.includes(shift), + }; + + checkProperties(expectedEvent, events[0]); + } +}); + +add_task(async function testClickCount({ client }) { + const { Input } = client; + + await loadURL(PAGE_URL); + + const testable_clickCounts = [ + { type: "click", clickCount: 1 }, + { type: "dblclick", clickCount: 2 }, + ]; + + for (const { clickCount, type } of testable_clickCounts) { + info(`MousePressed with clickCount ${clickCount} on the 'pointers' div.`); + + await resetEvents(); + await Input.dispatchMouseEvent({ + type: "mousePressed", + x: 80, + y: 180, + clickCount, + }); + await Input.dispatchMouseEvent({ + type: "mouseReleased", + x: 80, + y: 180, + clickCount, + }); + + const events = await getEvents(); + checkProperties({ type, button: 0 }, events[events.length - 1]); + } +}); + +add_task(async function testDispatchMouseEventAwaitClick({ client }) { + const { Input } = client; + + await setupForInput(PAGE_URL); + await loadURL( + toDataURL(` +
foo
+ `) + ); + + const { x, y } = await SpecialPowers.spawn( + gBrowser.selectedBrowser, + [], + () => { + const div = content.document.querySelector("div"); + return div.getBoundingClientRect(); + } + ); + + await Input.dispatchMouseEvent({ type: "mousePressed", x, y }); + await Input.dispatchMouseEvent({ type: "mouseReleased", x, y }); + + const context = await enableRuntime(client); + const { result } = await evaluate( + client, + context.id, + () => globalThis.result + ); + + is(result.value, "clicked", "Awaited click event handler"); +}); -- cgit v1.2.3