Bug 1754477 - [devtools] Clear Workers console message cache in WebConsoleActor#clearMessagesCache. r=ochameau.

With Bug 1674336 fixed, we can properly clear worker messages.
A test is added to check this works as expected.

Differential Revision: https://phabricator.services.mozilla.com/D138315
This commit is contained in:
nchevobbe 2022-02-10 10:45:03 +00:00
Родитель f737759a1b
Коммит 024839e002
3 изменённых файлов: 38 добавлений и 5 удалений

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

@ -83,4 +83,37 @@ async function testWorkerMessage(directConnectionToWorkerThread = false) {
const onMessagesCleared = hud.ui.once("messages-cleared");
await clearOutput(hud);
await onMessagesCleared;
is(
findMessage(hud, "initial-message-from-worker"),
undefined,
"cached message was removed"
);
is(findMessage(hud, "log-from-worker"), undefined, "as well as live message");
info("Close and reopen the console to check messages were cleared properly");
await closeConsole();
const toolbox = await openToolboxForTab(gBrowser.selectedTab, "webconsole");
const newHud = toolbox.getCurrentPanel().hud;
info(
"Log a message and wait for it to appear so older messages would have been displayed"
);
const onSmokeMessage = waitForMessage(newHud, "smoke");
SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
content.wrappedJSObject.console.log("smoke");
});
await onSmokeMessage;
is(
findMessage(newHud, "initial-message-from-worker"),
undefined,
"Message cache was cleared"
);
is(
findMessage(newHud, "log-from-worker"),
undefined,
"Live message were cleared as well"
);
await closeTabAndToolbox();
}

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

@ -2,6 +2,8 @@
* 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/. */
/* global clearConsoleEvents */
"use strict";
const { ActorClassWithSpec, Actor } = require("devtools/shared/protocol");
@ -1462,11 +1464,8 @@ const WebConsoleActor = ActorClassWithSpec(webconsoleSpec, {
*/
clearMessagesCache: function() {
if (isWorker) {
// At the moment there is no mechanism available to clear the Console API cache for
// a given worker target (See https://bugzilla.mozilla.org/show_bug.cgi?id=1674336).
// Worker messages from the console service (e.g. error) are emitted from the main
// thread, so this cache will be cleared when the associated document target cache
// is cleared.
// Defined on WorkerScope
clearConsoleEvents();
return;
}

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

@ -516,6 +516,7 @@ this.worker = new WorkerDebuggerLoader({
setImmediate: setImmediate,
retrieveConsoleEvents: this.retrieveConsoleEvents,
setConsoleEventHandler: this.setConsoleEventHandler,
clearConsoleEvents: this.clearConsoleEvents,
console: console,
btoa: this.btoa,
atob: this.atob,