Count open browser windows for bug 528776

This commit is contained in:
Dão Gottwald 2009-11-17 08:26:12 +01:00
Родитель f70a5a844a
Коммит 06e4128f91
8 изменённых файлов: 57 добавлений и 18 удалений

Просмотреть файл

@ -34,8 +34,21 @@
*
* ***** END LICENSE BLOCK ***** */
function browserWindowsCount() {
let count = 0;
let e = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator)
.getEnumerator("navigator:browser");
while (e.hasMoreElements()) {
if (!e.getNext().closed)
++count;
}
return count;
}
function test() {
/** Test for Bug 465223 **/
is(browserWindowsCount(), 1, "Only one browser window should be open initially");
// test setup
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
@ -49,7 +62,6 @@ function test() {
// open a window and set a value on it
let newWin = openDialog(location, "_blank", "chrome,all,dialog=no");
newWin.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, false);
ss.setWindowValue(newWin, uniqueKey1, uniqueValue1);
let newState = { windows: [{ tabs:[{ entries: [] }], extData: {} }] };
@ -75,6 +87,7 @@ function test() {
// clean up
newWin.close();
is(browserWindowsCount(), 1, "Only one browser window should be open eventually");
finish();
}, false);
}

Просмотреть файл

@ -45,14 +45,14 @@ function test() {
let tab = gBrowser.addTab(testURL);
tab.linkedBrowser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
let doc = tab.linkedBrowser.contentDocument;
doc.getElementById("reverse_thief").value = "/home/user/secret2";
doc.getElementById("bystander").value = testPath;
let tab2 = gBrowser.duplicateTab(tab);
tab2.linkedBrowser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
tab2.linkedBrowser.removeEventListener("load", arguments.callee, true);
doc = tab2.linkedBrowser.contentDocument;
is(doc.getElementById("thief").value, "",
"file path wasn't set to text field value");

Просмотреть файл

@ -43,7 +43,7 @@ function test() {
"browser/components/sessionstore/test/browser/browser_476161_sample.html";
let tab = gBrowser.addTab(testURL);
tab.linkedBrowser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
let doc = tab.linkedBrowser.contentDocument;
doc.getElementById("modify1").value += Math.random();
@ -51,7 +51,7 @@ function test() {
let tab2 = gBrowser.duplicateTab(tab);
tab2.linkedBrowser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
tab2.linkedBrowser.removeEventListener("load", arguments.callee, true);
let doc = tab2.linkedBrowser.contentDocument;
let changed = doc.getElementById("changed").textContent.trim().split();

Просмотреть файл

@ -34,8 +34,21 @@
*
* ***** END LICENSE BLOCK ***** */
function browserWindowsCount() {
let count = 0;
let e = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator)
.getEnumerator("navigator:browser");
while (e.hasMoreElements()) {
if (!e.getNext().closed)
++count;
}
return count;
}
function test() {
/** Test for Bug 477657 **/
is(browserWindowsCount(), 1, "Only one browser window should be open initially");
// Test fails randomly on OS X (bug 482975)
if ("nsILocalFileMac" in Ci)
@ -46,7 +59,6 @@ function test() {
let newWin = openDialog(location, "_blank", "chrome,all,dialog=no");
newWin.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, false);
let newState = { windows: [{
tabs: [{ entries: [] }],
_closedTabs: [{
@ -92,6 +104,7 @@ function test() {
"the window was explicitly unmaximized");
newWin.close();
is(browserWindowsCount(), 1, "Only one browser window should be open eventually");
finish();
}, 0);
}, 0);

Просмотреть файл

@ -34,8 +34,24 @@
*
* ***** END LICENSE BLOCK ***** */
function browserWindowsCount() {
let count = 0;
let e = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator)
.getEnumerator("navigator:browser");
while (e.hasMoreElements()) {
if (!e.getNext().closed)
++count;
}
return count;
}
function test() {
/** Test for Bug 484108 **/
is(browserWindowsCount(), 1, "Only one browser window should be open initially");
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
waitForExplicitFinish();
// builds the tests state based on a few parameters
function buildTestState(num, selected) {
@ -65,10 +81,6 @@ function test() {
return expected;
}
// test setup
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
waitForExplicitFinish();
// the number of tests we're running
let numTests = 4;
let completedTests = 0;
@ -111,6 +123,7 @@ function test() {
if (++completedTests == numTests) {
this.window.removeEventListener("load", this, false);
this.window.removeEventListener("SSTabRestoring", this, false);
is(browserWindowsCount(), 1, "Only one browser window should be open eventually");
finish();
}
},
@ -153,4 +166,4 @@ function test() {
runTest(4, 13, 11, 6, [10, 7, 8, 9, 11, 12, 0, 1, 2, 3, 4, 5, 6]);
// finish() is run by the last test to finish, so no cleanup down here
}
}

Просмотреть файл

@ -46,13 +46,13 @@ function test() {
gBrowser.selectedTab = tab;
let browser = tab.linkedBrowser;
browser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
browser.removeEventListener("load", arguments.callee, true);
let doc = browser.contentDocument;
// click on the "Start New Session" button after about:sessionrestore is loaded
doc.getElementById("errorCancel").click();
browser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
browser.removeEventListener("load", arguments.callee, true);
let doc = browser.contentDocument;
is(doc.URL, "about:blank", "loaded page is about:blank");
@ -64,13 +64,13 @@ function test() {
gPrefService.setIntPref("browser.startup.page", 1);
gBrowser.loadURI("about:sessionrestore");
browser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
browser.removeEventListener("load", arguments.callee, true);
let doc = browser.contentDocument;
// click on the "Start New Session" button after about:sessionrestore is loaded
doc.getElementById("errorCancel").click();
browser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
browser.removeEventListener("load", arguments.callee, true);
let doc = browser.contentDocument;
is(doc.URL, homepage, "loaded page is the homepage");

Просмотреть файл

@ -45,14 +45,14 @@ function test() {
"browser/components/sessionstore/test/browser/browser_485482_sample.html";
let tab = gBrowser.addTab(testURL);
tab.linkedBrowser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
let doc = tab.linkedBrowser.contentDocument;
doc.querySelector("input[type=text]").value = uniqueValue;
doc.querySelector("input[type=checkbox]").checked = true;
let tab2 = gBrowser.duplicateTab(tab);
tab2.linkedBrowser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
tab2.linkedBrowser.removeEventListener("load", arguments.callee, true);
doc = tab2.linkedBrowser.contentDocument;
is(doc.querySelector("input[type=text]").value, uniqueValue,
"generated XPath expression was valid");

Просмотреть файл

@ -44,7 +44,7 @@ function test() {
let tab = gBrowser.addTab();
tab.linkedBrowser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
ss.setTabValue(tab, "bug485563", uniqueValue);
let tabState = eval("(" + ss.getTabState(tab) + ")");
is(tabState.extData["bug485563"], uniqueValue,