Bug 728790 test_prompt_async.html doesn't track its dialogs correctly r=mayhemer a=akeybl
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Fri, 16 Mar 2012 21:57:13 +0000
changeset 91993 196ad34ad49afba00dbed57e8392d14f96fa73d8
parent 91992 b5ac0b5020792998f19fa1e3f0021c725bfaf1fd
child 91994 b0a19a26150cfafae5152e620d43b1c99159ae24
push idunknown
push userunknown
push dateunknown
reviewersmayhemer, akeybl
bugs728790
milestone13.0a2
Bug 728790 test_prompt_async.html doesn't track its dialogs correctly r=mayhemer a=akeybl
toolkit/components/passwordmgr/test/test_bug_627616.html
--- a/toolkit/components/passwordmgr/test/test_bug_627616.html
+++ b/toolkit/components/passwordmgr/test/test_bug_627616.html
@@ -26,21 +26,23 @@
         var pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
         login = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);
         login.init(mozproxy, null, "proxy_realm", "proxy_user", "proxy_pass", "", "");
         pwmgr.addLogin(login);
 
         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) {
       var xhr =  new XMLHttpRequest();
       xhr.open("GET", "authenticate.sjs?" +
                       "proxy_user=proxy_user&" +
                       "proxy_pass=proxy_pass&" +
                       "proxy_realm=proxy_realm&" +
@@ -54,17 +56,16 @@
         runNextTest();
       }
       return xhr;
     }
 
     function testNonAnonymousCredentials() {
       var xhr = makeXHR(200, "OK");
       xhr.send();
-      startCallbackTimer();
     }
 
     function testAnonymousCredentials() {
       // Test that an anonymous request correctly performs proxy authentication
       var xhr = makeXHR(401, "Authentication required");
       SpecialPowers.wrap(xhr).channel.loadFlags |= Ci.nsIChannel.LOAD_ANONYMOUS;
       xhr.send();
     }
@@ -72,35 +73,39 @@
     function testAnonymousNoAuth() {
       // Next, test that an anonymous request still does not include any non-proxy
       // authentication headers.
       var xhr = makeXHR(200, "Authorization header not found", "anonymous=1");
       SpecialPowers.wrap(xhr).channel.loadFlags |= Ci.nsIChannel.LOAD_ANONYMOUS;
       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();
         SimpleTest.finish();
       }
     }
 
-    var pendingTests = [testNonAnonymousCredentials, testAnonymousCredentials,
-                        testAnonymousNoAuth];
+    var pendingTests = [{expectedDialogs: 2, test: testNonAnonymousCredentials},
+                        {expectedDialogs: 1, test: testAnonymousCredentials},
+                        {expectedDialogs: 0, test: testAnonymousNoAuth}];
     init();
     runNextTest();
 
     function handleDialog(doc, testNum)
     {
         var dialog = doc.getElementById("commonDialog");
         dialog.acceptDialog();
-        if (gCurrentTest == testNonAnonymousCredentials) {
-          startCallbackTimer();
-        }
+        gExpectedDialogs--;
+        startCallbackTimer();
     }
 </script>
 </body>
 </html>