2011-08-25 00:34:16 +04:00
|
|
|
/* 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/";
|
|
|
|
|
|
|
|
function tearDown()
|
|
|
|
{
|
2012-02-19 09:21:57 +04:00
|
|
|
while (gBrowser.tabs.length > 1)
|
2011-08-25 00:34:16 +04:00
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
}
|
|
|
|
|
2016-05-03 20:51:55 +03:00
|
|
|
add_task(function*()
|
2011-08-25 00:34:16 +04:00
|
|
|
{
|
2012-02-24 10:04:55 +04:00
|
|
|
// Don't cache removed tabs, so "clear console cache on tab close" triggers.
|
2016-09-21 04:04:15 +03:00
|
|
|
yield SpecialPowers.pushPrefEnv({ set: [[ "browser.tabs.max_tabs_undo", 0 ]] });
|
2012-02-24 10:04:55 +04:00
|
|
|
|
2011-08-25 00:34:16 +04:00
|
|
|
registerCleanupFunction(tearDown);
|
|
|
|
|
2016-05-03 20:51:55 +03:00
|
|
|
// Open a keepalive tab in the background to make sure we don't accidentally
|
|
|
|
// kill the content process
|
|
|
|
var keepaliveTab = gBrowser.addTab("about:blank");
|
2011-08-25 00:34:16 +04:00
|
|
|
|
2016-05-03 20:51:55 +03:00
|
|
|
// Open the main tab to run the test in
|
|
|
|
var tab = gBrowser.addTab("about:blank");
|
2011-08-25 00:34:16 +04:00
|
|
|
gBrowser.selectedTab = tab;
|
|
|
|
var browser = gBrowser.selectedBrowser;
|
2016-05-03 20:51:55 +03:00
|
|
|
|
2016-09-21 04:04:15 +03:00
|
|
|
let observerPromise = ContentTask.spawn(browser, null, function* (opt) {
|
2016-05-03 20:51:55 +03:00
|
|
|
const TEST_URI = "http://example.com/browser/dom/tests/browser/test-console-api.html";
|
|
|
|
let ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"]
|
|
|
|
.getService(Ci.nsIConsoleAPIStorage);
|
|
|
|
|
2016-09-21 04:04:15 +03:00
|
|
|
let observerPromise = new Promise(resolve => {
|
2016-05-03 20:51:55 +03:00
|
|
|
let apiCallCount = 0;
|
|
|
|
let ConsoleObserver = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
|
|
|
|
|
|
|
|
observe: function(aSubject, aTopic, aData) {
|
|
|
|
if (aTopic == "console-storage-cache-event") {
|
|
|
|
apiCallCount++;
|
|
|
|
if (apiCallCount == 4) {
|
|
|
|
let windowId = content.window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
|
|
|
|
|
|
|
|
Services.obs.removeObserver(this, "console-storage-cache-event");
|
2016-09-21 04:04:15 +03:00
|
|
|
ok(ConsoleAPIStorage.getEvents(windowId).length >= 4, "Some messages found in the storage service");
|
2016-05-03 20:51:55 +03:00
|
|
|
ConsoleAPIStorage.clearEvents();
|
2016-09-21 04:04:15 +03:00
|
|
|
is(ConsoleAPIStorage.getEvents(windowId).length, 0, "Cleared Storage");
|
2016-05-03 20:51:55 +03:00
|
|
|
|
|
|
|
resolve(windowId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Services.obs.addObserver(ConsoleObserver, "console-storage-cache-event", false);
|
|
|
|
|
|
|
|
// Redirect the browser to the test URI
|
|
|
|
content.window.location = TEST_URI;
|
|
|
|
});
|
|
|
|
|
2016-09-21 04:04:15 +03:00
|
|
|
yield ContentTaskUtils.waitForEvent(this, "DOMContentLoaded");
|
|
|
|
|
|
|
|
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;
|
|
|
|
});
|
2011-08-25 00:34:16 +04:00
|
|
|
|
2016-05-03 20:51:55 +03:00
|
|
|
let windowId = yield observerPromise;
|
2016-09-21 04:04:15 +03:00
|
|
|
|
|
|
|
yield ContentTask.spawn(browser, null, function() {
|
|
|
|
// make sure a closed window's events are in fact removed from
|
|
|
|
// the storage cache
|
|
|
|
content.console.log("adding a new event");
|
|
|
|
});
|
2016-05-03 20:51:55 +03:00
|
|
|
|
|
|
|
// Close the window.
|
|
|
|
gBrowser.removeTab(tab, {animate: false});
|
|
|
|
// Ensure actual window destruction is not delayed (too long).
|
|
|
|
SpecialPowers.DOMWindowUtils.garbageCollect();
|
|
|
|
|
|
|
|
// Spawn the check in the keepaliveTab, so that we can read the ConsoleAPIStorage correctly
|
|
|
|
gBrowser.selectedTab = keepaliveTab;
|
|
|
|
browser = gBrowser.selectedBrowser;
|
|
|
|
|
2016-09-21 04:04:15 +03:00
|
|
|
// Spin the event loop to make sure everything is cleared.
|
|
|
|
yield ContentTask.spawn(browser, null, function () {
|
|
|
|
return Promise.resolve();
|
2016-05-03 20:51:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
yield ContentTask.spawn(browser, windowId, function(windowId) {
|
|
|
|
var ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"]
|
|
|
|
.getService(Ci.nsIConsoleAPIStorage);
|
2016-09-21 04:04:15 +03:00
|
|
|
is(ConsoleAPIStorage.getEvents(windowId).length, 0, "tab close is clearing the cache");
|
2016-05-03 20:51:55 +03:00
|
|
|
});
|
|
|
|
});
|