Bug 1543098 - Emit executionContextCreated for existing context when calling Runtime.enable. r=ato

Differential Revision: https://phabricator.services.mozilla.com/D28958

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2019-05-02 10:22:04 +00:00
Родитель 308a953c12
Коммит 2e7bacc0d1
2 изменённых файлов: 30 добавлений и 6 удалений

Просмотреть файл

@ -7,6 +7,7 @@
var EXPORTED_SYMBOLS = ["Runtime"];
const {ContentProcessDomain} = ChromeUtils.import("chrome://remote/content/domains/ContentProcessDomain.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
class Runtime extends ContentProcessDomain {
constructor(session) {
@ -25,6 +26,22 @@ class Runtime extends ContentProcessDomain {
this.enabled = true;
this.chromeEventHandler.addEventListener("DOMWindowCreated", this,
{mozSystemGroup: true});
// Spin the event loop in order to send the `executionContextCreated` event right
// after we replied to `enable` request.
Services.tm.dispatchToMainThread(() => {
const frameId = this.content.windowUtils.outerWindowID;
const id = this.content.windowUtils.currentInnerWindowID;
this.emit("Runtime.executionContextCreated", {
context: {
id,
auxData: {
isDefault: true,
frameId,
},
},
});
});
}
}

Просмотреть файл

@ -53,17 +53,24 @@ async function testCDP() {
await Runtime.enable();
ok(true, "Runtime domain has been enabled");
// Calling Runtime.enable will emit executionContextCreated for the existing contexts
const { context: context1 } = await Runtime.executionContextCreated();
ok(!!context1.id, "The execution context has an id");
ok(context1.auxData.isDefault, "The execution context is the default one");
ok(!!context1.auxData.frameId, "The execution context has a frame id set");
const executionContextCreated = Runtime.executionContextCreated();
const url = "data:text/html;charset=utf-8,test-page";
const { frameId } = await Page.navigate({ url });
const { frameId } = await Page.navigate({ url });
ok(true, "A new page has been loaded");
ok(frameId, "Page.navigate returned a frameId");
is(frameId, context1.auxData.frameId, "Page.navigate returns the same frameId than executionContextCreated");
const { context } = await executionContextCreated;
ok(!!context.id, "The execution context has an id");
ok(context.auxData.isDefault, "The execution context is the default one");
is(context.auxData.frameId, frameId, "The execution context frame id is the same " +
const { context: context2 } = await executionContextCreated;
ok(!!context2.id, "The execution context has an id");
isnot(context1.id, context2.id, "The new execution context has a different id");
ok(context2.auxData.isDefault, "The execution context is the default one");
is(context2.auxData.frameId, frameId, "The execution context frame id is the same " +
"the one returned by Page.navigate");
await client.close();