Bug 1635496 - [remote] Fixed dispatchMouseEvent to not await undefined promises. r=remote-protocol-reviewers,whimboo

The "this" state is not persistent across spawn-calls, using "this" in
"function" also does not make a whole lot of sense.

In order to persist the Promise across spawn-calls, the value is stored
in "content" instead.

Since one cannot reliably return an Event from SpecialPowers.spawn (due
to serialization issues), we are awaiting them instead of returning.

Differential Revision: https://phabricator.services.mozilla.com/D73913
This commit is contained in:
Etienne Bruines 2020-05-05 20:04:16 +00:00
parent cfa05dc693
commit da5b77f74b

View File

@ -10,13 +10,13 @@ add_task(async function testDispatchMouseEvent({ client }) {
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
const div = content.document.querySelector("div");
this.mouseDownPromise = new Promise(resolve => {
content.mouseDownPromise = new Promise(resolve => {
div.addEventListener("mousedown", resolve, { once: true });
});
this.mouseUpPromise = new Promise(resolve => {
content.mouseUpPromise = new Promise(resolve => {
div.addEventListener("mouseup", resolve, { once: true });
});
this.clickPromise = new Promise(resolve => {
content.clickPromise = new Promise(resolve => {
div.addEventListener("click", resolve, { once: true });
});
});
@ -36,8 +36,8 @@ add_task(async function testDispatchMouseEvent({ client }) {
});
info("Waiting for DOM mousedown event on the div");
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
return this.mouseDownPromise;
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function() {
await content.mouseDownPromise;
});
await Input.dispatchMouseEvent({
@ -47,13 +47,13 @@ add_task(async function testDispatchMouseEvent({ client }) {
});
info("Waiting for DOM mouseup event on the div");
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
return this.mouseUpPromise;
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function() {
await content.mouseUpPromise;
});
info("Waiting for DOM click event on the div");
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
return this.clickPromise;
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function() {
await content.clickPromise;
});
ok(true, "All events detected");