Bug 1268764 - Convert test_master_password_cleanup.html into a cleanup function in test_master_password.html draft
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Thu, 28 Apr 2016 22:56:51 -0700
changeset 357713 c6f5e9c2a9f65df5254ece4bc998dba28897cc69
parent 357266 2157fe6b6efd14c217404bf3fe7d28699dc47ce4
child 519683 1adddabd2d719d016abb4025a43483abf097f6c3
push id16822
push usermozilla@noorenberghe.ca
push dateFri, 29 Apr 2016 05:58:30 +0000
bugs1268764
milestone49.0a1
Bug 1268764 - Convert test_master_password_cleanup.html into a cleanup function in test_master_password.html MozReview-Commit-ID: C99hq7LMn0Y
toolkit/components/passwordmgr/test/mochitest.ini
toolkit/components/passwordmgr/test/pwmgr_common.js
toolkit/components/passwordmgr/test/test_master_password.html
toolkit/components/passwordmgr/test/test_master_password_cleanup.html
--- a/toolkit/components/passwordmgr/test/mochitest.ini
+++ b/toolkit/components/passwordmgr/test/mochitest.ini
@@ -7,18 +7,16 @@ support-files =
   notification_common.js
   prompt_common.js
   pwmgr_common.js
   subtst_master_pass.html
   subtst_prompt_async.html
 
 [test_master_password.html]
 skip-if = toolkit == 'android' # Tests desktop prompts
-[test_master_password_cleanup.html]
-skip-if = toolkit == 'android' # Tests desktop prompts
 [test_prompt.html]
 skip-if = os == "linux" || toolkit == 'android' # Tests desktop prompts
 [test_prompt_async.html]
 skip-if = toolkit == 'android' # Tests desktop prompts
 [test_xhr.html]
 skip-if = toolkit == 'android' # Tests desktop prompts
 [test_xml_load.html]
 skip-if = toolkit == 'android' # Tests desktop prompts
--- a/toolkit/components/passwordmgr/test/pwmgr_common.js
+++ b/toolkit/components/passwordmgr/test/pwmgr_common.js
@@ -215,17 +215,17 @@ function setMasterPassword(enable) {
     oldPW = masterPassword;
     newPW = "";
   }
   // Set master password. Note that this does not log you in, so the next
   // invocation of pwmgr can trigger a MP prompt.
 
   var pk11db = Cc["@mozilla.org/security/pk11tokendb;1"].getService(Ci.nsIPK11TokenDB);
   var token = pk11db.findTokenByName("");
-  ok(true, "change from " + oldPW + " to " + newPW);
+  info("MP change from " + oldPW + " to " + newPW);
   token.changePassword(oldPW, newPW);
 }
 
 function logoutMasterPassword() {
   var sdr = Cc["@mozilla.org/security/sdr;1"].getService(Ci.nsISecretDecoderRing);
   sdr.logoutAndTeardown();
 }
 
--- a/toolkit/components/passwordmgr/test/test_master_password.html
+++ b/toolkit/components/passwordmgr/test/test_master_password.html
@@ -276,28 +276,26 @@ function checkTest4C() {
     is(p.value, "pass2", "checking expected pass to have been filled in");
 
     // check contents of iframe2 fields
     u = SpecialPowers.wrap(iframe2).contentDocument.getElementById("userfield");
     p = SpecialPowers.wrap(iframe2).contentDocument.getElementById("passfield");
     is(u.value, "user1", "checking expected user to have been filled in");
     is(p.value, "pass1", "checking expected pass to have been filled in");
 
-    finishTest();
+    SimpleTest.finish();
 }
 
 // XXX do a test5ABC with clicking cancel?
 
-function finishTest() {
+SimpleTest.registerCleanupFunction(function finishTest() {
     disableMasterPassword();
-    ok(pwcrypt.isLoggedIn, "should be logged in");
 
     pwmgr.removeLogin(login1);
     pwmgr.removeLogin(login2);
-    SimpleTest.finish();
-}
+});
 
 window.addEventListener("runTests", startTest1);
 </script>
 </pre>
 </body>
 </html>
 
deleted file mode 100644
--- a/toolkit/components/passwordmgr/test/test_master_password_cleanup.html
+++ /dev/null
@@ -1,51 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <meta charset="utf-8">
-  <title>Test master password cleanup</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="text/javascript" src="pwmgr_common.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-</head>
-<body>
-Login Manager test: master password cleanup
-<p id="display"></p>
-
-<div id="content" style="display: none">
-</div>
-
-<pre id="test">
-<script class="testbody" type="text/javascript">
-
-
-/*
- * The entire purpose of this test is to make sure that, if the previous master
- * password test did not complete successfully, we don't screw up other pwmgr
- * tests by having a master password unexpectedly set.
- */
-function cleanup() {
-    ok(true, "ensuring MP is cleared");
-
-    var pk11db = Cc["@mozilla.org/security/pk11tokendb;1"].
-                 getService(Ci.nsIPK11TokenDB);
-    var token = pk11db.getInternalKeyToken();
-
-    if (!token.checkPassword("")) {
-        ok(true, "Oops! MP still set, clearing it...");
-        disableMasterPassword();
-    } else {
-        ok(true, "Master password already cleared.");
-    }
-
-  ok(true, "done.");
-}
-
-const Cc = SpecialPowers.Cc;
-const Ci = SpecialPowers.Ci;
-
-cleanup();
-</script>
-</pre>
-</body>
-</html>
-