Assert.stringMatches(
initialBrowserId,
uuidRegex, "Initial browser is a valid uuid"
); Assert.stringMatches(
newBrowserId,
uuidRegex, "New tab's browser is a valid uuid"
);
isnot(initialBrowserId, newBrowserId, "Both browsers have different ids");
Assert.stringMatches(
newContextId,
uuidRegex, "Top context is a valid uuid"
); Assert.stringMatches(
newFrameContextIds[0],
numberRegex, "First child context has a valid id"
); Assert.stringMatches(
newFrameContextIds[1],
numberRegex, "Second child context has a valid id"
);
isnot(
newContextId,
newFrameContextIds[0], "Id of top-level context is different from first child context"
);
isnot(
newContextId,
newFrameContextIds[0], "Id of top-level context is different from second child context"
);
is(
NavigableManager.getBrowsingContextById(newFrameContextIds[0]),
newFrameContexts[0], "Context of first child can be retrieved by id"
);
is(
NavigableManager.getBrowsingContextById(newFrameContextIds[1]),
newFrameContexts[1], "Context of second child can be retrieved by id"
);
});
it("Get the Navigable id for a browser", async function test_getIdForBrowser() { const { initialBrowser, newBrowser, newContext } = testData;
is(
NavigableManager.getIdForBrowser(newContext), null, "Requires a browser instance as argument"
);
const newBrowserId = NavigableManager.getIdForBrowser(newBrowser); Assert.stringMatches(
NavigableManager.getIdForBrowser(newBrowser),
uuidRegex, "Got a valid uuid for the browser"
);
is(
NavigableManager.getIdForBrowser(newBrowser),
newBrowserId, "For the same browser the identical id is returned"
);
isnot(
NavigableManager.getIdForBrowser(initialBrowser),
newBrowserId, "For a different browser the id is not the same"
);
});
it("Get the Navigable id for a BrowsingContext", async function test_getIdForBrowsingContext() { const { newBrowser, newContext, newFrameContexts } = testData;
Assert.stringMatches(
newContextId,
uuidRegex, "Got a valid uuid for top-level context"
);
is(
NavigableManager.getIdForBrowsingContext(newContext),
newContextId, "Id is always the same for a top-level context"
);
is(
NavigableManager.getIdForBrowsingContext(newContext),
NavigableManager.getIdForBrowser(newBrowser), "Id of a top-level context is equal to the browser id"
);
Assert.stringMatches(
newFrameContextIds[0],
numberRegex, "Got a valid id for a child context"
);
is(
NavigableManager.getIdForBrowsingContext(newFrameContexts[0]),
newFrameContextIds[0], "Id is always the same for a child context"
);
});
it("Get the Navigable for a BrowsingContext", async function test_getNavigableForBrowsingContext() { const { newBrowser, newContext, newFrameContexts, newTab } = testData;
const invalidValues = [undefined, null, 1, "test", {}, [], newBrowser];
invalidValues.forEach(invalidValue => Assert.throws(
() => NavigableManager.getNavigableForBrowsingContext(invalidValue),
/Expected browsingContext to be a CanonicalBrowsingContext/
)
);
is(
NavigableManager.getNavigableForBrowsingContext(newContext),
newBrowser, "Top-Level context has the content browser as navigable"
);
is(
NavigableManager.getNavigableForBrowsingContext(newFrameContexts[0]),
newFrameContexts[0], "Child context has itself as navigable"
);
gBrowser.removeTab(newTab);
});
it("Get discarded BrowsingContext by id", async function test_getDiscardedBrowsingContextById() { const { newBrowser, newContext, newFrameContexts, newTab } = testData;
is(
NavigableManager.getBrowsingContextById(newContextId),
newContext, "Top context can be retrieved by its id"
);
is(
NavigableManager.getBrowsingContextById(newFrameContextIds[0]),
newFrameContexts[0], "Child context can be retrieved by its id"
);
// Remove all the iframes
await SpecialPowers.spawn(newBrowser, [], async () => { const frames = content.document.querySelectorAll("iframe");
frames.forEach(frame => frame.remove());
});
is(
NavigableManager.getBrowsingContextById(newContextId),
newContext, "Top context can still be retrieved after removing all the frames"
);
is(
NavigableManager.getBrowsingContextById(newFrameContextIds[0]), null, "Child context can no longer be retrieved by its id after removing all the frames"
);
gBrowser.removeTab(newTab);
is(
NavigableManager.getBrowsingContextById(newContextId), null, "Top context can no longer be retrieved by its id after the tab is closed"
);
});
is(
NavigableManager.getIdForBrowser(newBrowser),
newBrowserId, "Id for the browser is still available after unloading the tab"
);
is(
NavigableManager.getBrowserById(newBrowserId),
newBrowser, "Unloaded browser can still be retrieved by id"
);
is(
NavigableManager.getIdForBrowsingContext(newContext),
newContextId, "Id for the browsing context is still available after unloading the tab"
);
is(
NavigableManager.getBrowsingContextById(newContextId), null, "Browsing context can no longer be retrieved after unloading the tab"
); Assert.throws(
() => NavigableManager.getNavigableForBrowsingContext(newContext),
/Expected browsingContext to be a CanonicalBrowsingContext/
);
// Loading a new page for new browsing contexts
await loadURL(newBrowser, TEST_URL);
is(
NavigableManager.getIdForBrowser(newBrowser),
newBrowserId, "Id for the browser is still the same when navigating after unloading the tab"
);
is(
NavigableManager.getBrowserById(newBrowserId),
newBrowser, "New browser can be retrieved by its id"
);
is(
NavigableManager.getIdForBrowsingContext(newBrowsingContext),
newContextId, "Id for the new top-level context is still the same"
);
is(
NavigableManager.getBrowsingContextById(newContextId),
newBrowsingContext, "Top-level context can be retrieved again"
);
is(
NavigableManager.getNavigableForBrowsingContext(newBrowsingContext),
newBrowser, "The navigable can be retrieved again"
);
});
it("Retrieve id for cross-group opener", async function test_crossGroupOpener() { const { newContext, newBrowser, newTab } = testData;
isnot(
browser.browsingContext.crossGroupOpener, null, "Opened popup window has a cross-group opener"
);
is(
NavigableManager.getIdForBrowsingContext(openerContext),
newContextId, "Id of cross-group opener context is correct"
);
// Remove the tab which opened the popup window
gBrowser.removeTab(newTab);
is(
NavigableManager.getIdForBrowsingContext(openerContext),
newContextId, "Id of cross-group opener context is still correct after closing the opener tab"
);
});
it("Start and stop tracking of browsing contexts", async function test_startStopTracking() {
async function addUnloadedTab(tabBrowser) {
info(`Open a new tab, navigate, and unload it immediately`); const newTab = await addTabAndWaitForNavigated(tabBrowser, TEST_URL);
// Calling start tracking multiple times doesn't cause failures.
NavigableManager.startTracking();
NavigableManager.startTracking();
{ // Stop tracking of new browsing contexts
NavigableManager.stopTracking();
let { newBrowser, newContext } = await addUnloadedTab(gBrowser);
Assert.stringMatches(
NavigableManager.getIdForBrowser(newBrowser),
uuidRegex, "There is always a valid uuid for the browser"
);
is(
NavigableManager.getIdForBrowsingContext(newContext), null, "There is no id of a temporarily open top-level context"
);
}
// Calling stop tracking multiple times doesn't cause failures.
NavigableManager.stopTracking();
let { newBrowser, newContext } = await addUnloadedTab(gBrowser);
Assert.stringMatches(
NavigableManager.getIdForBrowser(newBrowser),
uuidRegex, "Got a valid uuid for the browser"
); Assert.stringMatches(
NavigableManager.getIdForBrowsingContext(newContext),
uuidRegex, "Got a valid uuid for the top-level context"
);
});
it("Get the Navigable id for a chrome browsing context", async function test_getIdForChromeBrowsingContext() { // Get the parent process browsing context (chrome scope) const chromeContext = window.browsingContext;
ok(!chromeContext.isContent, "Chrome context is not a content context");
Assert.stringMatches(
chromeContextId,
uuidRegex, "Chrome context has valid uuid"
); Assert.stringMatches(
contentContextId,
uuidRegex, "Content context has valid uuid"
);
isnot(
chromeContextId,
contentContextId, "Chrome and content contexts have different ids"
);
});
it("Chrome browsing context cleanup on discard", async function test_chromeBrowsingContextDiscard() { // Open a new window to get a chrome browsing context we can close const newWindow = await BrowserTestUtils.openNewBrowserWindow(); const newChromeContext = BrowsingContext.getFromWindow(newWindow);
ok(
!newChromeContext.isContent, "New window's chrome context is not a content context"
);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.