mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1758502 - [remote] Add TabManager.getBrowsingContextById API r=webdriver-reviewers,whimboo
Differential Revision: https://phabricator.services.mozilla.com/D141944
This commit is contained in:
parent
e55ce25a0a
commit
45df9472d7
@ -135,7 +135,7 @@ var TabManager = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve a the browser element corresponding to the provided unique id,
|
||||
* Retrieve the browser element corresponding to the provided unique id,
|
||||
* previously generated via getIdForBrowser.
|
||||
*
|
||||
* TODO: To avoid creating strong references on browser elements and
|
||||
@ -163,6 +163,23 @@ var TabManager = {
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve the browsing context corresponding to the provided unique id.
|
||||
*
|
||||
* @param {String} id
|
||||
* A browsing context unique id (created by getIdForBrowsingContext).
|
||||
* @return {BrowsingContext=}
|
||||
* The browsing context found for this id, null if none was found.
|
||||
*/
|
||||
getBrowsingContextById(id) {
|
||||
const browser = this.getBrowserById(id);
|
||||
if (browser) {
|
||||
return browser.browsingContext;
|
||||
}
|
||||
|
||||
return BrowsingContext.get(id);
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve the unique id for the given xul browser element. The id is a
|
||||
* dynamically generated uuid associated with the permanentKey property of the
|
||||
|
@ -6,6 +6,7 @@ BROWSER_CHROME_MANIFESTS += [
|
||||
"listeners/test/browser/browser.ini",
|
||||
"messagehandler/test/browser/broadcast/browser.ini",
|
||||
"messagehandler/test/browser/browser.ini",
|
||||
"test/browser/browser.ini",
|
||||
]
|
||||
|
||||
XPCSHELL_TESTS_MANIFESTS += [
|
||||
|
5
remote/shared/test/browser/browser.ini
Normal file
5
remote/shared/test/browser/browser.ini
Normal file
@ -0,0 +1,5 @@
|
||||
[DEFAULT]
|
||||
tags = remote
|
||||
subsuite = remote
|
||||
|
||||
[browser_TabManager.js]
|
35
remote/shared/test/browser/browser_TabManager.js
Normal file
35
remote/shared/test/browser/browser_TabManager.js
Normal file
@ -0,0 +1,35 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const { TabManager } = ChromeUtils.import(
|
||||
"chrome://remote/content/shared/TabManager.jsm"
|
||||
);
|
||||
|
||||
const FRAME_URL = "https://example.com/document-builder.sjs?html=frame";
|
||||
const FRAME_MARKUP = `<iframe src="${encodeURI(FRAME_URL)}"></iframe>`;
|
||||
const TEST_URL = `https://example.com/document-builder.sjs?html=${encodeURI(
|
||||
FRAME_MARKUP
|
||||
)}`;
|
||||
|
||||
add_task(async function test_getBrowsingContextById() {
|
||||
const browser = gBrowser.selectedBrowser;
|
||||
|
||||
is(TabManager.getBrowsingContextById(null), null);
|
||||
is(TabManager.getBrowsingContextById(undefined), null);
|
||||
is(TabManager.getBrowsingContextById("wrong-id"), null);
|
||||
|
||||
info(`Navigate to ${TEST_URL}`);
|
||||
const loaded = BrowserTestUtils.browserLoaded(browser);
|
||||
BrowserTestUtils.loadURI(browser, TEST_URL);
|
||||
await loaded;
|
||||
|
||||
const contexts = browser.browsingContext.getAllBrowsingContextsInSubtree();
|
||||
is(contexts.length, 2, "Top context has 1 child");
|
||||
|
||||
const topContextId = TabManager.getIdForBrowsingContext(contexts[0]);
|
||||
is(TabManager.getBrowsingContextById(topContextId), contexts[0]);
|
||||
const childContextId = TabManager.getIdForBrowsingContext(contexts[1]);
|
||||
is(TabManager.getBrowsingContextById(childContextId), contexts[1]);
|
||||
});
|
@ -107,13 +107,7 @@ class BrowsingContextModule extends Module {
|
||||
`Expected "parent" to be a string, got ${parentId}`
|
||||
);
|
||||
|
||||
// If the parent id is for a top-level browsing context get the browsing
|
||||
// context via the unique id and the related content browser.
|
||||
const browser = TabManager.getBrowserById(parentId);
|
||||
contexts =
|
||||
browser !== null
|
||||
? [browser.browsingContext]
|
||||
: [this.#getBrowsingContext(parentId)];
|
||||
contexts = [this.#getBrowsingContext(parentId)];
|
||||
} else {
|
||||
// Return all top-level browsing contexts.
|
||||
contexts = TabManager.browsers.map(browser => browser.browsingContext);
|
||||
@ -143,7 +137,7 @@ class BrowsingContextModule extends Module {
|
||||
return null;
|
||||
}
|
||||
|
||||
const context = BrowsingContext.get(contextId);
|
||||
const context = TabManager.getBrowsingContextById(contextId);
|
||||
if (context === null) {
|
||||
throw new error.NoSuchFrameError(
|
||||
`Browsing Context with id ${contextId} not found`
|
||||
|
Loading…
Reference in New Issue
Block a user