mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 1562740
- Input:dispatchKeyEvent should wait for events in content process r=remote-protocol-reviewers,ochameau
Depends on D37165 Differential Revision: https://phabricator.services.mozilla.com/D37166 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
981f531b1f
commit
3958f91262
@ -10,4 +10,47 @@ const { ContentProcessDomain } = ChromeUtils.import(
|
||||
"chrome://remote/content/domains/ContentProcessDomain.jsm"
|
||||
);
|
||||
|
||||
class Input extends ContentProcessDomain {}
|
||||
class Input extends ContentProcessDomain {
|
||||
constructor(session) {
|
||||
super(session);
|
||||
|
||||
// Map of event name -> event handler promise.
|
||||
this._eventPromises = new Map();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not a CDP method.
|
||||
*
|
||||
* Add an event listener in the content page for the provided eventName.
|
||||
* To wait for the event, you should use `waitForContentEvent` with the same event name.
|
||||
*
|
||||
* Example usage from a parent process domain:
|
||||
*
|
||||
* await this.executeInChild("addContentEventListener", "click");
|
||||
* // do something that triggers a click in content
|
||||
* await this.executeInChild("waitForContentEvent", "click");
|
||||
*/
|
||||
addContentEventListener(eventName) {
|
||||
const eventPromise = new Promise(r => {
|
||||
this.chromeEventHandler.addEventListener(eventName, r, {
|
||||
mozSystemGroup: true,
|
||||
once: true,
|
||||
});
|
||||
});
|
||||
this._eventPromises.set(eventName, eventPromise);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not a CDP method.
|
||||
*
|
||||
* Wait for an event listener added via `addContentEventListener` to be fired.
|
||||
*/
|
||||
async waitForContentEvent(eventName) {
|
||||
const eventPromise = this._eventPromises.get(eventName);
|
||||
if (!eventPromise) {
|
||||
throw new Error("No event promise available for " + eventName);
|
||||
}
|
||||
await eventPromise;
|
||||
this._eventPromises.delete(eventName);
|
||||
}
|
||||
}
|
||||
|
@ -50,12 +50,7 @@ class Input extends Domain {
|
||||
const browserWindow = browser.ownerGlobal;
|
||||
|
||||
const EventUtils = this._getEventUtils(browserWindow);
|
||||
const onEvent = new Promise(r => {
|
||||
browserWindow.addEventListener(domType, r, {
|
||||
mozSystemGroup: true,
|
||||
once: true,
|
||||
});
|
||||
});
|
||||
await this.executeInChild("addContentEventListener", domType);
|
||||
|
||||
if (type == "char") {
|
||||
// type == "char" is used when doing `await page.keyboard.type( 'I’m a list' );`
|
||||
@ -77,7 +72,8 @@ class Input extends Domain {
|
||||
browserWindow
|
||||
);
|
||||
}
|
||||
await onEvent;
|
||||
|
||||
await this.executeInChild("waitForContentEvent", domType);
|
||||
}
|
||||
|
||||
async dispatchMouseEvent({ type, button, x, y, modifiers, clickCount }) {
|
||||
|
Loading…
Reference in New Issue
Block a user