mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1775141 - [webdriver-bidi] Send live "browsingContext.contextCreated" events with "about:blank" as URL. r=webdriver-reviewers,jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D151321
This commit is contained in:
parent
3e69adc940
commit
fc98681137
@ -20,6 +20,8 @@ XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
const OBSERVER_TOPIC_ATTACHED = "browsing-context-attached";
|
||||
const OBSERVER_TOPIC_DISCARDED = "browsing-context-discarded";
|
||||
|
||||
const OBSERVER_TOPIC_SET_EMBEDDER = "browsing-context-did-set-embedder";
|
||||
|
||||
/**
|
||||
* The BrowsingContextListener can be used to listen for notifications coming
|
||||
* from browsing contexts that get attached or discarded.
|
||||
@ -47,6 +49,7 @@ const OBSERVER_TOPIC_DISCARDED = "browsing-context-discarded";
|
||||
*/
|
||||
class BrowsingContextListener {
|
||||
#listening;
|
||||
#topContextsToAttach;
|
||||
|
||||
/**
|
||||
* Create a new BrowsingContextListener instance.
|
||||
@ -54,6 +57,11 @@ class BrowsingContextListener {
|
||||
constructor() {
|
||||
lazy.EventEmitter.decorate(this);
|
||||
|
||||
// A map that temporarily holds attached top-level browsing contexts until
|
||||
// their embedder element is set, which is required to successfully
|
||||
// retrieve a unique id for the content browser by the TabManager.
|
||||
this.#topContextsToAttach = new Map();
|
||||
|
||||
this.#listening = false;
|
||||
}
|
||||
|
||||
@ -64,11 +72,33 @@ class BrowsingContextListener {
|
||||
observe(subject, topic, data) {
|
||||
switch (topic) {
|
||||
case OBSERVER_TOPIC_ATTACHED:
|
||||
// Delay emitting the event for top-level browsing contexts until
|
||||
// the embedder element has been set.
|
||||
if (!subject.parent) {
|
||||
this.#topContextsToAttach.set(subject, data);
|
||||
return;
|
||||
}
|
||||
|
||||
this.emit("attached", { browsingContext: subject, why: data });
|
||||
break;
|
||||
|
||||
case OBSERVER_TOPIC_DISCARDED:
|
||||
// Remove a recently attached top-level browsing context if it's
|
||||
// immediately discarded.
|
||||
if (this.#topContextsToAttach.has(subject)) {
|
||||
this.#topContextsToAttach.delete(subject);
|
||||
}
|
||||
|
||||
this.emit("discarded", { browsingContext: subject, why: data });
|
||||
break;
|
||||
|
||||
case OBSERVER_TOPIC_SET_EMBEDDER:
|
||||
const why = this.#topContextsToAttach.get(subject);
|
||||
if (why !== undefined) {
|
||||
this.emit("attached", { browsingContext: subject, why });
|
||||
this.#topContextsToAttach.delete(subject);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,6 +109,7 @@ class BrowsingContextListener {
|
||||
|
||||
Services.obs.addObserver(this, OBSERVER_TOPIC_ATTACHED);
|
||||
Services.obs.addObserver(this, OBSERVER_TOPIC_DISCARDED);
|
||||
Services.obs.addObserver(this, OBSERVER_TOPIC_SET_EMBEDDER);
|
||||
|
||||
this.#listening = true;
|
||||
}
|
||||
@ -90,6 +121,9 @@ class BrowsingContextListener {
|
||||
|
||||
Services.obs.removeObserver(this, OBSERVER_TOPIC_ATTACHED);
|
||||
Services.obs.removeObserver(this, OBSERVER_TOPIC_DISCARDED);
|
||||
Services.obs.removeObserver(this, OBSERVER_TOPIC_SET_EMBEDDER);
|
||||
|
||||
this.#topContextsToAttach.clear();
|
||||
|
||||
this.#listening = false;
|
||||
}
|
||||
|
@ -28,6 +28,32 @@ add_task(async function test_attachedOnNewTab() {
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(async function test_attachedValidEmbedderElement() {
|
||||
const listener = new BrowsingContextListener();
|
||||
|
||||
let hasEmbedderElement = false;
|
||||
listener.on(
|
||||
"attached",
|
||||
(evtName, { browsingContext }) => {
|
||||
hasEmbedderElement = !!browsingContext.embedderElement;
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
|
||||
listener.startListening();
|
||||
|
||||
const tab = BrowserTestUtils.addTab(gBrowser, "about:blank");
|
||||
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
|
||||
ok(
|
||||
hasEmbedderElement,
|
||||
"Attached browsing context has a valid embedder element"
|
||||
);
|
||||
|
||||
listener.stopListening();
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(async function test_discardedOnCloseTab() {
|
||||
const listener = new BrowsingContextListener();
|
||||
const discarded = listener.once("discarded");
|
||||
|
@ -514,11 +514,6 @@ class BrowsingContextModule extends Module {
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait until navigation starts, so that an active document is attached.
|
||||
await lazy.waitForInitialNavigationCompleted(browsingContext.webProgress, {
|
||||
resolveWhenStarted: true,
|
||||
});
|
||||
|
||||
const contextInfo = this.#getBrowsingContextInfo(browsingContext, {
|
||||
maxDepth: 0,
|
||||
});
|
||||
|
@ -1,20 +1,11 @@
|
||||
[context_created.py]
|
||||
disabled:
|
||||
if os == "android": https://bugzilla.mozilla.org/show_bug.cgi?id=1506782
|
||||
expected:
|
||||
if (os == "win") and not debug and (processor == "x86_64"): [OK, TIMEOUT]
|
||||
[test_navigate_creates_iframes]
|
||||
expected:
|
||||
if debug and (os == "linux") and fission and not swgl: [FAIL, PASS]
|
||||
FAIL
|
||||
|
||||
[test_navigate_creates_nested_iframes]
|
||||
expected:
|
||||
if debug and (os == "linux") and not swgl: [FAIL, PASS]
|
||||
FAIL
|
||||
|
||||
[test_evaluate_window_open_without_url]
|
||||
bug: 1770754
|
||||
expected: FAIL
|
||||
|
||||
[test_evaluate_window_open_with_url]
|
||||
bug: 1770754
|
||||
expected: FAIL
|
||||
|
Loading…
Reference in New Issue
Block a user