Bug 917797 - Fix intermittent test_master_password.html with outer-window-destroyed. r=dolske
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Fri, 31 Jan 2014 12:39:52 -0800
changeset 182380 ee7513d5f51f5d1e55822331bb620ca94c57176e
parent 182379 438cab96ec8450b0895eeb1a98cea617758bc93a
child 182381 a36e188dbc74d0ae0696d07c3bb890345ccc20a8
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs917797
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 917797 - Fix intermittent test_master_password.html with outer-window-destroyed. r=dolske
toolkit/components/passwordmgr/test/mochitest.ini
toolkit/components/passwordmgr/test/test_master_password.html
--- a/toolkit/components/passwordmgr/test/mochitest.ini
+++ b/toolkit/components/passwordmgr/test/mochitest.ini
@@ -51,18 +51,16 @@ skip-if = true
 [test_bug_360493_2.html]
 [test_bug_391514.html]
 [test_bug_427033.html]
 [test_bug_444968.html]
 [test_bug_627616.html]
 [test_bug_654348.html]
 [test_bug_776171.html]
 [test_master_password.html]
-# Bug 917797 - too many intermittent failures
-skip-if = true
 [test_master_password_cleanup.html]
 [test_notifications.html]
 [test_notifications_popup.html]
 skip-if = os == "linux" # bug 934057
 [test_prompt.html]
 skip-if = os == "linux"
 [test_prompt_async.html]
 [test_xhr.html]
--- a/toolkit/components/passwordmgr/test/test_master_password.html
+++ b/toolkit/components/passwordmgr/test/test_master_password.html
@@ -5,16 +5,18 @@
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="text/javascript" src="pwmgr_common.js"></script>
   <script type="text/javascript" src="prompt_common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 Login Manager test: master password.
 <script>
+"use strict";
+
 commonInit();
 SimpleTest.waitForExplicitFinish();
 
 var pwmgr   = SpecialPowers.Cc["@mozilla.org/login-manager;1"]
                            .getService(SpecialPowers.Ci.nsILoginManager);
 var pwcrypt = SpecialPowers.Cc["@mozilla.org/login-manager/crypto/SDR;1"]
                            .getService(Ci.nsILoginManagerCrypto);
 
@@ -89,33 +91,45 @@ function handleDialog(doc, testNum) {
         passfield.setAttribute("value", masterPassword);
         break;
 
       default:
         ok(false, "Uhh, unhandled switch for testNum #" + testNum);
         break;
     }
 
+    didDialog = true;
+
     if (!doNothing) {
+        SpecialPowers.addObserver(outerWindowObserver, "outer-window-destroyed", false);
         if (clickOK)
             dialog.acceptDialog();
         else
             dialog.cancelDialog();
     }
 
-    ok(true, "handleDialog done");
-    didDialog = true;
+    ok(true, "handleDialog done for test " + testNum);
+
+    if (testNum == 4)
+        checkTest4A();
+}
 
-    if (testNum == 3)
-        SimpleTest.executeSoon(checkTest3);
-    else if (testNum == 4)
-        checkTest4A();
+var outerWindowObserver = {
+  observe: function(id) {
+    SpecialPowers.removeObserver(outerWindowObserver, "outer-window-destroyed");
+    if (testNum == 1)
+        startTest2();
+    else if (testNum == 2)
+        startTest3();
+    else if (testNum == 3)
+        checkTest3();
     else if (testNum == 5)
-        SimpleTest.executeSoon(checkTest4C);
-}
+        checkTest4C();
+  }
+};
 
 
 function startTest1() {
     ok(pwcrypt.isLoggedIn, "should be initially logged in (no MP)");
     enableMasterPassword();
     ok(!pwcrypt.isLoggedIn, "should be logged out after setting MP");
 
     // --- Test 1 ---
@@ -123,32 +137,34 @@ function startTest1() {
     startCallbackTimer();
     var logins = pwmgr.getAllLogins();
     ok(didDialog, "handleDialog was invoked");
     is(logins.length, 3, "expected number of logins");
 
     ok(pwcrypt.isLoggedIn, "should be logged in after MP prompt");
     logoutMasterPassword();
     ok(!pwcrypt.isLoggedIn, "should be logged out");
+}
 
-    // --- Test 2 ---
+function startTest2() {
     // Try again but click cancel.
     testNum++;
     startCallbackTimer();
     var failedAsExpected = false;
     logins = null;
     try {
         logins = pwmgr.getAllLogins();
     } catch (e) { failedAsExpected = true; }
     ok(didDialog, "handleDialog was invoked");
     ok(failedAsExpected, "getAllLogins should have thrown");
     is(logins, null, "shouldn't have gotten logins");
     ok(!pwcrypt.isLoggedIn, "should still be logged out");
+}
 
-    // --- Test 3 ---
+function startTest3() {
     // Load a single iframe to trigger a MP
     testNum++;
     iframe1.src = exampleCom + "subtst_master_pass.html";
     startCallbackTimer();
 }
 
 function checkTest3() {
     ok(true, "checkTest3 starting");