| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/tuple.h" | 17 #include "base/tuple.h" |
| 18 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 18 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| 19 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 19 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| 20 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h" | 20 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h" |
| 21 #include "chrome/browser/ui/autofill/mock_new_credit_card_bubble_controller.h" | 21 #include "chrome/browser/ui/autofill/mock_new_credit_card_bubble_controller.h" |
| 22 #include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_controlle
r.h" | 22 #include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_controlle
r.h" |
| 23 #include "chrome/browser/webdata/web_data_service_factory.h" | 23 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 24 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/render_messages.h" | 26 #include "chrome/common/render_messages.h" |
| 26 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 27 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 27 #include "chrome/test/base/scoped_testing_local_state.h" | 28 #include "chrome/test/base/scoped_testing_local_state.h" |
| 28 #include "chrome/test/base/testing_browser_process.h" | 29 #include "chrome/test/base/testing_browser_process.h" |
| 29 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
| 30 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" | 31 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" |
| 31 #include "components/autofill/content/browser/wallet/full_wallet.h" | 32 #include "components/autofill/content/browser/wallet/full_wallet.h" |
| 32 #include "components/autofill/content/browser/wallet/instrument.h" | 33 #include "components/autofill/content/browser/wallet/instrument.h" |
| 33 #include "components/autofill/content/browser/wallet/mock_wallet_client.h" | 34 #include "components/autofill/content/browser/wallet/mock_wallet_client.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 157 |
| 157 virtual void UpdateOverlay() OVERRIDE { | 158 virtual void UpdateOverlay() OVERRIDE { |
| 158 EXPECT_GE(updates_started_, 1); | 159 EXPECT_GE(updates_started_, 1); |
| 159 } | 160 } |
| 160 | 161 |
| 161 virtual void UpdateDetailArea() OVERRIDE { | 162 virtual void UpdateDetailArea() OVERRIDE { |
| 162 EXPECT_GE(updates_started_, 1); | 163 EXPECT_GE(updates_started_, 1); |
| 163 } | 164 } |
| 164 | 165 |
| 165 virtual void UpdateSection(DialogSection section) OVERRIDE { | 166 virtual void UpdateSection(DialogSection section) OVERRIDE { |
| 167 section_updates_[section]++; |
| 166 EXPECT_GE(updates_started_, 1); | 168 EXPECT_GE(updates_started_, 1); |
| 167 } | 169 } |
| 168 | 170 |
| 169 virtual void UpdateErrorBubble() OVERRIDE { | 171 virtual void UpdateErrorBubble() OVERRIDE { |
| 170 EXPECT_GE(updates_started_, 1); | 172 EXPECT_GE(updates_started_, 1); |
| 171 } | 173 } |
| 172 | 174 |
| 173 virtual void FillSection(DialogSection section, | 175 virtual void FillSection(DialogSection section, |
| 174 const DetailInput& originating_input) OVERRIDE {}; | 176 const DetailInput& originating_input) OVERRIDE {}; |
| 175 virtual void GetUserInput(DialogSection section, FieldValueMap* output) | 177 virtual void GetUserInput(DialogSection section, FieldValueMap* output) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 201 virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE {} | 203 virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE {} |
| 202 | 204 |
| 203 void SetUserInput(DialogSection section, const FieldValueMap& map) { | 205 void SetUserInput(DialogSection section, const FieldValueMap& map) { |
| 204 outputs_[section] = map; | 206 outputs_[section] = map; |
| 205 } | 207 } |
| 206 | 208 |
| 207 void CheckSaveDetailsLocallyCheckbox(bool checked) { | 209 void CheckSaveDetailsLocallyCheckbox(bool checked) { |
| 208 save_details_locally_checked_ = checked; | 210 save_details_locally_checked_ = checked; |
| 209 } | 211 } |
| 210 | 212 |
| 213 void ClearSectionUpdates() { |
| 214 section_updates_.clear(); |
| 215 } |
| 216 |
| 217 std::map<DialogSection, size_t> section_updates() const { |
| 218 return section_updates_; |
| 219 } |
| 220 |
| 211 private: | 221 private: |
| 212 std::map<DialogSection, FieldValueMap> outputs_; | 222 std::map<DialogSection, FieldValueMap> outputs_; |
| 223 std::map<DialogSection, size_t> section_updates_; |
| 213 | 224 |
| 214 int updates_started_; | 225 int updates_started_; |
| 215 bool save_details_locally_checked_; | 226 bool save_details_locally_checked_; |
| 216 | 227 |
| 217 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView); | 228 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView); |
| 218 }; | 229 }; |
| 219 | 230 |
| 220 class TestAutofillDialogController | 231 class TestAutofillDialogController |
| 221 : public AutofillDialogControllerImpl, | 232 : public AutofillDialogControllerImpl, |
| 222 public base::SupportsWeakPtr<TestAutofillDialogController> { | 233 public base::SupportsWeakPtr<TestAutofillDialogController> { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 ClearLastWalletItemsFetchTimestampForTesting; | 300 ClearLastWalletItemsFetchTimestampForTesting; |
| 290 | 301 |
| 291 // Returns the number of times that the submit button was delayed. | 302 // Returns the number of times that the submit button was delayed. |
| 292 int get_submit_button_delay_count() const { | 303 int get_submit_button_delay_count() const { |
| 293 return submit_button_delay_count_; | 304 return submit_button_delay_count_; |
| 294 } | 305 } |
| 295 | 306 |
| 296 MOCK_METHOD0(LoadRiskFingerprintData, void()); | 307 MOCK_METHOD0(LoadRiskFingerprintData, void()); |
| 297 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; | 308 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; |
| 298 using AutofillDialogControllerImpl::IsEditingExistingData; | 309 using AutofillDialogControllerImpl::IsEditingExistingData; |
| 310 using AutofillDialogControllerImpl::IsManuallyEditingSection; |
| 299 using AutofillDialogControllerImpl::IsSubmitPausedOn; | 311 using AutofillDialogControllerImpl::IsSubmitPausedOn; |
| 300 using AutofillDialogControllerImpl::NOT_CHECKED; | 312 using AutofillDialogControllerImpl::NOT_CHECKED; |
| 301 using AutofillDialogControllerImpl::SignedInState; | 313 using AutofillDialogControllerImpl::SignedInState; |
| 302 | 314 |
| 303 protected: | 315 protected: |
| 304 virtual PersonalDataManager* GetManager() OVERRIDE { | 316 virtual PersonalDataManager* GetManager() OVERRIDE { |
| 305 return &test_manager_; | 317 return &test_manager_; |
| 306 } | 318 } |
| 307 | 319 |
| 308 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { | 320 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 return true; | 567 return true; |
| 556 } | 568 } |
| 557 return false; | 569 return false; |
| 558 } | 570 } |
| 559 | 571 |
| 560 SuggestionsMenuModel* GetMenuModelForSection(DialogSection section) { | 572 SuggestionsMenuModel* GetMenuModelForSection(DialogSection section) { |
| 561 ui::MenuModel* model = controller()->MenuModelForSection(section); | 573 ui::MenuModel* model = controller()->MenuModelForSection(section); |
| 562 return static_cast<SuggestionsMenuModel*>(model); | 574 return static_cast<SuggestionsMenuModel*>(model); |
| 563 } | 575 } |
| 564 | 576 |
| 577 void SubmitAndVerifyShippingAndBillingResults() { |
| 578 // Test after setting use billing for shipping. |
| 579 UseBillingForShipping(); |
| 580 |
| 581 controller()->OnAccept(); |
| 582 |
| 583 ASSERT_EQ(20U, form_structure()->field_count()); |
| 584 EXPECT_EQ(ADDRESS_HOME_COUNTRY, |
| 585 form_structure()->field(11)->Type().GetStorableType()); |
| 586 EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(11)->Type().group()); |
| 587 EXPECT_EQ(ADDRESS_HOME_COUNTRY, |
| 588 form_structure()->field(18)->Type().GetStorableType()); |
| 589 EXPECT_EQ(ADDRESS_HOME, form_structure()->field(18)->Type().group()); |
| 590 string16 billing_country = form_structure()->field(11)->value; |
| 591 EXPECT_EQ(2U, billing_country.size()); |
| 592 string16 shipping_country = form_structure()->field(18)->value; |
| 593 EXPECT_EQ(2U, shipping_country.size()); |
| 594 EXPECT_FALSE(billing_country.empty()); |
| 595 EXPECT_FALSE(shipping_country.empty()); |
| 596 EXPECT_EQ(billing_country, shipping_country); |
| 597 |
| 598 EXPECT_EQ(CREDIT_CARD_NAME, |
| 599 form_structure()->field(1)->Type().GetStorableType()); |
| 600 string16 cc_name = form_structure()->field(1)->value; |
| 601 EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType()); |
| 602 EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group()); |
| 603 string16 billing_name = form_structure()->field(6)->value; |
| 604 EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType()); |
| 605 EXPECT_EQ(NAME, form_structure()->field(13)->Type().group()); |
| 606 string16 shipping_name = form_structure()->field(13)->value; |
| 607 |
| 608 EXPECT_FALSE(cc_name.empty()); |
| 609 EXPECT_FALSE(billing_name.empty()); |
| 610 EXPECT_FALSE(shipping_name.empty()); |
| 611 EXPECT_EQ(cc_name, billing_name); |
| 612 EXPECT_EQ(cc_name, shipping_name); |
| 613 } |
| 614 |
| 565 TestAutofillDialogController* controller() { return controller_.get(); } | 615 TestAutofillDialogController* controller() { return controller_.get(); } |
| 566 | 616 |
| 567 const FormStructure* form_structure() { return form_structure_; } | 617 const FormStructure* form_structure() { return form_structure_; } |
| 568 | 618 |
| 569 TestGeneratedCreditCardBubbleController* test_generated_bubble_controller() { | 619 TestGeneratedCreditCardBubbleController* test_generated_bubble_controller() { |
| 570 return test_generated_bubble_controller_; | 620 return test_generated_bubble_controller_; |
| 571 } | 621 } |
| 572 | 622 |
| 573 const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() { | 623 const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() { |
| 574 return mock_new_card_bubble_controller_.get(); | 624 return mock_new_card_bubble_controller_.get(); |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 EXPECT_FALSE(billing_name.empty()); | 1147 EXPECT_FALSE(billing_name.empty()); |
| 1098 EXPECT_FALSE(shipping_name.empty()); | 1148 EXPECT_FALSE(shipping_name.empty()); |
| 1099 // Billing name should always be the same as cardholder name. | 1149 // Billing name should always be the same as cardholder name. |
| 1100 EXPECT_EQ(cc_name, billing_name); | 1150 EXPECT_EQ(cc_name, billing_name); |
| 1101 EXPECT_NE(cc_name, shipping_name); | 1151 EXPECT_NE(cc_name, shipping_name); |
| 1102 } | 1152 } |
| 1103 | 1153 |
| 1104 // Test selecting UseBillingForShipping. | 1154 // Test selecting UseBillingForShipping. |
| 1105 TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) { | 1155 TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) { |
| 1106 SwitchToAutofill(); | 1156 SwitchToAutofill(); |
| 1157 |
| 1107 AutofillProfile full_profile(test::GetVerifiedProfile()); | 1158 AutofillProfile full_profile(test::GetVerifiedProfile()); |
| 1159 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
| 1160 |
| 1108 AutofillProfile full_profile2(test::GetVerifiedProfile2()); | 1161 AutofillProfile full_profile2(test::GetVerifiedProfile2()); |
| 1162 controller()->GetTestingManager()->AddTestingProfile(&full_profile2); |
| 1163 |
| 1109 CreditCard credit_card(test::GetVerifiedCreditCard()); | 1164 CreditCard credit_card(test::GetVerifiedCreditCard()); |
| 1110 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | |
| 1111 controller()->GetTestingManager()->AddTestingProfile(&full_profile2); | |
| 1112 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); | 1165 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); |
| 1113 | 1166 |
| 1114 // Test after setting use billing for shipping. | 1167 ASSERT_FALSE(controller()->IsManuallyEditingSection(SECTION_CC)); |
| 1115 UseBillingForShipping(); | 1168 ASSERT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING)); |
| 1116 | 1169 |
| 1117 controller()->OnAccept(); | 1170 SubmitAndVerifyShippingAndBillingResults(); |
| 1118 ASSERT_EQ(20U, form_structure()->field_count()); | 1171 } |
| 1119 EXPECT_EQ(ADDRESS_HOME_STATE, | |
| 1120 form_structure()->field(9)->Type().GetStorableType()); | |
| 1121 EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group()); | |
| 1122 EXPECT_EQ(ADDRESS_HOME_STATE, | |
| 1123 form_structure()->field(16)->Type().GetStorableType()); | |
| 1124 EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group()); | |
| 1125 string16 billing_state = form_structure()->field(9)->value; | |
| 1126 string16 shipping_state = form_structure()->field(16)->value; | |
| 1127 EXPECT_FALSE(billing_state.empty()); | |
| 1128 EXPECT_FALSE(shipping_state.empty()); | |
| 1129 EXPECT_EQ(billing_state, shipping_state); | |
| 1130 | 1172 |
| 1131 EXPECT_EQ(CREDIT_CARD_NAME, | 1173 TEST_F(AutofillDialogControllerTest, UseBillingAsShippingManualInput) { |
| 1132 form_structure()->field(1)->Type().GetStorableType()); | 1174 SwitchToAutofill(); |
| 1133 string16 cc_name = form_structure()->field(1)->value; | |
| 1134 EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType()); | |
| 1135 EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group()); | |
| 1136 string16 billing_name = form_structure()->field(6)->value; | |
| 1137 EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType()); | |
| 1138 EXPECT_EQ(NAME, form_structure()->field(13)->Type().group()); | |
| 1139 string16 shipping_name = form_structure()->field(13)->value; | |
| 1140 | 1175 |
| 1141 EXPECT_FALSE(cc_name.empty()); | 1176 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_CC)); |
| 1142 EXPECT_FALSE(billing_name.empty()); | 1177 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); |
| 1143 EXPECT_FALSE(shipping_name.empty()); | 1178 |
| 1144 EXPECT_EQ(cc_name, billing_name); | 1179 CreditCard credit_card(test::GetVerifiedCreditCard()); |
| 1145 EXPECT_EQ(cc_name, shipping_name); | 1180 FillInputs(SECTION_CC, credit_card); |
| 1181 |
| 1182 AutofillProfile full_profile(test::GetVerifiedProfile()); |
| 1183 FillInputs(SECTION_BILLING, full_profile); |
| 1184 |
| 1185 SubmitAndVerifyShippingAndBillingResults(); |
| 1146 } | 1186 } |
| 1147 | 1187 |
| 1148 // Tests that shipping and billing telephone fields are supported, and filled | 1188 // Tests that shipping and billing telephone fields are supported, and filled |
| 1149 // in by their respective profiles. http://crbug.com/244515 | 1189 // in by their respective profiles. http://crbug.com/244515 |
| 1150 TEST_F(AutofillDialogControllerTest, BillingVsShippingPhoneNumber) { | 1190 TEST_F(AutofillDialogControllerTest, BillingVsShippingPhoneNumber) { |
| 1151 FormFieldData shipping_tel; | 1191 FormFieldData shipping_tel; |
| 1152 shipping_tel.autocomplete_attribute = "shipping tel"; | 1192 shipping_tel.autocomplete_attribute = "shipping tel"; |
| 1153 FormFieldData billing_tel; | 1193 FormFieldData billing_tel; |
| 1154 billing_tel.autocomplete_attribute = "billing tel"; | 1194 billing_tel.autocomplete_attribute = "billing tel"; |
| 1155 | 1195 |
| (...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2655 TEST_F(AutofillDialogControllerTest, PassiveAuthFailure) { | 2695 TEST_F(AutofillDialogControllerTest, PassiveAuthFailure) { |
| 2656 controller()->OnDidGetWalletItems( | 2696 controller()->OnDidGetWalletItems( |
| 2657 wallet::GetTestWalletItemsWithRequiredAction( | 2697 wallet::GetTestWalletItemsWithRequiredAction( |
| 2658 wallet::PASSIVE_GAIA_AUTH)); | 2698 wallet::PASSIVE_GAIA_AUTH)); |
| 2659 EXPECT_TRUE(controller()->ShouldShowSpinner()); | 2699 EXPECT_TRUE(controller()->ShouldShowSpinner()); |
| 2660 controller()->OnPassiveSigninFailure(GoogleServiceAuthError( | 2700 controller()->OnPassiveSigninFailure(GoogleServiceAuthError( |
| 2661 GoogleServiceAuthError::NONE)); | 2701 GoogleServiceAuthError::NONE)); |
| 2662 EXPECT_FALSE(controller()->ShouldShowSpinner()); | 2702 EXPECT_FALSE(controller()->ShouldShowSpinner()); |
| 2663 } | 2703 } |
| 2664 | 2704 |
| 2705 TEST_F(AutofillDialogControllerTest, CountryChange) { |
| 2706 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 2707 ::switches::kEnableAutofillAddressInternationalization); |
| 2708 Reset(); |
| 2709 |
| 2710 TestAutofillDialogView* view = controller()->GetView(); |
| 2711 view->ClearSectionUpdates(); |
| 2712 |
| 2713 controller()->ComboboxItemSelected(ADDRESS_HOME_COUNTRY, 2); |
| 2714 std::map<DialogSection, size_t> updates = view->section_updates(); |
| 2715 EXPECT_EQ(1U, updates[SECTION_SHIPPING]); |
| 2716 EXPECT_EQ(1U, updates.size()); |
| 2717 |
| 2718 view->ClearSectionUpdates(); |
| 2719 |
| 2720 controller()->ComboboxItemSelected(ADDRESS_BILLING_COUNTRY, 3); |
| 2721 updates = view->section_updates(); |
| 2722 EXPECT_EQ(1U, updates[SECTION_CC_BILLING]); |
| 2723 EXPECT_EQ(1U, updates.size()); |
| 2724 |
| 2725 SwitchToAutofill(); |
| 2726 view->ClearSectionUpdates(); |
| 2727 |
| 2728 controller()->ComboboxItemSelected(ADDRESS_BILLING_COUNTRY, 4); |
| 2729 updates = view->section_updates(); |
| 2730 EXPECT_EQ(1U, updates[SECTION_BILLING]); |
| 2731 EXPECT_EQ(1U, updates.size()); |
| 2732 } |
| 2733 |
| 2665 } // namespace autofill | 2734 } // namespace autofill |
| OLD | NEW |