2011-08-24 13:34:16 -07:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
const TEST_URI = "http://example.com/browser/dom/tests/browser/test-console-api.html";
|
|
|
|
const TEST_URI_NAV = "http://example.com/browser/dom/tests/browser/";
|
|
|
|
|
2012-01-24 14:08:42 -08:00
|
|
|
let tempScope = {};
|
|
|
|
Cu.import("resource://gre/modules/ConsoleAPIStorage.jsm", tempScope);
|
|
|
|
let ConsoleAPIStorage = tempScope.ConsoleAPIStorage;
|
2011-08-24 13:34:16 -07:00
|
|
|
|
|
|
|
var apiCallCount;
|
|
|
|
|
|
|
|
var ConsoleObserver = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
|
|
|
|
|
|
|
|
init: function CO_init()
|
|
|
|
{
|
|
|
|
Services.obs.addObserver(this, "console-storage-cache-event", false);
|
|
|
|
apiCallCount = 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function CO_observe(aSubject, aTopic, aData)
|
|
|
|
{
|
|
|
|
if (aTopic == "console-storage-cache-event") {
|
|
|
|
apiCallCount ++;
|
|
|
|
if (apiCallCount == 4) {
|
2012-02-18 21:21:57 -08:00
|
|
|
Services.obs.removeObserver(this, "console-storage-cache-event");
|
|
|
|
|
2011-08-24 13:34:16 -07:00
|
|
|
try {
|
2012-02-18 21:21:57 -08:00
|
|
|
let tab = gBrowser.selectedTab;
|
2011-08-24 13:34:16 -07:00
|
|
|
let browser = gBrowser.selectedBrowser;
|
|
|
|
let win = XPCNativeWrapper.unwrap(browser.contentWindow);
|
|
|
|
let windowID = getWindowId(win);
|
|
|
|
let messages = ConsoleAPIStorage.getEvents(windowID);
|
|
|
|
ok(messages.length >= 4, "Some messages found in the storage service");
|
|
|
|
|
|
|
|
ConsoleAPIStorage.clearEvents();
|
|
|
|
messages = ConsoleAPIStorage.getEvents(windowID);
|
2012-02-18 21:21:57 -08:00
|
|
|
is(messages.length, 0, "Cleared Storage");
|
2011-08-24 13:34:16 -07:00
|
|
|
|
|
|
|
// make sure a closed window's events are in fact removed from the
|
|
|
|
// storage cache
|
|
|
|
win.console.log("adding a new event");
|
2012-02-23 22:04:55 -08:00
|
|
|
// Close the window.
|
2011-08-24 13:34:16 -07:00
|
|
|
gBrowser.removeTab(tab, {animate: false});
|
2012-02-23 22:04:55 -08:00
|
|
|
// Ensure actual window destruction is not delayed (too long).
|
2011-08-24 13:34:16 -07:00
|
|
|
window.QueryInterface(Ci.nsIInterfaceRequestor)
|
2012-02-18 21:21:57 -08:00
|
|
|
.getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
|
2012-02-23 22:04:55 -08:00
|
|
|
// Ensure "inner-window-destroyed" event is processed,
|
|
|
|
// so the storage cache is cleared.
|
2012-02-18 21:21:57 -08:00
|
|
|
executeSoon(function () {
|
2011-08-24 13:34:16 -07:00
|
|
|
// use the old windowID again to see if we have any stray cached messages
|
|
|
|
messages = ConsoleAPIStorage.getEvents(windowID);
|
2012-02-18 21:21:57 -08:00
|
|
|
is(messages.length, 0, "tab close is clearing the cache");
|
2011-08-24 13:34:16 -07:00
|
|
|
finish();
|
|
|
|
});
|
|
|
|
} catch (ex) {
|
|
|
|
dump(ex + "\n\n\n");
|
|
|
|
dump(ex.stack + "\n\n\n");
|
|
|
|
}
|
2012-02-18 21:21:57 -08:00
|
|
|
}
|
2011-08-24 13:34:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function tearDown()
|
|
|
|
{
|
2012-02-18 21:21:57 -08:00
|
|
|
while (gBrowser.tabs.length > 1)
|
2011-08-24 13:34:16 -07:00
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
}
|
|
|
|
|
|
|
|
function test()
|
|
|
|
{
|
2012-02-23 22:04:55 -08:00
|
|
|
// Don't cache removed tabs, so "clear console cache on tab close" triggers.
|
|
|
|
Services.prefs.setIntPref("browser.tabs.max_tabs_undo", 0);
|
|
|
|
registerCleanupFunction(function() {
|
|
|
|
Services.prefs.clearUserPref("browser.tabs.max_tabs_undo");
|
|
|
|
});
|
|
|
|
|
2011-08-24 13:34:16 -07:00
|
|
|
registerCleanupFunction(tearDown);
|
|
|
|
|
|
|
|
ConsoleObserver.init();
|
|
|
|
|
|
|
|
waitForExplicitFinish();
|
|
|
|
|
|
|
|
var tab = gBrowser.addTab(TEST_URI);
|
|
|
|
gBrowser.selectedTab = tab;
|
|
|
|
var browser = gBrowser.selectedBrowser;
|
|
|
|
browser.addEventListener("DOMContentLoaded", function onLoad(event) {
|
|
|
|
browser.removeEventListener("DOMContentLoaded", onLoad, false);
|
|
|
|
executeSoon(function test_executeSoon() {
|
2012-02-18 21:21:57 -08:00
|
|
|
let win = XPCNativeWrapper.unwrap(browser.contentWindow);
|
2011-08-24 13:34:16 -07:00
|
|
|
win.console.log("this", "is", "a", "log message");
|
|
|
|
win.console.info("this", "is", "a", "info message");
|
|
|
|
win.console.warn("this", "is", "a", "warn message");
|
|
|
|
win.console.error("this", "is", "a", "error message");
|
|
|
|
});
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getWindowId(aWindow)
|
|
|
|
{
|
|
|
|
return aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils)
|
|
|
|
.currentInnerWindowID;
|
|
|
|
}
|