Files
firefox/devtools/client/webconsole/test/browser/browser_webconsole_clear_cache.js
T
Nicolas Chevobbe cb68e10ddc Bug 1776145 - [devtools] Remove unnecessary WebConsoleUI additionalProxies. r=ochameau,devtools-backward-compat-reviewers,jdescottes.
`WebConsoleConnectionProxy` is now only used for:
- listening to `lastPrivateContextExited`, which can be done from the top-level
  console front instead
- setting `NetworkMonitor.saveRequestAndResponseBodies` for toolbox we don't have
  network resource support for, which would be better done in `startWatchingNetworkResources`.

This means we don't need to keep a Map of additional proxies.
The only impact is on `clearMessagesCache`, where we now fetch all fronts with
`getAllFronts` instead of looping through the Map of additional proxies.
This change highlighted some race condition in tests, as it's now slightly slower.
So we add a new `clearMessagesCacheAsync` function, which is doing the same thing
as `clearMessagesCache`, except it's not `oneway`, so we can know when the cache
was indeed cleared, and we emit an event to indicate when the cache was cleared.
We can't simply remove `oneway` from `clearMessagesCache` as it causes backward
compatibility issues we can't avoid.
This also highlighted an issue with the cache not being cleared on `console.clear`
when it is batched, so we fix this (a test was failing without it).

The next patch in the queue will completely remove `WebConsoleConnectionProxy`.

Differential Revision: https://phabricator.services.mozilla.com/D150085
2022-07-04 13:27:51 +00:00

87 lines
2.8 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,<!DOCTYPE html>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(() => findErrorMessage(hud, EXPECTED_REPORT));
await waitFor(() => findConsoleAPIMessage(hud, CACHED_MESSAGE));
info(
"Click the clear output button and wait until there's no messages in the output"
);
let onMessagesCacheCleared = hud.ui.once("messages-cache-cleared");
hud.ui.window.document.querySelector(".devtools-clear-icon").click();
await onMessagesCacheCleared;
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(
findConsoleAPIMessage(hud, CACHED_MESSAGE),
undefined,
"The cached message is not visible anymore"
);
is(
findErrorMessage(hud, EXPECTED_REPORT),
undefined,
"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");
onMessagesCacheCleared = hud.ui.once("messages-cache-cleared");
const onConsoleCleared = waitForMessageByType(
hud,
"Console was cleared",
".console-api"
);
SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
content.wrappedJSObject.console.clear();
});
await Promise.all([onConsoleCleared, onMessagesCacheCleared]);
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(
findConsoleAPIMessage(hud, NEW_CACHED_MESSAGE),
undefined,
"The new cached message is not visible anymore"
);
});
function logTextToConsole(hud, text) {
const onMessage = waitForMessageByType(hud, text, ".console-api");
SpecialPowers.spawn(gBrowser.selectedBrowser, [text], function(str) {
content.wrappedJSObject.console.log(str);
});
return onMessage;
}