mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
Bug 1332874: Check that extra windows and tabs are closed after each mochitest. r=aswan
MozReview-Commit-ID: GjJxHVnLJi1 --HG-- extra : rebase_source : 695612f3d73e2feb71b44d3702c583cd3be11626
This commit is contained in:
parent
40c4934907
commit
a8bcea0d5d
@ -208,14 +208,8 @@ SpecialPowersObserverAPI.prototype = {
|
||||
input.close();
|
||||
|
||||
var status;
|
||||
try {
|
||||
channel.QueryInterface(Ci.nsIHttpChannel);
|
||||
if (channel instanceof Ci.nsIHttpChannel) {
|
||||
status = channel.responseStatus;
|
||||
} catch(e) {
|
||||
/* The channel is not a nsIHttpCHannel, but that's fine */
|
||||
dump("-*- _readUrlAsString: Got an error while fetching " +
|
||||
"chrome script '" + aUrl + "': (" + e.name + ") " + e.message + ". " +
|
||||
"Ignoring.\n");
|
||||
}
|
||||
|
||||
if (status == 404) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
[DEFAULT]
|
||||
support-files =
|
||||
chrome_head.js
|
||||
chrome_cleanup_script.js
|
||||
head.js
|
||||
head_cookies.js
|
||||
file_sample.html
|
||||
|
@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
|
||||
/* global addMessageListener, sendAsyncMessage */
|
||||
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function* iterBrowserWindows() {
|
||||
let enm = Services.wm.getEnumerator("navigator:browser");
|
||||
while (enm.hasMoreElements()) {
|
||||
let win = enm.getNext();
|
||||
if (!win.closed && win.gBrowser) {
|
||||
yield win;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let initialTabs = new Map();
|
||||
for (let win of iterBrowserWindows()) {
|
||||
initialTabs.set(win, new Set(win.gBrowser.tabs));
|
||||
}
|
||||
|
||||
addMessageListener("check-cleanup", extensionId => {
|
||||
let results = {
|
||||
extraWindows: [],
|
||||
extraTabs: [],
|
||||
};
|
||||
|
||||
for (let win of iterBrowserWindows()) {
|
||||
if (initialTabs.has(win)) {
|
||||
let tabs = initialTabs.get(win);
|
||||
|
||||
for (let tab of win.gBrowser.tabs) {
|
||||
if (!tabs.has(tab)) {
|
||||
results.extraTabs.push(tab.linkedBrowser.currentURI.spec);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
results.extraWindows.push(
|
||||
Array.from(win.gBrowser.tabs,
|
||||
tab => tab.linkedBrowser.currentURI.spec));
|
||||
}
|
||||
}
|
||||
|
||||
initialTabs = null;
|
||||
|
||||
sendAsyncMessage("cleanup-results", results);
|
||||
});
|
@ -1,5 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
let {AppConstants} = SpecialPowers.Cu.import("resource://gre/modules/AppConstants.jsm", {});
|
||||
|
||||
// We run tests under two different configurations, from mochitest.ini and
|
||||
// mochitest-remote.ini. When running from mochitest-remote.ini, the tests are
|
||||
// copied to the sub-directory "test-oop-extensions", which we detect here, and
|
||||
@ -14,6 +16,22 @@ if (location.pathname.includes("test-oop-extensions")) {
|
||||
SpecialPowers.setIntPref("dom.ipc.keepProcessesAlive.extension", 1);
|
||||
}
|
||||
|
||||
if (AppConstants.MOZ_BUILD_APP === "browser") {
|
||||
let chromeScript = SpecialPowers.loadChromeScript(
|
||||
SimpleTest.getTestFileURL("chrome_cleanup_script.js"));
|
||||
|
||||
SimpleTest.registerCleanupFunction(async () => {
|
||||
chromeScript.sendAsyncMessage("check-cleanup");
|
||||
|
||||
let results = await chromeScript.promiseOneMessage("cleanup-results");
|
||||
chromeScript.destroy();
|
||||
|
||||
if (results.extraWindows.length || results.extraTabs.length) {
|
||||
ok(false, `Test left extra windows or tabs: ${JSON.stringify(results)}\n`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* exported waitForLoad */
|
||||
|
||||
function waitForLoad(win) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
[DEFAULT]
|
||||
support-files =
|
||||
chrome_cleanup_script.js
|
||||
head.js
|
||||
file_mixed.html
|
||||
head_webrequest.js
|
||||
|
@ -172,6 +172,8 @@ add_task(function* test_webRequest_filter_background() {
|
||||
|
||||
add_task(function* teardown() {
|
||||
testWindow.close();
|
||||
|
||||
yield new Promise(resolve => setTimeout(resolve, 0));
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
Loading…
Reference in New Issue
Block a user