Bug 1712567 - [devtools] Cover console persist feature with cross process navigation. r=nchevobbe

About browser_jsterm_autocomplete_getters_cache, we weren't correctly waiting
for popup to close because of the reload. Instead we probably worked around intermittents
by closing the popup explicitly before the reload.
But that creates other issue, where the reload may close the popup *after* we do Ctrl+Space.
(this patch doesn't trigger any issue with this test, but better fix that)

Differential Revision: https://phabricator.services.mozilla.com/D112231
This commit is contained in:
Alexandre Poirot 2021-05-24 15:19:22 +00:00
parent 14d49253c8
commit a13bc1e7d2
4 changed files with 110 additions and 30 deletions

View File

@ -3017,6 +3017,10 @@ Toolbox.prototype = {
}
await panel.once("reloaded");
// The toolbox may have been destroyed while the panel was reloading
if (this.isDestroying()) {
return;
}
const delay = this.win.performance.now() - start;
const telemetryKey = "DEVTOOLS_TOOLBOX_PAGE_RELOAD_DELAY_MS";

View File

@ -108,11 +108,9 @@ add_task(async function() {
"Reload the page to ensure asking for autocomplete again show the confirm dialog"
);
onPopupClose = autocompletePopup.once("popup-closed");
EventUtils.synthesizeKey("KEY_Escape");
await onPopupClose;
await refreshTab();
info("tab reloaded, waiting for the popup to close");
await onPopupClose;
info("Press Ctrl+Space to open the confirm dialog again");
EventUtils.synthesizeKey(" ", { ctrlKey: true });

View File

@ -5,19 +5,20 @@
"use strict";
const TEST_URI =
"http://example.com/browser/devtools/client/webconsole/" +
"test/browser/test-console.html";
const TEST_FILE = "test-console.html";
const TEST_COM_URI = URL_ROOT_COM + TEST_FILE;
const TEST_ORG_URI = URL_ROOT_ORG + TEST_FILE;
const TEST_NET_URI = URL_ROOT_NET + TEST_FILE;
registerCleanupFunction(() => {
Services.prefs.clearUserPref("devtools.webconsole.persistlog");
});
add_task(async function() {
info("Testing that messages disappear on a refresh if logs aren't persisted");
const hud = await openNewTabAndConsole(TEST_URI);
const INITIAL_LOGS_NUMBER = 5;
const INITIAL_LOGS_NUMBER = 5;
const { MESSAGE_TYPE } = require("devtools/client/webconsole/constants");
async function logAndAssertInitialMessages(hud) {
await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[INITIAL_LOGS_NUMBER],
@ -27,10 +28,34 @@ add_task(async function() {
);
await waitFor(() => findMessages(hud, "").length === INITIAL_LOGS_NUMBER);
ok(true, "Messages showed up initially");
}
add_task(async function() {
info("Testing that messages disappear on a refresh if logs aren't persisted");
const hud = await openNewTabAndConsole(TEST_COM_URI);
await logAndAssertInitialMessages(hud);
const onReloaded = hud.ui.once("reloaded");
await refreshTab();
await onReloaded;
info("Wait for messages to be cleared");
await waitFor(() => findMessages(hud, "").length === 0);
ok(true, "Messages disappeared");
await closeToolbox();
});
add_task(async function() {
info(
"Testing that messages disappear on a cross origin navigation if logs aren't persisted"
);
const hud = await openNewTabAndConsole(TEST_COM_URI);
await logAndAssertInitialMessages(hud);
await navigateTo(TEST_ORG_URI);
await waitFor(() => findMessages(hud, "").length === 0);
ok(true, "Messages disappeared");
@ -40,26 +65,21 @@ add_task(async function() {
add_task(async function() {
info("Testing that messages persist on a refresh if logs are persisted");
const hud = await openNewTabAndConsole(TEST_URI);
const hud = await openNewTabAndConsole(TEST_COM_URI);
await toggleConsoleSetting(
hud,
".webconsole-console-settings-menu-item-persistentLogs"
);
const INITIAL_LOGS_NUMBER = 5;
await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[INITIAL_LOGS_NUMBER],
count => {
content.wrappedJSObject.doLogs(count);
}
);
await waitFor(() => findMessages(hud, "").length === INITIAL_LOGS_NUMBER);
ok(true, "Messages showed up initially");
await logAndAssertInitialMessages(hud);
const onNavigatedMessage = waitForMessage(hud, "Navigated to");
const onNavigatedMessage = waitForMessage(
hud,
"Navigated to " + TEST_COM_URI
);
const onReloaded = hud.ui.once("reloaded");
let timeBeforeNavigation = Date.now();
refreshTab();
await onNavigatedMessage;
await onReloaded;
@ -71,17 +91,74 @@ add_task(async function() {
"Messages logged before navigation are still visible"
);
assertLastMessageIsNavigationMessage(hud, timeBeforeNavigation, TEST_COM_URI);
info(
"Testing that messages also persist when doing a cross origin navigation if logs are persisted"
);
const onNavigatedMessage2 = waitForMessage(
hud,
"Navigated to " + TEST_ORG_URI
);
timeBeforeNavigation = Date.now();
await navigateTo(TEST_ORG_URI);
await onNavigatedMessage2;
ok(true, "Second navigation message appeared as expected");
is(
findMessages(hud, "").length,
INITIAL_LOGS_NUMBER + 2,
"Messages logged before the second navigation are still visible"
);
assertLastMessageIsNavigationMessage(hud, timeBeforeNavigation, TEST_ORG_URI);
info(
"Test doing a second cross origin navigation in order to triger a target switching with a target following the window global lifecycle"
);
const onNavigatedMessage3 = waitForMessage(
hud,
"Navigated to " + TEST_NET_URI
);
timeBeforeNavigation = Date.now();
await navigateTo(TEST_NET_URI);
await onNavigatedMessage3;
ok(true, "Third navigation message appeared as expected");
is(
findMessages(hud, "").length,
INITIAL_LOGS_NUMBER + 3,
"Messages logged before the third navigation are still visible"
);
assertLastMessageIsNavigationMessage(hud, timeBeforeNavigation, TEST_NET_URI);
await closeToolbox();
});
function assertLastMessageIsNavigationMessage(hud, timeBeforeNavigation, url) {
const {
visibleMessages,
messagesById,
} = hud.ui.wrapper.getStore().getState().messages;
const [commandId, resultId] = visibleMessages;
const commandMessage = messagesById.get(commandId).timeStamp;
const resultMessage = messagesById.get(resultId).timeStamp;
const lastMessageId = visibleMessages.at(-1);
const lastMessage = messagesById.get(lastMessageId);
ok(
resultMessage > commandMessage && resultMessage < Date.now(),
"The result has a timestamp newer than the command and older than current time"
is(
lastMessage.type,
MESSAGE_TYPE.NAVIGATION_MARKER,
"The last message is a navigation marker"
);
await closeToolbox();
});
is(
lastMessage.messageText,
"Navigated to " + url,
"The navigation message is correct"
);
// It is surprising, but the navigation may be timestamped at the same exact time
// as timeBeforeNavigation time record.
ok(
lastMessage.timeStamp >= timeBeforeNavigation,
"The navigation message has a timestamp newer (or equal) than the time before the navigation..."
);
ok(lastMessage.timeStamp < Date.now(), "...and older than current time");
}

View File

@ -212,6 +212,7 @@ class WebConsoleUI {
resourceCommand.TYPES.PLATFORM_MESSAGE,
resourceCommand.TYPES.NETWORK_EVENT,
resourceCommand.TYPES.NETWORK_EVENT_STACKTRACE,
resourceCommand.TYPES.CLONED_CONTENT_PROCESS_MESSAGE,
],
{
onAvailable: this._onResourceAvailable,