Bug 1543098 - Implement Runtime.executionContextCreated. r=ato

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2019-05-02 10:21:56 +00:00
Родитель 7fa6018a95
Коммит 308a953c12
3 изменённых файлов: 99 добавлений и 0 удалений

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

@ -23,12 +23,34 @@ class Runtime extends ContentProcessDomain {
async enable() {
if (!this.enabled) {
this.enabled = true;
this.chromeEventHandler.addEventListener("DOMWindowCreated", this,
{mozSystemGroup: true});
}
}
disable() {
if (this.enabled) {
this.enabled = false;
this.chromeEventHandler.removeEventListener("DOMWindowCreated", this,
{mozSystemGroup: true});
}
}
handleEvent({type, target}) {
const frameId = target.defaultView.windowUtils.outerWindowID;
const id = target.defaultView.windowUtils.currentInnerWindowID;
switch (type) {
case "DOMWindowCreated":
this.emit("Runtime.executionContextCreated", {
context: {
id,
auxData: {
isDefault: target == this.content.document,
frameId,
},
},
});
break;
}
}
}

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

@ -9,5 +9,7 @@ skip-if = debug || asan # bug 1546945
[browser_cdp.js]
[browser_main_target.js]
[browser_page_frameNavigated.js]
[browser_runtime_executionContext.js]
skip-if = os == "mac" || (verify && os == 'win') # bug 1547961
[browser_tabs.js]
[browser_target.js]

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

@ -0,0 +1,75 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/* global getCDP */
const {RemoteAgent} = ChromeUtils.import("chrome://remote/content/RemoteAgent.jsm");
const {RemoteAgentError} = ChromeUtils.import("chrome://remote/content/Error.jsm");
// Test the Runtime execution context events
const TEST_URI = "data:text/html;charset=utf-8,default-test-page";
add_task(async function() {
try {
await testCDP();
} catch (e) {
// Display better error message with the server side stacktrace
// if an error happened on the server side:
if (e.response) {
throw RemoteAgentError.fromJSON(e.response);
} else {
throw e;
}
}
});
async function testCDP() {
// Open a test page, to prevent debugging the random default page
await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URI);
// Start the CDP server
RemoteAgent.init();
RemoteAgent.tabs.start();
RemoteAgent.listen(Services.io.newURI("http://localhost:9222"));
// Retrieve the chrome-remote-interface library object
const CDP = await getCDP();
// Connect to the server
const client = await CDP({
target(list) {
// Ensure debugging the right target, i.e. the one for our test tab.
return list.find(target => target.url == TEST_URI);
},
});
ok(true, "CDP client has been instantiated");
const {Page, Runtime} = client;
// turn on navigation related events, such as DOMContentLoaded et al.
await Runtime.enable();
ok(true, "Runtime domain has been enabled");
const executionContextCreated = Runtime.executionContextCreated();
const url = "data:text/html;charset=utf-8,test-page";
const { frameId } = await Page.navigate({ url });
ok(true, "A new page has been loaded");
ok(frameId, "Page.navigate returned a frameId");
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 " +
"the one returned by Page.navigate");
await client.close();
ok(true, "The client is closed");
BrowserTestUtils.removeTab(gBrowser.selectedTab);
await RemoteAgent.close();
}