Files
firefox/devtools/client/webconsole/test/browser/browser_webconsole_clear_cache.js
T
Nicolas Chevobbe a23e6858b0 Bug 1572008 - Re-organize WebConsole client tests folder. r=Honza.
- mochitest folder is renamed browser.
- unit folder is rename xpcshell.
- all the file and folder for mocha are put in a node folder.

We take this as an opportunity to revist our stub-generating
mochitests.
Previously we had 2 tests for each kind of stubs, one for check,
the other one for updating.
It was not ideal when you wanted to update all the stubs at once
because you add either to mention every 5 files, or unskip the
update test files.
We now merge the update and the check files in a single test.
By default, the test that the stubs are up to date, and if you
pass the --setenv WEBCONSOLE_STUBS_UPDATE=true param, it will
update the stubs.
This allow us to move the function that actually generate the stub
in the test file, and have a helper file for multi-purpose functions.
Because these tests are failing on TRY, let's disabled them so we
can land the test re-organization (we'll re-enable them in Bug 1572667).

Differential Revision: https://phabricator.services.mozilla.com/D41344
2019-08-09 09:54:41 +00:00

81 lines
2.5 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Check that clearing the output also clears the console cache.
"use strict";
const TEST_URI =
"data:text/html;charset=utf8,Test clear cache<script>abcdef</script>";
const EXPECTED_REPORT = "ReferenceError: abcdef is not defined";
add_task(async function() {
const tab = await addTab(TEST_URI);
let hud = await openConsole(tab);
const CACHED_MESSAGE = "CACHED_MESSAGE";
await logTextToConsole(hud, CACHED_MESSAGE);
info("Close and re-open the console");
await closeToolbox();
hud = await openConsole(tab);
await waitFor(() => findMessage(hud, EXPECTED_REPORT));
await waitFor(() => findMessage(hud, CACHED_MESSAGE));
info(
"Click the clear output button and wait until there's no messages in the output"
);
hud.ui.window.document.querySelector(".devtools-clear-icon").click();
await waitFor(() => findMessages(hud, "").length === 0);
info("Close and re-open the console");
await closeToolbox();
hud = await openConsole(tab);
info("Log a smoke message in order to know that the console is ready");
await logTextToConsole(hud, "Smoke message");
is(
findMessage(hud, CACHED_MESSAGE),
null,
"The cached message is not visible anymore"
);
is(
findMessage(hud, EXPECTED_REPORT),
null,
"The cached error message is not visible anymore as well"
);
// Test that we also clear the cache when calling console.clear().
const NEW_CACHED_MESSAGE = "NEW_CACHED_MESSAGE";
await logTextToConsole(hud, NEW_CACHED_MESSAGE);
info("Send a console.clear() from the content page");
const onConsoleCleared = waitForMessage(hud, "Console was cleared");
ContentTask.spawn(gBrowser.selectedBrowser, {}, () => {
content.wrappedJSObject.console.clear();
});
await onConsoleCleared;
info("Close and re-open the console");
await closeToolbox();
hud = await openConsole(tab);
info("Log a smoke message in order to know that the console is ready");
await logTextToConsole(hud, "Second smoke message");
is(
findMessage(hud, NEW_CACHED_MESSAGE),
null,
"The new cached message is not visible anymore"
);
});
function logTextToConsole(hud, text) {
const onMessage = waitForMessage(hud, text);
ContentTask.spawn(gBrowser.selectedBrowser, text, function(str) {
content.wrappedJSObject.console.log(str);
});
return onMessage;
}