fune/dom/tests/browser/browser_ConsoleStoragePBTest_perwindowpb.js
Cosmin Sabou 0f970fbb19 Backed out 20 changesets (bug 1602318) for causing multiple types of failures. CLOSED TREE
Backed out changeset f71e3eff7a8c (bug 1602318)
Backed out changeset 0e0bdebf223b (bug 1602318)
Backed out changeset 44e82f4339a1 (bug 1602318)
Backed out changeset 5f341ebd8591 (bug 1602318)
Backed out changeset 088ea9d20617 (bug 1602318)
Backed out changeset 5de6321939f2 (bug 1602318)
Backed out changeset f5742e84912b (bug 1602318)
Backed out changeset 13bec3079540 (bug 1602318)
Backed out changeset 6c24ba022911 (bug 1602318)
Backed out changeset 5d0fc0102a7f (bug 1602318)
Backed out changeset fc4efd11e643 (bug 1602318)
Backed out changeset 028bd63e710d (bug 1602318)
Backed out changeset 21ad350f9617 (bug 1602318)
Backed out changeset 8f27319f2c34 (bug 1602318)
Backed out changeset db2832973382 (bug 1602318)
Backed out changeset 1756c7584491 (bug 1602318)
Backed out changeset 983e5a9abe02 (bug 1602318)
Backed out changeset a1b9429b3298 (bug 1602318)
Backed out changeset 7d1c0d968a09 (bug 1602318)
Backed out changeset a3b056ec6be3 (bug 1602318)
2020-04-24 11:15:12 +03:00

101 lines
3 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/. */
function test() {
// initialization
waitForExplicitFinish();
let windowsToClose = [];
let innerID;
let beforeEvents;
let afterEvents;
let storageShouldOccur;
let consoleObserver;
let testURI =
"http://example.com/browser/dom/tests/browser/test-console-api.html";
let ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"].getService(
Ci.nsIConsoleAPIStorage
);
function getInnerWindowId(aWindow) {
return aWindow.windowUtils.currentInnerWindowID;
}
function whenNewWindowLoaded(aOptions, aCallback) {
let win = OpenBrowserWindow(aOptions);
win.addEventListener(
"load",
function() {
aCallback(win);
},
{ once: true }
);
}
function doTest(aIsPrivateMode, aWindow, aCallback) {
BrowserTestUtils.browserLoaded(aWindow.gBrowser.selectedBrowser).then(
() => {
consoleObserver = {
observe(aSubject, aTopic, aData) {
if (aTopic == "console-api-log-event") {
afterEvents = ConsoleAPIStorage.getEvents(innerID);
is(
beforeEvents.length == afterEvents.length - 1,
storageShouldOccur,
"storage should" + (storageShouldOccur ? "" : " not") + " occur"
);
executeSoon(function() {
Services.obs.removeObserver(
consoleObserver,
"console-api-log-event"
);
aCallback();
});
}
},
};
aWindow.Services.obs.addObserver(
consoleObserver,
"console-api-log-event"
);
aWindow.nativeConsole.log(
"foo bar baz (private: " + aIsPrivateMode + ")"
);
}
);
// We expect that console API messages are always stored.
storageShouldOccur = true;
innerID = getInnerWindowId(aWindow);
beforeEvents = ConsoleAPIStorage.getEvents(innerID);
BrowserTestUtils.loadURI(aWindow.gBrowser.selectedBrowser, testURI);
}
function testOnWindow(aOptions, aCallback) {
whenNewWindowLoaded(aOptions, function(aWin) {
windowsToClose.push(aWin);
// execute should only be called when need, like when you are opening
// web pages on the test. If calling executeSoon() is not necesary, then
// call whenNewWindowLoaded() instead of testOnWindow() on your test.
executeSoon(() => aCallback(aWin));
});
}
// this function is called after calling finish() on the test.
registerCleanupFunction(function() {
windowsToClose.forEach(function(aWin) {
aWin.close();
});
});
// test first when not on private mode
testOnWindow({}, function(aWin) {
doTest(false, aWin, function() {
// then test when on private mode
testOnWindow({ private: true }, function(aWin) {
doTest(true, aWin, finish);
});
});
});
}