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/events/test/pointerevents/mochitest_support_internal.js | |
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/events/test/pointerevents/mochitest_support_internal.js')
-rw-r--r-- | dom/events/test/pointerevents/mochitest_support_internal.js | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/dom/events/test/pointerevents/mochitest_support_internal.js b/dom/events/test/pointerevents/mochitest_support_internal.js new file mode 100644 index 0000000000..d46dd14f32 --- /dev/null +++ b/dom/events/test/pointerevents/mochitest_support_internal.js @@ -0,0 +1,125 @@ +// This file supports translating W3C tests +// to tests on auto MochiTest system with minimum changes. +// Author: Maksim Lebedev <alessarik@gmail.com> + +const PARENT_ORIGIN = "http://mochi.test:8888/"; + +// Since web platform tests don't check pointerId, we have to use some heuristic +// to test them. and thus pointerIds are send to mochitest_support_external.js +// before we start sending synthesized widget events. Here, we avoid using +// default values used in Gecko to insure everything works as expected. +const POINTER_MOUSE_ID = 7; +const POINTER_PEN_ID = 8; +const POINTER_TOUCH_ID = 9; // Extend for multiple touch points if needed. + +// Setup environment. +addListeners(document.getElementById("target0")); +addListeners(document.getElementById("target1")); + +// Setup communication between mochitest_support_external.js. +// Function allows to initialize prerequisites before testing +// and adds some callbacks to support mochitest system. +function resultCallback(aTestObj) { + var message = aTestObj.name + " ("; + message += "Get: " + JSON.stringify(aTestObj.status) + ", "; + message += "Expect: " + JSON.stringify(aTestObj.PASS) + ")"; + window.opener.postMessage( + { + type: "RESULT", + message, + result: aTestObj.status === aTestObj.PASS, + }, + PARENT_ORIGIN + ); +} + +add_result_callback(resultCallback); +add_completion_callback(() => { + window.opener.postMessage({ type: "FIN" }, PARENT_ORIGIN); +}); + +window.addEventListener("load", () => { + // Start testing. + var startMessage = { + type: "START", + message: { + mouseId: POINTER_MOUSE_ID, + penId: POINTER_PEN_ID, + touchId: POINTER_TOUCH_ID, + }, + }; + window.opener.postMessage(startMessage, PARENT_ORIGIN); +}); + +function addListeners(elem) { + if (!elem) { + return; + } + var All_Events = [ + "pointerdown", + "pointerup", + "pointercancel", + "pointermove", + "pointerover", + "pointerout", + "pointerenter", + "pointerleave", + "gotpointercapture", + "lostpointercapture", + ]; + All_Events.forEach(function (name) { + elem.addEventListener(name, function (event) { + console.log("(" + event.type + ")-(" + event.pointerType + ")"); + + // Perform checks only for trusted events. + if (!event.isTrusted) { + return; + } + + // Compute the desired event.pointerId from event.pointerType. + var pointerId = { + mouse: POINTER_MOUSE_ID, + pen: POINTER_PEN_ID, + touch: POINTER_TOUCH_ID, + }[event.pointerType]; + + // Compare the pointerId. + resultCallback({ + name: "Mismatched event.pointerId recieved.", + status: event.pointerId, + PASS: pointerId, + }); + }); + }); +} + +// mock the touchScrollInTarget to make the test work. +function touchScrollInTarget() { + return Promise.resolve(); +} + +// mock test_driver to make the test work. +function Actions() {} +Actions.prototype = { + addPointer() { + return this; + }, + pointerMove() { + return this; + }, + pointerDown() { + return this; + }, + pause() { + return this; + }, + pointerUp() { + return this; + }, + send() { + return Promise.resolve(); + }, +}; +const test_driver = { + Actions, +}; |