From b50c1e043a44856cb424faf151b656d02e784281 Mon Sep 17 00:00:00 2001 From: Shane Tomlinson <stomlinson@mozilla.com> Date: Thu, 9 Aug 2012 15:36:49 +0100 Subject: [PATCH] Fix the unresponsive set password screen if the staging wsapi returned a throttled response. --- resources/static/dialog/js/misc/state.js | 12 +++++-- .../static/test/cases/dialog/js/misc/state.js | 36 ++++++++++++++++++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/resources/static/dialog/js/misc/state.js b/resources/static/dialog/js/misc/state.js index dbbc61310..4f058c228 100644 --- a/resources/static/dialog/js/misc/state.js +++ b/resources/static/dialog/js/misc/state.js @@ -52,6 +52,13 @@ BrowserID.State = (function() { }; self.stagedEmail = info.email; + + // Keep these emails around until the user is actually staged. If the + // staging request is throttled, the next time set_password is called, + // these variables are needed to know which staging function to call. + // See issue #2258. + self.newUserEmail = self.addEmailEmail = self.resetPasswordEmail = null; + startAction(actionName, actionInfo); } @@ -150,6 +157,7 @@ BrowserID.State = (function() { mediator.publish("kpi_data", { new_account: true }); startAction(false, "doSetPassword", info); + complete(info.complete); }); handleState("password_set", function(msg, info) { @@ -167,15 +175,12 @@ BrowserID.State = (function() { self.stagedPassword = info.password; if(self.newUserEmail) { - self.newUserEmail = null; startAction(false, "doStageUser", info); } else if(self.addEmailEmail) { - self.addEmailEmail = null; startAction(false, "doStageEmail", info); } else if(self.resetPasswordEmail) { - self.resetPasswordEmail = null; startAction(false, "doStageResetPassword", info); } }); @@ -376,6 +381,7 @@ BrowserID.State = (function() { // point, the email confirmation screen will be shown. self.resetPasswordEmail = info.email; startAction(false, "doResetPassword", info); + complete(info.complete); }); handleState("reset_password_staged", handleEmailStaged.curry("doConfirmResetPassword")); diff --git a/resources/static/test/cases/dialog/js/misc/state.js b/resources/static/test/cases/dialog/js/misc/state.js index 50f12e31f..71d955a11 100644 --- a/resources/static/test/cases/dialog/js/misc/state.js +++ b/resources/static/test/cases/dialog/js/misc/state.js @@ -31,17 +31,37 @@ this.info[key] = info; }; }(key)); + ActionsMock.prototype.reset = function() { + for(var key in ActionsMock.prototype) { + if(bid.Modules.Actions.prototype.hasOwnProperty(key)) { + delete this.called[key]; + delete this.info[key]; + } + } + }; } } function testActionStarted(actionName, requiredOptions) { - ok(actions.called[actionName], actionName + "called"); + ok(actions.called[actionName], actionName + " called"); for(var key in requiredOptions) { equal(actions.info[actionName][key], requiredOptions[key], actionName + " called with " + key + "=" + requiredOptions[key]); } } + function testStagingThrottledRetry(startMessage, expectedStagingAction) { + mediator.publish(startMessage, { email: TEST_EMAIL, complete: function() { + mediator.publish("password_set"); + actions.reset(); + + mediator.publish("password_set"); + testActionStarted(expectedStagingAction, { email: TEST_EMAIL }); + start(); + } + }); + } + function testVerifyStagedAddress(startMessage, verifyScreenAction) { // start with a site name to ensure the site name is passed to the // verifyScreenAction. @@ -132,6 +152,10 @@ equal(actions.info.doStageUser.email, TEST_EMAIL, "correct email sent to doStageUser"); }); + asyncTest("multiple calls to password_set for new_user, simulate throttling - call doStageUser with correct email for each", function() { + testStagingThrottledRetry("new_user", "doStageUser"); + }); + test("password_set for add secondary email - call doStageEmail with correct email", function() { mediator.publish("stage_email", { email: TEST_EMAIL }); mediator.publish("password_set"); @@ -268,6 +292,11 @@ testActionStarted("doResetPassword", { email: TEST_EMAIL }); }); + asyncTest("multiple calls to password_set for forgot_password, simulate throttling - call doStageResetPassword with correct email for each", function() { + testStagingThrottledRetry("forgot_password", "doStageResetPassword"); + }); + + asyncTest("reset_password_staged to staged_address_confirmed - call doConfirmResetPassword then doEmailConfirmed", function() { testVerifyStagedAddress("reset_password_staged", "doConfirmResetPassword"); }); @@ -508,6 +537,11 @@ }); }); + asyncTest("multiple calls to password_set for stage_email, simulate throttling - call doAddEmail with correct email for each", function() { + testStagingThrottledRetry("stage_email", "doStageEmail"); + }); + + test("stage_reverify_email - call doStageReverifyEmail", function() { mediator.publish("stage_reverify_email", { email: TEST_EMAIL }); testActionStarted("doStageReverifyEmail", { email: TEST_EMAIL }); -- GitLab