Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3048)

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 23717029: Disable submit button briefly when launching rAc dialog (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge master Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
index ddb60c24ffcc8757fd6a83245bd67a20e3bc2bf1..0c25e595ba78f4df130c3fd979b51ecbba7fa622 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
@@ -241,7 +241,8 @@ class TestAutofillDialogController
mock_wallet_client_(
Profile::FromBrowserContext(contents->GetBrowserContext())->
GetRequestContext(), this),
- mock_new_card_bubble_controller_(mock_new_card_bubble_controller) {}
+ mock_new_card_bubble_controller_(mock_new_card_bubble_controller),
+ submit_button_delay_number_(0) {}
virtual ~TestAutofillDialogController() {}
@@ -278,6 +279,24 @@ class TestAutofillDialogController
#endif
}
+ void SimulateSubmitButtonDelayBegin() {
+ // 60 second delay to avoid test flakiness. The test would be flaky if this
Evan Stade 2013/09/05 16:29:44 I don't think this is necessary. The test executes
please use gerrit instead 2013/09/05 18:40:49 Using the same delay in production and in testing.
+ // delay expired before the test finishes. This delay does not affect
+ // execution time of the test.
+ static const int kSimulatedSubmitButtonDelaySeconds = 60;
+ AutofillDialogControllerImpl::SubmitButtonDelayBegin(
+ base::TimeDelta::FromSeconds(kSimulatedSubmitButtonDelaySeconds));
+ }
+
+ void SimulateSubmitButtonDelayEnd() {
+ AutofillDialogControllerImpl::SubmitButtonDelayEndForTesting();
+ }
+
+ // Returns the number of times that the submit button was delayed.
+ int get_submit_button_delay_number() const {
+ return submit_button_delay_number_;
+ }
+
MOCK_METHOD0(LoadRiskFingerprintData, void());
using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData;
using AutofillDialogControllerImpl::IsEditingExistingData;
@@ -308,6 +327,13 @@ class TestAutofillDialogController
billing_profile.Pass());
}
+ // AutofillDialogControllerImpl calls this method before showing the dialog
+ // window.
+ virtual void SubmitButtonDelayBegin(base::TimeDelta delay) OVERRIDE {
+ // Do not delay enabling the submit button in testing.
+ submit_button_delay_number_++;
+ }
+
private:
// To specify our own metric logger.
virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE {
@@ -320,6 +346,9 @@ class TestAutofillDialogController
GURL open_tab_url_;
MockNewCreditCardBubbleController* mock_new_card_bubble_controller_;
+ // The number of times that the submit button was delayed.
+ int submit_button_delay_number_;
+
DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController);
};
@@ -2379,4 +2408,70 @@ TEST_F(AutofillDialogControllerTest,
EXPECT_FALSE(controller()->ShouldSaveInChrome());
}
+TEST_F(AutofillDialogControllerTest, SubmitButtonIsDelayedOnShow) {
+ EXPECT_EQ(1, controller()->get_submit_button_delay_number());
Evan Stade 2013/09/05 16:29:44 nit: instead of having a separate test for this, a
please use gerrit instead 2013/09/05 18:40:49 Done.
+}
+
+TEST_F(AutofillDialogControllerTest,
+ SubmitButtonIsDisabled_SpinnerFinishesBeforeDelay) {
+ // Begin the submit button delay.
+ controller()->SimulateSubmitButtonDelayBegin();
+
+ EXPECT_TRUE(controller()->ShouldShowSpinner());
+ EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
+
+ // Stop the spinner.
+ controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
+
+ EXPECT_FALSE(controller()->ShouldShowSpinner());
+ EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
+
+ // End the submit button delay.
+ controller()->SimulateSubmitButtonDelayEnd();
+
+ EXPECT_FALSE(controller()->ShouldShowSpinner());
+ EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
+}
+
+TEST_F(AutofillDialogControllerTest,
+ SubmitButtonIsDisabled_SpinnerFinishesAfterDelay) {
+ // Begin the submit button delay.
+ controller()->SimulateSubmitButtonDelayBegin();
+
+ EXPECT_TRUE(controller()->ShouldShowSpinner());
+ EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
+
+ // End the submit button delay.
+ controller()->SimulateSubmitButtonDelayEnd();
+
+ EXPECT_TRUE(controller()->ShouldShowSpinner());
+ EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
+
+ // Stop the spinner.
+ controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
+
+ EXPECT_FALSE(controller()->ShouldShowSpinner());
+ EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
+}
+
+TEST_F(AutofillDialogControllerTest, SubmitButtonIsDisabled_NoSpinner) {
+ // Begin the submit button delay.
+ controller()->SimulateSubmitButtonDelayBegin();
+
+ EXPECT_TRUE(controller()->ShouldShowSpinner());
+ EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
+
+ // There's no spinner in Autofill mode.
+ SwitchToAutofill();
+
+ EXPECT_FALSE(controller()->ShouldShowSpinner());
+ EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
+
+ // End the submit button delay.
+ controller()->SimulateSubmitButtonDelayEnd();
+
+ EXPECT_FALSE(controller()->ShouldShowSpinner());
+ EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698