Skip to content

Commit

Permalink
Bug 1676671 - [marionette] Refactor driver::registerBrowser and brows…
Browse files Browse the repository at this point in the history
…er::register to infer id from browser element r=marionette-reviewers,maja_zf,whimboo

Depends on D98778

Differential Revision: https://phabricator.services.mozilla.com/D98779
  • Loading branch information
juliandescottes committed Dec 10, 2020
1 parent a0a8b63 commit 9a414fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
8 changes: 5 additions & 3 deletions testing/marionette/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,14 @@ browser.Context = class {
* if it is not already assigned, and if a) we already have a session
* or b) we're starting a new session and it is the right start frame.
*
* @param {string} uid
* Frame uid for use by Marionette.
* @param {xul:browser} target
* The <xul:browser> that was the target of the originating message.
*/
register(uid, target) {
register(target) {
// Note that browsing contexts can be swapped during navigation in which
// case this id would no longer match the target. See Bug 1680479.
const uid = target.browsingContext.id;

if (this.tabBrowser) {
// If we're setting up a new session on Firefox, we only process the
// registration for this frame if it belongs to the current tab.
Expand Down
31 changes: 16 additions & 15 deletions testing/marionette/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,35 +612,37 @@ GeckoDriver.prototype.getVisibleText = function(el, lines) {
/**
* Handles registration of new content listener browsers. Depending on
* their type they are either accepted or ignored.
*
* @param {xul:browser} browserElement
*/
GeckoDriver.prototype.registerBrowser = function(id, be) {
GeckoDriver.prototype.registerBrowser = function(browserElement) {
// We want to ignore frames that are XUL browsers that aren't in the "main"
// tabbrowser, but accept things on Fennec (which doesn't have a
// xul:tabbrowser), and accept HTML iframes (because tests depend on it),
// as well as XUL frames. Ideally this should be cleaned up and we should
// keep track of browsers a different way.
if (
this.appId != APP_ID_FIREFOX ||
be.namespaceURI != XUL_NS ||
be.nodeName != "browser" ||
be.getTabBrowser()
browserElement.namespaceURI != XUL_NS ||
browserElement.nodeName != "browser" ||
browserElement.getTabBrowser()
) {
// curBrowser holds all the registered frames in knownFrames
this.curBrowser.register(id, be);
this.curBrowser.register(browserElement);
}

this.wins.set(id, BrowsingContext.get(id).currentWindowGlobal);
const browsingContext = browserElement.browsingContext;
this.wins.set(browsingContext.id, browsingContext.currentWindowGlobal);

return id;
return browsingContext.id;
};

GeckoDriver.prototype.registerPromise = function() {
const li = "Marionette:Register";

return new Promise(resolve => {
let cb = ({ json, target }) => {
let { frameId } = json;
this.registerBrowser(frameId, target);
this.registerBrowser(target);

if (this.curBrowser.frameRegsPending > 0) {
this.curBrowser.frameRegsPending--;
Expand All @@ -651,7 +653,7 @@ GeckoDriver.prototype.registerPromise = function() {
resolve();
}

return { frameId };
return { frameId: json.frameId };
};
this.mm.addMessageListener(li, cb);
});
Expand Down Expand Up @@ -883,7 +885,7 @@ GeckoDriver.prototype.newSession = async function(cmd) {
const tabBrowser = browser.getTabBrowser(win);
for (const tab of tabBrowser.tabs) {
const contentBrowser = browser.getBrowserForTab(tab);
this.registerBrowser(contentBrowser.browsingContext.id, contentBrowser);
this.registerBrowser(contentBrowser);
}
}
} else {
Expand Down Expand Up @@ -1756,7 +1758,7 @@ GeckoDriver.prototype.setWindowHandle = async function(
: tabBrowser;

this.contentBrowsingContext = contentBrowser.browsingContext;
this.registerBrowser(this.contentBrowsingContext.id, contentBrowser);
this.registerBrowser(contentBrowser);
} else {
await registerBrowsers;
const id = await browserListening;
Expand Down Expand Up @@ -3697,9 +3699,8 @@ GeckoDriver.prototype.receiveMessage = function(message) {
break;

case "Marionette:Register":
let { frameId } = message.json;
this.registerBrowser(frameId, message.target);
return { frameId };
this.registerBrowser(message.target);
return { frameId: message.json.frameId };

case "Marionette:ListenersAttached":
if (MarionettePrefs.useActors) {
Expand Down

0 comments on commit 9a414fd

Please sign in to comment.