Skip to content

Commit

Permalink
Bug 1761445 - TabManager.getBrowsingContextById should not return clo…
Browse files Browse the repository at this point in the history
…sed browsing contexts. r=jdescottes,webdriver-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D225303
  • Loading branch information
Temidayo32 committed Dec 2, 2024
1 parent 938da3d commit 6b6b1a4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
13 changes: 10 additions & 3 deletions remote/shared/TabManager.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,22 @@ class TabManagerClass {
* @param {string} id
* A browsing context unique id (created by getIdForBrowsingContext).
* @returns {BrowsingContext=}
* The browsing context found for this id, null if none was found.
* The browsing context found for this id, null if none was found or
* browsing context is discarded.
*/
getBrowsingContextById(id) {
const browser = this.getBrowserById(id);
let browsingContext;
if (browser) {
return browser.browsingContext;
browsingContext = browser.browsingContext;
} else {
browsingContext = BrowsingContext.get(id);
}

return BrowsingContext.get(id);
if (!browsingContext || browsingContext.isDiscarded) {
return null;
}
return browsingContext;
}

/**
Expand Down
21 changes: 21 additions & 0 deletions remote/shared/test/browser/browser_TabManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@ add_task(async function test_getBrowsingContextById() {
is(TabManager.getBrowsingContextById(childContextId), contexts[1]);
});

add_task(async function test_getDiscardedBrowsingContextById() {
const tab = await TabManager.addTab();
const browser = tab.linkedBrowser;
const browsingContext = browser.browsingContext;
const contextId = TabManager.getIdForBrowsingContext(browsingContext);

is(
TabManager.getBrowsingContextById(contextId),
browsingContext,
"Browsing context is accessible by its ID"
);

gBrowser.removeTab(tab);

is(
TabManager.getBrowsingContextById(contextId),
null,
"Browsing context is no longer accessible after the tab is removed"
);
});

add_task(async function test_getIdForBrowsingContext() {
const browser = gBrowser.selectedBrowser;

Expand Down

0 comments on commit 6b6b1a4

Please sign in to comment.