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" |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 CreditCard credit_card(test::GetVerifiedCreditCard()); | 926 CreditCard credit_card(test::GetVerifiedCreditCard()); |
927 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 927 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
928 controller()->GetTestingManager()->AddTestingProfile(&full_profile2); | 928 controller()->GetTestingManager()->AddTestingProfile(&full_profile2); |
929 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); | 929 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); |
930 ui::MenuModel* shipping_model = | 930 ui::MenuModel* shipping_model = |
931 controller()->MenuModelForSection(SECTION_SHIPPING); | 931 controller()->MenuModelForSection(SECTION_SHIPPING); |
932 shipping_model->ActivatedAt(2); | 932 shipping_model->ActivatedAt(2); |
933 | 933 |
934 controller()->OnAccept(); | 934 controller()->OnAccept(); |
935 ASSERT_EQ(20U, form_structure()->field_count()); | 935 ASSERT_EQ(20U, form_structure()->field_count()); |
936 EXPECT_EQ(ADDRESS_BILLING_STATE, | |
937 form_structure()->field(9)->Type().native_type()); | |
938 EXPECT_EQ(ADDRESS_HOME_STATE, | 936 EXPECT_EQ(ADDRESS_HOME_STATE, |
939 form_structure()->field(16)->Type().native_type()); | 937 form_structure()->field(9)->Type().GetEquivalentNativeType()); |
| 938 EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group()); |
| 939 EXPECT_EQ(ADDRESS_HOME_STATE, |
| 940 form_structure()->field(16)->Type().GetEquivalentNativeType()); |
| 941 EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group()); |
940 string16 billing_state = form_structure()->field(9)->value; | 942 string16 billing_state = form_structure()->field(9)->value; |
941 string16 shipping_state = form_structure()->field(16)->value; | 943 string16 shipping_state = form_structure()->field(16)->value; |
942 EXPECT_FALSE(billing_state.empty()); | 944 EXPECT_FALSE(billing_state.empty()); |
943 EXPECT_FALSE(shipping_state.empty()); | 945 EXPECT_FALSE(shipping_state.empty()); |
944 EXPECT_NE(billing_state, shipping_state); | 946 EXPECT_NE(billing_state, shipping_state); |
945 | 947 |
946 EXPECT_EQ(CREDIT_CARD_NAME, form_structure()->field(1)->Type().native_type()); | 948 EXPECT_EQ(CREDIT_CARD_NAME, |
| 949 form_structure()->field(1)->Type().GetEquivalentNativeType()); |
947 string16 cc_name = form_structure()->field(1)->value; | 950 string16 cc_name = form_structure()->field(1)->value; |
948 EXPECT_EQ(NAME_BILLING_FULL, | 951 EXPECT_EQ(NAME_FULL, |
949 form_structure()->field(6)->Type().native_type()); | 952 form_structure()->field(6)->Type().GetEquivalentNativeType()); |
| 953 EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group()); |
950 string16 billing_name = form_structure()->field(6)->value; | 954 string16 billing_name = form_structure()->field(6)->value; |
951 EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().native_type()); | 955 EXPECT_EQ(NAME_FULL, |
| 956 form_structure()->field(13)->Type().GetEquivalentNativeType()); |
| 957 EXPECT_EQ(NAME, form_structure()->field(13)->Type().group()); |
952 string16 shipping_name = form_structure()->field(13)->value; | 958 string16 shipping_name = form_structure()->field(13)->value; |
953 | 959 |
954 EXPECT_FALSE(cc_name.empty()); | 960 EXPECT_FALSE(cc_name.empty()); |
955 EXPECT_FALSE(billing_name.empty()); | 961 EXPECT_FALSE(billing_name.empty()); |
956 EXPECT_FALSE(shipping_name.empty()); | 962 EXPECT_FALSE(shipping_name.empty()); |
957 // Billing name should always be the same as cardholder name. | 963 // Billing name should always be the same as cardholder name. |
958 EXPECT_EQ(cc_name, billing_name); | 964 EXPECT_EQ(cc_name, billing_name); |
959 EXPECT_NE(cc_name, shipping_name); | 965 EXPECT_NE(cc_name, shipping_name); |
960 } | 966 } |
961 | 967 |
962 // Test selecting UseBillingForShipping. | 968 // Test selecting UseBillingForShipping. |
963 TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) { | 969 TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) { |
964 AutofillProfile full_profile(test::GetVerifiedProfile()); | 970 AutofillProfile full_profile(test::GetVerifiedProfile()); |
965 AutofillProfile full_profile2(test::GetVerifiedProfile2()); | 971 AutofillProfile full_profile2(test::GetVerifiedProfile2()); |
966 CreditCard credit_card(test::GetVerifiedCreditCard()); | 972 CreditCard credit_card(test::GetVerifiedCreditCard()); |
967 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 973 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
968 controller()->GetTestingManager()->AddTestingProfile(&full_profile2); | 974 controller()->GetTestingManager()->AddTestingProfile(&full_profile2); |
969 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); | 975 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); |
970 | 976 |
971 // Test after setting use billing for shipping. | 977 // Test after setting use billing for shipping. |
972 UseBillingForShipping(); | 978 UseBillingForShipping(); |
973 | 979 |
974 controller()->OnAccept(); | 980 controller()->OnAccept(); |
975 ASSERT_EQ(20U, form_structure()->field_count()); | 981 ASSERT_EQ(20U, form_structure()->field_count()); |
976 EXPECT_EQ(ADDRESS_BILLING_STATE, | |
977 form_structure()->field(9)->Type().native_type()); | |
978 EXPECT_EQ(ADDRESS_HOME_STATE, | 982 EXPECT_EQ(ADDRESS_HOME_STATE, |
979 form_structure()->field(16)->Type().native_type()); | 983 form_structure()->field(9)->Type().GetEquivalentNativeType()); |
| 984 EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group()); |
| 985 EXPECT_EQ(ADDRESS_HOME_STATE, |
| 986 form_structure()->field(16)->Type().GetEquivalentNativeType()); |
| 987 EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group()); |
980 string16 billing_state = form_structure()->field(9)->value; | 988 string16 billing_state = form_structure()->field(9)->value; |
981 string16 shipping_state = form_structure()->field(16)->value; | 989 string16 shipping_state = form_structure()->field(16)->value; |
982 EXPECT_FALSE(billing_state.empty()); | 990 EXPECT_FALSE(billing_state.empty()); |
983 EXPECT_FALSE(shipping_state.empty()); | 991 EXPECT_FALSE(shipping_state.empty()); |
984 EXPECT_EQ(billing_state, shipping_state); | 992 EXPECT_EQ(billing_state, shipping_state); |
985 | 993 |
986 EXPECT_EQ(CREDIT_CARD_NAME, | 994 EXPECT_EQ(CREDIT_CARD_NAME, |
987 form_structure()->field(1)->Type().native_type()); | 995 form_structure()->field(1)->Type().GetEquivalentNativeType()); |
988 string16 cc_name = form_structure()->field(1)->value; | 996 string16 cc_name = form_structure()->field(1)->value; |
989 EXPECT_EQ(NAME_BILLING_FULL, | 997 EXPECT_EQ(NAME_FULL, |
990 form_structure()->field(6)->Type().native_type()); | 998 form_structure()->field(6)->Type().GetEquivalentNativeType()); |
| 999 EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group()); |
991 string16 billing_name = form_structure()->field(6)->value; | 1000 string16 billing_name = form_structure()->field(6)->value; |
992 EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().native_type()); | 1001 EXPECT_EQ(NAME_FULL, |
| 1002 form_structure()->field(13)->Type().GetEquivalentNativeType()); |
| 1003 EXPECT_EQ(NAME, form_structure()->field(13)->Type().group()); |
993 string16 shipping_name = form_structure()->field(13)->value; | 1004 string16 shipping_name = form_structure()->field(13)->value; |
994 | 1005 |
995 EXPECT_FALSE(cc_name.empty()); | 1006 EXPECT_FALSE(cc_name.empty()); |
996 EXPECT_FALSE(billing_name.empty()); | 1007 EXPECT_FALSE(billing_name.empty()); |
997 EXPECT_FALSE(shipping_name.empty()); | 1008 EXPECT_FALSE(shipping_name.empty()); |
998 EXPECT_EQ(cc_name, billing_name); | 1009 EXPECT_EQ(cc_name, billing_name); |
999 EXPECT_EQ(cc_name, shipping_name); | 1010 EXPECT_EQ(cc_name, shipping_name); |
1000 } | 1011 } |
1001 | 1012 |
1002 // Tests that shipping and billing telephone fields are supported, and filled | 1013 // Tests that shipping and billing telephone fields are supported, and filled |
(...skipping 17 matching lines...) Expand all Loading... |
1020 controller()->GetTestingManager()->AddTestingProfile(&shipping_profile); | 1031 controller()->GetTestingManager()->AddTestingProfile(&shipping_profile); |
1021 controller()->GetTestingManager()->AddTestingProfile(&billing_profile); | 1032 controller()->GetTestingManager()->AddTestingProfile(&billing_profile); |
1022 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); | 1033 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); |
1023 ui::MenuModel* billing_model = | 1034 ui::MenuModel* billing_model = |
1024 controller()->MenuModelForSection(SECTION_BILLING); | 1035 controller()->MenuModelForSection(SECTION_BILLING); |
1025 billing_model->ActivatedAt(1); | 1036 billing_model->ActivatedAt(1); |
1026 | 1037 |
1027 controller()->OnAccept(); | 1038 controller()->OnAccept(); |
1028 ASSERT_EQ(2U, form_structure()->field_count()); | 1039 ASSERT_EQ(2U, form_structure()->field_count()); |
1029 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, | 1040 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, |
1030 form_structure()->field(0)->Type().native_type()); | 1041 form_structure()->field(0)->Type().GetEquivalentNativeType()); |
1031 EXPECT_EQ(PHONE_BILLING_WHOLE_NUMBER, | 1042 EXPECT_EQ(PHONE_HOME, form_structure()->field(0)->Type().group()); |
1032 form_structure()->field(1)->Type().native_type()); | 1043 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, |
| 1044 form_structure()->field(1)->Type().GetEquivalentNativeType()); |
| 1045 EXPECT_EQ(PHONE_BILLING, form_structure()->field(1)->Type().group()); |
1033 EXPECT_EQ(shipping_profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER), | 1046 EXPECT_EQ(shipping_profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER), |
1034 form_structure()->field(0)->value); | 1047 form_structure()->field(0)->value); |
1035 EXPECT_EQ(billing_profile.GetRawInfo(PHONE_BILLING_WHOLE_NUMBER), | 1048 EXPECT_EQ(billing_profile.GetRawInfo(PHONE_BILLING_WHOLE_NUMBER), |
1036 form_structure()->field(1)->value); | 1049 form_structure()->field(1)->value); |
1037 EXPECT_NE(form_structure()->field(1)->value, | 1050 EXPECT_NE(form_structure()->field(1)->value, |
1038 form_structure()->field(0)->value); | 1051 form_structure()->field(0)->value); |
1039 } | 1052 } |
1040 | 1053 |
1041 TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) { | 1054 TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) { |
1042 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1055 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1956 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1969 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1957 | 1970 |
1958 // Email section should be hidden when using Wallet. | 1971 // Email section should be hidden when using Wallet. |
1959 EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL)); | 1972 EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL)); |
1960 | 1973 |
1961 controller()->OnAccept(); | 1974 controller()->OnAccept(); |
1962 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); | 1975 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); |
1963 | 1976 |
1964 size_t i = 0; | 1977 size_t i = 0; |
1965 for (; i < form_structure()->field_count(); ++i) { | 1978 for (; i < form_structure()->field_count(); ++i) { |
1966 if (form_structure()->field(i)->Type().native_type() == EMAIL_ADDRESS) { | 1979 if (form_structure()->field(i)->Type().GetEquivalentNativeType() == |
| 1980 EMAIL_ADDRESS) { |
1967 EXPECT_EQ(ASCIIToUTF16(kFakeEmail), form_structure()->field(i)->value); | 1981 EXPECT_EQ(ASCIIToUTF16(kFakeEmail), form_structure()->field(i)->value); |
1968 break; | 1982 break; |
1969 } | 1983 } |
1970 } | 1984 } |
1971 ASSERT_LT(i, form_structure()->field_count()); | 1985 ASSERT_LT(i, form_structure()->field_count()); |
1972 } | 1986 } |
1973 | 1987 |
1974 // Test if autofill types of returned form structure are correct for billing | 1988 // Test if autofill types of returned form structure are correct for billing |
1975 // entries. | 1989 // entries. |
1976 TEST_F(AutofillDialogControllerTest, AutofillTypes) { | 1990 TEST_F(AutofillDialogControllerTest, AutofillTypes) { |
1977 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); | 1991 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); |
1978 controller()->OnAccept(); | 1992 controller()->OnAccept(); |
1979 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); | 1993 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); |
1980 ASSERT_EQ(20U, form_structure()->field_count()); | 1994 ASSERT_EQ(20U, form_structure()->field_count()); |
1981 EXPECT_EQ(EMAIL_ADDRESS, form_structure()->field(0)->Type().native_type()); | 1995 EXPECT_EQ(EMAIL_ADDRESS, |
| 1996 form_structure()->field(0)->Type().GetEquivalentNativeType()); |
1982 EXPECT_EQ(CREDIT_CARD_NUMBER, | 1997 EXPECT_EQ(CREDIT_CARD_NUMBER, |
1983 form_structure()->field(2)->Type().native_type()); | 1998 form_structure()->field(2)->Type().GetEquivalentNativeType()); |
1984 EXPECT_EQ(ADDRESS_BILLING_STATE, | |
1985 form_structure()->field(9)->Type().native_type()); | |
1986 EXPECT_EQ(ADDRESS_HOME_STATE, | 1999 EXPECT_EQ(ADDRESS_HOME_STATE, |
1987 form_structure()->field(16)->Type().native_type()); | 2000 form_structure()->field(9)->Type().GetEquivalentNativeType()); |
| 2001 EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group()); |
| 2002 EXPECT_EQ(ADDRESS_HOME_STATE, |
| 2003 form_structure()->field(16)->Type().GetEquivalentNativeType()); |
| 2004 EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group()); |
1988 } | 2005 } |
1989 | 2006 |
1990 TEST_F(AutofillDialogControllerTest, SaveDetailsInChrome) { | 2007 TEST_F(AutofillDialogControllerTest, SaveDetailsInChrome) { |
1991 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); | 2008 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); |
1992 | 2009 |
1993 AutofillProfile full_profile(test::GetVerifiedProfile()); | 2010 AutofillProfile full_profile(test::GetVerifiedProfile()); |
1994 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 2011 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
1995 | 2012 |
1996 CreditCard card(test::GetVerifiedCreditCard()); | 2013 CreditCard card(test::GetVerifiedCreditCard()); |
1997 controller()->GetTestingManager()->AddTestingCreditCard(&card); | 2014 controller()->GetTestingManager()->AddTestingCreditCard(&card); |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2402 EXPECT_CALL(*test_bubble_controller(), ShowAsNewCardSavedBubble(_)).Times(0); | 2419 EXPECT_CALL(*test_bubble_controller(), ShowAsNewCardSavedBubble(_)).Times(0); |
2403 | 2420 |
2404 SubmitWithWalletItems(CompleteAndValidWalletItems()); | 2421 SubmitWithWalletItems(CompleteAndValidWalletItems()); |
2405 controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); | 2422 controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); |
2406 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); | 2423 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); |
2407 controller()->OnAutocheckoutError(); | 2424 controller()->OnAutocheckoutError(); |
2408 controller()->ViewClosed(); | 2425 controller()->ViewClosed(); |
2409 } | 2426 } |
2410 | 2427 |
2411 } // namespace autofill | 2428 } // namespace autofill |
OLD | NEW |