Bug 1691586 - [devtools] Enable browser_ConsoleStorageAPITests.js on fission. r=bomsy

The test was doing a navigation from about:blank to an example.com URL in a
ContentTask, which I guess was going bad with fission enabled since we were
creating a new content process.
I don't think there was a good reason to do that, so we start the test directly
with the "final" URL.
And since about:blank page can be special, we use a data url instead.
A few `info` calls are added to have better logs, and the test is slightly refactored
to be easier to follow.

Finally, the test was a bit loose, only checking the number of events we were
receiving. We take this opportunity to really check that we get the events that
are expected.

Differential Revision: https://phabricator.services.mozilla.com/D109278
This commit is contained in:
Nicolas Chevobbe 2021-03-22 12:32:00 +00:00
Родитель aaba56d47d
Коммит ec8bdecd6f
3 изменённых файлов: 40 добавлений и 44 удалений

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

@ -49,7 +49,6 @@ support-files =
[browser_ConsoleAPITests.js]
skip-if = e10s
[browser_ConsoleStorageAPITests.js]
skip-if = fission || (asan && os == "linux") # Bug 1614436
[browser_ConsoleStoragePBTest_perwindowpb.js]
[browser_data_document_crossOriginIsolated.js]
[browser_focus_steal_from_chrome.js]

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

@ -1,7 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TEST_URI_NAV = "http://example.com/browser/dom/tests/browser/";
const TEST_URI =
"http://example.com/browser/dom/tests/browser/test-console-api.html";
function tearDown() {
while (gBrowser.tabs.length > 1) {
@ -15,18 +16,19 @@ add_task(async function() {
registerCleanupFunction(tearDown);
// Open a keepalive tab in the background to make sure we don't accidentally
// kill the content process
var keepaliveTab = await BrowserTestUtils.addTab(gBrowser, "about:blank");
info(
"Open a keepalive tab in the background to make sure we don't accidentally kill the content process"
);
var keepaliveTab = await BrowserTestUtils.addTab(
gBrowser,
"data:text/html,<meta charset=utf8>Keep Alive Tab"
);
// Open the main tab to run the test in
var tab = await BrowserTestUtils.addTab(gBrowser, "about:blank");
gBrowser.selectedTab = tab;
info("Open the main tab to run the test in");
var tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URI);
var browser = gBrowser.selectedBrowser;
let observerPromise = ContentTask.spawn(browser, null, async function(opt) {
const TEST_URI =
"http://example.com/browser/dom/tests/browser/test-console-api.html";
const windowId = await ContentTask.spawn(browser, null, async function(opt) {
let ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"].getService(
Ci.nsIConsoleAPIStorage
);
@ -39,59 +41,52 @@ add_task(async function() {
observe(aSubject, aTopic, aData) {
if (aTopic == "console-storage-cache-event") {
apiCallCount++;
info(`Received ${apiCallCount} "console-storage-cache-event"`);
if (apiCallCount == 4) {
let windowId = content.windowGlobalChild.innerWindowId;
Services.obs.removeObserver(this, "console-storage-cache-event");
ok(
ConsoleAPIStorage.getEvents(windowId).length >= 4,
"Some messages found in the storage service"
);
ConsoleAPIStorage.clearEvents();
is(
ConsoleAPIStorage.getEvents(windowId).length,
0,
"Cleared Storage"
);
resolve(windowId);
resolve();
}
}
},
};
info("Setting up observer");
Services.obs.addObserver(ConsoleObserver, "console-storage-cache-event");
// Redirect the browser to the test URI
content.window.location = TEST_URI;
});
await ContentTaskUtils.waitForEvent(this, "DOMContentLoaded");
info("Emit a few console API logs");
content.console.log("this", "is", "a", "log", "message");
content.console.info("this", "is", "a", "info", "message");
content.console.warn("this", "is", "a", "warn", "message");
content.console.error("this", "is", "a", "error", "message");
// Wait for the test document to be fully loaded.
// This is a workaround to avoid JSWindowActor errors when moving on
// to the next phase of the test. See Bug 1603925.
await ContentTaskUtils.waitForCondition(
() => content.document.querySelector("#test-emptyTimeStamp"),
"Test document should be fully loaded"
info("Wait for the corresponding console-storage-cache-event");
await observerPromise;
const innerWindowId = content.windowGlobalChild.innerWindowId;
const events = ConsoleAPIStorage.getEvents(innerWindowId).filter(
message =>
message.arguments[0] === "this" &&
message.arguments[1] === "is" &&
message.arguments[2] === "a" &&
message.arguments[4] === "message"
);
is(events.length, 4, "The storage service got the messages we emitted");
content.console.log("this", "is", "a", "log message");
content.console.info("this", "is", "a", "info message");
content.console.warn("this", "is", "a", "warn message");
content.console.error("this", "is", "a", "error message");
return observerPromise;
info("Ensure clearEvents does remove the events from storage");
ConsoleAPIStorage.clearEvents();
is(ConsoleAPIStorage.getEvents(innerWindowId).length, 0, "Cleared Storage");
return content.windowGlobalChild.innerWindowId;
});
let windowId = await observerPromise;
await SpecialPowers.spawn(browser, [], function() {
// make sure a closed window's events are in fact removed from
// the storage cache
content.console.log("adding a new event");
});
// Close the window.
info("Close the window");
gBrowser.removeTab(tab, { animate: false });
// Ensure actual window destruction is not delayed (too long).
SpecialPowers.DOMWindowUtils.garbageCollect();

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

@ -1,5 +1,7 @@
<!DOCTYPE HTML>
<html dir="ltr" xml:lang="en-US" lang="en-US"><head>
<html dir="ltr" xml:lang="en-US" lang="en-US">
<head>
<meta charset=utf8>
<title>Console API test page</title>
<script type="text/javascript">
window.foobar585956c = function(a) {