From e022ca97693237d8f2dbe3ed54c00ccd8e5c73fd Mon Sep 17 00:00:00 2001 From: Shane Tomlinson <stomlinson@mozilla.com> Date: Thu, 19 Jan 2012 09:43:25 +0000 Subject: [PATCH] Fixing a problem where the "waiting for email validation" would go away. * The xhr_delay module would take away the wait screen as soon as any XHR message was complete, even if no xhr requests were delayed. close #913 --- resources/static/shared/modules/xhr_delay.js | 22 +++++++++++++++++-- .../shared/modules/xhr_delay_unit_test.js | 15 ++++++++++--- .../static/test/qunit/testHelpers/helpers.js | 8 +++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/resources/static/shared/modules/xhr_delay.js b/resources/static/shared/modules/xhr_delay.js index 2e1eb6c10..3186f8c9b 100644 --- a/resources/static/shared/modules/xhr_delay.js +++ b/resources/static/shared/modules/xhr_delay.js @@ -7,14 +7,32 @@ BrowserID.Modules.XHRDelay = (function() { var bid = BrowserID, wait = bid.Wait, + delayed, sc; + function delayStart() { + delayed = true; + // XXX - This has a flaw in it. If the user is waiting for at the email + // validation screen and an XHR delay occurs, it will overwrite the waiting + // for validation screen. When the xhr delay completes, then it will take + // away all wait screens and show the add email screen. Perhaps we need + // a new screen/layer to avoid this. + this.renderWait("wait", wait.slowXHR); + } + + function delayStop() { + if(delayed) { + delayed = false; + this.hideWait(); + } + } + var Module = bid.Modules.PageModule.extend({ start: function(options) { var self=this; - self.subscribe("xhr_delay", this.renderWait.curry("wait", wait.slowXHR)); - self.subscribe("xhr_complete", this.hideWait); + self.subscribe("xhr_delay", delayStart); + self.subscribe("xhr_complete", delayStop); sc.start.call(self, options); }, diff --git a/resources/static/test/qunit/shared/modules/xhr_delay_unit_test.js b/resources/static/test/qunit/shared/modules/xhr_delay_unit_test.js index e6588d1b5..1b06fa218 100644 --- a/resources/static/test/qunit/shared/modules/xhr_delay_unit_test.js +++ b/resources/static/test/qunit/shared/modules/xhr_delay_unit_test.js @@ -10,6 +10,7 @@ Module = bid.Modules.XHRDelay, testHelpers = bid.TestHelpers, mediator = bid.Mediator, + screens = bid.Screens, mod; function createModule(options) { @@ -31,10 +32,18 @@ test("xhr_delay shows the wait screen, xhr_complete hides the wait screen", function() { mediator.publish("xhr_delay"); - ok($("#slowXHR:visible").length, "slowXHR error screen is shown"); - equal($("body").hasClass("waiting"), true, "waiting screen shown"); + ok($("#slowXHR:visible").length, "slowXHR screen is shown"); + testHelpers.testWaitVisible(); mediator.publish("xhr_complete"); - equal($("body").hasClass("waiting"), false, "waiting screen not shown"); + equal(testHelpers.waitVisible(), false, "slowXHR screen no longer visible"); + }); + + test("xhr_complete does not hide wait screen if wait screen not started by xhr_delay", function() { + + screens.wait.show("wait", {title: "test wait", message: "testing"}); + + mediator.publish("xhr_complete"); + testHelpers.testWaitVisible(); }); }()); diff --git a/resources/static/test/qunit/testHelpers/helpers.js b/resources/static/test/qunit/testHelpers/helpers.js index f7703e275..70323eb42 100644 --- a/resources/static/test/qunit/testHelpers/helpers.js +++ b/resources/static/test/qunit/testHelpers/helpers.js @@ -112,6 +112,14 @@ BrowserID.TestHelpers = (function() { equal(TestHelpers.errorVisible(), true, "error screen is visible"); }, + waitVisible: function() { + return screens.wait.visible; + }, + + testWaitVisible: function() { + equal(TestHelpers.waitVisible(), true, "wait screen is visible"); + }, + checkNetworkError: checkNetworkError, unexpectedSuccess: function() { ok(false, "unexpected success"); -- GitLab