зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1765619 - [remote] Add getTabForBrowsingContext helper in TabManager r=webdriver-reviewers,whimboo
Depends on D159121 Differential Revision: https://phabricator.services.mozilla.com/D159334
This commit is contained in:
Родитель
e41ebdb2d7
Коммит
60cb11e9ff
|
@ -267,6 +267,25 @@ export var TabManager = {
|
|||
return count;
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve the tab owning a Browsing Context.
|
||||
*
|
||||
* @param {BrowsingContext=} browsingContext
|
||||
* The browsing context to get the tab from.
|
||||
*
|
||||
* @returns {Tab|null}
|
||||
* The tab owning the Browsing Context.
|
||||
*/
|
||||
getTabForBrowsingContext(browsingContext) {
|
||||
const browser = browsingContext?.top.embedderElement;
|
||||
if (!browser) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const tabBrowser = this.getTabBrowser(browser.ownerGlobal);
|
||||
return tabBrowser.getTabForBrowser(browser);
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove the given tab.
|
||||
*
|
||||
|
|
|
@ -127,3 +127,22 @@ add_task(async function test_addTab_window() {
|
|||
await BrowserTestUtils.closeWindow(win2);
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_getTabForBrowsingContext() {
|
||||
const tab = await TabManager.addTab();
|
||||
try {
|
||||
const browser = tab.linkedBrowser;
|
||||
|
||||
info(`Navigate to ${TEST_URL}`);
|
||||
const loaded = BrowserTestUtils.browserLoaded(browser);
|
||||
BrowserTestUtils.loadURI(browser, TEST_URL);
|
||||
await loaded;
|
||||
|
||||
const contexts = browser.browsingContext.getAllBrowsingContextsInSubtree();
|
||||
is(TabManager.getTabForBrowsingContext(contexts[0]), tab);
|
||||
is(TabManager.getTabForBrowsingContext(contexts[1]), tab);
|
||||
is(TabManager.getTabForBrowsingContext(null), null);
|
||||
} finally {
|
||||
gBrowser.removeTab(tab);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -123,10 +123,7 @@ class BrowsingContextModule extends Module {
|
|||
);
|
||||
}
|
||||
|
||||
const browser = context.embedderElement;
|
||||
const tabBrowser = lazy.TabManager.getTabBrowser(browser.ownerGlobal);
|
||||
const tab = tabBrowser.getTabForBrowser(browser);
|
||||
|
||||
const tab = lazy.TabManager.getTabForBrowsingContext(context);
|
||||
await lazy.TabManager.removeTab(tab);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче