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

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

Issue 23579009: [rAc] Move email address into billing address section. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update Mac test expectations Created 7 years, 3 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"
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 uint32 kMsgID = ChromeViewMsg_SetVisuallyDeemphasized::ID; 484 uint32 kMsgID = ChromeViewMsg_SetVisuallyDeemphasized::ID;
485 const IPC::Message* message = 485 const IPC::Message* message =
486 process()->sink().GetFirstMessageMatching(kMsgID); 486 process()->sink().GetFirstMessageMatching(kMsgID);
487 EXPECT_TRUE(message); 487 EXPECT_TRUE(message);
488 Tuple1<bool> payload; 488 Tuple1<bool> payload;
489 ChromeViewMsg_SetVisuallyDeemphasized::Read(message, &payload); 489 ChromeViewMsg_SetVisuallyDeemphasized::Read(message, &payload);
490 process()->sink().ClearMessages(); 490 process()->sink().ClearMessages();
491 return payload.a; 491 return payload.a;
492 } 492 }
493 493
494 // Returns true if the given |section| contains a field of the given |type|.
495 bool SectionContainsField(DialogSection section, ServerFieldType type) {
496 const DetailInputs& inputs =
497 controller()->RequestedFieldsForSection(section);
498 for (DetailInputs::const_iterator it = inputs.begin(); it != inputs.end();
499 ++it) {
500 if (it->type == type)
501 return true;
502 }
503 return false;
504 }
505
494 TestAutofillDialogController* controller() { return controller_.get(); } 506 TestAutofillDialogController* controller() { return controller_.get(); }
495 507
496 const FormStructure* form_structure() { return form_structure_; } 508 const FormStructure* form_structure() { return form_structure_; }
497 509
498 TestGeneratedCreditCardBubbleController* test_generated_bubble_controller() { 510 TestGeneratedCreditCardBubbleController* test_generated_bubble_controller() {
499 return test_generated_bubble_controller_; 511 return test_generated_bubble_controller_;
500 } 512 }
501 513
502 const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() { 514 const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() {
503 return mock_new_card_bubble_controller_.get(); 515 return mock_new_card_bubble_controller_.get();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 controller()->RequestedFieldsForSection(section); 582 controller()->RequestedFieldsForSection(section);
571 // Make sure country is United States. 583 // Make sure country is United States.
572 SetOutputValue(inputs, &outputs, address, ASCIIToUTF16("United States")); 584 SetOutputValue(inputs, &outputs, address, ASCIIToUTF16("United States"));
573 585
574 // Existing data should have no errors. 586 // Existing data should have no errors.
575 ValidityData validity_data = 587 ValidityData validity_data =
576 controller()->InputsAreValid(section, outputs, VALIDATE_FINAL); 588 controller()->InputsAreValid(section, outputs, VALIDATE_FINAL);
577 EXPECT_EQ(0U, validity_data.count(phone)); 589 EXPECT_EQ(0U, validity_data.count(phone));
578 590
579 // Input an empty phone number with VALIDATE_FINAL. 591 // Input an empty phone number with VALIDATE_FINAL.
580 SetOutputValue( inputs, &outputs, phone, base::string16()); 592 SetOutputValue(inputs, &outputs, phone, base::string16());
581 validity_data = 593 validity_data =
582 controller()->InputsAreValid(section, outputs, VALIDATE_FINAL); 594 controller()->InputsAreValid(section, outputs, VALIDATE_FINAL);
583 EXPECT_EQ(1U, validity_data.count(phone)); 595 EXPECT_EQ(1U, validity_data.count(phone));
584 596
585 // Input an empty phone number with VALIDATE_EDIT. 597 // Input an empty phone number with VALIDATE_EDIT.
586 validity_data = 598 validity_data =
587 controller()->InputsAreValid(section, outputs, VALIDATE_EDIT); 599 controller()->InputsAreValid(section, outputs, VALIDATE_EDIT);
588 EXPECT_EQ(0U, validity_data.count(phone)); 600 EXPECT_EQ(0U, validity_data.count(phone));
589 601
590 // Input an invalid phone number. 602 // Input an invalid phone number.
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 ui::MenuModel* shipping_model = 825 ui::MenuModel* shipping_model =
814 controller()->MenuModelForSection(SECTION_SHIPPING); 826 controller()->MenuModelForSection(SECTION_SHIPPING);
815 // Since the PersonalDataManager is empty, this should only have the 827 // Since the PersonalDataManager is empty, this should only have the
816 // "use billing", "add new" and "manage" menu items. 828 // "use billing", "add new" and "manage" menu items.
817 ASSERT_TRUE(shipping_model); 829 ASSERT_TRUE(shipping_model);
818 EXPECT_EQ(3, shipping_model->GetItemCount()); 830 EXPECT_EQ(3, shipping_model->GetItemCount());
819 // On the other hand, the other models should be NULL when there's no 831 // On the other hand, the other models should be NULL when there's no
820 // suggestion. 832 // suggestion.
821 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC)); 833 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC));
822 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_BILLING)); 834 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_BILLING));
823 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL));
824 835
825 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(3); 836 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(3);
826 837
827 // Empty profiles are ignored. 838 // Empty profiles are ignored.
828 AutofillProfile empty_profile(base::GenerateGUID(), kSettingsOrigin); 839 AutofillProfile empty_profile(base::GenerateGUID(), kSettingsOrigin);
829 empty_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); 840 empty_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe"));
830 controller()->GetTestingManager()->AddTestingProfile(&empty_profile); 841 controller()->GetTestingManager()->AddTestingProfile(&empty_profile);
831 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); 842 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING);
832 ASSERT_TRUE(shipping_model); 843 ASSERT_TRUE(shipping_model);
833 EXPECT_EQ(3, shipping_model->GetItemCount()); 844 EXPECT_EQ(3, shipping_model->GetItemCount());
834 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL));
835 845
836 // An otherwise full but unverified profile should be ignored. 846 // An otherwise full but unverified profile should be ignored.
837 AutofillProfile full_profile(test::GetFullProfile()); 847 AutofillProfile full_profile(test::GetFullProfile());
838 full_profile.set_origin("https://www.example.com"); 848 full_profile.set_origin("https://www.example.com");
839 full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); 849 full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16());
840 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 850 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
841 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); 851 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING);
842 ASSERT_TRUE(shipping_model); 852 ASSERT_TRUE(shipping_model);
843 EXPECT_EQ(3, shipping_model->GetItemCount()); 853 EXPECT_EQ(3, shipping_model->GetItemCount());
844 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL));
845 854
846 // A full, verified profile should be picked up. 855 // A full, verified profile should be picked up.
847 AutofillProfile verified_profile(test::GetVerifiedProfile()); 856 AutofillProfile verified_profile(test::GetVerifiedProfile());
848 verified_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); 857 verified_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16());
849 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); 858 controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
850 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); 859 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING);
851 ASSERT_TRUE(shipping_model); 860 ASSERT_TRUE(shipping_model);
852 EXPECT_EQ(4, shipping_model->GetItemCount()); 861 EXPECT_EQ(4, shipping_model->GetItemCount());
853 EXPECT_TRUE(!!controller()->MenuModelForSection(SECTION_EMAIL));
854 } 862 }
855 863
856 // Makes sure that the choice of which Autofill profile to use for each section 864 // Makes sure that the choice of which Autofill profile to use for each section
857 // is sticky. 865 // is sticky.
858 TEST_F(AutofillDialogControllerTest, AutofillProfileDefaults) { 866 TEST_F(AutofillDialogControllerTest, AutofillProfileDefaults) {
859 AutofillProfile full_profile(test::GetFullProfile()); 867 AutofillProfile full_profile(test::GetFullProfile());
860 full_profile.set_origin(kSettingsOrigin); 868 full_profile.set_origin(kSettingsOrigin);
861 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 869 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
862 AutofillProfile full_profile2(test::GetFullProfile2()); 870 AutofillProfile full_profile2(test::GetFullProfile2());
863 full_profile2.set_origin(kSettingsOrigin); 871 full_profile2.set_origin(kSettingsOrigin);
(...skipping 27 matching lines...) Expand all
891 controller()->OnAccept(); 899 controller()->OnAccept();
892 Reset(); 900 Reset();
893 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 901 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
894 shipping_model = static_cast<SuggestionsMenuModel*>( 902 shipping_model = static_cast<SuggestionsMenuModel*>(
895 controller()->MenuModelForSection(SECTION_SHIPPING)); 903 controller()->MenuModelForSection(SECTION_SHIPPING));
896 EXPECT_EQ(1, shipping_model->checked_item()); 904 EXPECT_EQ(1, shipping_model->checked_item());
897 } 905 }
898 906
899 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) { 907 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) {
900 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 908 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
901 ui::MenuModel* email_model = 909 ui::MenuModel* shipping_model =
902 controller()->MenuModelForSection(SECTION_EMAIL); 910 controller()->MenuModelForSection(SECTION_SHIPPING);
903 EXPECT_FALSE(email_model); 911 ASSERT_TRUE(!!shipping_model);
912 EXPECT_EQ(3, shipping_model->GetItemCount());
904 913
905 // Set up some variant data. 914 // Set up some variant data.
906 AutofillProfile full_profile(test::GetVerifiedProfile()); 915 AutofillProfile full_profile(test::GetVerifiedProfile());
907 std::vector<string16> names; 916 std::vector<string16> names;
908 names.push_back(ASCIIToUTF16("John Doe")); 917 names.push_back(ASCIIToUTF16("John Doe"));
909 names.push_back(ASCIIToUTF16("Jane Doe")); 918 names.push_back(ASCIIToUTF16("Jane Doe"));
910 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names); 919 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names);
911 const string16 kEmail1 = ASCIIToUTF16(kFakeEmail);
912 const string16 kEmail2 = ASCIIToUTF16("admin@example.com");
913 std::vector<string16> emails; 920 std::vector<string16> emails;
914 emails.push_back(kEmail1); 921 emails.push_back(ASCIIToUTF16(kFakeEmail));
915 emails.push_back(kEmail2); 922 emails.push_back(ASCIIToUTF16("admin@example.com"));
916 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails); 923 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails);
917 924
918 // Respect variants for the email address field only. 925 // Non-default variants are ignored by the dialog.
919 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 926 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
920 ui::MenuModel* shipping_model =
921 controller()->MenuModelForSection(SECTION_SHIPPING);
922 EXPECT_EQ(4, shipping_model->GetItemCount()); 927 EXPECT_EQ(4, shipping_model->GetItemCount());
923 email_model = controller()->MenuModelForSection(SECTION_EMAIL);
924 ASSERT_TRUE(!!email_model);
925 EXPECT_EQ(4, email_model->GetItemCount());
926
927 // The first one is the default.
928 SuggestionsMenuModel* email_suggestions = static_cast<SuggestionsMenuModel*>(
929 controller()->MenuModelForSection(SECTION_EMAIL));
930 EXPECT_EQ(0, email_suggestions->checked_item());
931
932 email_model->ActivatedAt(0);
933 EXPECT_EQ(kEmail1,
934 controller()->SuggestionStateForSection(SECTION_EMAIL).
935 vertically_compact_text);
936 email_model->ActivatedAt(1);
937 EXPECT_EQ(kEmail2,
938 controller()->SuggestionStateForSection(SECTION_EMAIL).
939 vertically_compact_text);
940
941 controller()->EditClickedForSection(SECTION_EMAIL);
942 const DetailInputs& inputs =
943 controller()->RequestedFieldsForSection(SECTION_EMAIL);
944 EXPECT_EQ(kEmail2, inputs[0].initial_value);
945
946 // The choice of variant is persisted across runs of the dialog.
947 email_model->ActivatedAt(0);
948 email_model->ActivatedAt(1);
949 FillCreditCardInputs();
950 controller()->OnAccept();
951
952 Reset();
953 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
954 email_suggestions = static_cast<SuggestionsMenuModel*>(
955 controller()->MenuModelForSection(SECTION_EMAIL));
956 EXPECT_EQ(1, email_suggestions->checked_item());
957 } 928 }
958 929
959 TEST_F(AutofillDialogControllerTest, SuggestValidEmail) { 930 TEST_F(AutofillDialogControllerTest, SuggestValidEmail) {
960 AutofillProfile profile(test::GetVerifiedProfile()); 931 AutofillProfile profile(test::GetVerifiedProfile());
961 const string16 kValidEmail = ASCIIToUTF16(kFakeEmail); 932 const string16 kValidEmail = ASCIIToUTF16(kFakeEmail);
962 profile.SetRawInfo(EMAIL_ADDRESS, kValidEmail); 933 profile.SetRawInfo(EMAIL_ADDRESS, kValidEmail);
963 controller()->GetTestingManager()->AddTestingProfile(&profile); 934 controller()->GetTestingManager()->AddTestingProfile(&profile);
964 935
965 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(0); 936 // "add", "manage", and 1 suggestion.
966 EXPECT_EQ(kValidEmail, 937 EXPECT_EQ(
967 controller()->SuggestionStateForSection(SECTION_EMAIL). 938 3, controller()->MenuModelForSection(SECTION_BILLING)->GetItemCount());
968 vertically_compact_text); 939 // "add", "manage", 1 suggestion, and "same as billing".
940 EXPECT_EQ(
941 4, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
969 } 942 }
970 943
971 TEST_F(AutofillDialogControllerTest, DoNotSuggestInvalidEmail) { 944 TEST_F(AutofillDialogControllerTest, DoNotSuggestInvalidEmail) {
972 AutofillProfile profile(test::GetVerifiedProfile()); 945 AutofillProfile profile(test::GetVerifiedProfile());
973 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(".!#$%&'*+/=?^_`-@-..")); 946 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(".!#$%&'*+/=?^_`-@-.."));
974 controller()->GetTestingManager()->AddTestingProfile(&profile); 947 controller()->GetTestingManager()->AddTestingProfile(&profile);
975 EXPECT_EQ(static_cast<ui::MenuModel*>(NULL),
976 controller()->MenuModelForSection(SECTION_EMAIL));
977 }
978 948
979 TEST_F(AutofillDialogControllerTest, DoNotSuggestEmailFromIncompleteProfile) { 949 EXPECT_FALSE(!!controller()->MenuModelForSection(SECTION_BILLING));
980 AutofillProfile profile(test::GetVerifiedProfile()); 950 // "add", "manage", 1 suggestion, and "same as billing".
981 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(kFakeEmail)); 951 EXPECT_EQ(
982 profile.SetRawInfo(ADDRESS_HOME_STATE, base::string16()); 952 4, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
983 controller()->GetTestingManager()->AddTestingProfile(&profile);
984 EXPECT_EQ(static_cast<ui::MenuModel*>(NULL),
985 controller()->MenuModelForSection(SECTION_EMAIL));
986 }
987
988 TEST_F(AutofillDialogControllerTest, DoNotSuggestEmailFromInvalidProfile) {
989 AutofillProfile profile(test::GetVerifiedProfile());
990 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(kFakeEmail));
991 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("C"));
992 controller()->GetTestingManager()->AddTestingProfile(&profile);
993 EXPECT_EQ(static_cast<ui::MenuModel*>(NULL),
994 controller()->MenuModelForSection(SECTION_EMAIL));
995 } 953 }
996 954
997 TEST_F(AutofillDialogControllerTest, SuggestValidAddress) { 955 TEST_F(AutofillDialogControllerTest, SuggestValidAddress) {
998 AutofillProfile full_profile(test::GetVerifiedProfile()); 956 AutofillProfile full_profile(test::GetVerifiedProfile());
999 full_profile.set_origin(kSettingsOrigin); 957 full_profile.set_origin(kSettingsOrigin);
1000 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 958 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
959 // "add", "manage", and 1 suggestion.
1001 EXPECT_EQ( 960 EXPECT_EQ(
1002 4, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); 961 3, controller()->MenuModelForSection(SECTION_BILLING)->GetItemCount());
1003 } 962 }
1004 963
1005 TEST_F(AutofillDialogControllerTest, DoNotSuggestInvalidAddress) { 964 TEST_F(AutofillDialogControllerTest, DoNotSuggestInvalidAddress) {
1006 AutofillProfile full_profile(test::GetVerifiedProfile()); 965 AutofillProfile full_profile(test::GetVerifiedProfile());
1007 full_profile.set_origin(kSettingsOrigin); 966 full_profile.set_origin(kSettingsOrigin);
1008 full_profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("C")); 967 full_profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("C"));
1009 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 968 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1010 EXPECT_EQ( 969
1011 3, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); 970 EXPECT_FALSE(!!controller()->MenuModelForSection(SECTION_BILLING));
971 }
972
973 TEST_F(AutofillDialogControllerTest, DoNotSuggestIncompleteAddress) {
974 AutofillProfile profile(test::GetVerifiedProfile());
975 profile.SetRawInfo(ADDRESS_HOME_STATE, base::string16());
976 controller()->GetTestingManager()->AddTestingProfile(&profile);
977
978 EXPECT_FALSE(!!controller()->MenuModelForSection(SECTION_BILLING));
1012 } 979 }
1013 980
1014 TEST_F(AutofillDialogControllerTest, AutofillCreditCards) { 981 TEST_F(AutofillDialogControllerTest, AutofillCreditCards) {
1015 // Since the PersonalDataManager is empty, this should only have the 982 // Since the PersonalDataManager is empty, this should only have the
1016 // default menu items. 983 // default menu items.
1017 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC)); 984 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC));
1018 985
1019 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(3); 986 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(3);
1020 987
1021 // Empty cards are ignored. 988 // Empty cards are ignored.
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 EXPECT_EQ("https", wallet_manage_instruments_url.scheme()); 1454 EXPECT_EQ("https", wallet_manage_instruments_url.scheme());
1488 1455
1489 EXPECT_NE(autofill_manage_url, wallet_manage_instruments_url); 1456 EXPECT_NE(autofill_manage_url, wallet_manage_instruments_url);
1490 EXPECT_NE(wallet_manage_instruments_url, wallet_manage_addresses_url); 1457 EXPECT_NE(wallet_manage_instruments_url, wallet_manage_addresses_url);
1491 } 1458 }
1492 1459
1493 TEST_F(AutofillDialogControllerTest, EditClicked) { 1460 TEST_F(AutofillDialogControllerTest, EditClicked) {
1494 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 1461 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
1495 1462
1496 AutofillProfile full_profile(test::GetVerifiedProfile()); 1463 AutofillProfile full_profile(test::GetVerifiedProfile());
1497 const string16 kEmail = ASCIIToUTF16("first@johndoe.com"); 1464 const string16 kName = ASCIIToUTF16("John Doe");
1498 full_profile.SetRawInfo(EMAIL_ADDRESS, kEmail); 1465 full_profile.SetRawInfo(NAME_FULL, kName);
1499 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 1466 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1500 1467
1501 ui::MenuModel* email_model = 1468 ui::MenuModel* billing_model =
1502 controller()->MenuModelForSection(SECTION_EMAIL); 1469 controller()->MenuModelForSection(SECTION_BILLING);
1503 EXPECT_EQ(3, email_model->GetItemCount()); 1470 // "add", "manage", and 1 suggestion.
1471 EXPECT_EQ(3, billing_model->GetItemCount());
1504 1472
1505 // When unedited, the initial_value should be empty. 1473 // When unedited, the initial_value should be empty.
1506 email_model->ActivatedAt(0); 1474 billing_model->ActivatedAt(0);
1507 const DetailInputs& inputs0 = 1475 const DetailInputs& inputs0 =
1508 controller()->RequestedFieldsForSection(SECTION_EMAIL); 1476 controller()->RequestedFieldsForSection(SECTION_BILLING);
1509 EXPECT_EQ(string16(), inputs0[0].initial_value); 1477 EXPECT_EQ(string16(), inputs0[0].initial_value);
1510 EXPECT_EQ(kEmail, 1478 EXPECT_NE(base::string16::npos,
1511 controller()->SuggestionStateForSection(SECTION_EMAIL). 1479 controller()->SuggestionStateForSection(SECTION_BILLING).
1512 vertically_compact_text); 1480 vertically_compact_text.find(kName));
1513 1481
1514 // When edited, the initial_value should contain the value. 1482 // When edited, the initial_value should contain the value.
1515 controller()->EditClickedForSection(SECTION_EMAIL); 1483 controller()->EditClickedForSection(SECTION_BILLING);
1516 const DetailInputs& inputs1 = 1484 const DetailInputs& inputs1 =
1517 controller()->RequestedFieldsForSection(SECTION_EMAIL); 1485 controller()->RequestedFieldsForSection(SECTION_BILLING);
1518 EXPECT_EQ(kEmail, inputs1[0].initial_value); 1486 EXPECT_EQ(kName, inputs1[0].initial_value);
1519 EXPECT_FALSE(controller()->SuggestionStateForSection(SECTION_EMAIL).visible); 1487 EXPECT_FALSE(
1488 controller()->SuggestionStateForSection(SECTION_BILLING).visible);
1520 } 1489 }
1521 1490
1522 // Tests that editing an autofill profile and then submitting works. 1491 // Tests that editing an autofill profile and then submitting works.
1523 TEST_F(AutofillDialogControllerTest, EditAutofillProfile) { 1492 TEST_F(AutofillDialogControllerTest, EditAutofillProfile) {
1524 SwitchToAutofill(); 1493 SwitchToAutofill();
1525 1494
1526 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); 1495 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2);
1527 1496
1528 AutofillProfile full_profile(test::GetVerifiedProfile()); 1497 AutofillProfile full_profile(test::GetVerifiedProfile());
1529 CreditCard credit_card(test::GetVerifiedCreditCard()); 1498 CreditCard credit_card(test::GetVerifiedCreditCard());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 const AutofillProfile& added_profile = 1554 const AutofillProfile& added_profile =
1586 controller()->GetTestingManager()->imported_profile(); 1555 controller()->GetTestingManager()->imported_profile();
1587 1556
1588 const DetailInputs& shipping_inputs = 1557 const DetailInputs& shipping_inputs =
1589 controller()->RequestedFieldsForSection(SECTION_SHIPPING); 1558 controller()->RequestedFieldsForSection(SECTION_SHIPPING);
1590 for (size_t i = 0; i < shipping_inputs.size(); ++i) { 1559 for (size_t i = 0; i < shipping_inputs.size(); ++i) {
1591 const DetailInput& input = shipping_inputs[i]; 1560 const DetailInput& input = shipping_inputs[i];
1592 EXPECT_EQ(full_profile2.GetInfo(AutofillType(input.type), "en-US"), 1561 EXPECT_EQ(full_profile2.GetInfo(AutofillType(input.type), "en-US"),
1593 added_profile.GetInfo(AutofillType(input.type), "en-US")); 1562 added_profile.GetInfo(AutofillType(input.type), "en-US"));
1594 } 1563 }
1595
1596 // Also, the currently selected email address should get added to the new
1597 // profile.
1598 string16 original_email =
1599 full_profile.GetInfo(AutofillType(EMAIL_ADDRESS), "en-US");
1600 EXPECT_FALSE(original_email.empty());
1601 EXPECT_EQ(original_email,
1602 added_profile.GetInfo(AutofillType(EMAIL_ADDRESS), "en-US"));
1603 }
1604
1605 // Makes sure that a newly added email address gets added to an existing profile
1606 // (as opposed to creating its own profile). http://crbug.com/240926
1607 TEST_F(AutofillDialogControllerTest, AddEmail) {
1608 SwitchToAutofill();
1609 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2);
1610
1611 AutofillProfile full_profile(test::GetVerifiedProfile());
1612 CreditCard credit_card(test::GetVerifiedCreditCard());
1613 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1614 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
1615
1616 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_EMAIL);
1617 ASSERT_TRUE(model);
1618 // Activate the "Add email address" menu item.
1619 model->ActivatedAt(model->GetItemCount() - 2);
1620
1621 // Fill in the inputs from the profile.
1622 DetailOutputMap outputs;
1623 const DetailInputs& inputs =
1624 controller()->RequestedFieldsForSection(SECTION_EMAIL);
1625 const DetailInput& input = inputs[0];
1626 string16 new_email = ASCIIToUTF16("addemailtest@example.com");
1627 outputs[&input] = new_email;
1628 controller()->GetView()->SetUserInput(SECTION_EMAIL, outputs);
1629
1630 FillCreditCardInputs();
1631 controller()->OnAccept();
1632 std::vector<base::string16> email_values;
1633 full_profile.GetMultiInfo(
1634 AutofillType(EMAIL_ADDRESS), "en-US", &email_values);
1635 ASSERT_EQ(2U, email_values.size());
1636 EXPECT_EQ(new_email, email_values[1]);
1637 } 1564 }
1638 1565
1639 TEST_F(AutofillDialogControllerTest, VerifyCvv) { 1566 TEST_F(AutofillDialogControllerTest, VerifyCvv) {
1640 EXPECT_CALL(*controller()->GetTestingWalletClient(), 1567 EXPECT_CALL(*controller()->GetTestingWalletClient(),
1641 GetFullWallet(_)).Times(1); 1568 GetFullWallet(_)).Times(1);
1642 EXPECT_CALL(*controller()->GetTestingWalletClient(), 1569 EXPECT_CALL(*controller()->GetTestingWalletClient(),
1643 AuthenticateInstrument(_, _)).Times(1); 1570 AuthenticateInstrument(_, _)).Times(1);
1644 1571
1645 SubmitWithWalletItems(CompleteAndValidWalletItems()); 1572 SubmitWithWalletItems(CompleteAndValidWalletItems());
1646 1573
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1976 1903
1977 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( 1904 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath(
1978 ::prefs::kAutofillDialogPayWithoutWallet)); 1905 ::prefs::kAutofillDialogPayWithoutWallet));
1979 EXPECT_FALSE(profile()->GetPrefs()->GetBoolean( 1906 EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(
1980 ::prefs::kAutofillDialogPayWithoutWallet)); 1907 ::prefs::kAutofillDialogPayWithoutWallet));
1981 } 1908 }
1982 1909
1983 TEST_F(AutofillDialogControllerTest, HideWalletEmail) { 1910 TEST_F(AutofillDialogControllerTest, HideWalletEmail) {
1984 SwitchToAutofill(); 1911 SwitchToAutofill();
1985 1912
1986 // Email section should be showing when using Autofill. 1913 // Email field should be showing when using Autofill.
1987 EXPECT_TRUE(controller()->SectionIsActive(SECTION_EMAIL)); 1914 EXPECT_TRUE(controller()->SectionIsActive(SECTION_BILLING));
1915 EXPECT_FALSE(controller()->SectionIsActive(SECTION_CC_BILLING));
1916 EXPECT_TRUE(SectionContainsField(SECTION_BILLING, EMAIL_ADDRESS));
1988 1917
1989 SwitchToWallet(); 1918 SwitchToWallet();
1990 1919
1991 // Setup some wallet state, submit, and get a full wallet to end the flow. 1920 // Setup some wallet state, submit, and get a full wallet to end the flow.
1992 scoped_ptr<wallet::WalletItems> wallet_items = CompleteAndValidWalletItems(); 1921 scoped_ptr<wallet::WalletItems> wallet_items = CompleteAndValidWalletItems();
1993 1922
1994 // Filling |form_structure()| depends on the current username and wallet items 1923 // Filling |form_structure()| depends on the current username and wallet items
1995 // being fetched. Until both of these have occurred, the user should not be 1924 // being fetched. Until both of these have occurred, the user should not be
1996 // able to click Submit if using Wallet. The username fetch happened earlier. 1925 // able to click Submit if using Wallet. The username fetch happened earlier.
1997 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1926 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1998 controller()->OnDidGetWalletItems(wallet_items.Pass()); 1927 controller()->OnDidGetWalletItems(wallet_items.Pass());
1999 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1928 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2000 1929
2001 // Email section should be hidden when using Wallet. 1930 // Email field should be absent when using Wallet.
2002 EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL)); 1931 EXPECT_FALSE(controller()->SectionIsActive(SECTION_BILLING));
1932 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING));
1933 EXPECT_FALSE(SectionContainsField(SECTION_CC_BILLING, EMAIL_ADDRESS));
2003 1934
2004 controller()->OnAccept(); 1935 controller()->OnAccept();
2005 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 1936 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
2006 controller()->ForceFinishSubmit(); 1937 controller()->ForceFinishSubmit();
2007 1938
2008 ASSERT_TRUE(form_structure()); 1939 ASSERT_TRUE(form_structure());
2009 size_t i = 0; 1940 size_t i = 0;
2010 for (; i < form_structure()->field_count(); ++i) { 1941 for (; i < form_structure()->field_count(); ++i) {
2011 if (form_structure()->field(i)->Type().GetStorableType() == EMAIL_ADDRESS) { 1942 if (form_structure()->field(i)->Type().GetStorableType() == EMAIL_ADDRESS) {
2012 EXPECT_EQ(ASCIIToUTF16(kFakeEmail), form_structure()->field(i)->value); 1943 EXPECT_EQ(ASCIIToUTF16(kFakeEmail), form_structure()->field(i)->value);
2013 break; 1944 break;
2014 } 1945 }
2015 } 1946 }
2016 ASSERT_LT(i, form_structure()->field_count()); 1947 EXPECT_LT(i, form_structure()->field_count());
2017 } 1948 }
2018 1949
2019 // Test if autofill types of returned form structure are correct for billing 1950 // Test if autofill types of returned form structure are correct for billing
2020 // entries. 1951 // entries.
2021 TEST_F(AutofillDialogControllerTest, AutofillTypes) { 1952 TEST_F(AutofillDialogControllerTest, AutofillTypes) {
2022 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); 1953 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
2023 controller()->OnAccept(); 1954 controller()->OnAccept();
2024 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 1955 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
2025 controller()->ForceFinishSubmit(); 1956 controller()->ForceFinishSubmit();
2026 ASSERT_TRUE(form_structure()); 1957 ASSERT_TRUE(form_structure());
(...skipping 14 matching lines...) Expand all
2041 SwitchToAutofill(); 1972 SwitchToAutofill();
2042 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); 1973 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2);
2043 1974
2044 AutofillProfile full_profile(test::GetVerifiedProfile()); 1975 AutofillProfile full_profile(test::GetVerifiedProfile());
2045 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 1976 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
2046 1977
2047 CreditCard card(test::GetVerifiedCreditCard()); 1978 CreditCard card(test::GetVerifiedCreditCard());
2048 controller()->GetTestingManager()->AddTestingCreditCard(&card); 1979 controller()->GetTestingManager()->AddTestingCreditCard(&card);
2049 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 1980 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
2050 1981
2051 controller()->EditClickedForSection(SECTION_EMAIL); 1982 controller()->EditClickedForSection(SECTION_BILLING);
2052 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); 1983 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome());
2053 1984
2054 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(0); 1985 controller()->MenuModelForSection(SECTION_BILLING)->ActivatedAt(0);
2055 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 1986 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
2056 1987
2057 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); 1988 controller()->MenuModelForSection(SECTION_BILLING)->ActivatedAt(1);
2058 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); 1989 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome());
2059 1990
2060 profile()->ForceIncognito(true); 1991 profile()->ForceIncognito(true);
2061 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 1992 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
2062 } 1993 }
2063 1994
2064 // Tests that user is prompted when using instrument with minimal address. 1995 // Tests that user is prompted when using instrument with minimal address.
2065 TEST_F(AutofillDialogControllerTest, UpgradeMinimalAddress) { 1996 TEST_F(AutofillDialogControllerTest, UpgradeMinimalAddress) {
2066 // A minimal address being selected should trigger error validation in the 1997 // A minimal address being selected should trigger error validation in the
2067 // view. Called once for each incomplete suggestion. 1998 // view. Called once for each incomplete suggestion.
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
2373 SaveInChromePreferenceRememberedOnSuccess) { 2304 SaveInChromePreferenceRememberedOnSuccess) {
2374 EXPECT_TRUE(controller()->ShouldSaveInChrome()); 2305 EXPECT_TRUE(controller()->ShouldSaveInChrome());
2375 SwitchToAutofill(); 2306 SwitchToAutofill();
2376 FillCreditCardInputs(); 2307 FillCreditCardInputs();
2377 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(false); 2308 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(false);
2378 controller()->OnAccept(); 2309 controller()->OnAccept();
2379 EXPECT_FALSE(controller()->ShouldSaveInChrome()); 2310 EXPECT_FALSE(controller()->ShouldSaveInChrome());
2380 } 2311 }
2381 2312
2382 } // namespace autofill 2313 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc ('k') | chrome/browser/ui/autofill/autofill_dialog_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698