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

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

Issue 22040002: [Autofill] Add a separate enumeration for HTML field type hints. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix browser test Created 7 years, 4 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 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 CreditCard credit_card(test::GetVerifiedCreditCard()); 1004 CreditCard credit_card(test::GetVerifiedCreditCard());
1005 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 1005 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1006 controller()->GetTestingManager()->AddTestingProfile(&full_profile2); 1006 controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
1007 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); 1007 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
1008 ui::MenuModel* shipping_model = 1008 ui::MenuModel* shipping_model =
1009 controller()->MenuModelForSection(SECTION_SHIPPING); 1009 controller()->MenuModelForSection(SECTION_SHIPPING);
1010 shipping_model->ActivatedAt(2); 1010 shipping_model->ActivatedAt(2);
1011 1011
1012 controller()->OnAccept(); 1012 controller()->OnAccept();
1013 ASSERT_EQ(20U, form_structure()->field_count()); 1013 ASSERT_EQ(20U, form_structure()->field_count());
1014 EXPECT_EQ(ADDRESS_BILLING_STATE,
1015 form_structure()->field(9)->Type().server_type());
1016 EXPECT_EQ(ADDRESS_HOME_STATE, 1014 EXPECT_EQ(ADDRESS_HOME_STATE,
1017 form_structure()->field(16)->Type().server_type()); 1015 form_structure()->field(9)->Type().GetStorableType());
1016 EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group());
1017 EXPECT_EQ(ADDRESS_HOME_STATE,
1018 form_structure()->field(16)->Type().GetStorableType());
1019 EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group());
1018 string16 billing_state = form_structure()->field(9)->value; 1020 string16 billing_state = form_structure()->field(9)->value;
1019 string16 shipping_state = form_structure()->field(16)->value; 1021 string16 shipping_state = form_structure()->field(16)->value;
1020 EXPECT_FALSE(billing_state.empty()); 1022 EXPECT_FALSE(billing_state.empty());
1021 EXPECT_FALSE(shipping_state.empty()); 1023 EXPECT_FALSE(shipping_state.empty());
1022 EXPECT_NE(billing_state, shipping_state); 1024 EXPECT_NE(billing_state, shipping_state);
1023 1025
1024 EXPECT_EQ(CREDIT_CARD_NAME, form_structure()->field(1)->Type().server_type()); 1026 EXPECT_EQ(CREDIT_CARD_NAME,
1027 form_structure()->field(1)->Type().GetStorableType());
1025 string16 cc_name = form_structure()->field(1)->value; 1028 string16 cc_name = form_structure()->field(1)->value;
1026 EXPECT_EQ(NAME_BILLING_FULL, 1029 EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType());
1027 form_structure()->field(6)->Type().server_type()); 1030 EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group());
1028 string16 billing_name = form_structure()->field(6)->value; 1031 string16 billing_name = form_structure()->field(6)->value;
1029 EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().server_type()); 1032 EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType());
1033 EXPECT_EQ(NAME, form_structure()->field(13)->Type().group());
1030 string16 shipping_name = form_structure()->field(13)->value; 1034 string16 shipping_name = form_structure()->field(13)->value;
1031 1035
1032 EXPECT_FALSE(cc_name.empty()); 1036 EXPECT_FALSE(cc_name.empty());
1033 EXPECT_FALSE(billing_name.empty()); 1037 EXPECT_FALSE(billing_name.empty());
1034 EXPECT_FALSE(shipping_name.empty()); 1038 EXPECT_FALSE(shipping_name.empty());
1035 // Billing name should always be the same as cardholder name. 1039 // Billing name should always be the same as cardholder name.
1036 EXPECT_EQ(cc_name, billing_name); 1040 EXPECT_EQ(cc_name, billing_name);
1037 EXPECT_NE(cc_name, shipping_name); 1041 EXPECT_NE(cc_name, shipping_name);
1038 } 1042 }
1039 1043
1040 // Test selecting UseBillingForShipping. 1044 // Test selecting UseBillingForShipping.
1041 TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) { 1045 TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) {
1042 AutofillProfile full_profile(test::GetVerifiedProfile()); 1046 AutofillProfile full_profile(test::GetVerifiedProfile());
1043 AutofillProfile full_profile2(test::GetVerifiedProfile2()); 1047 AutofillProfile full_profile2(test::GetVerifiedProfile2());
1044 CreditCard credit_card(test::GetVerifiedCreditCard()); 1048 CreditCard credit_card(test::GetVerifiedCreditCard());
1045 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 1049 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1046 controller()->GetTestingManager()->AddTestingProfile(&full_profile2); 1050 controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
1047 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); 1051 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
1048 1052
1049 // Test after setting use billing for shipping. 1053 // Test after setting use billing for shipping.
1050 UseBillingForShipping(); 1054 UseBillingForShipping();
1051 1055
1052 controller()->OnAccept(); 1056 controller()->OnAccept();
1053 ASSERT_EQ(20U, form_structure()->field_count()); 1057 ASSERT_EQ(20U, form_structure()->field_count());
1054 EXPECT_EQ(ADDRESS_BILLING_STATE,
1055 form_structure()->field(9)->Type().server_type());
1056 EXPECT_EQ(ADDRESS_HOME_STATE, 1058 EXPECT_EQ(ADDRESS_HOME_STATE,
1057 form_structure()->field(16)->Type().server_type()); 1059 form_structure()->field(9)->Type().GetStorableType());
1060 EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group());
1061 EXPECT_EQ(ADDRESS_HOME_STATE,
1062 form_structure()->field(16)->Type().GetStorableType());
1063 EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group());
1058 string16 billing_state = form_structure()->field(9)->value; 1064 string16 billing_state = form_structure()->field(9)->value;
1059 string16 shipping_state = form_structure()->field(16)->value; 1065 string16 shipping_state = form_structure()->field(16)->value;
1060 EXPECT_FALSE(billing_state.empty()); 1066 EXPECT_FALSE(billing_state.empty());
1061 EXPECT_FALSE(shipping_state.empty()); 1067 EXPECT_FALSE(shipping_state.empty());
1062 EXPECT_EQ(billing_state, shipping_state); 1068 EXPECT_EQ(billing_state, shipping_state);
1063 1069
1064 EXPECT_EQ(CREDIT_CARD_NAME, 1070 EXPECT_EQ(CREDIT_CARD_NAME,
1065 form_structure()->field(1)->Type().server_type()); 1071 form_structure()->field(1)->Type().GetStorableType());
1066 string16 cc_name = form_structure()->field(1)->value; 1072 string16 cc_name = form_structure()->field(1)->value;
1067 EXPECT_EQ(NAME_BILLING_FULL, 1073 EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType());
1068 form_structure()->field(6)->Type().server_type()); 1074 EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group());
1069 string16 billing_name = form_structure()->field(6)->value; 1075 string16 billing_name = form_structure()->field(6)->value;
1070 EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().server_type()); 1076 EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType());
1077 EXPECT_EQ(NAME, form_structure()->field(13)->Type().group());
1071 string16 shipping_name = form_structure()->field(13)->value; 1078 string16 shipping_name = form_structure()->field(13)->value;
1072 1079
1073 EXPECT_FALSE(cc_name.empty()); 1080 EXPECT_FALSE(cc_name.empty());
1074 EXPECT_FALSE(billing_name.empty()); 1081 EXPECT_FALSE(billing_name.empty());
1075 EXPECT_FALSE(shipping_name.empty()); 1082 EXPECT_FALSE(shipping_name.empty());
1076 EXPECT_EQ(cc_name, billing_name); 1083 EXPECT_EQ(cc_name, billing_name);
1077 EXPECT_EQ(cc_name, shipping_name); 1084 EXPECT_EQ(cc_name, shipping_name);
1078 } 1085 }
1079 1086
1080 // Tests that shipping and billing telephone fields are supported, and filled 1087 // Tests that shipping and billing telephone fields are supported, and filled
(...skipping 17 matching lines...) Expand all
1098 controller()->GetTestingManager()->AddTestingProfile(&shipping_profile); 1105 controller()->GetTestingManager()->AddTestingProfile(&shipping_profile);
1099 controller()->GetTestingManager()->AddTestingProfile(&billing_profile); 1106 controller()->GetTestingManager()->AddTestingProfile(&billing_profile);
1100 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); 1107 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
1101 ui::MenuModel* billing_model = 1108 ui::MenuModel* billing_model =
1102 controller()->MenuModelForSection(SECTION_BILLING); 1109 controller()->MenuModelForSection(SECTION_BILLING);
1103 billing_model->ActivatedAt(1); 1110 billing_model->ActivatedAt(1);
1104 1111
1105 controller()->OnAccept(); 1112 controller()->OnAccept();
1106 ASSERT_EQ(2U, form_structure()->field_count()); 1113 ASSERT_EQ(2U, form_structure()->field_count());
1107 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, 1114 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
1108 form_structure()->field(0)->Type().server_type()); 1115 form_structure()->field(0)->Type().GetStorableType());
1109 EXPECT_EQ(PHONE_BILLING_WHOLE_NUMBER, 1116 EXPECT_EQ(PHONE_HOME, form_structure()->field(0)->Type().group());
1110 form_structure()->field(1)->Type().server_type()); 1117 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
1118 form_structure()->field(1)->Type().GetStorableType());
1119 EXPECT_EQ(PHONE_BILLING, form_structure()->field(1)->Type().group());
1111 EXPECT_EQ(shipping_profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER), 1120 EXPECT_EQ(shipping_profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER),
1112 form_structure()->field(0)->value); 1121 form_structure()->field(0)->value);
1113 EXPECT_EQ(billing_profile.GetRawInfo(PHONE_BILLING_WHOLE_NUMBER), 1122 EXPECT_EQ(billing_profile.GetRawInfo(PHONE_BILLING_WHOLE_NUMBER),
1114 form_structure()->field(1)->value); 1123 form_structure()->field(1)->value);
1115 EXPECT_NE(form_structure()->field(1)->value, 1124 EXPECT_NE(form_structure()->field(1)->value,
1116 form_structure()->field(0)->value); 1125 form_structure()->field(0)->value);
1117 } 1126 }
1118 1127
1119 TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) { 1128 TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) {
1120 EXPECT_CALL(*controller()->GetTestingWalletClient(), 1129 EXPECT_CALL(*controller()->GetTestingWalletClient(),
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 2043 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2035 2044
2036 // Email section should be hidden when using Wallet. 2045 // Email section should be hidden when using Wallet.
2037 EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL)); 2046 EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL));
2038 2047
2039 controller()->OnAccept(); 2048 controller()->OnAccept();
2040 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 2049 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
2041 2050
2042 size_t i = 0; 2051 size_t i = 0;
2043 for (; i < form_structure()->field_count(); ++i) { 2052 for (; i < form_structure()->field_count(); ++i) {
2044 if (form_structure()->field(i)->Type().server_type() == EMAIL_ADDRESS) { 2053 if (form_structure()->field(i)->Type().GetStorableType() == EMAIL_ADDRESS) {
2045 EXPECT_EQ(ASCIIToUTF16(kFakeEmail), form_structure()->field(i)->value); 2054 EXPECT_EQ(ASCIIToUTF16(kFakeEmail), form_structure()->field(i)->value);
2046 break; 2055 break;
2047 } 2056 }
2048 } 2057 }
2049 ASSERT_LT(i, form_structure()->field_count()); 2058 ASSERT_LT(i, form_structure()->field_count());
2050 } 2059 }
2051 2060
2052 // Test if autofill types of returned form structure are correct for billing 2061 // Test if autofill types of returned form structure are correct for billing
2053 // entries. 2062 // entries.
2054 TEST_F(AutofillDialogControllerTest, AutofillTypes) { 2063 TEST_F(AutofillDialogControllerTest, AutofillTypes) {
2055 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); 2064 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
2056 controller()->OnAccept(); 2065 controller()->OnAccept();
2057 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 2066 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
2058 ASSERT_EQ(20U, form_structure()->field_count()); 2067 ASSERT_EQ(20U, form_structure()->field_count());
2059 EXPECT_EQ(EMAIL_ADDRESS, form_structure()->field(0)->Type().server_type()); 2068 EXPECT_EQ(EMAIL_ADDRESS,
2069 form_structure()->field(0)->Type().GetStorableType());
2060 EXPECT_EQ(CREDIT_CARD_NUMBER, 2070 EXPECT_EQ(CREDIT_CARD_NUMBER,
2061 form_structure()->field(2)->Type().server_type()); 2071 form_structure()->field(2)->Type().GetStorableType());
2062 EXPECT_EQ(ADDRESS_BILLING_STATE,
2063 form_structure()->field(9)->Type().server_type());
2064 EXPECT_EQ(ADDRESS_HOME_STATE, 2072 EXPECT_EQ(ADDRESS_HOME_STATE,
2065 form_structure()->field(16)->Type().server_type()); 2073 form_structure()->field(9)->Type().GetStorableType());
2074 EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group());
2075 EXPECT_EQ(ADDRESS_HOME_STATE,
2076 form_structure()->field(16)->Type().GetStorableType());
2077 EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group());
2066 } 2078 }
2067 2079
2068 TEST_F(AutofillDialogControllerTest, SaveDetailsInChrome) { 2080 TEST_F(AutofillDialogControllerTest, SaveDetailsInChrome) {
2069 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); 2081 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2);
2070 2082
2071 AutofillProfile full_profile(test::GetVerifiedProfile()); 2083 AutofillProfile full_profile(test::GetVerifiedProfile());
2072 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 2084 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
2073 2085
2074 CreditCard card(test::GetVerifiedCreditCard()); 2086 CreditCard card(test::GetVerifiedCreditCard());
2075 controller()->GetTestingManager()->AddTestingCreditCard(&card); 2087 controller()->GetTestingManager()->AddTestingCreditCard(&card);
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
2481 EXPECT_CALL(*test_bubble_controller(), ShowAsNewCardSavedBubble(_)).Times(0); 2493 EXPECT_CALL(*test_bubble_controller(), ShowAsNewCardSavedBubble(_)).Times(0);
2482 2494
2483 SubmitWithWalletItems(CompleteAndValidWalletItems()); 2495 SubmitWithWalletItems(CompleteAndValidWalletItems());
2484 controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); 2496 controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT);
2485 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 2497 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
2486 controller()->OnAutocheckoutError(); 2498 controller()->OnAutocheckoutError();
2487 controller()->ViewClosed(); 2499 controller()->ViewClosed();
2488 } 2500 }
2489 2501
2490 } // namespace autofill 2502 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc ('k') | chrome/browser/ui/autofill/data_model_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698