Bug 1151666 - avoid multiple verified email timers from running and avoid 'pending' calls in the test. r=zaach
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 30 Apr 2015 17:02:02 +1000
changeset 273188 461b2cd49f3c7701c3186fa42b2a9d44194b6d60
parent 273187 e608444e72aabd5c585d99d337307e00b196994a
child 273189 99afe078d60228a2d660963428d6bf4bd7e6d358
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszaach
bugs1151666
milestone40.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 1151666 - avoid multiple verified email timers from running and avoid 'pending' calls in the test. r=zaach
services/fxaccounts/FxAccounts.jsm
services/fxaccounts/tests/xpcshell/test_accounts.js
--- a/services/fxaccounts/FxAccounts.jsm
+++ b/services/fxaccounts/FxAccounts.jsm
@@ -1063,16 +1063,22 @@ FxAccountsInternal.prototype = {
     log.debug("Notifying observers of " + topic);
     Services.obs.notifyObservers(null, topic, data);
   },
 
   // XXX - pollEmailStatus should maybe be on the AccountState object?
   pollEmailStatus: function pollEmailStatus(currentState, sessionToken, why) {
     log.debug("entering pollEmailStatus: " + why);
     if (why == "start") {
+      if (this.currentTimer) {
+        log.debug("pollEmailStatus starting while existing timer is running");
+        clearTimeout(this.currentTimer);
+        this.currentTimer = null;
+      }
+
       // If we were already polling, stop and start again.  This could happen
       // if the user requested the verification email to be resent while we
       // were already polling for receipt of an earlier email.
       this.pollStartDate = Date.now();
       if (!currentState.whenVerifiedDeferred) {
         currentState.whenVerifiedDeferred = Promise.defer();
         // This deferred might not end up with any handlers (eg, if sync
         // is yet to start up.)  This might cause "A promise chain failed to
--- a/services/fxaccounts/tests/xpcshell/test_accounts.js
+++ b/services/fxaccounts/tests/xpcshell/test_accounts.js
@@ -34,21 +34,16 @@ Services.prefs.setCharPref("identity.fxa
 
 
 const PROFILE_SERVER_URL = "http://example.com/v1";
 const CONTENT_URL = "http://accounts.example.com/";
 
 Services.prefs.setCharPref("identity.fxaccounts.remote.profile.uri", PROFILE_SERVER_URL);
 Services.prefs.setCharPref("identity.fxaccounts.settings.uri", CONTENT_URL);
 
-
-function run_test() {
-  run_next_test();
-}
-
 /*
  * The FxAccountsClient communicates with the remote Firefox
  * Accounts auth server.  Mock the server calls, with a little
  * lag time to simulate some latency.
  *
  * We add the _verified attribute to mock the change in verification
  * state on the FXA server.
  */
@@ -259,52 +254,46 @@ add_task(function* test_getCertificate()
       do_check_eq(err, "Error: OFFLINE");
     }
   );
 });
 
 
 // Sanity-check that our mocked client is working correctly
 add_test(function test_client_mock() {
-  do_test_pending();
-
   let fxa = new MockFxAccounts();
   let client = fxa.internal.fxAccountsClient;
   do_check_eq(client._verified, false);
   do_check_eq(typeof client.signIn, "function");
 
   // The recoveryEmailStatus function eventually fulfills its promise
   client.recoveryEmailStatus()
     .then(response => {
       do_check_eq(response.verified, false);
-      do_test_finished();
       run_next_test();
     });
 });
 
 // Sign in a user, and after a little while, verify the user's email.
 // Right after signing in the user, we should get the 'onlogin' notification.
 // Polling should detect that the email is verified, and eventually
 // 'onverified' should be observed
 add_test(function test_verification_poll() {
-  do_test_pending();
-
   let fxa = new MockFxAccounts();
   let test_user = getTestUser("francine");
   let login_notification_received = false;
 
   makeObserver(ONVERIFIED_NOTIFICATION, function() {
     log.debug("test_verification_poll observed onverified");
     // Once email verification is complete, we will observe onverified
     fxa.internal.getUserAccountData().then(user => {
       // And confirm that the user's state has changed
       do_check_eq(user.verified, true);
       do_check_eq(user.email, test_user.email);
       do_check_true(login_notification_received);
-      do_test_finished();
       run_next_test();
     });
   });
 
   makeObserver(ONLOGIN_NOTIFICATION, function() {
     log.debug("test_verification_poll observer onlogin");
     login_notification_received = true;
   });
@@ -321,18 +310,16 @@ add_test(function test_verification_poll
     });
   });
 });
 
 // Sign in the user, but never verify the email.  The check-email
 // poll should time out.  No verifiedlogin event should be observed, and the
 // internal whenVerified promise should be rejected
 add_test(function test_polling_timeout() {
-  do_test_pending();
-
   // This test could be better - the onverified observer might fire on
   // somebody else's stack, and we're not making sure that we're not receiving
   // such a message. In other words, this tests either failure, or success, but
   // not both.
 
   let fxa = new MockFxAccounts();
   let test_user = getTestUser("carol");
 
@@ -346,25 +333,23 @@ add_test(function test_polling_timeout()
 
   fxa.setSignedInUser(test_user).then(() => {
     p.then(
       (success) => {
         do_throw("this should not succeed");
       },
       (fail) => {
         removeObserver();
-        do_test_finished();
-        run_next_test();
+        fxa.signOut().then(run_next_test);
       }
     );
   });
 });
 
 add_test(function test_getKeys() {
-  do_test_pending();
   let fxa = new MockFxAccounts();
   let user = getTestUser("eusebius");
 
   // Once email has been verified, we will be able to get keys
   user.verified = true;
 
   fxa.setSignedInUser(user).then(() => {
     fxa.getSignedInUser().then((user) => {
@@ -379,36 +364,32 @@ add_test(function test_getKeys() {
         fxa.getSignedInUser().then((user) => {
           // Now we should have keys
           do_check_eq(fxa.internal.isUserEmailVerified(user), true);
           do_check_eq(!!user.verified, true);
           do_check_eq(user.kA, expandHex("11"));
           do_check_eq(user.kB, expandHex("66"));
           do_check_eq(user.keyFetchToken, undefined);
           do_check_eq(user.unwrapBKey, undefined);
-          do_test_finished();
           run_next_test();
         });
       });
     });
   });
 });
 
 //  fetchAndUnwrapKeys with no keyFetchToken should trigger signOut
 add_test(function test_fetchAndUnwrapKeys_no_token() {
-  do_test_pending();
-
   let fxa = new MockFxAccounts();
   let user = getTestUser("lettuce.protheroe");
   delete user.keyFetchToken
 
   makeObserver(ONLOGOUT_NOTIFICATION, function() {
     log.debug("test_fetchAndUnwrapKeys_no_token observed logout");
     fxa.internal.getUserAccountData().then(user => {
-      do_test_finished();
       run_next_test();
     });
   });
 
   fxa.setSignedInUser(user).then(
     user => {
       return fxa.internal.fetchAndUnwrapKeys();
     }
@@ -419,29 +400,26 @@ add_test(function test_fetchAndUnwrapKey
     }
   )
 });
 
 // Alice (User A) signs up but never verifies her email.  Then Bob (User B)
 // signs in with a verified email.  Ensure that no sign-in events are triggered
 // on Alice's behalf.  In the end, Bob should be the signed-in user.
 add_test(function test_overlapping_signins() {
-  do_test_pending();
-
   let fxa = new MockFxAccounts();
   let alice = getTestUser("alice");
   let bob = getTestUser("bob");
 
   makeObserver(ONVERIFIED_NOTIFICATION, function() {
     log.debug("test_overlapping_signins observed onverified");
     // Once email verification is complete, we will observe onverified
     fxa.internal.getUserAccountData().then(user => {
       do_check_eq(user.email, bob.email);
       do_check_eq(user.verified, true);
-      do_test_finished();
       run_next_test();
     });
   });
 
   // Alice is the user signing in; her email is unverified.
   fxa.setSignedInUser(alice).then(() => {
     log.debug("Alice signing in ...");
     fxa.internal.getUserAccountData().then(user => {
@@ -609,17 +587,17 @@ add_test(function test_accountStatus() {
             (result) => {
                // FxAccounts.accountStatus() should match Client.accountStatus()
                do_check_true(result);
                fxa.internal.fxAccountsClient._deletedOnServer = true;
                fxa.accountStatus().then(
                  (result) => {
                    do_check_false(result);
                    fxa.internal.fxAccountsClient._deletedOnServer = false;
-                   run_next_test();
+                   fxa.signOut().then(run_next_test);
                  }
                );
             }
           )
         }
       );
     }
   );
@@ -662,48 +640,44 @@ add_test(function test_resend_email() {
         fxa.internal.abortExistingFlow();
         run_next_test();
       });
     });
   });
 });
 
 add_test(function test_sign_out() {
-  do_test_pending();
   let fxa = new MockFxAccounts();
   let remoteSignOutCalled = false;
   let client = fxa.internal.fxAccountsClient;
   client.signOut = function() { remoteSignOutCalled = true; return Promise.resolve(); };
   makeObserver(ONLOGOUT_NOTIFICATION, function() {
     log.debug("test_sign_out_with_remote_error observed onlogout");
     // user should be undefined after sign out
     fxa.internal.getUserAccountData().then(user => {
       do_check_eq(user, null);
       do_check_true(remoteSignOutCalled);
-      do_test_finished();
       run_next_test();
     });
   });
   fxa.signOut();
 });
 
 add_test(function test_sign_out_with_remote_error() {
-  do_test_pending();
   let fxa = new MockFxAccounts();
   let client = fxa.internal.fxAccountsClient;
   let remoteSignOutCalled = false;
   // Force remote sign out to trigger an error
   client.signOut = function() { remoteSignOutCalled = true; throw "Remote sign out error"; };
   makeObserver(ONLOGOUT_NOTIFICATION, function() {
     log.debug("test_sign_out_with_remote_error observed onlogout");
     // user should be undefined after sign out
     fxa.internal.getUserAccountData().then(user => {
       do_check_eq(user, null);
       do_check_true(remoteSignOutCalled);
-      do_test_finished();
       run_next_test();
     });
   });
   fxa.signOut();
 });
 
 add_test(function test_getOAuthToken() {
   let fxa = new MockFxAccounts();
@@ -843,67 +817,67 @@ add_task(function* test_getOAuthTokenCac
 
 Services.prefs.setCharPref("identity.fxaccounts.remote.oauth.uri", "https://example.com/v1");
 add_test(function test_getOAuthToken_invalid_param() {
   let fxa = new MockFxAccounts();
 
   fxa.getOAuthToken()
     .then(null, err => {
        do_check_eq(err.message, "INVALID_PARAMETER");
-       run_next_test();
+       fxa.signOut().then(run_next_test);
     });
 });
 
 add_test(function test_getOAuthToken_invalid_scope_array() {
   let fxa = new MockFxAccounts();
 
   fxa.getOAuthToken({scope: []})
     .then(null, err => {
        do_check_eq(err.message, "INVALID_PARAMETER");
-       run_next_test();
+       fxa.signOut().then(run_next_test);
     });
 });
 
 add_test(function test_getOAuthToken_misconfigure_oauth_uri() {
   let fxa = new MockFxAccounts();
 
   Services.prefs.deleteBranch("identity.fxaccounts.remote.oauth.uri");
 
   fxa.getOAuthToken()
     .then(null, err => {
        do_check_eq(err.message, "INVALID_PARAMETER");
        // revert the pref
        Services.prefs.setCharPref("identity.fxaccounts.remote.oauth.uri", "https://example.com/v1");
-       run_next_test();
+       fxa.signOut().then(run_next_test);
     });
 });
 
 add_test(function test_getOAuthToken_no_account() {
   let fxa = new MockFxAccounts();
 
   fxa.internal.currentAccountState.getUserAccountData = function () {
     return Promise.resolve(null);
   };
 
   fxa.getOAuthToken({ scope: "profile" })
     .then(null, err => {
        do_check_eq(err.message, "NO_ACCOUNT");
-       run_next_test();
+       fxa.signOut().then(run_next_test);
     });
 });
 
 add_test(function test_getOAuthToken_unverified() {
   let fxa = new MockFxAccounts();
   let alice = getTestUser("alice");
 
   fxa.setSignedInUser(alice).then(() => {
     fxa.getOAuthToken({ scope: "profile" })
       .then(null, err => {
          do_check_eq(err.message, "UNVERIFIED_ACCOUNT");
-         run_next_test();
+         fxa.signOut().then(run_next_test);
       });
   });
 });
 
 add_test(function test_getOAuthToken_network_error() {
   let fxa = new MockFxAccounts();
   let alice = getTestUser("alice");
   alice.verified = true;
@@ -1066,49 +1040,49 @@ add_test(function test_getSignedInUserPr
     let accountState = fxa.internal.currentAccountState;
     accountState.getProfile = function () {
       return Promise.reject("boom");
     };
 
     fxa.getSignedInUserProfile()
       .catch(error => {
          do_check_eq(error.message, "UNKNOWN_ERROR");
-         run_next_test();
+         fxa.signOut().then(run_next_test);
       });
   });
 
 });
 
 add_test(function test_getSignedInUserProfile_unverified_account() {
   let fxa = new MockFxAccounts();
   let alice = getTestUser("alice");
 
   fxa.setSignedInUser(alice).then(() => {
     let accountState = fxa.internal.currentAccountState;
 
     fxa.getSignedInUserProfile()
       .catch(error => {
          do_check_eq(error.message, "UNVERIFIED_ACCOUNT");
-         run_next_test();
+         fxa.signOut().then(run_next_test);
       });
   });
 
 });
 
 add_test(function test_getSignedInUserProfile_no_account_data() {
   let fxa = new MockFxAccounts();
 
   fxa.internal.getSignedInUser = function () {
     return Promise.resolve(null);
   };
 
   fxa.getSignedInUserProfile()
     .catch(error => {
        do_check_eq(error.message, "NO_ACCOUNT");
-       run_next_test();
+       fxa.signOut().then(run_next_test);
     });
 
 });
 
 /*
  * End of tests.
  * Utility functions follow.
  */