mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1822466 - [marionette] Add global WebDriverSession map as singleton and allow access for Marionette command parent actor. r=webdriver-reviewers,jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D177490
This commit is contained in:
parent
fc3d58cac0
commit
7d0e610e9a
@ -16,6 +16,11 @@ XPCOMUtils.defineLazyGetter(lazy, "logger", () =>
|
||||
lazy.Log.get(lazy.Log.TYPES.MARIONETTE)
|
||||
);
|
||||
|
||||
// Because Marionette supports a single session only we store its id
|
||||
// globally so that the parent actor can access it.
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
let webDriverSessionId = null;
|
||||
|
||||
export class MarionetteCommandsParent extends JSWindowActorParent {
|
||||
actorCreated() {
|
||||
this._resolveDialogOpened = null;
|
||||
@ -350,8 +355,11 @@ export function getMarionetteCommandsActorProxy(browsingContextFn) {
|
||||
|
||||
/**
|
||||
* Register the MarionetteCommands actor that holds all the commands.
|
||||
*
|
||||
* @param {string} sessionId
|
||||
* The id of the current WebDriver session.
|
||||
*/
|
||||
export function registerCommandsActor() {
|
||||
export function registerCommandsActor(sessionId) {
|
||||
try {
|
||||
ChromeUtils.registerWindowActor("MarionetteCommands", {
|
||||
kind: "JSWindowActor",
|
||||
@ -374,8 +382,12 @@ export function registerCommandsActor() {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
webDriverSessionId = sessionId;
|
||||
}
|
||||
|
||||
export function unregisterCommandsActor() {
|
||||
webDriverSessionId = null;
|
||||
|
||||
ChromeUtils.unregisterWindowActor("MarionetteCommands");
|
||||
}
|
||||
|
@ -473,7 +473,7 @@ GeckoDriver.prototype.newSession = async function(cmd) {
|
||||
this.dialog = lazy.modal.findModalDialogs(this.curBrowser);
|
||||
}
|
||||
|
||||
lazy.registerCommandsActor();
|
||||
lazy.registerCommandsActor(this.currentSession.id);
|
||||
lazy.enableEventsActor();
|
||||
|
||||
Services.obs.addObserver(this, TOPIC_BROWSER_READY);
|
||||
|
@ -201,9 +201,13 @@ export class WebDriverSession {
|
||||
}
|
||||
|
||||
lazy.registerProcessDataActor();
|
||||
|
||||
webDriverSessions.set(this.id, this);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
webDriverSessions.delete(this.id);
|
||||
|
||||
lazy.allowAllCerts.disable();
|
||||
|
||||
// Close all open connections which unregister themselves.
|
||||
@ -346,3 +350,18 @@ export class WebDriverSession {
|
||||
return ChromeUtils.generateQI(["nsIHttpRequestHandler"]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} sessionId
|
||||
* The ID of the WebDriver session to retrieve.
|
||||
*
|
||||
* @returns {WebDriverSession}
|
||||
* The WebDriver session.
|
||||
*/
|
||||
export function getWebDriverSessionById(sessionId) {
|
||||
return webDriverSessions.get(sessionId);
|
||||
}
|
||||
|
||||
// Global singleton that holds active WebDriver sessions
|
||||
const webDriverSessions = new Map();
|
||||
|
@ -7,7 +7,10 @@
|
||||
const { Capabilities, Timeouts } = ChromeUtils.importESModule(
|
||||
"chrome://remote/content/shared/webdriver/Capabilities.sys.mjs"
|
||||
);
|
||||
const { WebDriverSession } = ChromeUtils.importESModule(
|
||||
const {
|
||||
WebDriverSession,
|
||||
getWebDriverSessionById,
|
||||
} = ChromeUtils.importESModule(
|
||||
"chrome://remote/content/shared/webdriver/Session.sys.mjs"
|
||||
);
|
||||
|
||||
@ -18,6 +21,12 @@ add_task(function test_WebDriverSession_ctor() {
|
||||
ok(session.capabilities instanceof Capabilities);
|
||||
});
|
||||
|
||||
add_task(function test_WebDriverSession_destroy() {
|
||||
const session = new WebDriverSession();
|
||||
|
||||
session.destroy();
|
||||
});
|
||||
|
||||
add_task(function test_WebDriverSession_getters() {
|
||||
const session = new WebDriverSession();
|
||||
|
||||
@ -47,3 +56,19 @@ add_task(function test_WebDriverSession_setters() {
|
||||
session.timeouts = timeouts;
|
||||
equal(session.timeouts, session.capabilities.get("timeouts"));
|
||||
});
|
||||
|
||||
add_task(function test_getWebDriverSessionById() {
|
||||
const session1 = new WebDriverSession();
|
||||
const session2 = new WebDriverSession();
|
||||
|
||||
equal(getWebDriverSessionById(session1.id), session1);
|
||||
equal(getWebDriverSessionById(session2.id), session2);
|
||||
|
||||
session1.destroy();
|
||||
equal(getWebDriverSessionById(session1.id), undefined);
|
||||
equal(getWebDriverSessionById(session2.id), session2);
|
||||
|
||||
session2.destroy();
|
||||
equal(getWebDriverSessionById(session1.id), undefined);
|
||||
equal(getWebDriverSessionById(session2.id), undefined);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user