зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1270115 - Rewrite browser_ConsoleStorageAPITests.js to run in e10s. r=bz
This commit is contained in:
Родитель
3c3f655608
Коммит
1a795be9f7
|
@ -20,7 +20,6 @@ skip-if = buildapp == 'mulet'
|
||||||
skip-if = e10s
|
skip-if = e10s
|
||||||
[browser_ConsoleAPI_originAttributes.js]
|
[browser_ConsoleAPI_originAttributes.js]
|
||||||
[browser_ConsoleStorageAPITests.js]
|
[browser_ConsoleStorageAPITests.js]
|
||||||
skip-if = e10s
|
|
||||||
[browser_ConsoleStoragePBTest_perwindowpb.js]
|
[browser_ConsoleStoragePBTest_perwindowpb.js]
|
||||||
[browser_autofocus_background.js]
|
[browser_autofocus_background.js]
|
||||||
skip-if= buildapp == 'mulet'
|
skip-if= buildapp == 'mulet'
|
||||||
|
|
|
@ -1,74 +1,15 @@
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
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/";
|
const TEST_URI_NAV = "http://example.com/browser/dom/tests/browser/";
|
||||||
|
|
||||||
var ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"]
|
|
||||||
.getService(Ci.nsIConsoleAPIStorage);
|
|
||||||
|
|
||||||
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) {
|
|
||||||
Services.obs.removeObserver(this, "console-storage-cache-event");
|
|
||||||
|
|
||||||
try {
|
|
||||||
let tab = gBrowser.selectedTab;
|
|
||||||
let browser = gBrowser.selectedBrowser;
|
|
||||||
let win = 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);
|
|
||||||
is(messages.length, 0, "Cleared Storage");
|
|
||||||
|
|
||||||
// make sure a closed window's events are in fact removed from the
|
|
||||||
// storage cache
|
|
||||||
win.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();
|
|
||||||
// Ensure "inner-window-destroyed" event is processed,
|
|
||||||
// so the storage cache is cleared.
|
|
||||||
executeSoon(function () {
|
|
||||||
// use the old windowID again to see if we have any stray cached messages
|
|
||||||
messages = ConsoleAPIStorage.getEvents(windowID);
|
|
||||||
is(messages.length, 0, "tab close is clearing the cache");
|
|
||||||
finish();
|
|
||||||
});
|
|
||||||
} catch (ex) {
|
|
||||||
dump(ex + "\n\n\n");
|
|
||||||
dump(ex.stack + "\n\n\n");
|
|
||||||
ok(false, "We got an unexpected exception");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function tearDown()
|
function tearDown()
|
||||||
{
|
{
|
||||||
while (gBrowser.tabs.length > 1)
|
while (gBrowser.tabs.length > 1)
|
||||||
gBrowser.removeCurrentTab();
|
gBrowser.removeCurrentTab();
|
||||||
}
|
}
|
||||||
|
|
||||||
function test()
|
add_task(function*()
|
||||||
{
|
{
|
||||||
// Don't cache removed tabs, so "clear console cache on tab close" triggers.
|
// Don't cache removed tabs, so "clear console cache on tab close" triggers.
|
||||||
Services.prefs.setIntPref("browser.tabs.max_tabs_undo", 0);
|
Services.prefs.setIntPref("browser.tabs.max_tabs_undo", 0);
|
||||||
|
@ -78,26 +19,86 @@ function test()
|
||||||
|
|
||||||
registerCleanupFunction(tearDown);
|
registerCleanupFunction(tearDown);
|
||||||
|
|
||||||
ConsoleObserver.init();
|
// Open a keepalive tab in the background to make sure we don't accidentally
|
||||||
|
// kill the content process
|
||||||
|
var keepaliveTab = gBrowser.addTab("about:blank");
|
||||||
|
|
||||||
waitForExplicitFinish();
|
// Open the main tab to run the test in
|
||||||
|
var tab = gBrowser.addTab("about:blank");
|
||||||
var tab = gBrowser.addTab(TEST_URI);
|
|
||||||
gBrowser.selectedTab = tab;
|
gBrowser.selectedTab = tab;
|
||||||
var browser = gBrowser.selectedBrowser;
|
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);
|
||||||
|
|
||||||
|
return 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");
|
||||||
|
Assert.ok(ConsoleAPIStorage.getEvents(windowId).length >= 4, "Some messages found in the storage service");
|
||||||
|
ConsoleAPIStorage.clearEvents();
|
||||||
|
Assert.equal(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;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
let win;
|
||||||
browser.addEventListener("DOMContentLoaded", function onLoad(event) {
|
browser.addEventListener("DOMContentLoaded", function onLoad(event) {
|
||||||
browser.removeEventListener("DOMContentLoaded", onLoad, false);
|
browser.removeEventListener("DOMContentLoaded", onLoad, false);
|
||||||
executeSoon(function test_executeSoon() {
|
executeSoon(function test_executeSoon() {
|
||||||
let win = browser.contentWindow;
|
win = browser.contentWindow;
|
||||||
win.console.log("this", "is", "a", "log message");
|
win.console.log("this", "is", "a", "log message");
|
||||||
win.console.info("this", "is", "a", "info message");
|
win.console.info("this", "is", "a", "info message");
|
||||||
win.console.warn("this", "is", "a", "warn message");
|
win.console.warn("this", "is", "a", "warn message");
|
||||||
win.console.error("this", "is", "a", "error message");
|
win.console.error("this", "is", "a", "error message");
|
||||||
});
|
});
|
||||||
}, false);
|
}, false);
|
||||||
}
|
|
||||||
|
|
||||||
function getWindowId(aWindow)
|
let windowId = yield observerPromise;
|
||||||
{
|
// make sure a closed window's events are in fact removed from
|
||||||
return SpecialPowers.getDOMWindowUtils(aWindow).currentInnerWindowID;
|
// the storage cache
|
||||||
}
|
win.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;
|
||||||
|
|
||||||
|
// Ensure the "inner-window-destroyed" event is processed,
|
||||||
|
// so the storage cache is cleared. We do this in the content
|
||||||
|
// process because that is where the event will be processed.
|
||||||
|
yield ContentTask.spawn(browser, null, function() {
|
||||||
|
yield new Promise(resolve => setTimeout(resolve, 0));
|
||||||
|
});
|
||||||
|
|
||||||
|
yield ContentTask.spawn(browser, windowId, function(windowId) {
|
||||||
|
var ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"]
|
||||||
|
.getService(Ci.nsIConsoleAPIStorage);
|
||||||
|
Assert.equal(ConsoleAPIStorage.getEvents(windowId).length, 0, "tab close is clearing the cache");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Загрузка…
Ссылка в новой задаче