| 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 bb5be6d427aa9c5e9f82843c5cbd7924bf0af831..30b0bb977438efb02c4b8836599bf5420f18eb93 100644
|
| --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
|
| +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
|
| @@ -21,6 +21,7 @@
|
| #include "chrome/browser/ui/autofill/mock_new_credit_card_bubble_controller.h"
|
| #include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_controller.h"
|
| #include "chrome/browser/webdata/web_data_service_factory.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/pref_names.h"
|
| #include "chrome/common/render_messages.h"
|
| #include "chrome/test/base/chrome_render_view_host_test_harness.h"
|
| @@ -163,6 +164,7 @@ class TestAutofillDialogView : public AutofillDialogView {
|
| }
|
|
|
| virtual void UpdateSection(DialogSection section) OVERRIDE {
|
| + section_updates_[section]++;
|
| EXPECT_GE(updates_started_, 1);
|
| }
|
|
|
| @@ -208,8 +210,17 @@ class TestAutofillDialogView : public AutofillDialogView {
|
| save_details_locally_checked_ = checked;
|
| }
|
|
|
| + void ClearSectionUpdates() {
|
| + section_updates_.clear();
|
| + }
|
| +
|
| + std::map<DialogSection, size_t> section_updates() const {
|
| + return section_updates_;
|
| + }
|
| +
|
| private:
|
| std::map<DialogSection, FieldValueMap> outputs_;
|
| + std::map<DialogSection, size_t> section_updates_;
|
|
|
| int updates_started_;
|
| bool save_details_locally_checked_;
|
| @@ -296,6 +307,7 @@ class TestAutofillDialogController
|
| MOCK_METHOD0(LoadRiskFingerprintData, void());
|
| using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData;
|
| using AutofillDialogControllerImpl::IsEditingExistingData;
|
| + using AutofillDialogControllerImpl::IsManuallyEditingSection;
|
| using AutofillDialogControllerImpl::IsSubmitPausedOn;
|
| using AutofillDialogControllerImpl::NOT_CHECKED;
|
| using AutofillDialogControllerImpl::SignedInState;
|
| @@ -562,6 +574,44 @@ class AutofillDialogControllerTest : public ChromeRenderViewHostTestHarness {
|
| return static_cast<SuggestionsMenuModel*>(model);
|
| }
|
|
|
| + void SubmitAndVerifyShippingAndBillingResults() {
|
| + // Test after setting use billing for shipping.
|
| + UseBillingForShipping();
|
| +
|
| + controller()->OnAccept();
|
| +
|
| + ASSERT_EQ(20U, form_structure()->field_count());
|
| + EXPECT_EQ(ADDRESS_HOME_COUNTRY,
|
| + form_structure()->field(11)->Type().GetStorableType());
|
| + EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(11)->Type().group());
|
| + EXPECT_EQ(ADDRESS_HOME_COUNTRY,
|
| + form_structure()->field(18)->Type().GetStorableType());
|
| + EXPECT_EQ(ADDRESS_HOME, form_structure()->field(18)->Type().group());
|
| + string16 billing_country = form_structure()->field(11)->value;
|
| + EXPECT_EQ(2U, billing_country.size());
|
| + string16 shipping_country = form_structure()->field(18)->value;
|
| + EXPECT_EQ(2U, shipping_country.size());
|
| + EXPECT_FALSE(billing_country.empty());
|
| + EXPECT_FALSE(shipping_country.empty());
|
| + EXPECT_EQ(billing_country, shipping_country);
|
| +
|
| + EXPECT_EQ(CREDIT_CARD_NAME,
|
| + form_structure()->field(1)->Type().GetStorableType());
|
| + string16 cc_name = form_structure()->field(1)->value;
|
| + EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType());
|
| + EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group());
|
| + string16 billing_name = form_structure()->field(6)->value;
|
| + EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType());
|
| + EXPECT_EQ(NAME, form_structure()->field(13)->Type().group());
|
| + string16 shipping_name = form_structure()->field(13)->value;
|
| +
|
| + EXPECT_FALSE(cc_name.empty());
|
| + EXPECT_FALSE(billing_name.empty());
|
| + EXPECT_FALSE(shipping_name.empty());
|
| + EXPECT_EQ(cc_name, billing_name);
|
| + EXPECT_EQ(cc_name, shipping_name);
|
| + }
|
| +
|
| TestAutofillDialogController* controller() { return controller_.get(); }
|
|
|
| const FormStructure* form_structure() { return form_structure_; }
|
| @@ -1104,45 +1154,35 @@ TEST_F(AutofillDialogControllerTest, DontUseBillingAsShipping) {
|
| // Test selecting UseBillingForShipping.
|
| TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) {
|
| SwitchToAutofill();
|
| +
|
| AutofillProfile full_profile(test::GetVerifiedProfile());
|
| - AutofillProfile full_profile2(test::GetVerifiedProfile2());
|
| - CreditCard credit_card(test::GetVerifiedCreditCard());
|
| controller()->GetTestingManager()->AddTestingProfile(&full_profile);
|
| +
|
| + AutofillProfile full_profile2(test::GetVerifiedProfile2());
|
| controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
|
| +
|
| + CreditCard credit_card(test::GetVerifiedCreditCard());
|
| controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
|
|
|
| - // Test after setting use billing for shipping.
|
| - UseBillingForShipping();
|
| + ASSERT_FALSE(controller()->IsManuallyEditingSection(SECTION_CC));
|
| + ASSERT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING));
|
|
|
| - controller()->OnAccept();
|
| - ASSERT_EQ(20U, form_structure()->field_count());
|
| - EXPECT_EQ(ADDRESS_HOME_STATE,
|
| - form_structure()->field(9)->Type().GetStorableType());
|
| - EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group());
|
| - EXPECT_EQ(ADDRESS_HOME_STATE,
|
| - form_structure()->field(16)->Type().GetStorableType());
|
| - EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group());
|
| - string16 billing_state = form_structure()->field(9)->value;
|
| - string16 shipping_state = form_structure()->field(16)->value;
|
| - EXPECT_FALSE(billing_state.empty());
|
| - EXPECT_FALSE(shipping_state.empty());
|
| - EXPECT_EQ(billing_state, shipping_state);
|
| + SubmitAndVerifyShippingAndBillingResults();
|
| +}
|
|
|
| - EXPECT_EQ(CREDIT_CARD_NAME,
|
| - form_structure()->field(1)->Type().GetStorableType());
|
| - string16 cc_name = form_structure()->field(1)->value;
|
| - EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType());
|
| - EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group());
|
| - string16 billing_name = form_structure()->field(6)->value;
|
| - EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType());
|
| - EXPECT_EQ(NAME, form_structure()->field(13)->Type().group());
|
| - string16 shipping_name = form_structure()->field(13)->value;
|
| +TEST_F(AutofillDialogControllerTest, UseBillingAsShippingManualInput) {
|
| + SwitchToAutofill();
|
|
|
| - EXPECT_FALSE(cc_name.empty());
|
| - EXPECT_FALSE(billing_name.empty());
|
| - EXPECT_FALSE(shipping_name.empty());
|
| - EXPECT_EQ(cc_name, billing_name);
|
| - EXPECT_EQ(cc_name, shipping_name);
|
| + ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_CC));
|
| + ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING));
|
| +
|
| + CreditCard credit_card(test::GetVerifiedCreditCard());
|
| + FillInputs(SECTION_CC, credit_card);
|
| +
|
| + AutofillProfile full_profile(test::GetVerifiedProfile());
|
| + FillInputs(SECTION_BILLING, full_profile);
|
| +
|
| + SubmitAndVerifyShippingAndBillingResults();
|
| }
|
|
|
| // Tests that shipping and billing telephone fields are supported, and filled
|
| @@ -2662,4 +2702,33 @@ TEST_F(AutofillDialogControllerTest, PassiveAuthFailure) {
|
| EXPECT_FALSE(controller()->ShouldShowSpinner());
|
| }
|
|
|
| +TEST_F(AutofillDialogControllerTest, CountryChange) {
|
| + CommandLine::ForCurrentProcess()->AppendSwitch(
|
| + ::switches::kEnableAutofillAddressInternationalization);
|
| + Reset();
|
| +
|
| + TestAutofillDialogView* view = controller()->GetView();
|
| + view->ClearSectionUpdates();
|
| +
|
| + controller()->ComboboxItemSelected(ADDRESS_HOME_COUNTRY, 2);
|
| + std::map<DialogSection, size_t> updates = view->section_updates();
|
| + EXPECT_EQ(1U, updates[SECTION_SHIPPING]);
|
| + EXPECT_EQ(1U, updates.size());
|
| +
|
| + view->ClearSectionUpdates();
|
| +
|
| + controller()->ComboboxItemSelected(ADDRESS_BILLING_COUNTRY, 3);
|
| + updates = view->section_updates();
|
| + EXPECT_EQ(1U, updates[SECTION_CC_BILLING]);
|
| + EXPECT_EQ(1U, updates.size());
|
| +
|
| + SwitchToAutofill();
|
| + view->ClearSectionUpdates();
|
| +
|
| + controller()->ComboboxItemSelected(ADDRESS_BILLING_COUNTRY, 4);
|
| + updates = view->section_updates();
|
| + EXPECT_EQ(1U, updates[SECTION_BILLING]);
|
| + EXPECT_EQ(1U, updates.size());
|
| +}
|
| +
|
| } // namespace autofill
|
|
|