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

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

Issue 124533003: Add country combobox to change country and rebuild address inputs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "chrome/browser/autofill/personal_data_manager_factory.h" 14 #include "chrome/browser/autofill/personal_data_manager_factory.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/autofill/account_chooser_model.h" 16 #include "chrome/browser/ui/autofill/account_chooser_model.h"
17 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 17 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
18 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h"
18 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" 19 #include "chrome/browser/ui/autofill/autofill_dialog_view.h"
19 #include "chrome/browser/ui/autofill/data_model_wrapper.h" 20 #include "chrome/browser/ui/autofill/data_model_wrapper.h"
20 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" 21 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
21 #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"
22 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" 23 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h"
23 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_tabstrip.h" 25 #include "chrome/browser/ui/browser_tabstrip.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" 26 #include "chrome/browser/ui/tabs/tab_strip_model.h"
27 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
27 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
28 #include "chrome/test/base/in_process_browser_test.h" 30 #include "chrome/test/base/in_process_browser_test.h"
29 #include "chrome/test/base/ui_test_utils.h" 31 #include "chrome/test/base/ui_test_utils.h"
30 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" 32 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h"
33 #include "components/autofill/content/browser/wallet/gaia_account.h"
31 #include "components/autofill/content/browser/wallet/mock_wallet_client.h" 34 #include "components/autofill/content/browser/wallet/mock_wallet_client.h"
32 #include "components/autofill/content/browser/wallet/wallet_service_url.h" 35 #include "components/autofill/content/browser/wallet/wallet_service_url.h"
33 #include "components/autofill/content/browser/wallet/wallet_test_util.h" 36 #include "components/autofill/content/browser/wallet/wallet_test_util.h"
34 #include "components/autofill/core/browser/autofill_metrics.h" 37 #include "components/autofill/core/browser/autofill_metrics.h"
35 #include "components/autofill/core/browser/autofill_test_utils.h" 38 #include "components/autofill/core/browser/autofill_test_utils.h"
36 #include "components/autofill/core/browser/test_personal_data_manager.h" 39 #include "components/autofill/core/browser/test_personal_data_manager.h"
37 #include "components/autofill/core/browser/validation.h" 40 #include "components/autofill/core/browser/validation.h"
38 #include "components/autofill/core/common/autofill_switches.h" 41 #include "components/autofill/core/common/autofill_switches.h"
39 #include "components/autofill/core/common/form_data.h" 42 #include "components/autofill/core/common/form_data.h"
40 #include "components/autofill/core/common/form_field_data.h" 43 #include "components/autofill/core/common/form_field_data.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 181
179 void set_notifications(const std::vector<DialogNotification>& notifications) { 182 void set_notifications(const std::vector<DialogNotification>& notifications) {
180 notifications_ = notifications; 183 notifications_ = notifications;
181 } 184 }
182 185
183 TestPersonalDataManager* GetTestingManager() { 186 TestPersonalDataManager* GetTestingManager() {
184 return &test_manager_; 187 return &test_manager_;
185 } 188 }
186 189
187 using AutofillDialogControllerImpl::IsEditingExistingData; 190 using AutofillDialogControllerImpl::IsEditingExistingData;
191 using AutofillDialogControllerImpl::IsManuallyEditingSection;
188 using AutofillDialogControllerImpl::IsPayingWithWallet; 192 using AutofillDialogControllerImpl::IsPayingWithWallet;
189 using AutofillDialogControllerImpl::IsSubmitPausedOn; 193 using AutofillDialogControllerImpl::IsSubmitPausedOn;
190 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; 194 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData;
191 using AutofillDialogControllerImpl::AccountChooserModelForTesting; 195 using AutofillDialogControllerImpl::AccountChooserModelForTesting;
192 using AutofillDialogControllerImpl:: 196 using AutofillDialogControllerImpl::
193 ClearLastWalletItemsFetchTimestampForTesting; 197 ClearLastWalletItemsFetchTimestampForTesting;
194 198
195 void set_use_validation(bool use_validation) { 199 void set_use_validation(bool use_validation) {
196 use_validation_ = use_validation; 200 use_validation_ = use_validation;
197 } 201 }
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 RunMessageLoop(); 553 RunMessageLoop();
550 554
551 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, 555 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED,
552 metric_logger().dialog_dismissal_action()); 556 metric_logger().dialog_dismissal_action());
553 } 557 }
554 558
555 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) { 559 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) {
556 AutofillProfile full_profile(test::GetFullProfile()); 560 AutofillProfile full_profile(test::GetFullProfile());
557 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 561 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
558 562
563 // Select "Add new shipping address...".
564 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_SHIPPING);
565 model->ActivatedAt(model->GetItemCount() - 2);
566 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING));
567
559 const DetailInputs& inputs = 568 const DetailInputs& inputs =
560 controller()->RequestedFieldsForSection(SECTION_SHIPPING); 569 controller()->RequestedFieldsForSection(SECTION_SHIPPING);
561 const ServerFieldType triggering_type = inputs[0].type; 570 const ServerFieldType triggering_type = inputs[0].type;
562 base::string16 value = full_profile.GetRawInfo(triggering_type); 571 base::string16 value = full_profile.GetRawInfo(triggering_type);
563 TestableAutofillDialogView* view = controller()->GetTestableView(); 572 TestableAutofillDialogView* view = controller()->GetTestableView();
564 view->SetTextContentsOfInput(triggering_type, 573 view->SetTextContentsOfInput(triggering_type,
565 value.substr(0, value.size() / 2)); 574 value.substr(0, value.size() / 2));
566 view->ActivateInput(triggering_type); 575 view->ActivateInput(triggering_type);
567 576
568 ASSERT_EQ(triggering_type, controller()->popup_input_type()); 577 ASSERT_EQ(triggering_type, controller()->popup_input_type());
569 controller()->DidAcceptSuggestion(base::string16(), 0); 578 controller()->DidAcceptSuggestion(base::string16(), 0);
570 579
571 // All inputs should be filled. 580 // All inputs should be filled.
572 AutofillProfileWrapper wrapper(&full_profile); 581 AutofillProfileWrapper wrapper(&full_profile);
573 for (size_t i = 0; i < inputs.size(); ++i) { 582 for (size_t i = 0; i < inputs.size(); ++i) {
574 EXPECT_EQ(wrapper.GetInfo(AutofillType(inputs[i].type)), 583 EXPECT_EQ(wrapper.GetInfo(AutofillType(inputs[i].type)),
575 view->GetTextContentsOfInput(inputs[i].type)); 584 view->GetTextContentsOfInput(inputs[i].type));
576 } 585 }
577 586
578 // Now simulate some user edits and try again. 587 // Now simulate some user edits and try again.
579 std::vector<base::string16> expectations; 588 std::vector<base::string16> expectations;
580 for (size_t i = 0; i < inputs.size(); ++i) { 589 for (size_t i = 0; i < inputs.size(); ++i) {
590 if (controller()->ComboboxModelForAutofillType(inputs[i].type)) {
591 expectations.push_back(base::string16());
592 continue;
593 }
581 base::string16 users_input = i % 2 == 0 ? base::string16() 594 base::string16 users_input = i % 2 == 0 ? base::string16()
582 : ASCIIToUTF16("dummy"); 595 : ASCIIToUTF16("dummy");
583 view->SetTextContentsOfInput(inputs[i].type, users_input); 596 view->SetTextContentsOfInput(inputs[i].type, users_input);
584 // Empty inputs should be filled, others should be left alone. 597 // Empty inputs should be filled, others should be left alone.
585 base::string16 expectation = 598 base::string16 expectation =
586 inputs[i].type == triggering_type || users_input.empty() ? 599 inputs[i].type == triggering_type || users_input.empty() ?
587 wrapper.GetInfo(AutofillType(inputs[i].type)) : 600 wrapper.GetInfo(AutofillType(inputs[i].type)) :
588 users_input; 601 users_input;
589 expectations.push_back(expectation); 602 expectations.push_back(expectation);
590 } 603 }
591 604
592 view->SetTextContentsOfInput(triggering_type, 605 view->SetTextContentsOfInput(triggering_type,
593 value.substr(0, value.size() / 2)); 606 value.substr(0, value.size() / 2));
594 view->ActivateInput(triggering_type); 607 view->ActivateInput(triggering_type);
595 ASSERT_EQ(triggering_type, controller()->popup_input_type()); 608 ASSERT_EQ(triggering_type, controller()->popup_input_type());
596 controller()->DidAcceptSuggestion(base::string16(), 0); 609 controller()->DidAcceptSuggestion(base::string16(), 0);
597 610
598 for (size_t i = 0; i < inputs.size(); ++i) { 611 for (size_t i = 0; i < inputs.size(); ++i) {
612 if (controller()->ComboboxModelForAutofillType(inputs[i].type))
613 continue;
599 EXPECT_EQ(expectations[i], view->GetTextContentsOfInput(inputs[i].type)); 614 EXPECT_EQ(expectations[i], view->GetTextContentsOfInput(inputs[i].type));
600 } 615 }
601 } 616 }
602 617
603 // For now, no matter what, the country must always be US. See 618 // For now, no matter what, the country must always be US. See
604 // http://crbug.com/247518 619 // http://crbug.com/247518
605 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, 620 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
606 FillInputFromForeignProfile) { 621 FillInputFromForeignProfile) {
607 AutofillProfile full_profile(test::GetFullProfile()); 622 AutofillProfile full_profile(test::GetFullProfile());
608 full_profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), 623 full_profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY),
609 ASCIIToUTF16("France"), "en-US"); 624 ASCIIToUTF16("France"), "en-US");
610 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 625 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
611 626
627 // Select "Add new shipping address...".
628 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_SHIPPING);
629 model->ActivatedAt(model->GetItemCount() - 2);
630 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING));
631
612 const DetailInputs& inputs = 632 const DetailInputs& inputs =
613 controller()->RequestedFieldsForSection(SECTION_SHIPPING); 633 controller()->RequestedFieldsForSection(SECTION_SHIPPING);
614 const ServerFieldType triggering_type = inputs[0].type; 634 const ServerFieldType triggering_type = inputs[0].type;
615 base::string16 value = full_profile.GetRawInfo(triggering_type); 635 base::string16 value = full_profile.GetRawInfo(triggering_type);
616 TestableAutofillDialogView* view = controller()->GetTestableView(); 636 TestableAutofillDialogView* view = controller()->GetTestableView();
617 view->SetTextContentsOfInput(triggering_type, 637 view->SetTextContentsOfInput(triggering_type,
618 value.substr(0, value.size() / 2)); 638 value.substr(0, value.size() / 2));
619 view->ActivateInput(triggering_type); 639 view->ActivateInput(triggering_type);
620 640
621 ASSERT_EQ(triggering_type, controller()->popup_input_type()); 641 ASSERT_EQ(triggering_type, controller()->popup_input_type());
622 controller()->DidAcceptSuggestion(base::string16(), 0); 642 controller()->DidAcceptSuggestion(base::string16(), 0);
623 643
624 // All inputs should be filled. 644 // All inputs should be filled.
625 AutofillProfileWrapper wrapper(&full_profile); 645 AutofillProfileWrapper wrapper(&full_profile);
626 for (size_t i = 0; i < inputs.size(); ++i) { 646 for (size_t i = 0; i < inputs.size(); ++i) {
627 const ServerFieldType type = inputs[i].type; 647 const ServerFieldType type = inputs[i].type;
628 base::string16 expectation = 648 base::string16 expectation =
629 AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY ? 649 AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY ?
630 ASCIIToUTF16("United States") : wrapper.GetInfo(AutofillType(type)); 650 ASCIIToUTF16("United States") : wrapper.GetInfo(AutofillType(type));
631 EXPECT_EQ(expectation, view->GetTextContentsOfInput(type)); 651 EXPECT_EQ(expectation, view->GetTextContentsOfInput(type));
632 } 652 }
633 653
634 // Now simulate some user edits and try again. 654 // Now simulate some user edits and try again.
635 std::vector<base::string16> expectations; 655 std::vector<base::string16> expectations;
636 for (size_t i = 0; i < inputs.size(); ++i) { 656 for (size_t i = 0; i < inputs.size(); ++i) {
657 if (controller()->ComboboxModelForAutofillType(inputs[i].type)) {
658 expectations.push_back(base::string16());
659 continue;
660 }
637 base::string16 users_input = i % 2 == 0 ? base::string16() 661 base::string16 users_input = i % 2 == 0 ? base::string16()
638 : ASCIIToUTF16("dummy"); 662 : ASCIIToUTF16("dummy");
639 view->SetTextContentsOfInput(inputs[i].type, users_input); 663 view->SetTextContentsOfInput(inputs[i].type, users_input);
640 // Empty inputs should be filled, others should be left alone. 664 // Empty inputs should be filled, others should be left alone.
641 base::string16 expectation = 665 base::string16 expectation =
642 inputs[i].type == triggering_type || users_input.empty() ? 666 inputs[i].type == triggering_type || users_input.empty() ?
643 wrapper.GetInfo(AutofillType(inputs[i].type)) : 667 wrapper.GetInfo(AutofillType(inputs[i].type)) :
644 users_input; 668 users_input;
645 if (AutofillType(inputs[i].type).GetStorableType() == ADDRESS_HOME_COUNTRY) 669 if (AutofillType(inputs[i].type).GetStorableType() == ADDRESS_HOME_COUNTRY)
646 expectation = ASCIIToUTF16("United States"); 670 expectation = ASCIIToUTF16("United States");
647 671
648 expectations.push_back(expectation); 672 expectations.push_back(expectation);
649 } 673 }
650 674
651 view->SetTextContentsOfInput(triggering_type, 675 view->SetTextContentsOfInput(triggering_type,
652 value.substr(0, value.size() / 2)); 676 value.substr(0, value.size() / 2));
653 view->ActivateInput(triggering_type); 677 view->ActivateInput(triggering_type);
654 ASSERT_EQ(triggering_type, controller()->popup_input_type()); 678 ASSERT_EQ(triggering_type, controller()->popup_input_type());
655 controller()->DidAcceptSuggestion(base::string16(), 0); 679 controller()->DidAcceptSuggestion(base::string16(), 0);
656 680
657 for (size_t i = 0; i < inputs.size(); ++i) { 681 for (size_t i = 0; i < inputs.size(); ++i) {
682 if (controller()->ComboboxModelForAutofillType(inputs[i].type))
683 continue;
658 EXPECT_EQ(expectations[i], view->GetTextContentsOfInput(inputs[i].type)); 684 EXPECT_EQ(expectations[i], view->GetTextContentsOfInput(inputs[i].type));
659 } 685 }
660 } 686 }
661 687
662 // This test makes sure that picking a profile variant in the Autofill 688 // This test makes sure that picking a profile variant in the Autofill
663 // popup works as expected. 689 // popup works as expected.
664 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, 690 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
665 FillInputFromAutofillVariant) { 691 FillInputFromAutofillVariant) {
666 AutofillProfile full_profile(test::GetFullProfile()); 692 AutofillProfile full_profile(test::GetFullProfile());
667 693
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 // happen if the WebContents is deleted while proccessing a nav entry commit). 1121 // happen if the WebContents is deleted while proccessing a nav entry commit).
1096 EXPECT_TRUE(account_chooser_model->WalletIsSelected()); 1122 EXPECT_TRUE(account_chooser_model->WalletIsSelected());
1097 } 1123 }
1098 1124
1099 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AddAccount) { 1125 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AddAccount) {
1100 #if defined(OS_WIN) 1126 #if defined(OS_WIN)
1101 // TODO(msw): Fix potential flakiness on Windows XP; http://crbug.com/333641 1127 // TODO(msw): Fix potential flakiness on Windows XP; http://crbug.com/333641
1102 if (base::win::GetVersion() <= base::win::VERSION_XP) 1128 if (base::win::GetVersion() <= base::win::VERSION_XP)
1103 return; 1129 return;
1104 #endif 1130 #endif
1105 InitializeController();
1106 1131
1107 controller()->OnDidFetchWalletCookieValue(std::string()); 1132 controller()->OnDidFetchWalletCookieValue(std::string());
1108 std::vector<std::string> usernames; 1133 std::vector<std::string> usernames;
1109 usernames.push_back("user_0@example.com"); 1134 usernames.push_back("user_0@example.com");
1110 controller()->OnDidGetWalletItems( 1135 controller()->OnDidGetWalletItems(
1111 wallet::GetTestWalletItemsWithUsers(usernames, 0)); 1136 wallet::GetTestWalletItemsWithUsers(usernames, 0));
1112 1137
1113 // Switch to Autofill. 1138 // Switch to Autofill.
1114 AccountChooserModel* account_chooser_model = 1139 AccountChooserModel* account_chooser_model =
1115 controller()->AccountChooserModelForTesting(); 1140 controller()->AccountChooserModelForTesting();
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerSecurityTest, 1426 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerSecurityTest,
1402 MAYBE_DoesntWorkOnBrokenHttps) { 1427 MAYBE_DoesntWorkOnBrokenHttps) {
1403 net::SpawnedTestServer https_server( 1428 net::SpawnedTestServer https_server(
1404 net::SpawnedTestServer::TYPE_HTTPS, 1429 net::SpawnedTestServer::TYPE_HTTPS,
1405 SSLOptions(SSLOptions::CERT_EXPIRED), 1430 SSLOptions(SSLOptions::CERT_EXPIRED),
1406 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 1431 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1407 ASSERT_TRUE(https_server.Start()); 1432 ASSERT_TRUE(https_server.Start());
1408 EXPECT_FALSE(RunTestPage(https_server)); 1433 EXPECT_FALSE(RunTestPage(https_server));
1409 } 1434 }
1410 1435
1436 class AutofillDialogControllerI18nTest : public AutofillDialogControllerTest {
1437 public:
1438 AutofillDialogControllerI18nTest() {}
1439 virtual ~AutofillDialogControllerI18nTest() {}
1440
1441 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
1442 command_line->AppendSwitch(::switches::kEnableAutofillAddressI18n);
1443 CHECK(i18ninput::Enabled());
1444 }
1445 };
1446
1447 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerI18nTest,
1448 CountryChangeRebuildsSection) {
1449 const DetailInputs& us_billing_inputs =
1450 controller()->RequestedFieldsForSection(SECTION_BILLING);
1451 const DetailInputs& us_shipping_inputs =
1452 controller()->RequestedFieldsForSection(SECTION_SHIPPING);
1453
1454 // Check that there's no dependent locality for the US layout.
1455 for (size_t i = 0; i < us_billing_inputs.size(); ++i) {
1456 EXPECT_NE(us_billing_inputs[i].type, ADDRESS_BILLING_DEPENDENT_LOCALITY);
1457 }
1458 for (size_t i = 0; i < us_shipping_inputs.size(); ++i) {
1459 EXPECT_NE(us_shipping_inputs[i].type, ADDRESS_HOME_DEPENDENT_LOCALITY);
1460 }
1461
1462 // Select "Add new shipping address...".
1463 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(1);
1464
1465 // Add some valid user input that should be preserved when country changes.
1466 TestableAutofillDialogView* view = controller()->GetTestableView();
1467 view->SetTextContentsOfInput(NAME_FULL, ASCIIToUTF16("B. Loblaw"));
1468
1469 // Change both sections' countries.
1470 view->SetTextContentsOfInput(ADDRESS_BILLING_COUNTRY, ASCIIToUTF16("China"));
1471 view->ActivateInput(ADDRESS_BILLING_COUNTRY);
1472 view->SetTextContentsOfInput(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("France"));
1473 view->ActivateInput(ADDRESS_HOME_COUNTRY);
1474
1475 // Verify the name is still there.
1476 EXPECT_EQ(ASCIIToUTF16("B. Loblaw"), view->GetTextContentsOfInput(NAME_FULL));
1477
1478 const DetailInputs& cn_billing_inputs =
1479 controller()->RequestedFieldsForSection(SECTION_BILLING);
1480 const DetailInputs& fr_shipping_inputs =
1481 controller()->RequestedFieldsForSection(SECTION_SHIPPING);
1482
1483 // Check that there is dependent locality for the Chinese layout.
1484 size_t i = 0;
1485 for (; i < cn_billing_inputs.size(); ++i) {
1486 if (cn_billing_inputs[i].type == ADDRESS_BILLING_DEPENDENT_LOCALITY)
1487 break;
1488 }
1489 EXPECT_LT(i, cn_billing_inputs.size());
1490
1491 // Check that there's a sorting code (CEDEX) for French layout.
1492 for (i = 0; i < fr_shipping_inputs.size(); ++i) {
1493 if (fr_shipping_inputs[i].type == ADDRESS_HOME_SORTING_CODE)
1494 break;
1495 }
1496 EXPECT_LT(i, fr_shipping_inputs.size());
1497 }
1498
1499 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerI18nTest,
1500 ChangingDataSourcePreservesCountry) {
1501 AutofillProfile verified_profile(test::GetVerifiedProfile());
1502 controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
1503
1504 CreditCard verified_card(test::GetVerifiedCreditCard());
1505 controller()->GetTestingManager()->AddTestingCreditCard(&verified_card);
1506
1507 controller()->OnDidFetchWalletCookieValue(std::string());
1508 scoped_ptr<wallet::WalletItems> items =
1509 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED);
1510 items->AddAccount(wallet::GetTestGaiaAccount());
1511 items->AddInstrument(wallet::GetTestMaskedInstrument());
1512 items->AddAddress(wallet::GetTestShippingAddress());
1513 controller()->OnDidGetWalletItems(items.Pass());
1514
1515 EXPECT_TRUE(controller()->IsPayingWithWallet());
1516
1517 // Select "Add new billing/shipping address...".
1518 controller()->MenuModelForSection(SECTION_CC_BILLING)->ActivatedAt(1);
1519 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(2);
1520
1521 TestableAutofillDialogView* view = controller()->GetTestableView();
1522 ASSERT_EQ(ASCIIToUTF16("United States"),
1523 view->GetTextContentsOfInput(ADDRESS_BILLING_COUNTRY));
1524 ASSERT_EQ(ASCIIToUTF16("United States"),
1525 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY));
1526
1527 // Switch both billing and shipping countries.
1528 view->SetTextContentsOfInput(ADDRESS_BILLING_COUNTRY, ASCIIToUTF16("China"));
1529 view->ActivateInput(ADDRESS_BILLING_COUNTRY);
1530 view->SetTextContentsOfInput(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("France"));
1531 view->ActivateInput(ADDRESS_HOME_COUNTRY);
1532
1533 // Switch to using Autofill instead of Wallet.
1534 ui::MenuModel* account_chooser = controller()->MenuModelForAccountChooser();
1535 account_chooser->ActivatedAt(account_chooser->GetItemCount() - 1);
1536
1537 EXPECT_FALSE(controller()->IsPayingWithWallet());
1538
1539 // Countries should have stayed the same.
1540 EXPECT_EQ(ASCIIToUTF16("China"),
1541 view->GetTextContentsOfInput(ADDRESS_BILLING_COUNTRY));
1542 EXPECT_EQ(ASCIIToUTF16("France"),
1543 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY));
1544 }
1545
1546 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerI18nTest, AddNewResetsCountry) {
1547 AutofillProfile verified_profile(test::GetVerifiedProfile());
1548 controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
1549
1550 // Select "Add new billing/shipping address...".
1551 controller()->MenuModelForSection(SECTION_BILLING)->ActivatedAt(1);
1552 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(2);
1553
1554 TestableAutofillDialogView* view = controller()->GetTestableView();
1555 ASSERT_EQ(ASCIIToUTF16("United States"),
1556 view->GetTextContentsOfInput(ADDRESS_BILLING_COUNTRY));
1557 ASSERT_EQ(ASCIIToUTF16("United States"),
1558 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY));
1559
1560 // Switch both billing and shipping countries.
1561 view->SetTextContentsOfInput(ADDRESS_BILLING_COUNTRY, ASCIIToUTF16("China"));
1562 view->ActivateInput(ADDRESS_BILLING_COUNTRY);
1563 view->SetTextContentsOfInput(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("France"));
1564 view->ActivateInput(ADDRESS_HOME_COUNTRY);
1565
1566 // Select "Add new billing/shipping address...".
1567 controller()->MenuModelForSection(SECTION_BILLING)->ActivatedAt(1);
1568 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(2);
1569
1570 EXPECT_EQ(ASCIIToUTF16("United States"),
1571 view->GetTextContentsOfInput(ADDRESS_BILLING_COUNTRY));
1572 EXPECT_EQ(ASCIIToUTF16("United States"),
1573 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY));
1574 }
1575
1576 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerI18nTest,
1577 FillingFormRebuildsInputs) {
1578 AutofillProfile full_profile(test::GetFullProfile());
1579 full_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CN"));
1580 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1581
1582 // Select "Add new shipping address...".
1583 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(1);
1584
1585 TestableAutofillDialogView* view = controller()->GetTestableView();
1586 ASSERT_EQ(ASCIIToUTF16("United States"),
1587 view->GetTextContentsOfInput(ADDRESS_BILLING_COUNTRY));
1588 ASSERT_EQ(ASCIIToUTF16("United States"),
1589 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY));
1590
1591 base::string16 name = full_profile.GetRawInfo(NAME_FULL);
1592 view->SetTextContentsOfInput(NAME_FULL, name.substr(0, name.size() / 2));
1593 view->ActivateInput(NAME_FULL);
1594 ASSERT_EQ(NAME_FULL, controller()->popup_input_type());
1595 controller()->DidAcceptSuggestion(base::string16(), 0);
1596
1597 EXPECT_EQ(ASCIIToUTF16("China"),
1598 view->GetTextContentsOfInput(ADDRESS_BILLING_COUNTRY));
1599 EXPECT_EQ(ASCIIToUTF16("China"),
1600 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY));
1601 }
1602
1411 } // namespace autofill 1603 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_common.cc ('k') | chrome/browser/ui/autofill/autofill_dialog_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698