mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 09:15:35 +00:00
Bug 1597905 - Replace usage of webConsoleUI.clearOutput to head.js clearOutput in tests. r=jdescottes.
The helper function waits for an event to be dispatched, which adds extra safety. Differential Revision: https://phabricator.services.mozilla.com/D53927 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
53115e71e2
commit
fb841e986b
@ -43,7 +43,7 @@ add_task(async function() {
|
||||
});
|
||||
|
||||
async function testMessages(hud) {
|
||||
hud.ui.clearOutput(true);
|
||||
await clearOutput(hud);
|
||||
|
||||
executeSoon(() => {
|
||||
expectUncaughtException();
|
||||
|
@ -11,7 +11,7 @@ add_task(async function() {
|
||||
await pushPref("devtools.browserconsole.contentMessages", true);
|
||||
|
||||
const hud = await BrowserConsoleManager.toggleBrowserConsole();
|
||||
await hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
await openNewTabAndConsole(
|
||||
`data:text/html,<script>console.log("hello from content")</script>`
|
||||
);
|
||||
|
@ -17,7 +17,7 @@ add_task(async function testCategoryLogs() {
|
||||
|
||||
await checkMessageExists(hud, "bug861338-log-cached");
|
||||
|
||||
hud.ui.clearOutput(true);
|
||||
await clearOutput(hud);
|
||||
|
||||
function testTrace() {
|
||||
console.trace();
|
||||
@ -46,7 +46,7 @@ add_task(async function testCategoryLogs() {
|
||||
await checkMessageExists(hud, "console.trace()");
|
||||
await checkMessageExists(hud, "foobarTimer");
|
||||
|
||||
hud.ui.clearOutput(true);
|
||||
await clearOutput(hud);
|
||||
await BrowserConsoleManager.toggleBrowserConsole();
|
||||
});
|
||||
|
||||
@ -79,7 +79,7 @@ add_task(async function testFilter() {
|
||||
await checkMessageHidden(hud, shouldBeHidden);
|
||||
|
||||
await resetFilters(hud);
|
||||
hud.ui.clearOutput(true);
|
||||
await clearOutput(hud);
|
||||
await BrowserConsoleManager.toggleBrowserConsole();
|
||||
});
|
||||
|
||||
|
@ -56,12 +56,6 @@ async function checkContentConsoleApiMessages(nonPrimitiveVariablesDisplayed) {
|
||||
const hud = await BrowserConsoleManager.toggleBrowserConsole();
|
||||
await setFilterState(hud, { text: FILTER_PREFIX });
|
||||
|
||||
// we need to wait for the
|
||||
// if (nonPrimitiveVariablesDisplayed) {
|
||||
// await waitFor(() => hud.ui.outputNode.querySelector(".new-consoletable"));
|
||||
// }
|
||||
// await clearOutput(hud);
|
||||
|
||||
// In non fission world, we don't retrieve cached messages, so we need to reload the
|
||||
// tab to see them.
|
||||
if (!nonPrimitiveVariablesDisplayed) {
|
||||
|
@ -15,8 +15,8 @@ const stringToCopy = "foobazbarBug642615";
|
||||
|
||||
add_task(async function() {
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
const { jsterm, ui } = hud;
|
||||
ui.clearOutput();
|
||||
const { jsterm } = hud;
|
||||
await clearOutput(hud);
|
||||
ok(!getInputCompletionValue(hud), "no completeNode.value");
|
||||
|
||||
setInputValue(hud, "doc");
|
||||
|
@ -13,7 +13,7 @@ add_task(async function() {
|
||||
await pushPref("devtools.debugger.features.map-await-expression", true);
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
const delays = [3000, 500, 9000, 6000];
|
||||
const inputs = delays.map(
|
||||
delay => `await new Promise(
|
||||
|
@ -12,7 +12,7 @@ const TEST_URI = `data:text/html;charset=utf8,<p>test code completion
|
||||
|
||||
add_task(async function() {
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
const { jsterm, ui } = hud;
|
||||
const { jsterm } = hud;
|
||||
const { autocompletePopup } = jsterm;
|
||||
|
||||
// Test typing 'docu'.
|
||||
@ -65,7 +65,7 @@ add_task(async function() {
|
||||
);
|
||||
checkInputCompletionValue(hud, "entById", "'document.getElem' completion");
|
||||
|
||||
ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
await setInputValueForAutocompletion(hud, "docu");
|
||||
checkInputCompletionValue(hud, "ment", "'docu' completion");
|
||||
|
@ -26,7 +26,7 @@ add_task(async function() {
|
||||
const hud = await openConsole();
|
||||
const { jsterm } = hud;
|
||||
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
const { autocompletePopup } = jsterm;
|
||||
|
||||
|
@ -24,7 +24,8 @@ add_task(async function() {
|
||||
const errorUrl = ErrorDocs.GetURL({ errorMessageName });
|
||||
const title = errorUrl.split("?")[0];
|
||||
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
const { node } = await executeAndWaitForMessage(
|
||||
hud,
|
||||
expression,
|
||||
|
@ -17,7 +17,7 @@ add_task(async function() {
|
||||
}
|
||||
};
|
||||
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
execute(hud, "help()");
|
||||
execute(hud, "help");
|
||||
execute(hud, "?");
|
||||
|
@ -77,5 +77,5 @@ async function executeWindowTest(hud, iframeRole) {
|
||||
);
|
||||
|
||||
// Clear the output so we don't pollute the next assertions.
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
}
|
||||
|
@ -22,6 +22,6 @@ add_task(async function() {
|
||||
);
|
||||
|
||||
const onMessagesCleared = hud.ui.once("messages-cleared");
|
||||
hud.ui.clearOutput(true);
|
||||
await clearOutput(hud);
|
||||
await onMessagesCleared;
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ add_task(async function() {
|
||||
await pushPref("devtools.webconsole.filter.net", true);
|
||||
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
info("Test Copy URL menu item for text log");
|
||||
|
||||
@ -48,7 +48,7 @@ add_task(async function() {
|
||||
ok(true, "Expected text was copied to the clipboard.");
|
||||
|
||||
await hideContextMenu(hud);
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
info("Test Copy URL menu item for network log");
|
||||
|
||||
@ -71,7 +71,7 @@ add_task(async function() {
|
||||
ok(true, "Expected text was copied to the clipboard.");
|
||||
|
||||
await hideContextMenu(hud);
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
info("Test Copy URL menu item from [Learn More] link");
|
||||
|
||||
|
@ -46,7 +46,7 @@ var FileUtils = Cu.import("resource://gre/modules/FileUtils.jsm").FileUtils;
|
||||
|
||||
add_task(async function testExportToClipboard() {
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
info("Call the log function defined in the test page");
|
||||
await ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
|
||||
@ -70,7 +70,7 @@ add_task(async function testExportToClipboard() {
|
||||
|
||||
add_task(async function testExportToFile() {
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
info("Call the log function defined in the test page");
|
||||
await ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
|
||||
|
@ -15,7 +15,7 @@ add_task(async function() {
|
||||
await pushPref("devtools.webconsole.filter.net", true);
|
||||
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
info("Test Open URL menu item for text log");
|
||||
|
||||
@ -32,7 +32,7 @@ add_task(async function() {
|
||||
ok(!openUrlItem, "Open URL menu item is not available");
|
||||
|
||||
await hideContextMenu(hud);
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
info("Test Open URL menu item for network log");
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
add_task(async function() {
|
||||
const TEST_URI = "data:text/html;charset=utf8,Web Console CSP violation test";
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
{
|
||||
const TEST_VIOLATION =
|
||||
"https://example.com/browser/devtools/client/webconsole/" +
|
||||
@ -23,7 +23,7 @@ add_task(async function() {
|
||||
await onRepeatedMessage;
|
||||
ok(true, "Received expected messages");
|
||||
}
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
// Testing CSP Inline Violations
|
||||
{
|
||||
const TEST_VIOLATION =
|
||||
@ -44,7 +44,7 @@ add_task(async function() {
|
||||
"Printed the CSP Violation with HTML Context"
|
||||
);
|
||||
// Triggering the Violation via JS
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
msg = await executeAndWaitForMessage(
|
||||
hud,
|
||||
"window.violate()",
|
||||
@ -57,7 +57,7 @@ add_task(async function() {
|
||||
"Printed the CSP Violation with JS Context"
|
||||
);
|
||||
}
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
// Testing Base URI
|
||||
{
|
||||
const TEST_VIOLATION =
|
||||
@ -69,7 +69,7 @@ add_task(async function() {
|
||||
let msg = await waitFor(() => findMessage(hud, CSP_VIOLATION));
|
||||
ok(msg, "Base-URI validation was Printed");
|
||||
// Triggering the Violation via JS
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
msg = await executeAndWaitForMessage(
|
||||
hud,
|
||||
"window.violate()",
|
||||
@ -82,7 +82,7 @@ add_task(async function() {
|
||||
"Base-URI validation was Printed with the Responsible JS Line"
|
||||
);
|
||||
}
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
// Testing CSP Form Action
|
||||
{
|
||||
const TEST_VIOLATION =
|
||||
@ -100,7 +100,7 @@ add_task(async function() {
|
||||
"JS Line which Triggered the CSP-Form Action Violation was Printed"
|
||||
);
|
||||
}
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
// Testing CSP Frame Ancestors Directive
|
||||
{
|
||||
const TEST_VIOLATION =
|
||||
|
@ -52,5 +52,5 @@ add_task(async function() {
|
||||
"Confirmed that CSP and CSP-Report-Only log different messages to console"
|
||||
);
|
||||
|
||||
hud.ui.clearOutput(true);
|
||||
await clearOutput(hud);
|
||||
});
|
||||
|
@ -11,7 +11,7 @@ const TEST_URI =
|
||||
|
||||
add_task(async function() {
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
const onInputMessage = waitForMessage(
|
||||
hud,
|
||||
|
@ -34,7 +34,7 @@ add_task(async function() {
|
||||
const { browser } = await loadTab("about:blank", remoteType);
|
||||
|
||||
hud = await openConsole();
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
const loaded = loadBrowser(browser);
|
||||
BrowserTestUtils.loadURI(gBrowser.selectedBrowser, uri.spec);
|
||||
|
@ -29,12 +29,12 @@ add_task(async function() {
|
||||
info("Picker mode stopped, <h1> selected, now switching to the console");
|
||||
const hud = await openConsole();
|
||||
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
await executeAndWaitForMessage(hud, "$0", "<h1>", ".result");
|
||||
ok(true, "correct output for $0");
|
||||
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
const newH1Content = "newH1Content";
|
||||
await executeAndWaitForMessage(
|
||||
|
@ -136,7 +136,7 @@ add_task(async function() {
|
||||
});
|
||||
|
||||
async function navigateAndCheckForWarningMessage({ name, text, url }, hud) {
|
||||
hud.ui.clearOutput(true);
|
||||
await clearOutput(hud);
|
||||
|
||||
const onMessage = waitForMessage(hud, text, ".message.warn");
|
||||
BrowserTestUtils.loadURI(gBrowser.selectedBrowser, url);
|
||||
|
@ -86,7 +86,7 @@ add_task(async function() {
|
||||
});
|
||||
|
||||
async function navigateAndCheckWarningMessage({ url, name, text }, hud) {
|
||||
hud.ui.clearOutput(true);
|
||||
await clearOutput(hud);
|
||||
|
||||
const onMessage = waitForMessage(hud, text, ".message.warn");
|
||||
BrowserTestUtils.loadURI(gBrowser.selectedBrowser, url);
|
||||
|
@ -89,7 +89,7 @@ add_task(async function() {
|
||||
setInputValue(hud, "");
|
||||
testLayout(appNode);
|
||||
|
||||
ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
testLayout(appNode);
|
||||
is(outputNode.offsetHeight, 0, "output node has no height");
|
||||
is(
|
||||
|
@ -16,7 +16,7 @@ add_task(async function() {
|
||||
info("Focus after console is opened");
|
||||
ok(isInputFocused(hud), "input node is focused after console is opened");
|
||||
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
ok(isInputFocused(hud), "input node is focused after output is cleared");
|
||||
|
||||
info("Focus during message logging");
|
||||
|
@ -12,7 +12,7 @@ const TEST_URI =
|
||||
add_task(async function() {
|
||||
await pushPref("devtools.hud.loglimit", 140);
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
let onMessage = waitForMessage(hud, "test message [149]");
|
||||
ContentTask.spawn(gBrowser.selectedBrowser, {}, async function() {
|
||||
|
@ -17,7 +17,7 @@ const CSP_VIOLATION_MSG =
|
||||
|
||||
add_task(async function() {
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
const onRepeatedMessage = waitForRepeatedMessage(hud, CSP_VIOLATION_MSG, 2);
|
||||
await loadDocument(TEST_VIOLATION);
|
||||
|
@ -108,7 +108,7 @@ async function openRequestAfterUpdates(target, hud) {
|
||||
async function openRequestBeforeUpdates(target, hud, tab) {
|
||||
const toolbox = gDevTools.getToolbox(target);
|
||||
|
||||
hud.ui.clearOutput(true);
|
||||
await clearOutput(hud);
|
||||
|
||||
const xhrUrl = TEST_PATH + "sjs_slow-response-test-server.sjs";
|
||||
const onMessage = waitForMessage(hud, xhrUrl);
|
||||
|
@ -58,7 +58,7 @@ add_task(async function() {
|
||||
|
||||
// Check that expected output and actual trimmed output match
|
||||
for (const { name, command, expected } of TEST_ITEMS) {
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
await executeAndWaitForMessage(hud, command, "", ".result");
|
||||
|
||||
const result = await waitFor(() => getDisplayedInput(hud));
|
||||
|
@ -19,7 +19,7 @@ add_task(async function() {
|
||||
|
||||
expectUncaughtExceptionNoE10s();
|
||||
let hud = await openNewTabAndConsole(TEST_URI);
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
expectUncaughtExceptionNoE10s();
|
||||
await refreshTab();
|
||||
|
@ -31,7 +31,7 @@ add_task(async function() {
|
||||
ok(!findMessage(hud, "Permission denied"), "no permission denied errors");
|
||||
|
||||
info("wait for window.location.href after page navigation");
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
await executeAndWaitForMessage(
|
||||
hud,
|
||||
"window.location.href",
|
||||
|
@ -67,5 +67,5 @@ async function testScriptError(hud, testData) {
|
||||
|
||||
ok(hrefs.has(url), `Expected a link to ${url}.`);
|
||||
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ add_task(async function testSelectAll() {
|
||||
|
||||
async function testSelectionWhenMovingBetweenBoxes(hud) {
|
||||
// Fill the console with some output.
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
await executeAndWaitForMessage(hud, "1 + 2", "3", ".result");
|
||||
await executeAndWaitForMessage(hud, "3 + 4", "7", ".result");
|
||||
await executeAndWaitForMessage(hud, "5 + 6", "11", ".result");
|
||||
|
@ -14,7 +14,7 @@ const SAMPLE_MSG = "specified a header that could not be parsed successfully.";
|
||||
|
||||
add_task(async function() {
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
await loadDocument(TEST_DOC);
|
||||
|
||||
await waitFor(() => findMessage(hud, SAMPLE_MSG, ".message.warn"));
|
||||
|
@ -66,7 +66,7 @@ add_task(async function() {
|
||||
"No message is printed to " + "the console when the timer starts"
|
||||
);
|
||||
|
||||
hud2.ui.clearOutput();
|
||||
await clearOutput(hud2);
|
||||
|
||||
// Calling console.time('bTimer') on a page, then navigating to another page
|
||||
// and calling console.timeEnd('bTimer') on the new console front-end should
|
||||
|
@ -177,7 +177,7 @@ async function testStorageAccessBlockedGrouping(groupLabel) {
|
||||
const { hud, win, tab } = await openNewWindowAndConsole(TEST_URI);
|
||||
const now = Date.now();
|
||||
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
|
||||
const getWarningMessage = url => groupLabel.replace("<URL>", url);
|
||||
|
||||
@ -218,7 +218,7 @@ async function testStorageAccessBlockedGrouping(groupLabel) {
|
||||
`| ${getWarningMessage(TRACKER_IMG + "?2&" + now)}`,
|
||||
]);
|
||||
|
||||
hud.ui.clearOutput();
|
||||
await clearOutput(hud);
|
||||
await win.close();
|
||||
}
|
||||
|
||||
|
@ -1577,8 +1577,14 @@ async function waitForLazyRequests(toolbox) {
|
||||
});
|
||||
}
|
||||
|
||||
async function clearOutput(hud, clearStorage = true) {
|
||||
/**
|
||||
* Clear the console output and when for the "messages-cleared" event to be emitted.
|
||||
* @param {WebConsole} hud
|
||||
* @param {Object} An options object with the following properties:
|
||||
* - {Boolean} keepStorage: true to prevent clearing the messages storage.
|
||||
*/
|
||||
async function clearOutput(hud, { keepStorage = false } = {}) {
|
||||
const onMessagesCleared = hud.ui.once("messages-cleared");
|
||||
hud.ui.clearOutput(clearStorage);
|
||||
hud.ui.clearOutput(!keepStorage);
|
||||
await onMessagesCleared;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user