Bug 1615283 - Migrate console from loadDocument to navigateTo. r=nchevobbe

See the first bug's changeset, we don't really need a context, but only the URL.
I choose "navigateTo" name as it aligns with other existing helper and the method on the Target actor.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2020-02-17 16:52:29 +00:00
Родитель e86eab6af2
Коммит 886c4f828b
23 изменённых файлов: 40 добавлений и 74 удалений

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

@ -34,7 +34,7 @@ add_task(async function() {
info("Test SHA1 warnings"); info("Test SHA1 warnings");
let onContentLog = waitForMessage(hud, TRIGGER_MSG); let onContentLog = waitForMessage(hud, TRIGGER_MSG);
const onSha1Warning = waitForMessage(hud, "SHA-1"); const onSha1Warning = waitForMessage(hud, "SHA-1");
await loadDocument(hud.toolbox, SHA1_URL); await navigateTo(SHA1_URL);
await Promise.all([onContentLog, onSha1Warning]); await Promise.all([onContentLog, onSha1Warning]);
let { textContent } = hud.ui.outputNode; let { textContent } = hud.ui.outputNode;
@ -46,7 +46,7 @@ add_task(async function() {
info("Test SSL warnings appropriately not present"); info("Test SSL warnings appropriately not present");
onContentLog = waitForMessage(hud, TRIGGER_MSG); onContentLog = waitForMessage(hud, TRIGGER_MSG);
await loadDocument(hud.toolbox, SHA256_URL); await navigateTo(SHA256_URL);
await onContentLog; await onContentLog;
textContent = hud.ui.outputNode.textContent; textContent = hud.ui.outputNode.textContent;
@ -66,7 +66,7 @@ add_task(async function() {
Services.prefs.setIntPref("security.tls.version.min", 1); Services.prefs.setIntPref("security.tls.version.min", 1);
Services.prefs.setIntPref("security.tls.version.max", 4); Services.prefs.setIntPref("security.tls.version.max", 4);
onContentLog = waitForMessage(hud, TRIGGER_MSG); onContentLog = waitForMessage(hud, TRIGGER_MSG);
await loadDocument(hud.toolbox, TLS_1_0_URL); await navigateTo(TLS_1_0_URL);
await onContentLog; await onContentLog;
textContent = hud.ui.outputNode.textContent; textContent = hud.ui.outputNode.textContent;

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

@ -19,7 +19,7 @@ const TEST_URI =
add_task(async function() { add_task(async function() {
await pushPref("devtools.target-switching.enabled", true); await pushPref("devtools.target-switching.enabled", true);
const hud = await openNewTabAndConsole(TEST_URI); const hud = await openNewTabAndConsole(TEST_URI);
await loadDocument(hud.toolbox, TEST_FILE); await navigateTo(TEST_FILE);
await waitFor(() => findMessage(hud, EXPECTED_RESULT, ".message.warn")); await waitFor(() => findMessage(hud, EXPECTED_RESULT, ".message.warn"));
ok( ok(

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

@ -21,7 +21,7 @@ add_task(async function() {
"blocked the loading of a resource at " + "blocked the loading of a resource at " +
"http://some.example.com/test.png (\u201cimg-src\u201d)."; "http://some.example.com/test.png (\u201cimg-src\u201d).";
const onRepeatedMessage = waitForRepeatedMessage(hud, CSP_VIOLATION_MSG, 2); const onRepeatedMessage = waitForRepeatedMessage(hud, CSP_VIOLATION_MSG, 2);
await loadDocument(hud.toolbox, TEST_VIOLATION); await navigateTo(TEST_VIOLATION);
await onRepeatedMessage; await onRepeatedMessage;
ok(true, "Received expected messages"); ok(true, "Received expected messages");
} }
@ -36,7 +36,7 @@ add_task(async function() {
` the loading of a resource at inline (“style-src”).`; ` the loading of a resource at inline (“style-src”).`;
const VIOLATION_LOCATION_HTML = "test-csp-violation-inline.html:18:1"; const VIOLATION_LOCATION_HTML = "test-csp-violation-inline.html:18:1";
const VIOLATION_LOCATION_JS = "test-csp-violation-inline.html:14:24"; const VIOLATION_LOCATION_JS = "test-csp-violation-inline.html:14:24";
await loadDocument(hud.toolbox, TEST_VIOLATION); await navigateTo(TEST_VIOLATION);
// Triggering the Violation via HTML // Triggering the Violation via HTML
let msg = await waitFor(() => findMessage(hud, CSP_VIOLATION)); let msg = await waitFor(() => findMessage(hud, CSP_VIOLATION));
let locationNode = msg.querySelector(".message-location"); let locationNode = msg.querySelector(".message-location");
@ -67,7 +67,7 @@ add_task(async function() {
"test/browser/test-csp-violation-base-uri.html"; "test/browser/test-csp-violation-base-uri.html";
const CSP_VIOLATION = `Content Security Policy: The pages settings blocked the loading of a resource at https://evil.com/ (“base-uri”).`; const CSP_VIOLATION = `Content Security Policy: The pages settings blocked the loading of a resource at https://evil.com/ (“base-uri”).`;
const VIOLATION_LOCATION = "test-csp-violation-base-uri.html:15:24"; const VIOLATION_LOCATION = "test-csp-violation-base-uri.html:15:24";
await loadDocument(hud.toolbox, TEST_VIOLATION); await navigateTo(TEST_VIOLATION);
let msg = await waitFor(() => findMessage(hud, CSP_VIOLATION)); let msg = await waitFor(() => findMessage(hud, CSP_VIOLATION));
ok(msg, "Base-URI validation was Printed"); ok(msg, "Base-URI validation was Printed");
// Triggering the Violation via JS // Triggering the Violation via JS
@ -93,7 +93,7 @@ add_task(async function() {
const CSP_VIOLATION = `Content Security Policy: The pages settings blocked the loading of a resource at https://evil.com/evil.com (“form-action”).`; const CSP_VIOLATION = `Content Security Policy: The pages settings blocked the loading of a resource at https://evil.com/evil.com (“form-action”).`;
const VIOLATION_LOCATION = "test-csp-violation-form-action.html:14:39"; const VIOLATION_LOCATION = "test-csp-violation-form-action.html:14:39";
await loadDocument(hud.toolbox, TEST_VIOLATION); await navigateTo(TEST_VIOLATION);
const msg = await waitFor(() => findMessage(hud, CSP_VIOLATION)); const msg = await waitFor(() => findMessage(hud, CSP_VIOLATION));
const locationNode = msg.querySelector(".message-location"); const locationNode = msg.querySelector(".message-location");
info(`EXPECT ${VIOLATION_LOCATION} GOT: ${locationNode.textContent}`); info(`EXPECT ${VIOLATION_LOCATION} GOT: ${locationNode.textContent}`);
@ -111,7 +111,7 @@ add_task(async function() {
const CSP_VIOLATION = const CSP_VIOLATION =
`Content Security Policy: The pages settings blocked` + `Content Security Policy: The pages settings blocked` +
` the loading of a resource at ${TEST_VIOLATION} (“frame-ancestors”).`; ` the loading of a resource at ${TEST_VIOLATION} (“frame-ancestors”).`;
await loadDocument(hud.toolbox, TEST_VIOLATION); await navigateTo(TEST_VIOLATION);
const msg = await waitFor(() => findMessage(hud, CSP_VIOLATION)); const msg = await waitFor(() => findMessage(hud, CSP_VIOLATION));
ok(msg, "Frame-Ancestors violation by html was printed"); ok(msg, "Frame-Ancestors violation by html was printed");
} }

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

@ -44,7 +44,7 @@ add_task(async function() {
); );
info("Load a page with CSP warnings."); info("Load a page with CSP warnings.");
await loadDocument(hud.toolbox, TEST_VIOLATION); await navigateTo(TEST_VIOLATION);
await onCspViolationMessage; await onCspViolationMessage;
await onCspReportMessage; await onCspReportMessage;

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

@ -31,14 +31,12 @@ add_task(async function() {
gMultiProcessBrowser, gMultiProcessBrowser,
gFissionBrowser gFissionBrowser
); );
const { browser } = await loadTab("about:blank", remoteType); await loadTab("about:blank", remoteType);
hud = await openConsole(); hud = await openConsole();
await clearOutput(hud); await clearOutput(hud);
const loaded = loadBrowser(browser); await navigateTo(uri.spec);
await loadDocument(hud.toolbox, uri.spec);
await loaded;
await testMessages(); await testMessages();

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

@ -141,7 +141,7 @@ async function navigateAndCheckForWarningMessage({ name, text, url }, hud) {
await clearOutput(hud); await clearOutput(hud);
const onMessage = waitForMessage(hud, text, ".message.warn"); const onMessage = waitForMessage(hud, text, ".message.warn");
await loadDocument(hud.toolbox, url); await navigateTo(url);
const { node } = await onMessage; const { node } = await onMessage;
ok(node, name); ok(node, name);

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

@ -91,7 +91,7 @@ async function navigateAndCheckWarningMessage({ url, name, text }, hud) {
await clearOutput(hud); await clearOutput(hud);
const onMessage = waitForMessage(hud, text, ".message.warn"); const onMessage = waitForMessage(hud, text, ".message.warn");
await loadDocument(hud.toolbox, url); await navigateTo(url);
const { node } = await onMessage; const { node } = await onMessage;
ok(node, name); ok(node, name);

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

@ -32,7 +32,7 @@ add_task(async function() {
"Navigate and wait for the 'foobar' message to be logged by the frame" "Navigate and wait for the 'foobar' message to be logged by the frame"
); );
const onMessage = waitForMessage(hud, "foobar"); const onMessage = waitForMessage(hud, "foobar");
await loadDocument(hud.toolbox, TEST_URI); await navigateTo(TEST_URI);
({ node } = await onMessage); ({ node } = await onMessage);
} }

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

@ -128,7 +128,7 @@ async function runTest(test, hud) {
}); });
info("Load test file " + file); info("Load test file " + file);
await loadDocument(hud.toolbox, TESTS_PATH + file); await navigateTo(TESTS_PATH + file);
// Call test specific callback if defined // Call test specific callback if defined
if (onload) { if (onload) {

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

@ -21,7 +21,7 @@ add_task(async function() {
await clearOutput(hud); await clearOutput(hud);
const onRepeatedMessage = waitForRepeatedMessage(hud, CSP_VIOLATION_MSG, 2); const onRepeatedMessage = waitForRepeatedMessage(hud, CSP_VIOLATION_MSG, 2);
await loadDocument(hud.toolbox, TEST_VIOLATION); await navigateTo(TEST_VIOLATION);
await onRepeatedMessage; await onRepeatedMessage;
ok(true, "Received expected messages"); ok(true, "Received expected messages");

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

@ -22,7 +22,7 @@ add_task(async function() {
} }
const onMessage = waitForMessage(hud, "bug618078exception"); const onMessage = waitForMessage(hud, "bug618078exception");
await loadDocument(hud.toolbox, TEST_URI2); await navigateTo(TEST_URI2);
const { node } = await onMessage; const { node } = await onMessage;
ok(true, "Network exception logged as expected."); ok(true, "Network exception logged as expected.");
ok(node.classList.contains("error"), "Network exception is logged as error."); ok(node.classList.contains("error"), "Network exception is logged as error.");

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

@ -32,7 +32,7 @@ add_task(async function task() {
const toolbox = gDevTools.getToolbox(target); const toolbox = gDevTools.getToolbox(target);
const documentUrl = TEST_PATH + TEST_FILE; const documentUrl = TEST_PATH + TEST_FILE;
await loadDocument(hud.toolbox, documentUrl); await navigateTo(documentUrl);
info("Document loaded."); info("Document loaded.");
await openMessageInNetmonitor(toolbox, hud, documentUrl); await openMessageInNetmonitor(toolbox, hud, documentUrl);

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

@ -18,7 +18,7 @@ add_task(async function task() {
const hud = await openNewTabAndConsole(TEST_URI); const hud = await openNewTabAndConsole(TEST_URI);
const documentUrl = TEST_PATH + TEST_FILE; const documentUrl = TEST_PATH + TEST_FILE;
await loadDocument(hud.toolbox, documentUrl); await navigateTo(documentUrl);
info("Document loaded."); info("Document loaded.");
const message = await waitFor(() => findMessage(hud, documentUrl)); const message = await waitFor(() => findMessage(hud, documentUrl));

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

@ -27,7 +27,7 @@ add_task(async function() {
}); });
info("Wait for document to load"); info("Wait for document to load");
await loadDocument(hud.toolbox, TEST_PATH + "test-network.html"); await navigateTo(TEST_PATH + "test-network.html");
info("Wait for expected messages to appear"); info("Wait for expected messages to appear");
await onMessages; await onMessages;

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

@ -26,7 +26,7 @@ add_task(async function() {
); );
// load second url // load second url
await loadDocument(hud.toolbox, TEST_URI2); await navigateTo(TEST_URI2);
ok(!findMessage(hud, "Permission denied"), "no permission denied errors"); ok(!findMessage(hud, "Permission denied"), "no permission denied errors");

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

@ -43,7 +43,7 @@ async function testScriptError(hud, testData) {
expectUncaughtException(); expectUncaughtException();
} }
await loadDocument(hud.toolbox, makeURIData(testData.script)); await navigateTo(makeURIData(testData.script));
const msg = "the expected error message was displayed"; const msg = "the expected error message was displayed";
info(`waiting for ${msg} to be displayed`); info(`waiting for ${msg} to be displayed`);

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

@ -16,7 +16,7 @@ add_task(async function() {
await pushPref("devtools.target-switching.enabled", true); await pushPref("devtools.target-switching.enabled", true);
const hud = await openNewTabAndConsole(TEST_URI); const hud = await openNewTabAndConsole(TEST_URI);
await clearOutput(hud); await clearOutput(hud);
await loadDocument(hud.toolbox, TEST_DOC); await navigateTo(TEST_DOC);
await waitFor(() => findMessage(hud, SAMPLE_MSG, ".message.warn")); await waitFor(() => findMessage(hud, SAMPLE_MSG, ".message.warn"));

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

@ -37,7 +37,7 @@ add_task(async function task() {
], ],
}); });
await loadDocument(hud.toolbox, TEST_PATH); await navigateTo(TEST_PATH);
info("Document loaded."); info("Document loaded.");
await onMessageAdded; await onMessageAdded;

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

@ -24,7 +24,7 @@ add_task(async function() {
const toolbox = await openNewTabAndToolbox(TEST_URI, "netmonitor"); const toolbox = await openNewTabAndToolbox(TEST_URI, "netmonitor");
info("Network panel is open."); info("Network panel is open.");
await loadDocument(toolbox, TEST_PATH); await navigateTo(TEST_PATH);
info("Document loaded."); info("Document loaded.");
// Test that the request appears in the network panel. // Test that the request appears in the network panel.

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

@ -10,19 +10,19 @@ add_task(async function() {
"data:text/html;charset=utf8,empty page" "data:text/html;charset=utf8,empty page"
); );
await loadScriptURI(hud, "'use strict';var arguments;"); await loadScriptURI("'use strict';var arguments;");
await waitForError( await waitForError(
hud, hud,
"SyntaxError: 'arguments' can't be defined or assigned to in strict mode code" "SyntaxError: 'arguments' can't be defined or assigned to in strict mode code"
); );
await loadScriptURI(hud, "'use strict';function f(a, a) {};"); await loadScriptURI("'use strict';function f(a, a) {};");
await waitForError(hud, "SyntaxError: duplicate formal argument a"); await waitForError(hud, "SyntaxError: duplicate formal argument a");
await loadScriptURI(hud, "'use strict';var o = {get p() {}};o.p = 1;"); await loadScriptURI("'use strict';var o = {get p() {}};o.p = 1;");
await waitForError(hud, 'TypeError: setting getter-only property "p"'); await waitForError(hud, 'TypeError: setting getter-only property "p"');
await loadScriptURI(hud, "'use strict';v = 1;"); await loadScriptURI("'use strict';v = 1;");
await waitForError( await waitForError(
hud, hud,
"ReferenceError: assignment to undeclared variable v" "ReferenceError: assignment to undeclared variable v"
@ -34,12 +34,12 @@ async function waitForError(hud, text) {
ok(true, "Received expected error message"); ok(true, "Received expected error message");
} }
function loadScriptURI(hud, script) { function loadScriptURI(script) {
// On e10s, the exception is triggered in child process // On e10s, the exception is triggered in child process
// and is ignored by test harness // and is ignored by test harness
if (!Services.appinfo.browserTabsRemoteAutostart) { if (!Services.appinfo.browserTabsRemoteAutostart) {
expectUncaughtException(); expectUncaughtException();
} }
const uri = "data:text/html;charset=utf8,<script>" + script + "</script>"; const uri = "data:text/html;charset=utf8,<script>" + script + "</script>";
return loadDocument(hud.toolbox, uri); return navigateTo(uri);
} }

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

@ -50,7 +50,7 @@ add_task(async function() {
// The next tests make sure that timers with the same name but in separate // The next tests make sure that timers with the same name but in separate
// pages do not contain the same value. // pages do not contain the same value.
await loadDocument(hud2.toolbox, TEST_URI3); await navigateTo(TEST_URI3);
// The new console front-end does not display a message when timers are started, // The new console front-end does not display a message when timers are started,
// so there should not be a 'bTimer started' message on the output // so there should not be a 'bTimer started' message on the output
@ -72,7 +72,7 @@ add_task(async function() {
// and calling console.timeEnd('bTimer') on the new console front-end should // and calling console.timeEnd('bTimer') on the new console front-end should
// result on a warning message: 'Timer "bTimer" does not exist', // result on a warning message: 'Timer "bTimer" does not exist',
// as the timers in different pages are not related // as the timers in different pages are not related
await loadDocument(hud2.toolbox, TEST_URI4); await navigateTo(TEST_URI4);
const error2 = await waitFor(() => const error2 = await waitFor(() =>
findMessage(hud2, "bTimer", ".message.timeEnd.warn") findMessage(hud2, "bTimer", ".message.timeEnd.warn")

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

@ -18,7 +18,12 @@ add_task(async function() {
await testWarningNotPresent(hud); await testWarningNotPresent(hud);
await closeToolbox(); await closeToolbox();
await loadDocument(hud.toolbox, TEST_URI_REPLACED); // Use BrowserTestUtils instead of navigateTo as there is no toolbox opened
const onBrowserLoaded = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser
);
await BrowserTestUtils.loadURI(gBrowser.selectedBrowser, TEST_URI_REPLACED);
await onBrowserLoaded;
const toolbox = await openToolboxForTab(gBrowser.selectedTab, "webconsole"); const toolbox = await openToolboxForTab(gBrowser.selectedTab, "webconsole");
hud = toolbox.getCurrentPanel().hud; hud = toolbox.getCurrentPanel().hud;

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

@ -393,43 +393,6 @@ function _getContextMenu(hud) {
return doc.getElementById("webconsole-menu"); return doc.getElementById("webconsole-menu");
} }
async function loadDocument(
toolbox,
newUrl,
browser = gBrowser.selectedBrowser
) {
const currentToolboxTarget = toolbox.target;
// If fission and target switching are enabled, and if we're switching origin, we need
// to wait for the 'switched-target' event to make sure everything is ready.
const onTargetSwitched = isTargetSwitchingEnabled()
? toolbox.once("switched-target")
: null;
info(`Load document "${newUrl}"`);
const onBrowserLoaded = BrowserTestUtils.browserLoaded(browser);
BrowserTestUtils.loadURI(browser, newUrl);
info(`Waiting for page to be loaded…`);
await onBrowserLoaded;
info(`→ page loaded`);
if (onTargetSwitched && toolbox.target !== currentToolboxTarget) {
info(`Waiting for target switch…`);
await onTargetSwitched;
info(`→ switched-target emitted`);
}
}
function isFissionEnabled() {
return SpecialPowers.useRemoteSubframes;
}
function isTargetSwitchingEnabled() {
return (
isFissionEnabled() &&
Services.prefs.getBoolPref("devtools.target-switching.enabled", false)
);
}
async function toggleConsoleSetting(hud, selector) { async function toggleConsoleSetting(hud, selector) {
const toolbox = hud.toolbox; const toolbox = hud.toolbox;
const doc = toolbox ? toolbox.doc : hud.chromeWindow.document; const doc = toolbox ? toolbox.doc : hud.chromeWindow.document;