Bug 1776989 - Make the test wait expected pointermove event before synthesizing the last click r=edgar,dom-core

When the test fails, `pointerup` event which is used to call
`SimpleTest.finish()` may be fired before `pointermove` which is the target of
the test.  Therefore, the test may run after a call of `SimpleTest.finish()`.

I checked the previous test running before the test which is
`test_bug1725416.html` [1].  It synthesizes a native tap (touch contact and
touch remove).  However, before finishing the test, it waits a `pointerup`.
Therefore, I think that it does not cause this bug.

The most failures occur on Linux, and Linux widget puts a synthesized event
onto the native event queue [2].  The `gdk_event_put` reference says "Appends
a copy of the given event onto the front of the event queue" [3].  Therefore,
the click may be inserted before the preceding mouse move in the event queue.
However, the test waits end of synthesizing each mouse move before synthesizing
a click.  Therefore, I have no idea what's going on.

This patch makes the test wait `pointermove` before synthesizing a click to
avoid the odd event order.

1. https://searchfox.org/mozilla-central/rev/ee9fd5e2df79c6d69af5aa9bc36041166f483227/dom/events/test/pointerevents/test_bug1725416.html
2. https://searchfox.org/mozilla-central/rev/ee9fd5e2df79c6d69af5aa9bc36041166f483227/widget/gtk/nsWindow.cpp#9481
3. https://docs.gtk.org/gdk3/method.Event.put.html

Differential Revision: https://phabricator.services.mozilla.com/D208309
This commit is contained in:
Masayuki Nakano 2024-04-23 12:30:27 +00:00
parent f7d0d6476b
commit e2f9920eb1
2 changed files with 24 additions and 22 deletions

View File

@ -64,7 +64,6 @@ support-files = ["!/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js
skip-if = [
"os == 'android'", # Bug 1312791
"display == 'wayland' && os_version == '22.04'", # Bug 1856971
"verify && os == 'win'", # Bug 1659744
]
["test_getCoalescedEvents_touch.html"]

View File

@ -18,14 +18,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1303957
/** Test for Bug 1303957 **/
SimpleTest.waitForExplicitFinish();
function runTests() {
let target0 = window.document.getElementById("target0");
let utils = SpecialPowers.getDOMWindowUtils(window);
SimpleTest.waitForFocus(async () => {
await SpecialPowers.pushPrefEnv({"set": [["dom.events.coalesce.mousemove", true]]});
const target0 = window.document.getElementById("target0");
const utils = SpecialPowers.getDOMWindowUtils(window);
utils.advanceTimeAndRefresh(0);
SimpleTest.executeSoon(async () => {
// Flush all pending mouse events before synthesizing events.
await new Promise(resolve => SimpleTest.executeSoon(resolve));
const waitForPointerMove = new Promise(resolve => {
target0.addEventListener("pointermove", (ev) => {
let length = ev.getCoalescedEvents().length;
ok(length >= 1, "Coalesced events should >= 1, got " + length);
@ -49,11 +51,11 @@ function runTests() {
ok(coalescedEvent.offsetX >= prevOffsetX, "getCoalescedEvents()[" + i + "].offsetX = " + coalescedEvent.offsetX);
ok(coalescedEvent.offsetX == 5 || coalescedEvent.offsetX == 10 ||
coalescedEvent.offsetX == 15 || coalescedEvent.offsetX == 20, "expected offsetX");
coalescedEvent.offsetX == 15 || coalescedEvent.offsetX == 20, "expected offsetX");
ok(coalescedEvent.offsetY >= prevOffsetY, "getCoalescedEvents()[" + i + "].offsetY = " + coalescedEvent.offsetY);
ok(coalescedEvent.offsetY == 5 || coalescedEvent.offsetY == 10 ||
coalescedEvent.offsetY == 15 || coalescedEvent.offsetY == 20, "expected offsetY");
coalescedEvent.offsetY == 15 || coalescedEvent.offsetY == 20, "expected offsetY");
prevOffsetX = coalescedEvent.offsetX;
prevOffsetY = coalescedEvent.offsetY;
@ -64,23 +66,24 @@ function runTests() {
ok((coalescedEvent.clientX <= x+2) && (coalescedEvent.clientX >= x-2), "getCoalescedEvents()[" + i + "].clientX");
ok((coalescedEvent.clientY <= y+2) && (coalescedEvent.clientY >= y-2), "getCoalescedEvents()[" + i + "].clientY");
}
resolve();
}, { once: true });
target0.addEventListener("pointerup", (ev) => {
utils.restoreNormalRefresh();
SimpleTest.finish();
}, { once: true });
await promiseNativeMouseEvent({ type: "mousemove", target: target0, offsetX: 5, offsetY: 5 });
await promiseNativeMouseEvent({ type: "mousemove", target: target0, offsetX: 10, offsetY: 10 });
await promiseNativeMouseEvent({ type: "mousemove", target: target0, offsetX: 15, offsetY: 15 });
await promiseNativeMouseEvent({ type: "mousemove", target: target0, offsetX: 20, offsetY: 20 });
synthesizeNativeMouseEvent({ type: "click", target: target0, offsetX: 20, offsetY: 20 });
});
}
SimpleTest.waitForFocus(() => {
SpecialPowers.pushPrefEnv({"set": [["dom.events.coalesce.mousemove", true]]}, runTests);
info("Synthesizing native mouse moves....");
await promiseNativeMouseEvent({ type: "mousemove", target: target0, offsetX: 5, offsetY: 5 });
await promiseNativeMouseEvent({ type: "mousemove", target: target0, offsetX: 10, offsetY: 10 });
await promiseNativeMouseEvent({ type: "mousemove", target: target0, offsetX: 15, offsetY: 15 });
await promiseNativeMouseEvent({ type: "mousemove", target: target0, offsetX: 20, offsetY: 20 });
utils.restoreNormalRefresh();
await waitForPointerMove;
target0.addEventListener("pointerup", (ev) => {
SimpleTest.finish();
}, { once: true });
info("Synthesizing a native click....");
synthesizeNativeMouseEvent({ type: "click", target: target0, offsetX: 20, offsetY: 20 });
});
</script>