Bug 728790 test_prompt_async.html doesn't track its dialogs correctly r=mayhemer
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Fri, 16 Mar 2012 21:57:13 +0000
changeset 89578 5fa704e28601190eddb77e3e6ab9ecde5074c804
parent 89577 c7ef262e3024774de5d1bf274cd7f7d6c09aee05
child 89579 94ad7c1c0de7579f6ba067c883e1055a52e62b3b
child 90699 a205b93931513b8d4a2f90af7e71e1c347fc9a7e
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmayhemer
bugs728790
milestone14.0a1
Bug 728790 test_prompt_async.html doesn't track its dialogs correctly r=mayhemer
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>