Chromium Code Reviews| 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 48e65212395d73b6cb9e53cb78535619ca6e735e..2331805722febc250e7808e325591b8c6aa04446 100644 |
| --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc |
| +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc |
| @@ -248,6 +248,10 @@ class TestAutofillDialogController |
| MOCK_METHOD0(LoadRiskFingerprintData, void()); |
| using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; |
| + void SimulateSigninError() { |
| + OnWalletSigninError(); |
| + } |
| + |
| protected: |
| virtual PersonalDataManager* GetManager() OVERRIDE { |
| return &test_manager_; |
| @@ -297,18 +301,11 @@ class AutofillDialogControllerTest : public testing::Test { |
| // testing::Test implementation: |
| virtual void SetUp() OVERRIDE { |
| - FormData form_data; |
| - for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) { |
| - FormFieldData field; |
| - field.autocomplete_attribute = kFieldsFromPage[i]; |
| - form_data.fields.push_back(field); |
| - } |
| - |
| profile()->CreateRequestContext(); |
| test_web_contents_.reset( |
| content::WebContentsTester::CreateTestWebContents(profile(), NULL)); |
| - SetUpControllerWithFormData(form_data); |
| + SetUpControllerWithFormData(DefaultFormData()); |
| } |
| virtual void TearDown() OVERRIDE { |
| @@ -317,6 +314,16 @@ class AutofillDialogControllerTest : public testing::Test { |
| } |
| protected: |
| + FormData DefaultFormData() { |
| + FormData form_data; |
| + for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) { |
| + FormFieldData field; |
| + field.autocomplete_attribute = kFieldsFromPage[i]; |
| + form_data.fields.push_back(field); |
| + } |
| + return form_data; |
| + } |
| + |
| void SetUpControllerWithFormData(const FormData& form_data) { |
| if (controller_) |
| controller_->ViewClosed(); |
| @@ -368,6 +375,10 @@ class AutofillDialogControllerTest : public testing::Test { |
| TestAccountChooserModel::kActiveWalletItemId); |
| } |
| + void SimulateSigninError() { |
| + controller_->SimulateSigninError(); |
| + } |
| + |
| void UseBillingForShipping() { |
| controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(0); |
| } |
| @@ -1645,20 +1656,61 @@ TEST_F(AutofillDialogControllerTest, ViewCancelDoesntSetPref) { |
| ::prefs::kAutofillDialogPayWithoutWallet)); |
| } |
| +TEST_F(AutofillDialogControllerTest, SubmitWithSigninErrorDoesntSetPref) { |
| + ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( |
| + ::prefs::kAutofillDialogPayWithoutWallet)); |
| + |
| + SimulateSigninError(); |
| + FillCreditCardInputs(); |
| + controller()->OnAccept(); |
|
Dan Beam
2013/05/31 22:22:53
^ oh yeah, the other reason I didn't review this C
Evan Stade
2013/05/31 22:41:10
it would be nice to have mentioned that, but given
|
| + |
| + EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath( |
| + ::prefs::kAutofillDialogPayWithoutWallet)); |
| +} |
| + |
| TEST_F(AutofillDialogControllerTest, ViewSubmitSetsPref) { |
| ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( |
| ::prefs::kAutofillDialogPayWithoutWallet)); |
| SwitchToAutofill(); |
| + FillCreditCardInputs(); |
| + controller()->OnAccept(); |
| - // We also have to simulate CC inputs to keep the controller happy. |
| + EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( |
| + ::prefs::kAutofillDialogPayWithoutWallet)); |
| + EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( |
| + ::prefs::kAutofillDialogPayWithoutWallet)); |
| + |
| + // Try again with a signin error (just leaves the pref alone). |
| + SetUpControllerWithFormData(DefaultFormData()); |
| + |
| + // Setting up the controller again should not change the pref. |
| + EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( |
| + ::prefs::kAutofillDialogPayWithoutWallet)); |
| + EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( |
| + ::prefs::kAutofillDialogPayWithoutWallet)); |
| + |
| + SimulateSigninError(); |
| FillCreditCardInputs(); |
| + controller()->OnAccept(); |
| + EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( |
| + ::prefs::kAutofillDialogPayWithoutWallet)); |
| + EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( |
| + ::prefs::kAutofillDialogPayWithoutWallet)); |
| + |
| + // Succesfully choosing wallet does set the pref. |
| + SetUpControllerWithFormData(DefaultFormData()); |
| + SwitchToWallet(); |
| + scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
| + wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
| + controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| + controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); |
| controller()->OnAccept(); |
|
Dan Beam
2013/05/31 22:22:53
^ reverse the order of these to fix your test
Evan Stade
2013/05/31 22:41:10
that did the trick.
|
| EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( |
| ::prefs::kAutofillDialogPayWithoutWallet)); |
| - EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( |
| + EXPECT_FALSE(profile()->GetPrefs()->GetBoolean( |
| ::prefs::kAutofillDialogPayWithoutWallet)); |
| } |