diff --git a/toolkit/components/passwordmgr/test/test_bug_627616.html b/toolkit/components/passwordmgr/test/test_bug_627616.html index eaa2d8982d98..7b498bfdfac5 100644 --- a/toolkit/components/passwordmgr/test/test_bug_627616.html +++ b/toolkit/components/passwordmgr/test/test_bug_627616.html @@ -31,11 +31,13 @@ login2 = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo); login2.init("http://mochi.test:8888", null, "mochirealm", "user1name", "user1pass", "", ""); pwmgr.addLogin(login2); + startCallbackTimer(); } function cleanup() { var pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); pwmgr.removeLogin(login); pwmgr.removeLogin(login2); + timer.cancel(); } function makeXHR(expectedStatus, expectedText, extra) { @@ -59,7 +61,6 @@ function testNonAnonymousCredentials() { var xhr = makeXHR(200, "OK"); xhr.send(); - startCallbackTimer(); } function testAnonymousCredentials() { @@ -77,10 +78,14 @@ xhr.send(); } + var gExpectedDialogs = 0; var gCurrentTest; function runNextTest() { + is(gExpectedDialogs, 0, "received expected number of auth dialogs"); + Cc["@mozilla.org/network/http-auth-manager;1"].getService(Components.interfaces.nsIHttpAuthManager).clearAll(); if (pendingTests.length > 0) { - gCurrentTest = pendingTests.shift(); + ({expectedDialogs: gExpectedDialogs, + test: gCurrentTest}) = pendingTests.shift(); gCurrentTest.call(this); } else { cleanup(); @@ -88,8 +93,9 @@ } } - var pendingTests = [testNonAnonymousCredentials, testAnonymousCredentials, - testAnonymousNoAuth]; + var pendingTests = [{expectedDialogs: 2, test: testNonAnonymousCredentials}, + {expectedDialogs: 1, test: testAnonymousCredentials}, + {expectedDialogs: 0, test: testAnonymousNoAuth}]; init(); runNextTest(); @@ -97,9 +103,8 @@ { var dialog = doc.getElementById("commonDialog"); dialog.acceptDialog(); - if (gCurrentTest == testNonAnonymousCredentials) { - startCallbackTimer(); - } + gExpectedDialogs--; + startCallbackTimer(); }