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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 63053003: Ask libaddressinput for address components to use in requestAutocomplete(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: base:: Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/gaia_account.h" 33 #include "components/autofill/content/browser/wallet/gaia_account.h"
33 #include "components/autofill/content/browser/wallet/instrument.h" 34 #include "components/autofill/content/browser/wallet/instrument.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 164
164 virtual void UpdateOverlay() OVERRIDE { 165 virtual void UpdateOverlay() OVERRIDE {
165 EXPECT_GE(updates_started_, 1); 166 EXPECT_GE(updates_started_, 1);
166 } 167 }
167 168
168 virtual void UpdateDetailArea() OVERRIDE { 169 virtual void UpdateDetailArea() OVERRIDE {
169 EXPECT_GE(updates_started_, 1); 170 EXPECT_GE(updates_started_, 1);
170 } 171 }
171 172
172 virtual void UpdateSection(DialogSection section) OVERRIDE { 173 virtual void UpdateSection(DialogSection section) OVERRIDE {
174 section_updates_[section]++;
173 EXPECT_GE(updates_started_, 1); 175 EXPECT_GE(updates_started_, 1);
174 } 176 }
175 177
176 virtual void UpdateErrorBubble() OVERRIDE { 178 virtual void UpdateErrorBubble() OVERRIDE {
177 EXPECT_GE(updates_started_, 1); 179 EXPECT_GE(updates_started_, 1);
178 } 180 }
179 181
180 virtual void FillSection(DialogSection section, 182 virtual void FillSection(DialogSection section,
181 const DetailInput& originating_input) OVERRIDE {}; 183 const DetailInput& originating_input) OVERRIDE {};
182 virtual void GetUserInput(DialogSection section, FieldValueMap* output) 184 virtual void GetUserInput(DialogSection section, FieldValueMap* output)
(...skipping 25 matching lines...) Expand all
208 virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE {} 210 virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE {}
209 211
210 void SetUserInput(DialogSection section, const FieldValueMap& map) { 212 void SetUserInput(DialogSection section, const FieldValueMap& map) {
211 outputs_[section] = map; 213 outputs_[section] = map;
212 } 214 }
213 215
214 void CheckSaveDetailsLocallyCheckbox(bool checked) { 216 void CheckSaveDetailsLocallyCheckbox(bool checked) {
215 save_details_locally_checked_ = checked; 217 save_details_locally_checked_ = checked;
216 } 218 }
217 219
220 void ClearSectionUpdates() {
221 section_updates_.clear();
222 }
223
224 std::map<DialogSection, size_t> section_updates() const {
225 return section_updates_;
226 }
227
218 private: 228 private:
219 std::map<DialogSection, FieldValueMap> outputs_; 229 std::map<DialogSection, FieldValueMap> outputs_;
230 std::map<DialogSection, size_t> section_updates_;
220 231
221 int updates_started_; 232 int updates_started_;
222 bool save_details_locally_checked_; 233 bool save_details_locally_checked_;
223 234
224 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView); 235 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView);
225 }; 236 };
226 237
227 class TestAutofillDialogController 238 class TestAutofillDialogController
228 : public AutofillDialogControllerImpl, 239 : public AutofillDialogControllerImpl,
229 public base::SupportsWeakPtr<TestAutofillDialogController> { 240 public base::SupportsWeakPtr<TestAutofillDialogController> {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 308
298 // Returns the number of times that the submit button was delayed. 309 // Returns the number of times that the submit button was delayed.
299 int get_submit_button_delay_count() const { 310 int get_submit_button_delay_count() const {
300 return submit_button_delay_count_; 311 return submit_button_delay_count_;
301 } 312 }
302 313
303 MOCK_METHOD0(LoadRiskFingerprintData, void()); 314 MOCK_METHOD0(LoadRiskFingerprintData, void());
304 using AutofillDialogControllerImpl::AccountChooserModelForTesting; 315 using AutofillDialogControllerImpl::AccountChooserModelForTesting;
305 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; 316 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData;
306 using AutofillDialogControllerImpl::IsEditingExistingData; 317 using AutofillDialogControllerImpl::IsEditingExistingData;
318 using AutofillDialogControllerImpl::IsManuallyEditingSection;
307 using AutofillDialogControllerImpl::IsSubmitPausedOn; 319 using AutofillDialogControllerImpl::IsSubmitPausedOn;
308 using AutofillDialogControllerImpl::NOT_CHECKED; 320 using AutofillDialogControllerImpl::NOT_CHECKED;
309 using AutofillDialogControllerImpl::SignedInState; 321 using AutofillDialogControllerImpl::SignedInState;
310 322
311 protected: 323 protected:
312 virtual PersonalDataManager* GetManager() const OVERRIDE { 324 virtual PersonalDataManager* GetManager() const OVERRIDE {
313 return const_cast<TestAutofillDialogController*>(this)-> 325 return const_cast<TestAutofillDialogController*>(this)->
314 GetTestingManager(); 326 GetTestingManager();
315 } 327 }
316 328
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 return true; 558 return true;
547 } 559 }
548 return false; 560 return false;
549 } 561 }
550 562
551 SuggestionsMenuModel* GetMenuModelForSection(DialogSection section) { 563 SuggestionsMenuModel* GetMenuModelForSection(DialogSection section) {
552 ui::MenuModel* model = controller()->MenuModelForSection(section); 564 ui::MenuModel* model = controller()->MenuModelForSection(section);
553 return static_cast<SuggestionsMenuModel*>(model); 565 return static_cast<SuggestionsMenuModel*>(model);
554 } 566 }
555 567
568 void SubmitAndVerifyShippingAndBillingResults() {
569 // Test after setting use billing for shipping.
570 UseBillingForShipping();
571
572 controller()->OnAccept();
573
574 ASSERT_EQ(20U, form_structure()->field_count());
575 EXPECT_EQ(ADDRESS_HOME_COUNTRY,
576 form_structure()->field(11)->Type().GetStorableType());
577 EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(11)->Type().group());
578 EXPECT_EQ(ADDRESS_HOME_COUNTRY,
579 form_structure()->field(18)->Type().GetStorableType());
580 EXPECT_EQ(ADDRESS_HOME, form_structure()->field(18)->Type().group());
581 base::string16 billing_country = form_structure()->field(11)->value;
582 EXPECT_EQ(2U, billing_country.size());
583 base::string16 shipping_country = form_structure()->field(18)->value;
584 EXPECT_EQ(2U, shipping_country.size());
585 EXPECT_FALSE(billing_country.empty());
586 EXPECT_FALSE(shipping_country.empty());
587 EXPECT_EQ(billing_country, shipping_country);
588
589 EXPECT_EQ(CREDIT_CARD_NAME,
590 form_structure()->field(1)->Type().GetStorableType());
591 base::string16 cc_name = form_structure()->field(1)->value;
592 EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType());
593 EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group());
594 base::string16 billing_name = form_structure()->field(6)->value;
595 EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType());
596 EXPECT_EQ(NAME, form_structure()->field(13)->Type().group());
597 base::string16 shipping_name = form_structure()->field(13)->value;
598
599 EXPECT_FALSE(cc_name.empty());
600 EXPECT_FALSE(billing_name.empty());
601 EXPECT_FALSE(shipping_name.empty());
602 EXPECT_EQ(cc_name, billing_name);
603 EXPECT_EQ(cc_name, shipping_name);
604 }
605
556 TestAutofillDialogController* controller() { return controller_.get(); } 606 TestAutofillDialogController* controller() { return controller_.get(); }
557 607
558 const FormStructure* form_structure() { return form_structure_; } 608 const FormStructure* form_structure() { return form_structure_; }
559 609
560 TestGeneratedCreditCardBubbleController* test_generated_bubble_controller() { 610 TestGeneratedCreditCardBubbleController* test_generated_bubble_controller() {
561 return test_generated_bubble_controller_; 611 return test_generated_bubble_controller_;
562 } 612 }
563 613
564 const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() { 614 const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() {
565 return mock_new_card_bubble_controller_.get(); 615 return mock_new_card_bubble_controller_.get();
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 EXPECT_FALSE(billing_name.empty()); 1138 EXPECT_FALSE(billing_name.empty());
1089 EXPECT_FALSE(shipping_name.empty()); 1139 EXPECT_FALSE(shipping_name.empty());
1090 // Billing name should always be the same as cardholder name. 1140 // Billing name should always be the same as cardholder name.
1091 EXPECT_EQ(cc_name, billing_name); 1141 EXPECT_EQ(cc_name, billing_name);
1092 EXPECT_NE(cc_name, shipping_name); 1142 EXPECT_NE(cc_name, shipping_name);
1093 } 1143 }
1094 1144
1095 // Test selecting UseBillingForShipping. 1145 // Test selecting UseBillingForShipping.
1096 TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) { 1146 TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) {
1097 SwitchToAutofill(); 1147 SwitchToAutofill();
1148
1098 AutofillProfile full_profile(test::GetVerifiedProfile()); 1149 AutofillProfile full_profile(test::GetVerifiedProfile());
1150 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1151
1099 AutofillProfile full_profile2(test::GetVerifiedProfile2()); 1152 AutofillProfile full_profile2(test::GetVerifiedProfile2());
1153 controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
1154
1100 CreditCard credit_card(test::GetVerifiedCreditCard()); 1155 CreditCard credit_card(test::GetVerifiedCreditCard());
1101 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1102 controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
1103 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); 1156 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
1104 1157
1105 // Test after setting use billing for shipping. 1158 ASSERT_FALSE(controller()->IsManuallyEditingSection(SECTION_CC));
1106 UseBillingForShipping(); 1159 ASSERT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING));
1107 1160
1108 controller()->OnAccept(); 1161 SubmitAndVerifyShippingAndBillingResults();
1109 ASSERT_EQ(20U, form_structure()->field_count()); 1162 }
1110 EXPECT_EQ(ADDRESS_HOME_STATE,
1111 form_structure()->field(9)->Type().GetStorableType());
1112 EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group());
1113 EXPECT_EQ(ADDRESS_HOME_STATE,
1114 form_structure()->field(16)->Type().GetStorableType());
1115 EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group());
1116 base::string16 billing_state = form_structure()->field(9)->value;
1117 base::string16 shipping_state = form_structure()->field(16)->value;
1118 EXPECT_FALSE(billing_state.empty());
1119 EXPECT_FALSE(shipping_state.empty());
1120 EXPECT_EQ(billing_state, shipping_state);
1121 1163
1122 EXPECT_EQ(CREDIT_CARD_NAME, 1164 TEST_F(AutofillDialogControllerTest, UseBillingAsShippingManualInput) {
1123 form_structure()->field(1)->Type().GetStorableType()); 1165 SwitchToAutofill();
1124 base::string16 cc_name = form_structure()->field(1)->value;
1125 EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType());
1126 EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group());
1127 base::string16 billing_name = form_structure()->field(6)->value;
1128 EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType());
1129 EXPECT_EQ(NAME, form_structure()->field(13)->Type().group());
1130 base::string16 shipping_name = form_structure()->field(13)->value;
1131 1166
1132 EXPECT_FALSE(cc_name.empty()); 1167 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_CC));
1133 EXPECT_FALSE(billing_name.empty()); 1168 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING));
1134 EXPECT_FALSE(shipping_name.empty()); 1169
1135 EXPECT_EQ(cc_name, billing_name); 1170 CreditCard credit_card(test::GetVerifiedCreditCard());
1136 EXPECT_EQ(cc_name, shipping_name); 1171 FillInputs(SECTION_CC, credit_card);
1172
1173 AutofillProfile full_profile(test::GetVerifiedProfile());
1174 FillInputs(SECTION_BILLING, full_profile);
1175
1176 SubmitAndVerifyShippingAndBillingResults();
1137 } 1177 }
1138 1178
1139 // Tests that shipping and billing telephone fields are supported, and filled 1179 // Tests that shipping and billing telephone fields are supported, and filled
1140 // in by their respective profiles. http://crbug.com/244515 1180 // in by their respective profiles. http://crbug.com/244515
1141 TEST_F(AutofillDialogControllerTest, BillingVsShippingPhoneNumber) { 1181 TEST_F(AutofillDialogControllerTest, BillingVsShippingPhoneNumber) {
1142 FormFieldData shipping_tel; 1182 FormFieldData shipping_tel;
1143 shipping_tel.autocomplete_attribute = "shipping tel"; 1183 shipping_tel.autocomplete_attribute = "shipping tel";
1144 FormFieldData billing_tel; 1184 FormFieldData billing_tel;
1145 billing_tel.autocomplete_attribute = "billing tel"; 1185 billing_tel.autocomplete_attribute = "billing tel";
1146 1186
(...skipping 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after
2762 }; 2802 };
2763 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 2803 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
2764 for (size_t i = 0; i < arraysize(kSupportedCardIdrs); ++i) { 2804 for (size_t i = 0; i < arraysize(kSupportedCardIdrs); ++i) {
2765 SCOPED_TRACE(base::IntToString(i)); 2805 SCOPED_TRACE(base::IntToString(i));
2766 gfx::Image supported_card_icon = rb.GetImageNamed(kSupportedCardIdrs[i]); 2806 gfx::Image supported_card_icon = rb.GetImageNamed(kSupportedCardIdrs[i]);
2767 EXPECT_GE(placeholder_icon.Width(), supported_card_icon.Width()); 2807 EXPECT_GE(placeholder_icon.Width(), supported_card_icon.Width());
2768 EXPECT_GE(placeholder_icon.Height(), supported_card_icon.Height()); 2808 EXPECT_GE(placeholder_icon.Height(), supported_card_icon.Height());
2769 } 2809 }
2770 } 2810 }
2771 2811
2812 TEST_F(AutofillDialogControllerTest, CountryChange) {
2813 CommandLine* command_line = CommandLine::ForCurrentProcess();
2814 command_line->AppendSwitch(::switches::kEnableAutofillAddressI18n);
2815 Reset();
2816
2817 TestAutofillDialogView* view = controller()->GetView();
2818 view->ClearSectionUpdates();
2819
2820 controller()->ComboboxItemSelected(ADDRESS_HOME_COUNTRY, 2);
2821 std::map<DialogSection, size_t> updates = view->section_updates();
2822 EXPECT_EQ(1U, updates[SECTION_SHIPPING]);
2823 EXPECT_EQ(1U, updates.size());
2824
2825 view->ClearSectionUpdates();
2826
2827 controller()->ComboboxItemSelected(ADDRESS_BILLING_COUNTRY, 3);
2828 updates = view->section_updates();
2829 EXPECT_EQ(1U, updates[SECTION_CC_BILLING]);
2830 EXPECT_EQ(1U, updates.size());
2831
2832 SwitchToAutofill();
2833 view->ClearSectionUpdates();
2834
2835 controller()->ComboboxItemSelected(ADDRESS_BILLING_COUNTRY, 4);
2836 updates = view->section_updates();
2837 EXPECT_EQ(1U, updates[SECTION_BILLING]);
2838 EXPECT_EQ(1U, updates.size());
2839 }
2840
2772 } // namespace autofill 2841 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698