diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/tests/browser/browser_ConsoleStorageAPITests.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/tests/browser/browser_ConsoleStorageAPITests.js')
-rw-r--r-- | dom/tests/browser/browser_ConsoleStorageAPITests.js | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/dom/tests/browser/browser_ConsoleStorageAPITests.js b/dom/tests/browser/browser_ConsoleStorageAPITests.js new file mode 100644 index 000000000..742f6f877 --- /dev/null +++ b/dom/tests/browser/browser_ConsoleStorageAPITests.js @@ -0,0 +1,98 @@ +/* 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() +{ + while (gBrowser.tabs.length > 1) + gBrowser.removeCurrentTab(); +} + +add_task(function*() +{ + // Don't cache removed tabs, so "clear console cache on tab close" triggers. + yield SpecialPowers.pushPrefEnv({ set: [[ "browser.tabs.max_tabs_undo", 0 ]] }); + + registerCleanupFunction(tearDown); + + // Open a keepalive tab in the background to make sure we don't accidentally + // kill the content process + var keepaliveTab = gBrowser.addTab("about:blank"); + + // Open the main tab to run the test in + var tab = gBrowser.addTab("about:blank"); + gBrowser.selectedTab = tab; + var browser = gBrowser.selectedBrowser; + + let observerPromise = ContentTask.spawn(browser, null, function* (opt) { + 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); + + let observerPromise = new Promise(resolve => { + 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"); + 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); + } + } + } + }; + + Services.obs.addObserver(ConsoleObserver, "console-storage-cache-event", false); + + // Redirect the browser to the test URI + content.window.location = TEST_URI; + }); + + 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; + }); + + let windowId = yield observerPromise; + + 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"); + }); + + // 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; + + // Spin the event loop to make sure everything is cleared. + yield ContentTask.spawn(browser, null, function () { + return Promise.resolve(); + }); + + yield ContentTask.spawn(browser, windowId, function(windowId) { + var ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"] + .getService(Ci.nsIConsoleAPIStorage); + is(ConsoleAPIStorage.getEvents(windowId).length, 0, "tab close is clearing the cache"); + }); +}); |