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

Side by Side Diff: components/autofill/core/browser/personal_data_manager_unittest.cc

Issue 2776223002: Adds UKM for autofill attributes in form_structure. (Closed)
Patch Set: Resolves merge conflicts with FORM_CONTAINS_UPI_VPA_HINT. Created 3 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/autofill/core/browser/personal_data_manager.h" 5 #include "components/autofill/core/browser/personal_data_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 return personal_data_->ImportCreditCard(form, should_return_local_card, 257 return personal_data_->ImportCreditCard(form, should_return_local_card,
258 imported_credit_card); 258 imported_credit_card);
259 } 259 }
260 260
261 void SubmitFormAndExpectImportedCardWithData(const FormData& form, 261 void SubmitFormAndExpectImportedCardWithData(const FormData& form,
262 const char* exp_name, 262 const char* exp_name,
263 const char* exp_cc_num, 263 const char* exp_cc_num,
264 const char* exp_cc_month, 264 const char* exp_cc_month,
265 const char* exp_cc_year) { 265 const char* exp_cc_year) {
266 FormStructure form_structure(form); 266 FormStructure form_structure(form);
267 form_structure.DetermineHeuristicTypes(); 267 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
268 std::unique_ptr<CreditCard> imported_credit_card; 268 std::unique_ptr<CreditCard> imported_credit_card;
269 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 269 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
270 ASSERT_TRUE(imported_credit_card); 270 ASSERT_TRUE(imported_credit_card);
271 personal_data_->SaveImportedCreditCard(*imported_credit_card); 271 personal_data_->SaveImportedCreditCard(*imported_credit_card);
272 272
273 // Verify that the web database has been updated and the notification sent. 273 // Verify that the web database has been updated and the notification sent.
274 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 274 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
275 .WillOnce(QuitMainMessageLoop()); 275 .WillOnce(QuitMainMessageLoop());
276 base::RunLoop().Run(); 276 base::RunLoop().Run();
277 277
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 test::CreateTestFormField( 1026 test::CreateTestFormField(
1027 "Address:", "address1", "21 Laussat St", "text", &field); 1027 "Address:", "address1", "21 Laussat St", "text", &field);
1028 form.fields.push_back(field); 1028 form.fields.push_back(field);
1029 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); 1029 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
1030 form.fields.push_back(field); 1030 form.fields.push_back(field);
1031 test::CreateTestFormField("State:", "state", "California", "text", &field); 1031 test::CreateTestFormField("State:", "state", "California", "text", &field);
1032 form.fields.push_back(field); 1032 form.fields.push_back(field);
1033 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1033 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1034 form.fields.push_back(field); 1034 form.fields.push_back(field);
1035 FormStructure form_structure(form); 1035 FormStructure form_structure(form);
1036 form_structure.DetermineHeuristicTypes(); 1036 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
1037 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1037 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1038 1038
1039 // Verify that the web database has been updated and the notification sent. 1039 // Verify that the web database has been updated and the notification sent.
1040 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1040 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1041 .WillOnce(QuitMainMessageLoop()); 1041 .WillOnce(QuitMainMessageLoop());
1042 base::RunLoop().Run(); 1042 base::RunLoop().Run();
1043 1043
1044 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1044 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1045 test::SetProfileInfo(&expected, "George", NULL, 1045 test::SetProfileInfo(&expected, "George", NULL,
1046 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, 1046 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL,
(...skipping 17 matching lines...) Expand all
1064 test::CreateTestFormField( 1064 test::CreateTestFormField(
1065 "Address:", "address1", "21 Laussat St", "text", &field); 1065 "Address:", "address1", "21 Laussat St", "text", &field);
1066 form.fields.push_back(field); 1066 form.fields.push_back(field);
1067 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); 1067 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
1068 form.fields.push_back(field); 1068 form.fields.push_back(field);
1069 test::CreateTestFormField("State:", "state", "California", "text", &field); 1069 test::CreateTestFormField("State:", "state", "California", "text", &field);
1070 form.fields.push_back(field); 1070 form.fields.push_back(field);
1071 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1071 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1072 form.fields.push_back(field); 1072 form.fields.push_back(field);
1073 FormStructure form_structure(form); 1073 FormStructure form_structure(form);
1074 form_structure.DetermineHeuristicTypes(); 1074 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
1075 EXPECT_FALSE(ImportAddressProfiles(form_structure)); 1075 EXPECT_FALSE(ImportAddressProfiles(form_structure));
1076 1076
1077 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 1077 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
1078 ASSERT_EQ(0U, results.size()); 1078 ASSERT_EQ(0U, results.size());
1079 } 1079 }
1080 1080
1081 // Tests that a 'confirm email' field does not block profile import. 1081 // Tests that a 'confirm email' field does not block profile import.
1082 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_TwoEmails) { 1082 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_TwoEmails) {
1083 FormData form; 1083 FormData form;
1084 FormFieldData field; 1084 FormFieldData field;
1085 test::CreateTestFormField( 1085 test::CreateTestFormField(
1086 "Name:", "name", "George Washington", "text", &field); 1086 "Name:", "name", "George Washington", "text", &field);
1087 form.fields.push_back(field); 1087 form.fields.push_back(field);
1088 test::CreateTestFormField( 1088 test::CreateTestFormField(
1089 "Address:", "address1", "21 Laussat St", "text", &field); 1089 "Address:", "address1", "21 Laussat St", "text", &field);
1090 form.fields.push_back(field); 1090 form.fields.push_back(field);
1091 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); 1091 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
1092 form.fields.push_back(field); 1092 form.fields.push_back(field);
1093 test::CreateTestFormField("State:", "state", "California", "text", &field); 1093 test::CreateTestFormField("State:", "state", "California", "text", &field);
1094 form.fields.push_back(field); 1094 form.fields.push_back(field);
1095 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1095 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1096 form.fields.push_back(field); 1096 form.fields.push_back(field);
1097 test::CreateTestFormField( 1097 test::CreateTestFormField(
1098 "Email:", "email", "example@example.com", "text", &field); 1098 "Email:", "email", "example@example.com", "text", &field);
1099 form.fields.push_back(field); 1099 form.fields.push_back(field);
1100 test::CreateTestFormField( 1100 test::CreateTestFormField(
1101 "Confirm email:", "confirm_email", "example@example.com", "text", &field); 1101 "Confirm email:", "confirm_email", "example@example.com", "text", &field);
1102 form.fields.push_back(field); 1102 form.fields.push_back(field);
1103 FormStructure form_structure(form); 1103 FormStructure form_structure(form);
1104 form_structure.DetermineHeuristicTypes(); 1104 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
1105 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1105 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1106 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 1106 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
1107 ASSERT_EQ(1U, results.size()); 1107 ASSERT_EQ(1U, results.size());
1108 } 1108 }
1109 1109
1110 // Tests two email fields containing different values blocks profile import. 1110 // Tests two email fields containing different values blocks profile import.
1111 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_TwoDifferentEmails) { 1111 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_TwoDifferentEmails) {
1112 FormData form; 1112 FormData form;
1113 FormFieldData field; 1113 FormFieldData field;
1114 test::CreateTestFormField( 1114 test::CreateTestFormField(
1115 "Name:", "name", "George Washington", "text", &field); 1115 "Name:", "name", "George Washington", "text", &field);
1116 form.fields.push_back(field); 1116 form.fields.push_back(field);
1117 test::CreateTestFormField( 1117 test::CreateTestFormField(
1118 "Address:", "address1", "21 Laussat St", "text", &field); 1118 "Address:", "address1", "21 Laussat St", "text", &field);
1119 form.fields.push_back(field); 1119 form.fields.push_back(field);
1120 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); 1120 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
1121 form.fields.push_back(field); 1121 form.fields.push_back(field);
1122 test::CreateTestFormField("State:", "state", "California", "text", &field); 1122 test::CreateTestFormField("State:", "state", "California", "text", &field);
1123 form.fields.push_back(field); 1123 form.fields.push_back(field);
1124 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1124 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1125 form.fields.push_back(field); 1125 form.fields.push_back(field);
1126 test::CreateTestFormField( 1126 test::CreateTestFormField(
1127 "Email:", "email", "example@example.com", "text", &field); 1127 "Email:", "email", "example@example.com", "text", &field);
1128 form.fields.push_back(field); 1128 form.fields.push_back(field);
1129 test::CreateTestFormField( 1129 test::CreateTestFormField(
1130 "Email:", "email2", "example2@example.com", "text", &field); 1130 "Email:", "email2", "example2@example.com", "text", &field);
1131 form.fields.push_back(field); 1131 form.fields.push_back(field);
1132 FormStructure form_structure(form); 1132 FormStructure form_structure(form);
1133 form_structure.DetermineHeuristicTypes(); 1133 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
1134 EXPECT_FALSE(ImportAddressProfiles(form_structure)); 1134 EXPECT_FALSE(ImportAddressProfiles(form_structure));
1135 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 1135 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
1136 ASSERT_EQ(0U, results.size()); 1136 ASSERT_EQ(0U, results.size());
1137 } 1137 }
1138 1138
1139 // Tests that not enough filled fields will result in not importing an address. 1139 // Tests that not enough filled fields will result in not importing an address.
1140 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_NotEnoughFilledFields) { 1140 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_NotEnoughFilledFields) {
1141 FormData form; 1141 FormData form;
1142 FormFieldData field; 1142 FormFieldData field;
1143 test::CreateTestFormField( 1143 test::CreateTestFormField(
1144 "First name:", "first_name", "George", "text", &field); 1144 "First name:", "first_name", "George", "text", &field);
1145 form.fields.push_back(field); 1145 form.fields.push_back(field);
1146 test::CreateTestFormField( 1146 test::CreateTestFormField(
1147 "Last name:", "last_name", "Washington", "text", &field); 1147 "Last name:", "last_name", "Washington", "text", &field);
1148 form.fields.push_back(field); 1148 form.fields.push_back(field);
1149 test::CreateTestFormField( 1149 test::CreateTestFormField(
1150 "Card number:", "card_number", "4111 1111 1111 1111", "text", &field); 1150 "Card number:", "card_number", "4111 1111 1111 1111", "text", &field);
1151 form.fields.push_back(field); 1151 form.fields.push_back(field);
1152 FormStructure form_structure(form); 1152 FormStructure form_structure(form);
1153 form_structure.DetermineHeuristicTypes(); 1153 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
1154 EXPECT_FALSE(ImportAddressProfiles(form_structure)); 1154 EXPECT_FALSE(ImportAddressProfiles(form_structure));
1155 1155
1156 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); 1156 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
1157 ASSERT_EQ(0U, profiles.size()); 1157 ASSERT_EQ(0U, profiles.size());
1158 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); 1158 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards();
1159 ASSERT_EQ(0U, cards.size()); 1159 ASSERT_EQ(0U, cards.size());
1160 } 1160 }
1161 1161
1162 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_MinimumAddressUSA) { 1162 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_MinimumAddressUSA) {
1163 // United States addresses must specifiy one address line, a city, state and 1163 // United States addresses must specifiy one address line, a city, state and
1164 // zip code. 1164 // zip code.
1165 FormData form; 1165 FormData form;
1166 FormFieldData field; 1166 FormFieldData field;
1167 test::CreateTestFormField("Name:", "name", "Barack Obama", "text", &field); 1167 test::CreateTestFormField("Name:", "name", "Barack Obama", "text", &field);
1168 form.fields.push_back(field); 1168 form.fields.push_back(field);
1169 test::CreateTestFormField( 1169 test::CreateTestFormField(
1170 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field); 1170 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field);
1171 form.fields.push_back(field); 1171 form.fields.push_back(field);
1172 test::CreateTestFormField("City:", "city", "Washington", "text", &field); 1172 test::CreateTestFormField("City:", "city", "Washington", "text", &field);
1173 form.fields.push_back(field); 1173 form.fields.push_back(field);
1174 test::CreateTestFormField("State:", "state", "DC", "text", &field); 1174 test::CreateTestFormField("State:", "state", "DC", "text", &field);
1175 form.fields.push_back(field); 1175 form.fields.push_back(field);
1176 test::CreateTestFormField("Zip:", "zip", "20500", "text", &field); 1176 test::CreateTestFormField("Zip:", "zip", "20500", "text", &field);
1177 form.fields.push_back(field); 1177 form.fields.push_back(field);
1178 test::CreateTestFormField("Country:", "country", "USA", "text", &field); 1178 test::CreateTestFormField("Country:", "country", "USA", "text", &field);
1179 form.fields.push_back(field); 1179 form.fields.push_back(field);
1180 FormStructure form_structure(form); 1180 FormStructure form_structure(form);
1181 form_structure.DetermineHeuristicTypes(); 1181 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
1182 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1182 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1183 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); 1183 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
1184 ASSERT_EQ(1U, profiles.size()); 1184 ASSERT_EQ(1U, profiles.size());
1185 } 1185 }
1186 1186
1187 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_MinimumAddressGB) { 1187 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_MinimumAddressGB) {
1188 // British addresses do not require a state/province as the county is usually 1188 // British addresses do not require a state/province as the county is usually
1189 // not requested on forms. 1189 // not requested on forms.
1190 FormData form; 1190 FormData form;
1191 FormFieldData field; 1191 FormFieldData field;
1192 test::CreateTestFormField("Name:", "name", "David Cameron", "text", &field); 1192 test::CreateTestFormField("Name:", "name", "David Cameron", "text", &field);
1193 form.fields.push_back(field); 1193 form.fields.push_back(field);
1194 test::CreateTestFormField( 1194 test::CreateTestFormField(
1195 "Address:", "address", "10 Downing Street", "text", &field); 1195 "Address:", "address", "10 Downing Street", "text", &field);
1196 form.fields.push_back(field); 1196 form.fields.push_back(field);
1197 test::CreateTestFormField("City:", "city", "London", "text", &field); 1197 test::CreateTestFormField("City:", "city", "London", "text", &field);
1198 form.fields.push_back(field); 1198 form.fields.push_back(field);
1199 test::CreateTestFormField( 1199 test::CreateTestFormField(
1200 "Postcode:", "postcode", "SW1A 2AA", "text", &field); 1200 "Postcode:", "postcode", "SW1A 2AA", "text", &field);
1201 form.fields.push_back(field); 1201 form.fields.push_back(field);
1202 test::CreateTestFormField( 1202 test::CreateTestFormField(
1203 "Country:", "country", "United Kingdom", "text", &field); 1203 "Country:", "country", "United Kingdom", "text", &field);
1204 form.fields.push_back(field); 1204 form.fields.push_back(field);
1205 FormStructure form_structure(form); 1205 FormStructure form_structure(form);
1206 form_structure.DetermineHeuristicTypes(); 1206 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
1207 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1207 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1208 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); 1208 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
1209 ASSERT_EQ(1U, profiles.size()); 1209 ASSERT_EQ(1U, profiles.size());
1210 } 1210 }
1211 1211
1212 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_MinimumAddressGI) { 1212 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_MinimumAddressGI) {
1213 // Gibraltar has the most minimal set of requirements for a valid address. 1213 // Gibraltar has the most minimal set of requirements for a valid address.
1214 // There are no cities or provinces and no postal/zip code system. 1214 // There are no cities or provinces and no postal/zip code system.
1215 FormData form; 1215 FormData form;
1216 FormFieldData field; 1216 FormFieldData field;
1217 test::CreateTestFormField( 1217 test::CreateTestFormField(
1218 "Name:", "name", "Sir Adrian Johns", "text", &field); 1218 "Name:", "name", "Sir Adrian Johns", "text", &field);
1219 form.fields.push_back(field); 1219 form.fields.push_back(field);
1220 test::CreateTestFormField( 1220 test::CreateTestFormField(
1221 "Address:", "address", "The Convent, Main Street", "text", &field); 1221 "Address:", "address", "The Convent, Main Street", "text", &field);
1222 form.fields.push_back(field); 1222 form.fields.push_back(field);
1223 test::CreateTestFormField("Country:", "country", "Gibraltar", "text", &field); 1223 test::CreateTestFormField("Country:", "country", "Gibraltar", "text", &field);
1224 form.fields.push_back(field); 1224 form.fields.push_back(field);
1225 FormStructure form_structure(form); 1225 FormStructure form_structure(form);
1226 form_structure.DetermineHeuristicTypes(); 1226 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
1227 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1227 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1228 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); 1228 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
1229 ASSERT_EQ(1U, profiles.size()); 1229 ASSERT_EQ(1U, profiles.size());
1230 } 1230 }
1231 1231
1232 TEST_F(PersonalDataManagerTest, 1232 TEST_F(PersonalDataManagerTest,
1233 ImportAddressProfiles_PhoneNumberSplitAcrossMultipleFields) { 1233 ImportAddressProfiles_PhoneNumberSplitAcrossMultipleFields) {
1234 FormData form; 1234 FormData form;
1235 FormFieldData field; 1235 FormFieldData field;
1236 test::CreateTestFormField( 1236 test::CreateTestFormField(
(...skipping 17 matching lines...) Expand all
1254 test::CreateTestFormField( 1254 test::CreateTestFormField(
1255 "Address:", "address1", "21 Laussat St", "text", &field); 1255 "Address:", "address1", "21 Laussat St", "text", &field);
1256 form.fields.push_back(field); 1256 form.fields.push_back(field);
1257 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); 1257 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
1258 form.fields.push_back(field); 1258 form.fields.push_back(field);
1259 test::CreateTestFormField("State:", "state", "California", "text", &field); 1259 test::CreateTestFormField("State:", "state", "California", "text", &field);
1260 form.fields.push_back(field); 1260 form.fields.push_back(field);
1261 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1261 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1262 form.fields.push_back(field); 1262 form.fields.push_back(field);
1263 FormStructure form_structure(form); 1263 FormStructure form_structure(form);
1264 form_structure.DetermineHeuristicTypes(); 1264 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
1265 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1265 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1266 1266
1267 // Verify that the web database has been updated and the notification sent. 1267 // Verify that the web database has been updated and the notification sent.
1268 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1268 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1269 .WillOnce(QuitMainMessageLoop()); 1269 .WillOnce(QuitMainMessageLoop());
1270 base::RunLoop().Run(); 1270 base::RunLoop().Run();
1271 1271
1272 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1272 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1273 test::SetProfileInfo(&expected, "George", NULL, 1273 test::SetProfileInfo(&expected, "George", NULL,
1274 "Washington", NULL, NULL, "21 Laussat St", NULL, 1274 "Washington", NULL, NULL, "21 Laussat St", NULL,
(...skipping 23 matching lines...) Expand all
1298 "textarea", 1298 "textarea",
1299 &field); 1299 &field);
1300 form.fields.push_back(field); 1300 form.fields.push_back(field);
1301 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); 1301 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
1302 form.fields.push_back(field); 1302 form.fields.push_back(field);
1303 test::CreateTestFormField("State:", "state", "California", "text", &field); 1303 test::CreateTestFormField("State:", "state", "California", "text", &field);
1304 form.fields.push_back(field); 1304 form.fields.push_back(field);
1305 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1305 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1306 form.fields.push_back(field); 1306 form.fields.push_back(field);
1307 FormStructure form_structure(form); 1307 FormStructure form_structure(form);
1308 form_structure.DetermineHeuristicTypes(); 1308 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
1309 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1309 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1310 1310
1311 // Verify that the web database has been updated and the notification sent. 1311 // Verify that the web database has been updated and the notification sent.
1312 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1312 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1313 .WillOnce(QuitMainMessageLoop()); 1313 .WillOnce(QuitMainMessageLoop());
1314 base::RunLoop().Run(); 1314 base::RunLoop().Run();
1315 1315
1316 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1316 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1317 test::SetProfileInfo(&expected, "George", NULL, 1317 test::SetProfileInfo(&expected, "George", NULL,
1318 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", "Apt. #42", 1318 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", "Apt. #42",
(...skipping 20 matching lines...) Expand all
1339 "Address:", "address1", "21 Laussat St", "text", &field); 1339 "Address:", "address1", "21 Laussat St", "text", &field);
1340 form1.fields.push_back(field); 1340 form1.fields.push_back(field);
1341 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); 1341 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
1342 form1.fields.push_back(field); 1342 form1.fields.push_back(field);
1343 test::CreateTestFormField("State:", "state", "California", "text", &field); 1343 test::CreateTestFormField("State:", "state", "California", "text", &field);
1344 form1.fields.push_back(field); 1344 form1.fields.push_back(field);
1345 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1345 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1346 form1.fields.push_back(field); 1346 form1.fields.push_back(field);
1347 1347
1348 FormStructure form_structure1(form1); 1348 FormStructure form_structure1(form1);
1349 form_structure1.DetermineHeuristicTypes(); 1349 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
1350 EXPECT_TRUE(ImportAddressProfiles(form_structure1)); 1350 EXPECT_TRUE(ImportAddressProfiles(form_structure1));
1351 1351
1352 // Verify that the web database has been updated and the notification sent. 1352 // Verify that the web database has been updated and the notification sent.
1353 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1353 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1354 .WillOnce(QuitMainMessageLoop()); 1354 .WillOnce(QuitMainMessageLoop());
1355 base::RunLoop().Run(); 1355 base::RunLoop().Run();
1356 1356
1357 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1357 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1358 test::SetProfileInfo(&expected, "George", NULL, 1358 test::SetProfileInfo(&expected, "George", NULL,
1359 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, 1359 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL,
(...skipping 17 matching lines...) Expand all
1377 "Address:", "address1", "22 Laussat St", "text", &field); 1377 "Address:", "address1", "22 Laussat St", "text", &field);
1378 form2.fields.push_back(field); 1378 form2.fields.push_back(field);
1379 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); 1379 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
1380 form2.fields.push_back(field); 1380 form2.fields.push_back(field);
1381 test::CreateTestFormField("State:", "state", "California", "text", &field); 1381 test::CreateTestFormField("State:", "state", "California", "text", &field);
1382 form2.fields.push_back(field); 1382 form2.fields.push_back(field);
1383 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1383 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1384 form2.fields.push_back(field); 1384 form2.fields.push_back(field);
1385 1385
1386 FormStructure form_structure2(form2); 1386 FormStructure form_structure2(form2);
1387 form_structure2.DetermineHeuristicTypes(); 1387 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
1388 EXPECT_TRUE(ImportAddressProfiles(form_structure2)); 1388 EXPECT_TRUE(ImportAddressProfiles(form_structure2));
1389 1389
1390 // Verify that the web database has been updated and the notification sent. 1390 // Verify that the web database has been updated and the notification sent.
1391 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1391 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1392 .WillOnce(QuitMainMessageLoop()); 1392 .WillOnce(QuitMainMessageLoop());
1393 base::RunLoop().Run(); 1393 base::RunLoop().Run();
1394 1394
1395 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com"); 1395 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com");
1396 test::SetProfileInfo(&expected2, "John", NULL, 1396 test::SetProfileInfo(&expected2, "John", NULL,
1397 "Adams", "second@gmail.com", NULL, "22 Laussat St", NULL, 1397 "Adams", "second@gmail.com", NULL, "22 Laussat St", NULL,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 &field); 1438 &field);
1439 form.fields.push_back(field); 1439 form.fields.push_back(field);
1440 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); 1440 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
1441 form.fields.push_back(field); 1441 form.fields.push_back(field);
1442 test::CreateTestFormField("State:", "state", "California", "text", &field); 1442 test::CreateTestFormField("State:", "state", "California", "text", &field);
1443 form.fields.push_back(field); 1443 form.fields.push_back(field);
1444 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1444 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1445 form.fields.push_back(field); 1445 form.fields.push_back(field);
1446 1446
1447 FormStructure form_structure(form); 1447 FormStructure form_structure(form);
1448 form_structure.DetermineHeuristicTypes(); 1448 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
1449 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1449 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1450 1450
1451 // Verify that the web database has been updated and the notification sent. 1451 // Verify that the web database has been updated and the notification sent.
1452 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1452 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1453 .WillOnce(QuitMainMessageLoop()); 1453 .WillOnce(QuitMainMessageLoop());
1454 base::RunLoop().Run(); 1454 base::RunLoop().Run();
1455 1455
1456 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1456 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1457 test::SetProfileInfo(&expected, "George", NULL, "Washington", 1457 test::SetProfileInfo(&expected, "George", NULL, "Washington",
1458 "theprez@gmail.com", NULL, "21 Laussat St", NULL, 1458 "theprez@gmail.com", NULL, "21 Laussat St", NULL,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 form.fields.push_back(field); 1516 form.fields.push_back(field);
1517 test::CreateTestFormField("State:", "state", "", "text", &field); 1517 test::CreateTestFormField("State:", "state", "", "text", &field);
1518 field.is_focusable = false; 1518 field.is_focusable = false;
1519 form.fields.push_back(field); 1519 form.fields.push_back(field);
1520 test::CreateTestFormField("Zip:", "zip", "", "text", &field); 1520 test::CreateTestFormField("Zip:", "zip", "", "text", &field);
1521 field.is_focusable = false; 1521 field.is_focusable = false;
1522 form.fields.push_back(field); 1522 form.fields.push_back(field);
1523 1523
1524 // Still able to do the import. 1524 // Still able to do the import.
1525 FormStructure form_structure(form); 1525 FormStructure form_structure(form);
1526 form_structure.DetermineHeuristicTypes(); 1526 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
1527 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1527 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1528 1528
1529 // Verify that the web database has been updated and the notification sent. 1529 // Verify that the web database has been updated and the notification sent.
1530 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1530 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1531 .WillOnce(QuitMainMessageLoop()); 1531 .WillOnce(QuitMainMessageLoop());
1532 base::RunLoop().Run(); 1532 base::RunLoop().Run();
1533 1533
1534 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1534 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1535 test::SetProfileInfo(&expected, "George", NULL, "Washington", 1535 test::SetProfileInfo(&expected, "George", NULL, "Washington",
1536 "theprez@gmail.com", NULL, "21 Laussat St", NULL, 1536 "theprez@gmail.com", NULL, "21 Laussat St", NULL,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 test::CreateTestFormField("City:", "city", "London", "text", &field); 1600 test::CreateTestFormField("City:", "city", "London", "text", &field);
1601 form.fields.push_back(field); 1601 form.fields.push_back(field);
1602 test::CreateTestFormField("Postcode:", "postcode", "SW1A 2AA", "text", 1602 test::CreateTestFormField("Postcode:", "postcode", "SW1A 2AA", "text",
1603 &field); 1603 &field);
1604 form.fields.push_back(field); 1604 form.fields.push_back(field);
1605 test::CreateTestFormField("Country:", "country", "United Kingdom", "text", 1605 test::CreateTestFormField("Country:", "country", "United Kingdom", "text",
1606 &field); 1606 &field);
1607 form.fields.push_back(field); 1607 form.fields.push_back(field);
1608 1608
1609 FormStructure form_structure(form); 1609 FormStructure form_structure(form);
1610 form_structure.DetermineHeuristicTypes(); 1610 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
1611 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1611 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1612 1612
1613 // Verify that the web database has been updated and the notification sent. 1613 // Verify that the web database has been updated and the notification sent.
1614 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1614 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1615 .WillOnce(QuitMainMessageLoop()); 1615 .WillOnce(QuitMainMessageLoop());
1616 base::RunLoop().Run(); 1616 base::RunLoop().Run();
1617 1617
1618 // Only two are saved. 1618 // Only two are saved.
1619 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1619 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1620 test::SetProfileInfo(&expected, "George", NULL, "Washington", 1620 test::SetProfileInfo(&expected, "George", NULL, "Washington",
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 form1.fields.push_back(field); 1655 form1.fields.push_back(field);
1656 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1656 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1657 form1.fields.push_back(field); 1657 form1.fields.push_back(field);
1658 test::CreateTestFormField( 1658 test::CreateTestFormField(
1659 "Email:", "email", "theprez@gmail.com", "text", &field); 1659 "Email:", "email", "theprez@gmail.com", "text", &field);
1660 form1.fields.push_back(field); 1660 form1.fields.push_back(field);
1661 test::CreateTestFormField("Phone:", "phone", "6505556666", "text", &field); 1661 test::CreateTestFormField("Phone:", "phone", "6505556666", "text", &field);
1662 form1.fields.push_back(field); 1662 form1.fields.push_back(field);
1663 1663
1664 FormStructure form_structure1(form1); 1664 FormStructure form_structure1(form1);
1665 form_structure1.DetermineHeuristicTypes(); 1665 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
1666 EXPECT_TRUE(ImportAddressProfiles(form_structure1)); 1666 EXPECT_TRUE(ImportAddressProfiles(form_structure1));
1667 1667
1668 // Verify that the web database has been updated and the notification sent. 1668 // Verify that the web database has been updated and the notification sent.
1669 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1669 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1670 .WillOnce(QuitMainMessageLoop()); 1670 .WillOnce(QuitMainMessageLoop());
1671 base::RunLoop().Run(); 1671 base::RunLoop().Run();
1672 1672
1673 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1673 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1674 test::SetProfileInfo(&expected, "George", nullptr, "Washington", 1674 test::SetProfileInfo(&expected, "George", nullptr, "Washington",
1675 "theprez@gmail.com", nullptr, "1600 Pennsylvania Avenue", 1675 "theprez@gmail.com", nullptr, "1600 Pennsylvania Avenue",
(...skipping 27 matching lines...) Expand all
1703 "Email:", "email", "theprez@gmail.com", "text", &field); 1703 "Email:", "email", "theprez@gmail.com", "text", &field);
1704 form2.fields.push_back(field); 1704 form2.fields.push_back(field);
1705 // Country gets added. 1705 // Country gets added.
1706 test::CreateTestFormField("Country:", "country", "USA", "text", &field); 1706 test::CreateTestFormField("Country:", "country", "USA", "text", &field);
1707 form2.fields.push_back(field); 1707 form2.fields.push_back(field);
1708 // Same phone number with different formatting doesn't create a new profile. 1708 // Same phone number with different formatting doesn't create a new profile.
1709 test::CreateTestFormField("Phone:", "phone", "650-555-6666", "text", &field); 1709 test::CreateTestFormField("Phone:", "phone", "650-555-6666", "text", &field);
1710 form2.fields.push_back(field); 1710 form2.fields.push_back(field);
1711 1711
1712 FormStructure form_structure2(form2); 1712 FormStructure form_structure2(form2);
1713 form_structure2.DetermineHeuristicTypes(); 1713 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
1714 EXPECT_TRUE(ImportAddressProfiles(form_structure2)); 1714 EXPECT_TRUE(ImportAddressProfiles(form_structure2));
1715 1715
1716 // Verify that the web database has been updated and the notification sent. 1716 // Verify that the web database has been updated and the notification sent.
1717 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1717 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1718 .WillOnce(QuitMainMessageLoop()); 1718 .WillOnce(QuitMainMessageLoop());
1719 base::RunLoop().Run(); 1719 base::RunLoop().Run();
1720 1720
1721 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 1721 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
1722 1722
1723 // Full name, phone formatting and country are updated. 1723 // Full name, phone formatting and country are updated.
(...skipping 17 matching lines...) Expand all
1741 "Address Line 1:", "address", "190 High Street", "text", &field); 1741 "Address Line 1:", "address", "190 High Street", "text", &field);
1742 form1.fields.push_back(field); 1742 form1.fields.push_back(field);
1743 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); 1743 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field);
1744 form1.fields.push_back(field); 1744 form1.fields.push_back(field);
1745 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field); 1745 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field);
1746 form1.fields.push_back(field); 1746 form1.fields.push_back(field);
1747 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); 1747 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field);
1748 form1.fields.push_back(field); 1748 form1.fields.push_back(field);
1749 1749
1750 FormStructure form_structure1(form1); 1750 FormStructure form_structure1(form1);
1751 form_structure1.DetermineHeuristicTypes(); 1751 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
1752 EXPECT_TRUE(ImportAddressProfiles(form_structure1)); 1752 EXPECT_TRUE(ImportAddressProfiles(form_structure1));
1753 1753
1754 // Verify that the web database has been updated and the notification sent. 1754 // Verify that the web database has been updated and the notification sent.
1755 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1755 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1756 .WillOnce(QuitMainMessageLoop()); 1756 .WillOnce(QuitMainMessageLoop());
1757 base::RunLoop().Run(); 1757 base::RunLoop().Run();
1758 1758
1759 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1759 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1760 test::SetProfileInfo(&expected, "George", NULL, 1760 test::SetProfileInfo(&expected, "George", NULL,
1761 "Washington", NULL, NULL, "190 High Street", NULL, 1761 "Washington", NULL, NULL, "190 High Street", NULL,
(...skipping 17 matching lines...) Expand all
1779 "Address Line 1:", "address", "190 High Street", "text", &field); 1779 "Address Line 1:", "address", "190 High Street", "text", &field);
1780 form2.fields.push_back(field); 1780 form2.fields.push_back(field);
1781 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); 1781 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field);
1782 form2.fields.push_back(field); 1782 form2.fields.push_back(field);
1783 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field); 1783 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field);
1784 form2.fields.push_back(field); 1784 form2.fields.push_back(field);
1785 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); 1785 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field);
1786 form2.fields.push_back(field); 1786 form2.fields.push_back(field);
1787 1787
1788 FormStructure form_structure2(form2); 1788 FormStructure form_structure2(form2);
1789 form_structure2.DetermineHeuristicTypes(); 1789 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
1790 EXPECT_TRUE(ImportAddressProfiles(form_structure2)); 1790 EXPECT_TRUE(ImportAddressProfiles(form_structure2));
1791 1791
1792 // Verify that the web database has been updated and the notification sent. 1792 // Verify that the web database has been updated and the notification sent.
1793 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1793 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1794 .WillOnce(QuitMainMessageLoop()); 1794 .WillOnce(QuitMainMessageLoop());
1795 base::RunLoop().Run(); 1795 base::RunLoop().Run();
1796 1796
1797 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 1797 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
1798 1798
1799 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com"); 1799 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com");
(...skipping 24 matching lines...) Expand all
1824 "Address Line 1:", "address", "190 High Street", "text", &field); 1824 "Address Line 1:", "address", "190 High Street", "text", &field);
1825 form1.fields.push_back(field); 1825 form1.fields.push_back(field);
1826 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); 1826 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field);
1827 form1.fields.push_back(field); 1827 form1.fields.push_back(field);
1828 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field); 1828 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field);
1829 form1.fields.push_back(field); 1829 form1.fields.push_back(field);
1830 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); 1830 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field);
1831 form1.fields.push_back(field); 1831 form1.fields.push_back(field);
1832 1832
1833 FormStructure form_structure1(form1); 1833 FormStructure form_structure1(form1);
1834 form_structure1.DetermineHeuristicTypes(); 1834 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
1835 EXPECT_TRUE(ImportAddressProfiles(form_structure1)); 1835 EXPECT_TRUE(ImportAddressProfiles(form_structure1));
1836 1836
1837 // Verify that the web database has been updated and the notification sent. 1837 // Verify that the web database has been updated and the notification sent.
1838 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1838 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1839 .WillOnce(QuitMainMessageLoop()); 1839 .WillOnce(QuitMainMessageLoop());
1840 base::RunLoop().Run(); 1840 base::RunLoop().Run();
1841 1841
1842 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1842 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1843 test::SetProfileInfo(&expected, "George", NULL, 1843 test::SetProfileInfo(&expected, "George", NULL,
1844 "Washington", "theprez@gmail.com", "Government", "190 High Street", NULL, 1844 "Washington", "theprez@gmail.com", "Government", "190 High Street", NULL,
(...skipping 18 matching lines...) Expand all
1863 "Address Line 1:", "address", "190 High Street", "text", &field); 1863 "Address Line 1:", "address", "190 High Street", "text", &field);
1864 form2.fields.push_back(field); 1864 form2.fields.push_back(field);
1865 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); 1865 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field);
1866 form2.fields.push_back(field); 1866 form2.fields.push_back(field);
1867 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field); 1867 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field);
1868 form2.fields.push_back(field); 1868 form2.fields.push_back(field);
1869 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); 1869 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field);
1870 form2.fields.push_back(field); 1870 form2.fields.push_back(field);
1871 1871
1872 FormStructure form_structure2(form2); 1872 FormStructure form_structure2(form2);
1873 form_structure2.DetermineHeuristicTypes(); 1873 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
1874 EXPECT_TRUE(ImportAddressProfiles(form_structure2)); 1874 EXPECT_TRUE(ImportAddressProfiles(form_structure2));
1875 1875
1876 // Verify that the web database has been updated and the notification sent. 1876 // Verify that the web database has been updated and the notification sent.
1877 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1877 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1878 .WillOnce(QuitMainMessageLoop()); 1878 .WillOnce(QuitMainMessageLoop());
1879 base::RunLoop().Run(); 1879 base::RunLoop().Run();
1880 1880
1881 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 1881 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
1882 1882
1883 // The merge operation will populate the full name if it's empty. 1883 // The merge operation will populate the full name if it's empty.
(...skipping 17 matching lines...) Expand all
1901 test::CreateTestFormField( 1901 test::CreateTestFormField(
1902 "Email:", "email", "theprez@gmail.com", "text", &field); 1902 "Email:", "email", "theprez@gmail.com", "text", &field);
1903 form1.fields.push_back(field); 1903 form1.fields.push_back(field);
1904 test::CreateTestFormField( 1904 test::CreateTestFormField(
1905 "Address Line 1:", "address", "190 High Street", "text", &field); 1905 "Address Line 1:", "address", "190 High Street", "text", &field);
1906 form1.fields.push_back(field); 1906 form1.fields.push_back(field);
1907 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); 1907 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field);
1908 form1.fields.push_back(field); 1908 form1.fields.push_back(field);
1909 1909
1910 FormStructure form_structure1(form1); 1910 FormStructure form_structure1(form1);
1911 form_structure1.DetermineHeuristicTypes(); 1911 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
1912 EXPECT_FALSE(ImportAddressProfiles(form_structure1)); 1912 EXPECT_FALSE(ImportAddressProfiles(form_structure1));
1913 1913
1914 // Since no refresh is expected, reload the data from the database to make 1914 // Since no refresh is expected, reload the data from the database to make
1915 // sure no changes were written out. 1915 // sure no changes were written out.
1916 ResetPersonalDataManager(USER_MODE_NORMAL); 1916 ResetPersonalDataManager(USER_MODE_NORMAL);
1917 1917
1918 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); 1918 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
1919 ASSERT_EQ(0U, profiles.size()); 1919 ASSERT_EQ(0U, profiles.size());
1920 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); 1920 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards();
1921 ASSERT_EQ(0U, cards.size()); 1921 ASSERT_EQ(0U, cards.size());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 &field); 1958 &field);
1959 form.fields.push_back(field); 1959 form.fields.push_back(field);
1960 test::CreateTestFormField("City:", "city", "Hollywood", "text", &field); 1960 test::CreateTestFormField("City:", "city", "Hollywood", "text", &field);
1961 form.fields.push_back(field); 1961 form.fields.push_back(field);
1962 test::CreateTestFormField("State:", "state", "CA", "text", &field); 1962 test::CreateTestFormField("State:", "state", "CA", "text", &field);
1963 form.fields.push_back(field); 1963 form.fields.push_back(field);
1964 test::CreateTestFormField("Zip:", "zip", "91601", "text", &field); 1964 test::CreateTestFormField("Zip:", "zip", "91601", "text", &field);
1965 form.fields.push_back(field); 1965 form.fields.push_back(field);
1966 1966
1967 FormStructure form_structure(form); 1967 FormStructure form_structure(form);
1968 form_structure.DetermineHeuristicTypes(); 1968 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
1969 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1969 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1970 1970
1971 // Wait for the refresh, which in this case is a no-op. 1971 // Wait for the refresh, which in this case is a no-op.
1972 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1972 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1973 .WillOnce(QuitMainMessageLoop()); 1973 .WillOnce(QuitMainMessageLoop());
1974 base::RunLoop().Run(); 1974 base::RunLoop().Run();
1975 1975
1976 // Expect that no new profile is saved. 1976 // Expect that no new profile is saved.
1977 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 1977 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
1978 ASSERT_EQ(1U, results.size()); 1978 ASSERT_EQ(1U, results.size());
1979 EXPECT_EQ(0, profile.Compare(*results[0])); 1979 EXPECT_EQ(0, profile.Compare(*results[0]));
1980 1980
1981 // Try the same thing, but without "Mitchell". The profiles should still match 1981 // Try the same thing, but without "Mitchell". The profiles should still match
1982 // because the non empty name pieces (first and last) match that stored in the 1982 // because the non empty name pieces (first and last) match that stored in the
1983 // profile. 1983 // profile.
1984 test::CreateTestFormField("First name:", "first_name", "Marion", "text", 1984 test::CreateTestFormField("First name:", "first_name", "Marion", "text",
1985 &field); 1985 &field);
1986 form.fields[0] = field; 1986 form.fields[0] = field;
1987 1987
1988 FormStructure form_structure2(form); 1988 FormStructure form_structure2(form);
1989 form_structure2.DetermineHeuristicTypes(); 1989 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
1990 EXPECT_TRUE(ImportAddressProfiles(form_structure2)); 1990 EXPECT_TRUE(ImportAddressProfiles(form_structure2));
1991 1991
1992 // Wait for the refresh, which in this case is a no-op. 1992 // Wait for the refresh, which in this case is a no-op.
1993 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1993 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1994 .WillOnce(QuitMainMessageLoop()); 1994 .WillOnce(QuitMainMessageLoop());
1995 base::RunLoop().Run(); 1995 base::RunLoop().Run();
1996 1996
1997 // Expect that no new profile is saved. 1997 // Expect that no new profile is saved.
1998 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 1998 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
1999 ASSERT_EQ(1U, results2.size()); 1999 ASSERT_EQ(1U, results2.size());
(...skipping 20 matching lines...) Expand all
2020 form.fields.push_back(field); 2020 form.fields.push_back(field);
2021 test::CreateTestFormField("State:", "state", "California", "text", &field); 2021 test::CreateTestFormField("State:", "state", "California", "text", &field);
2022 form.fields.push_back(field); 2022 form.fields.push_back(field);
2023 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 2023 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
2024 form.fields.push_back(field); 2024 form.fields.push_back(field);
2025 test::CreateTestFormField("Country:", "country", "Notacountry", "text", 2025 test::CreateTestFormField("Country:", "country", "Notacountry", "text",
2026 &field); 2026 &field);
2027 form.fields.push_back(field); 2027 form.fields.push_back(field);
2028 2028
2029 FormStructure form_structure(form); 2029 FormStructure form_structure(form);
2030 form_structure.DetermineHeuristicTypes(); 2030 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
2031 EXPECT_FALSE(ImportAddressProfiles(form_structure)); 2031 EXPECT_FALSE(ImportAddressProfiles(form_structure));
2032 2032
2033 // Since no refresh is expected, reload the data from the database to make 2033 // Since no refresh is expected, reload the data from the database to make
2034 // sure no changes were written out. 2034 // sure no changes were written out.
2035 ResetPersonalDataManager(USER_MODE_NORMAL); 2035 ResetPersonalDataManager(USER_MODE_NORMAL);
2036 2036
2037 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); 2037 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
2038 ASSERT_EQ(0U, profiles.size()); 2038 ASSERT_EQ(0U, profiles.size());
2039 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); 2039 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards();
2040 ASSERT_EQ(0U, cards.size()); 2040 ASSERT_EQ(0U, cards.size());
(...skipping 20 matching lines...) Expand all
2061 form.fields.push_back(field); 2061 form.fields.push_back(field);
2062 test::CreateTestFormField("State:", "state", "California", "text", &field); 2062 test::CreateTestFormField("State:", "state", "California", "text", &field);
2063 form.fields.push_back(field); 2063 form.fields.push_back(field);
2064 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 2064 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
2065 form.fields.push_back(field); 2065 form.fields.push_back(field);
2066 test::CreateTestFormField("Country:", "country", "Myanmar [Burma]", "text", 2066 test::CreateTestFormField("Country:", "country", "Myanmar [Burma]", "text",
2067 &field); 2067 &field);
2068 form.fields.push_back(field); 2068 form.fields.push_back(field);
2069 2069
2070 FormStructure form_structure(form); 2070 FormStructure form_structure(form);
2071 form_structure.DetermineHeuristicTypes(); 2071 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
2072 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 2072 EXPECT_TRUE(ImportAddressProfiles(form_structure));
2073 2073
2074 // Verify that the web database has been updated and the notification sent. 2074 // Verify that the web database has been updated and the notification sent.
2075 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2075 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2076 .WillOnce(QuitMainMessageLoop()); 2076 .WillOnce(QuitMainMessageLoop());
2077 base::RunLoop().Run(); 2077 base::RunLoop().Run();
2078 2078
2079 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 2079 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
2080 test::SetProfileInfo(&expected, "George", nullptr, "Washington", 2080 test::SetProfileInfo(&expected, "George", nullptr, "Washington",
2081 "theprez@gmail.com", nullptr, "21 Laussat St", nullptr, 2081 "theprez@gmail.com", nullptr, "21 Laussat St", nullptr,
(...skipping 28 matching lines...) Expand all
2110 test::CreateTestFormField("State:", "state", "California", "text", &field); 2110 test::CreateTestFormField("State:", "state", "California", "text", &field);
2111 form.fields.push_back(field); 2111 form.fields.push_back(field);
2112 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 2112 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
2113 form.fields.push_back(field); 2113 form.fields.push_back(field);
2114 test::CreateTestFormField("Country:", "country", 2114 test::CreateTestFormField("Country:", "country",
2115 "Myanmar", // Missing the [Burma] part 2115 "Myanmar", // Missing the [Burma] part
2116 "text", &field); 2116 "text", &field);
2117 form.fields.push_back(field); 2117 form.fields.push_back(field);
2118 2118
2119 FormStructure form_structure(form); 2119 FormStructure form_structure(form);
2120 form_structure.DetermineHeuristicTypes(); 2120 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
2121 EXPECT_FALSE(ImportAddressProfiles(form_structure)); 2121 EXPECT_FALSE(ImportAddressProfiles(form_structure));
2122 2122
2123 // Since no refresh is expected, reload the data from the database to make 2123 // Since no refresh is expected, reload the data from the database to make
2124 // sure no changes were written out. 2124 // sure no changes were written out.
2125 ResetPersonalDataManager(USER_MODE_NORMAL); 2125 ResetPersonalDataManager(USER_MODE_NORMAL);
2126 2126
2127 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); 2127 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
2128 ASSERT_EQ(0U, profiles.size()); 2128 ASSERT_EQ(0U, profiles.size());
2129 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); 2129 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards();
2130 ASSERT_EQ(0U, cards.size()); 2130 ASSERT_EQ(0U, cards.size());
2131 } 2131 }
2132 2132
2133 // ImportCreditCard tests. 2133 // ImportCreditCard tests.
2134 2134
2135 // Tests that a valid credit card is extracted. 2135 // Tests that a valid credit card is extracted.
2136 TEST_F(PersonalDataManagerTest, ImportCreditCard_Valid) { 2136 TEST_F(PersonalDataManagerTest, ImportCreditCard_Valid) {
2137 // Add a single valid credit card form. 2137 // Add a single valid credit card form.
2138 FormData form; 2138 FormData form;
2139 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", 2139 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01",
2140 "2999"); 2140 "2999");
2141 2141
2142 FormStructure form_structure(form); 2142 FormStructure form_structure(form);
2143 form_structure.DetermineHeuristicTypes(); 2143 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
2144 std::unique_ptr<CreditCard> imported_credit_card; 2144 std::unique_ptr<CreditCard> imported_credit_card;
2145 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 2145 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
2146 ASSERT_TRUE(imported_credit_card); 2146 ASSERT_TRUE(imported_credit_card);
2147 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2147 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2148 2148
2149 // Verify that the web database has been updated and the notification sent. 2149 // Verify that the web database has been updated and the notification sent.
2150 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2150 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2151 .WillOnce(QuitMainMessageLoop()); 2151 .WillOnce(QuitMainMessageLoop());
2152 base::RunLoop().Run(); 2152 base::RunLoop().Run();
2153 2153
2154 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2154 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2155 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", 2155 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01",
2156 "2999"); 2156 "2999");
2157 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2157 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2158 ASSERT_EQ(1U, results.size()); 2158 ASSERT_EQ(1U, results.size());
2159 EXPECT_EQ(0, expected.Compare(*results[0])); 2159 EXPECT_EQ(0, expected.Compare(*results[0]));
2160 } 2160 }
2161 2161
2162 // Tests that an invalid credit card is not extracted. 2162 // Tests that an invalid credit card is not extracted.
2163 TEST_F(PersonalDataManagerTest, ImportCreditCard_Invalid) { 2163 TEST_F(PersonalDataManagerTest, ImportCreditCard_Invalid) {
2164 FormData form; 2164 FormData form;
2165 AddFullCreditCardForm(&form, "Jim Johansen", "1000000000000000", "02", 2165 AddFullCreditCardForm(&form, "Jim Johansen", "1000000000000000", "02",
2166 "2999"); 2166 "2999");
2167 2167
2168 FormStructure form_structure(form); 2168 FormStructure form_structure(form);
2169 form_structure.DetermineHeuristicTypes(); 2169 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
2170 std::unique_ptr<CreditCard> imported_credit_card; 2170 std::unique_ptr<CreditCard> imported_credit_card;
2171 EXPECT_FALSE(ImportCreditCard(form_structure, false, &imported_credit_card)); 2171 EXPECT_FALSE(ImportCreditCard(form_structure, false, &imported_credit_card));
2172 ASSERT_FALSE(imported_credit_card); 2172 ASSERT_FALSE(imported_credit_card);
2173 2173
2174 // Since no refresh is expected, reload the data from the database to make 2174 // Since no refresh is expected, reload the data from the database to make
2175 // sure no changes were written out. 2175 // sure no changes were written out.
2176 ResetPersonalDataManager(USER_MODE_NORMAL); 2176 ResetPersonalDataManager(USER_MODE_NORMAL);
2177 2177
2178 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2178 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2179 ASSERT_EQ(0U, results.size()); 2179 ASSERT_EQ(0U, results.size());
(...skipping 13 matching lines...) Expand all
2193 values.push_back(ASCIIToUTF16("2")); 2193 values.push_back(ASCIIToUTF16("2"));
2194 values.push_back(ASCIIToUTF16("3")); 2194 values.push_back(ASCIIToUTF16("3"));
2195 std::vector<base::string16> contents; 2195 std::vector<base::string16> contents;
2196 contents.push_back(ASCIIToUTF16("Jan (1)")); 2196 contents.push_back(ASCIIToUTF16("Jan (1)"));
2197 contents.push_back(ASCIIToUTF16("Feb (2)")); 2197 contents.push_back(ASCIIToUTF16("Feb (2)"));
2198 contents.push_back(ASCIIToUTF16("Mar (3)")); 2198 contents.push_back(ASCIIToUTF16("Mar (3)"));
2199 form.fields[2].option_values = values; 2199 form.fields[2].option_values = values;
2200 form.fields[2].option_contents = contents; 2200 form.fields[2].option_contents = contents;
2201 2201
2202 FormStructure form_structure(form); 2202 FormStructure form_structure(form);
2203 form_structure.DetermineHeuristicTypes(); 2203 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
2204 std::unique_ptr<CreditCard> imported_credit_card; 2204 std::unique_ptr<CreditCard> imported_credit_card;
2205 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 2205 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
2206 ASSERT_TRUE(imported_credit_card); 2206 ASSERT_TRUE(imported_credit_card);
2207 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2207 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2208 2208
2209 // Verify that the web database has been updated and the notification sent. 2209 // Verify that the web database has been updated and the notification sent.
2210 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2210 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2211 .WillOnce(QuitMainMessageLoop()); 2211 .WillOnce(QuitMainMessageLoop());
2212 base::RunLoop().Run(); 2212 base::RunLoop().Run();
2213 2213
2214 // See that the invalid option text was converted to the right value. 2214 // See that the invalid option text was converted to the right value.
2215 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2215 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2216 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "02", 2216 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "02",
2217 "2999"); 2217 "2999");
2218 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2218 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2219 ASSERT_EQ(1U, results.size()); 2219 ASSERT_EQ(1U, results.size());
2220 EXPECT_EQ(0, expected.Compare(*results[0])); 2220 EXPECT_EQ(0, expected.Compare(*results[0]));
2221 } 2221 }
2222 2222
2223 TEST_F(PersonalDataManagerTest, ImportCreditCard_TwoValidCards) { 2223 TEST_F(PersonalDataManagerTest, ImportCreditCard_TwoValidCards) {
2224 // Start with a single valid credit card form. 2224 // Start with a single valid credit card form.
2225 FormData form1; 2225 FormData form1;
2226 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", 2226 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01",
2227 "2999"); 2227 "2999");
2228 2228
2229 FormStructure form_structure1(form1); 2229 FormStructure form_structure1(form1);
2230 form_structure1.DetermineHeuristicTypes(); 2230 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
2231 std::unique_ptr<CreditCard> imported_credit_card; 2231 std::unique_ptr<CreditCard> imported_credit_card;
2232 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); 2232 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card));
2233 ASSERT_TRUE(imported_credit_card); 2233 ASSERT_TRUE(imported_credit_card);
2234 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2234 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2235 2235
2236 // Verify that the web database has been updated and the notification sent. 2236 // Verify that the web database has been updated and the notification sent.
2237 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2237 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2238 .WillOnce(QuitMainMessageLoop()); 2238 .WillOnce(QuitMainMessageLoop());
2239 base::RunLoop().Run(); 2239 base::RunLoop().Run();
2240 2240
2241 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2241 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2242 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", 2242 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01",
2243 "2999"); 2243 "2999");
2244 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2244 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2245 ASSERT_EQ(1U, results.size()); 2245 ASSERT_EQ(1U, results.size());
2246 EXPECT_EQ(0, expected.Compare(*results[0])); 2246 EXPECT_EQ(0, expected.Compare(*results[0]));
2247 2247
2248 // Add a second different valid credit card. 2248 // Add a second different valid credit card.
2249 FormData form2; 2249 FormData form2;
2250 AddFullCreditCardForm(&form2, "", "5500 0000 0000 0004", "02", "2999"); 2250 AddFullCreditCardForm(&form2, "", "5500 0000 0000 0004", "02", "2999");
2251 2251
2252 FormStructure form_structure2(form2); 2252 FormStructure form_structure2(form2);
2253 form_structure2.DetermineHeuristicTypes(); 2253 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
2254 std::unique_ptr<CreditCard> imported_credit_card2; 2254 std::unique_ptr<CreditCard> imported_credit_card2;
2255 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); 2255 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2));
2256 ASSERT_TRUE(imported_credit_card2); 2256 ASSERT_TRUE(imported_credit_card2);
2257 personal_data_->SaveImportedCreditCard(*imported_credit_card2); 2257 personal_data_->SaveImportedCreditCard(*imported_credit_card2);
2258 2258
2259 // Verify that the web database has been updated and the notification sent. 2259 // Verify that the web database has been updated and the notification sent.
2260 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2260 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2261 .WillOnce(QuitMainMessageLoop()); 2261 .WillOnce(QuitMainMessageLoop());
2262 base::RunLoop().Run(); 2262 base::RunLoop().Run();
2263 2263
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2358 test::SetServerCreditCards(autofill_table_, server_cards); 2358 test::SetServerCreditCards(autofill_table_, server_cards);
2359 2359
2360 // Type the same data as the masked card into a form. 2360 // Type the same data as the masked card into a form.
2361 FormData form; 2361 FormData form;
2362 AddFullCreditCardForm(&form, "John Dillinger", "4111111111111111", "01", 2362 AddFullCreditCardForm(&form, "John Dillinger", "4111111111111111", "01",
2363 "2999"); 2363 "2999");
2364 2364
2365 // The card should be offered to be saved locally because it only matches the 2365 // The card should be offered to be saved locally because it only matches the
2366 // masked server card. 2366 // masked server card.
2367 FormStructure form_structure(form); 2367 FormStructure form_structure(form);
2368 form_structure.DetermineHeuristicTypes(); 2368 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
2369 std::unique_ptr<CreditCard> imported_credit_card; 2369 std::unique_ptr<CreditCard> imported_credit_card;
2370 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 2370 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
2371 ASSERT_TRUE(imported_credit_card); 2371 ASSERT_TRUE(imported_credit_card);
2372 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2372 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2373 2373
2374 // Verify that the web database has been updated and the notification sent. 2374 // Verify that the web database has been updated and the notification sent.
2375 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2375 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2376 .WillOnce(QuitMainMessageLoop()); 2376 .WillOnce(QuitMainMessageLoop());
2377 base::RunLoop().Run(); 2377 base::RunLoop().Run();
2378 } 2378 }
2379 2379
2380 // Tests that a credit card is not extracted because it matches a full server 2380 // Tests that a credit card is not extracted because it matches a full server
2381 // card. 2381 // card.
2382 TEST_F(PersonalDataManagerTest, 2382 TEST_F(PersonalDataManagerTest,
2383 ImportCreditCard_DuplicateServerCards_FullCard) { 2383 ImportCreditCard_DuplicateServerCards_FullCard) {
2384 // Add a full server card. 2384 // Add a full server card.
2385 std::vector<CreditCard> server_cards; 2385 std::vector<CreditCard> server_cards;
2386 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 2386 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
2387 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 2387 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
2388 "347666888555" /* American Express */, "04", "2999"); 2388 "347666888555" /* American Express */, "04", "2999");
2389 test::SetServerCreditCards(autofill_table_, server_cards); 2389 test::SetServerCreditCards(autofill_table_, server_cards);
2390 2390
2391 // Type the same data as the unmasked card into a form. 2391 // Type the same data as the unmasked card into a form.
2392 FormData form; 2392 FormData form;
2393 AddFullCreditCardForm(&form, "Clyde Barrow", "347666888555", "04", "2999"); 2393 AddFullCreditCardForm(&form, "Clyde Barrow", "347666888555", "04", "2999");
2394 2394
2395 // The card should not be offered to be saved locally because it only matches 2395 // The card should not be offered to be saved locally because it only matches
2396 // the full server card. 2396 // the full server card.
2397 FormStructure form_structure(form); 2397 FormStructure form_structure(form);
2398 form_structure.DetermineHeuristicTypes(); 2398 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
2399 std::unique_ptr<CreditCard> imported_credit_card; 2399 std::unique_ptr<CreditCard> imported_credit_card;
2400 EXPECT_FALSE(ImportCreditCard(form_structure, false, &imported_credit_card)); 2400 EXPECT_FALSE(ImportCreditCard(form_structure, false, &imported_credit_card));
2401 ASSERT_FALSE(imported_credit_card); 2401 ASSERT_FALSE(imported_credit_card);
2402 } 2402 }
2403 2403
2404 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCreditCardWithConflict) { 2404 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCreditCardWithConflict) {
2405 // Start with a single valid credit card form. 2405 // Start with a single valid credit card form.
2406 FormData form1; 2406 FormData form1;
2407 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", 2407 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01",
2408 "2998"); 2408 "2998");
2409 2409
2410 FormStructure form_structure1(form1); 2410 FormStructure form_structure1(form1);
2411 form_structure1.DetermineHeuristicTypes(); 2411 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
2412 std::unique_ptr<CreditCard> imported_credit_card; 2412 std::unique_ptr<CreditCard> imported_credit_card;
2413 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); 2413 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card));
2414 ASSERT_TRUE(imported_credit_card); 2414 ASSERT_TRUE(imported_credit_card);
2415 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2415 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2416 2416
2417 // Verify that the web database has been updated and the notification sent. 2417 // Verify that the web database has been updated and the notification sent.
2418 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2418 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2419 .WillOnce(QuitMainMessageLoop()); 2419 .WillOnce(QuitMainMessageLoop());
2420 base::RunLoop().Run(); 2420 base::RunLoop().Run();
2421 2421
2422 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2422 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2423 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", 2423 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01",
2424 "2998"); 2424 "2998");
2425 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2425 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2426 ASSERT_EQ(1U, results.size()); 2426 ASSERT_EQ(1U, results.size());
2427 EXPECT_EQ(0, expected.Compare(*results[0])); 2427 EXPECT_EQ(0, expected.Compare(*results[0]));
2428 2428
2429 // Add a second different valid credit card where the year is different but 2429 // Add a second different valid credit card where the year is different but
2430 // the credit card number matches. 2430 // the credit card number matches.
2431 FormData form2; 2431 FormData form2;
2432 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", 2432 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01",
2433 /* different year */ "2999"); 2433 /* different year */ "2999");
2434 2434
2435 FormStructure form_structure2(form2); 2435 FormStructure form_structure2(form2);
2436 form_structure2.DetermineHeuristicTypes(); 2436 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
2437 std::unique_ptr<CreditCard> imported_credit_card2; 2437 std::unique_ptr<CreditCard> imported_credit_card2;
2438 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); 2438 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2));
2439 EXPECT_FALSE(imported_credit_card2); 2439 EXPECT_FALSE(imported_credit_card2);
2440 2440
2441 // Verify that the web database has been updated and the notification sent. 2441 // Verify that the web database has been updated and the notification sent.
2442 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2442 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2443 .WillOnce(QuitMainMessageLoop()); 2443 .WillOnce(QuitMainMessageLoop());
2444 base::RunLoop().Run(); 2444 base::RunLoop().Run();
2445 2445
2446 // Expect that the newer information is saved. In this case the year is 2446 // Expect that the newer information is saved. In this case the year is
2447 // updated to "2999". 2447 // updated to "2999".
2448 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); 2448 CreditCard expected2(base::GenerateGUID(), "https://www.example.com");
2449 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", 2449 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01",
2450 "2999"); 2450 "2999");
2451 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); 2451 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards();
2452 ASSERT_EQ(1U, results2.size()); 2452 ASSERT_EQ(1U, results2.size());
2453 EXPECT_EQ(0, expected2.Compare(*results2[0])); 2453 EXPECT_EQ(0, expected2.Compare(*results2[0]));
2454 } 2454 }
2455 2455
2456 TEST_F(PersonalDataManagerTest, ImportCreditCard_ShouldReturnLocalCard) { 2456 TEST_F(PersonalDataManagerTest, ImportCreditCard_ShouldReturnLocalCard) {
2457 // Start with a single valid credit card form. 2457 // Start with a single valid credit card form.
2458 FormData form1; 2458 FormData form1;
2459 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", 2459 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01",
2460 "2998"); 2460 "2998");
2461 2461
2462 FormStructure form_structure1(form1); 2462 FormStructure form_structure1(form1);
2463 form_structure1.DetermineHeuristicTypes(); 2463 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
2464 std::unique_ptr<CreditCard> imported_credit_card; 2464 std::unique_ptr<CreditCard> imported_credit_card;
2465 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); 2465 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card));
2466 ASSERT_TRUE(imported_credit_card); 2466 ASSERT_TRUE(imported_credit_card);
2467 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2467 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2468 2468
2469 // Verify that the web database has been updated and the notification sent. 2469 // Verify that the web database has been updated and the notification sent.
2470 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2470 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2471 .WillOnce(QuitMainMessageLoop()); 2471 .WillOnce(QuitMainMessageLoop());
2472 base::RunLoop().Run(); 2472 base::RunLoop().Run();
2473 2473
2474 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2474 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2475 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", 2475 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01",
2476 "2998"); 2476 "2998");
2477 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2477 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2478 ASSERT_EQ(1U, results.size()); 2478 ASSERT_EQ(1U, results.size());
2479 EXPECT_EQ(0, expected.Compare(*results[0])); 2479 EXPECT_EQ(0, expected.Compare(*results[0]));
2480 2480
2481 // Add a second different valid credit card where the year is different but 2481 // Add a second different valid credit card where the year is different but
2482 // the credit card number matches. 2482 // the credit card number matches.
2483 FormData form2; 2483 FormData form2;
2484 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", 2484 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01",
2485 /* different year */ "2999"); 2485 /* different year */ "2999");
2486 2486
2487 FormStructure form_structure2(form2); 2487 FormStructure form_structure2(form2);
2488 form_structure2.DetermineHeuristicTypes(); 2488 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
2489 std::unique_ptr<CreditCard> imported_credit_card2; 2489 std::unique_ptr<CreditCard> imported_credit_card2;
2490 EXPECT_TRUE(ImportCreditCard(form_structure2, 2490 EXPECT_TRUE(ImportCreditCard(form_structure2,
2491 /* should_return_local_card= */ true, 2491 /* should_return_local_card= */ true,
2492 &imported_credit_card2)); 2492 &imported_credit_card2));
2493 // The local card is returned after an update. 2493 // The local card is returned after an update.
2494 EXPECT_TRUE(imported_credit_card2); 2494 EXPECT_TRUE(imported_credit_card2);
2495 2495
2496 // Verify that the web database has been updated and the notification sent. 2496 // Verify that the web database has been updated and the notification sent.
2497 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2497 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2498 .WillOnce(QuitMainMessageLoop()); 2498 .WillOnce(QuitMainMessageLoop());
2499 base::RunLoop().Run(); 2499 base::RunLoop().Run();
2500 2500
2501 // Expect that the newer information is saved. In this case the year is 2501 // Expect that the newer information is saved. In this case the year is
2502 // updated to "2999". 2502 // updated to "2999".
2503 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); 2503 CreditCard expected2(base::GenerateGUID(), "https://www.example.com");
2504 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", 2504 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01",
2505 "2999"); 2505 "2999");
2506 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); 2506 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards();
2507 ASSERT_EQ(1U, results2.size()); 2507 ASSERT_EQ(1U, results2.size());
2508 EXPECT_EQ(0, expected2.Compare(*results2[0])); 2508 EXPECT_EQ(0, expected2.Compare(*results2[0]));
2509 } 2509 }
2510 2510
2511 TEST_F(PersonalDataManagerTest, ImportCreditCard_EmptyCardWithConflict) { 2511 TEST_F(PersonalDataManagerTest, ImportCreditCard_EmptyCardWithConflict) {
2512 // Start with a single valid credit card form. 2512 // Start with a single valid credit card form.
2513 FormData form1; 2513 FormData form1;
2514 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", 2514 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01",
2515 "2998"); 2515 "2998");
2516 2516
2517 FormStructure form_structure1(form1); 2517 FormStructure form_structure1(form1);
2518 form_structure1.DetermineHeuristicTypes(); 2518 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
2519 std::unique_ptr<CreditCard> imported_credit_card; 2519 std::unique_ptr<CreditCard> imported_credit_card;
2520 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); 2520 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card));
2521 ASSERT_TRUE(imported_credit_card); 2521 ASSERT_TRUE(imported_credit_card);
2522 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2522 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2523 2523
2524 // Verify that the web database has been updated and the notification sent. 2524 // Verify that the web database has been updated and the notification sent.
2525 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2525 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2526 .WillOnce(QuitMainMessageLoop()); 2526 .WillOnce(QuitMainMessageLoop());
2527 base::RunLoop().Run(); 2527 base::RunLoop().Run();
2528 2528
2529 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2529 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2530 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", 2530 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01",
2531 "2998"); 2531 "2998");
2532 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2532 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2533 ASSERT_EQ(1U, results.size()); 2533 ASSERT_EQ(1U, results.size());
2534 EXPECT_EQ(0, expected.Compare(*results[0])); 2534 EXPECT_EQ(0, expected.Compare(*results[0]));
2535 2535
2536 // Add a second credit card with no number. 2536 // Add a second credit card with no number.
2537 FormData form2; 2537 FormData form2;
2538 AddFullCreditCardForm(&form2, "Biggie Smalls", /* no number */ nullptr, "01", 2538 AddFullCreditCardForm(&form2, "Biggie Smalls", /* no number */ nullptr, "01",
2539 "2999"); 2539 "2999");
2540 2540
2541 FormStructure form_structure2(form2); 2541 FormStructure form_structure2(form2);
2542 form_structure2.DetermineHeuristicTypes(); 2542 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
2543 std::unique_ptr<CreditCard> imported_credit_card2; 2543 std::unique_ptr<CreditCard> imported_credit_card2;
2544 EXPECT_FALSE( 2544 EXPECT_FALSE(
2545 ImportCreditCard(form_structure2, false, &imported_credit_card2)); 2545 ImportCreditCard(form_structure2, false, &imported_credit_card2));
2546 EXPECT_FALSE(imported_credit_card2); 2546 EXPECT_FALSE(imported_credit_card2);
2547 2547
2548 // Since no refresh is expected, reload the data from the database to make 2548 // Since no refresh is expected, reload the data from the database to make
2549 // sure no changes were written out. 2549 // sure no changes were written out.
2550 ResetPersonalDataManager(USER_MODE_NORMAL); 2550 ResetPersonalDataManager(USER_MODE_NORMAL);
2551 2551
2552 // No change is expected. 2552 // No change is expected.
2553 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); 2553 CreditCard expected2(base::GenerateGUID(), "https://www.example.com");
2554 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", 2554 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01",
2555 "2998"); 2555 "2998");
2556 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); 2556 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards();
2557 ASSERT_EQ(1U, results2.size()); 2557 ASSERT_EQ(1U, results2.size());
2558 EXPECT_EQ(0, expected2.Compare(*results2[0])); 2558 EXPECT_EQ(0, expected2.Compare(*results2[0]));
2559 } 2559 }
2560 2560
2561 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInNew) { 2561 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInNew) {
2562 // Start with a single valid credit card form. 2562 // Start with a single valid credit card form.
2563 FormData form1; 2563 FormData form1;
2564 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", 2564 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01",
2565 "2999"); 2565 "2999");
2566 2566
2567 FormStructure form_structure1(form1); 2567 FormStructure form_structure1(form1);
2568 form_structure1.DetermineHeuristicTypes(); 2568 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
2569 std::unique_ptr<CreditCard> imported_credit_card; 2569 std::unique_ptr<CreditCard> imported_credit_card;
2570 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); 2570 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card));
2571 ASSERT_TRUE(imported_credit_card); 2571 ASSERT_TRUE(imported_credit_card);
2572 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2572 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2573 2573
2574 // Verify that the web database has been updated and the notification sent. 2574 // Verify that the web database has been updated and the notification sent.
2575 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2575 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2576 .WillOnce(QuitMainMessageLoop()); 2576 .WillOnce(QuitMainMessageLoop());
2577 base::RunLoop().Run(); 2577 base::RunLoop().Run();
2578 2578
2579 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2579 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2580 test::SetCreditCardInfo(&expected, 2580 test::SetCreditCardInfo(&expected,
2581 "Biggie Smalls", "4111111111111111", "01", "2999"); 2581 "Biggie Smalls", "4111111111111111", "01", "2999");
2582 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2582 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2583 ASSERT_EQ(1U, results.size()); 2583 ASSERT_EQ(1U, results.size());
2584 EXPECT_EQ(0, expected.Compare(*results[0])); 2584 EXPECT_EQ(0, expected.Compare(*results[0]));
2585 2585
2586 // Add a second different valid credit card where the name is missing but 2586 // Add a second different valid credit card where the name is missing but
2587 // the credit card number matches. 2587 // the credit card number matches.
2588 FormData form2; 2588 FormData form2;
2589 AddFullCreditCardForm(&form2, /* missing name */ nullptr, 2589 AddFullCreditCardForm(&form2, /* missing name */ nullptr,
2590 "4111-1111-1111-1111", "01", "2999"); 2590 "4111-1111-1111-1111", "01", "2999");
2591 2591
2592 FormStructure form_structure2(form2); 2592 FormStructure form_structure2(form2);
2593 form_structure2.DetermineHeuristicTypes(); 2593 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
2594 std::unique_ptr<CreditCard> imported_credit_card2; 2594 std::unique_ptr<CreditCard> imported_credit_card2;
2595 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); 2595 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2));
2596 EXPECT_FALSE(imported_credit_card2); 2596 EXPECT_FALSE(imported_credit_card2);
2597 2597
2598 // Since no refresh is expected, reload the data from the database to make 2598 // Since no refresh is expected, reload the data from the database to make
2599 // sure no changes were written out. 2599 // sure no changes were written out.
2600 ResetPersonalDataManager(USER_MODE_NORMAL); 2600 ResetPersonalDataManager(USER_MODE_NORMAL);
2601 2601
2602 // No change is expected. 2602 // No change is expected.
2603 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); 2603 CreditCard expected2(base::GenerateGUID(), "https://www.example.com");
2604 test::SetCreditCardInfo(&expected2, 2604 test::SetCreditCardInfo(&expected2,
2605 "Biggie Smalls", "4111111111111111", "01", "2999"); 2605 "Biggie Smalls", "4111111111111111", "01", "2999");
2606 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); 2606 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards();
2607 ASSERT_EQ(1U, results2.size()); 2607 ASSERT_EQ(1U, results2.size());
2608 EXPECT_EQ(0, expected2.Compare(*results2[0])); 2608 EXPECT_EQ(0, expected2.Compare(*results2[0]));
2609 2609
2610 // Add a third credit card where the expiration date is missing. 2610 // Add a third credit card where the expiration date is missing.
2611 FormData form3; 2611 FormData form3;
2612 AddFullCreditCardForm(&form3, "Johnny McEnroe", "5555555555554444", 2612 AddFullCreditCardForm(&form3, "Johnny McEnroe", "5555555555554444",
2613 /* no month */ nullptr, 2613 /* no month */ nullptr,
2614 /* no year */ nullptr); 2614 /* no year */ nullptr);
2615 2615
2616 FormStructure form_structure3(form3); 2616 FormStructure form_structure3(form3);
2617 form_structure3.DetermineHeuristicTypes(); 2617 form_structure3.DetermineHeuristicTypes(nullptr /* ukm_service */);
2618 std::unique_ptr<CreditCard> imported_credit_card3; 2618 std::unique_ptr<CreditCard> imported_credit_card3;
2619 EXPECT_FALSE( 2619 EXPECT_FALSE(
2620 ImportCreditCard(form_structure3, false, &imported_credit_card3)); 2620 ImportCreditCard(form_structure3, false, &imported_credit_card3));
2621 ASSERT_FALSE(imported_credit_card3); 2621 ASSERT_FALSE(imported_credit_card3);
2622 2622
2623 // Since no refresh is expected, reload the data from the database to make 2623 // Since no refresh is expected, reload the data from the database to make
2624 // sure no changes were written out. 2624 // sure no changes were written out.
2625 ResetPersonalDataManager(USER_MODE_NORMAL); 2625 ResetPersonalDataManager(USER_MODE_NORMAL);
2626 2626
2627 // No change is expected. 2627 // No change is expected.
(...skipping 22 matching lines...) Expand all
2650 ASSERT_EQ(1U, results1.size()); 2650 ASSERT_EQ(1U, results1.size());
2651 EXPECT_EQ(saved_credit_card, *results1[0]); 2651 EXPECT_EQ(saved_credit_card, *results1[0]);
2652 2652
2653 // Add a second different valid credit card where the year is different but 2653 // Add a second different valid credit card where the year is different but
2654 // the credit card number matches. 2654 // the credit card number matches.
2655 FormData form; 2655 FormData form;
2656 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", 2656 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01",
2657 /* different year */ "2999"); 2657 /* different year */ "2999");
2658 2658
2659 FormStructure form_structure(form); 2659 FormStructure form_structure(form);
2660 form_structure.DetermineHeuristicTypes(); 2660 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
2661 std::unique_ptr<CreditCard> imported_credit_card; 2661 std::unique_ptr<CreditCard> imported_credit_card;
2662 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 2662 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
2663 EXPECT_FALSE(imported_credit_card); 2663 EXPECT_FALSE(imported_credit_card);
2664 2664
2665 // Verify that the web database has been updated and the notification sent. 2665 // Verify that the web database has been updated and the notification sent.
2666 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2666 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2667 .WillOnce(QuitMainMessageLoop()); 2667 .WillOnce(QuitMainMessageLoop());
2668 base::RunLoop().Run(); 2668 base::RunLoop().Run();
2669 2669
2670 // Expect that the newer information is saved. In this case the year is 2670 // Expect that the newer information is saved. In this case the year is
(...skipping 24 matching lines...) Expand all
2695 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); 2695 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards();
2696 ASSERT_EQ(1U, results1.size()); 2696 ASSERT_EQ(1U, results1.size());
2697 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); 2697 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0]));
2698 2698
2699 // Import the same card info, but with different separators in the number. 2699 // Import the same card info, but with different separators in the number.
2700 FormData form; 2700 FormData form;
2701 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", 2701 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01",
2702 "2999"); 2702 "2999");
2703 2703
2704 FormStructure form_structure(form); 2704 FormStructure form_structure(form);
2705 form_structure.DetermineHeuristicTypes(); 2705 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
2706 std::unique_ptr<CreditCard> imported_credit_card; 2706 std::unique_ptr<CreditCard> imported_credit_card;
2707 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 2707 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
2708 EXPECT_FALSE(imported_credit_card); 2708 EXPECT_FALSE(imported_credit_card);
2709 2709
2710 // Since no refresh is expected, reload the data from the database to make 2710 // Since no refresh is expected, reload the data from the database to make
2711 // sure no changes were written out. 2711 // sure no changes were written out.
2712 ResetPersonalDataManager(USER_MODE_NORMAL); 2712 ResetPersonalDataManager(USER_MODE_NORMAL);
2713 2713
2714 // Expect that no new card is saved. 2714 // Expect that no new card is saved.
2715 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); 2715 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards();
(...skipping 18 matching lines...) Expand all
2734 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2734 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2735 .WillOnce(QuitMainMessageLoop()); 2735 .WillOnce(QuitMainMessageLoop());
2736 base::RunLoop().Run(); 2736 base::RunLoop().Run();
2737 2737
2738 // Simulate a form submission with conflicting expiration year. 2738 // Simulate a form submission with conflicting expiration year.
2739 FormData form; 2739 FormData form;
2740 AddFullCreditCardForm(&form, "Biggie Smalls", "4111 1111 1111 1111", "01", 2740 AddFullCreditCardForm(&form, "Biggie Smalls", "4111 1111 1111 1111", "01",
2741 /* different year */ "2999"); 2741 /* different year */ "2999");
2742 2742
2743 FormStructure form_structure(form); 2743 FormStructure form_structure(form);
2744 form_structure.DetermineHeuristicTypes(); 2744 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
2745 std::unique_ptr<CreditCard> imported_credit_card; 2745 std::unique_ptr<CreditCard> imported_credit_card;
2746 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 2746 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
2747 ASSERT_FALSE(imported_credit_card); 2747 ASSERT_FALSE(imported_credit_card);
2748 2748
2749 // Since no refresh is expected, reload the data from the database to make 2749 // Since no refresh is expected, reload the data from the database to make
2750 // sure no changes were written out. 2750 // sure no changes were written out.
2751 ResetPersonalDataManager(USER_MODE_NORMAL); 2751 ResetPersonalDataManager(USER_MODE_NORMAL);
2752 2752
2753 // Expect that the saved credit card is not modified. 2753 // Expect that the saved credit card is not modified.
2754 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2754 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
(...skipping 26 matching lines...) Expand all
2781 test::CreateTestFormField("State:", "state", "California", "text", &field); 2781 test::CreateTestFormField("State:", "state", "California", "text", &field);
2782 form.fields.push_back(field); 2782 form.fields.push_back(field);
2783 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 2783 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
2784 form.fields.push_back(field); 2784 form.fields.push_back(field);
2785 2785
2786 // Credit card section. 2786 // Credit card section.
2787 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", 2787 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01",
2788 "2999"); 2788 "2999");
2789 2789
2790 FormStructure form_structure(form); 2790 FormStructure form_structure(form);
2791 form_structure.DetermineHeuristicTypes(); 2791 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
2792 std::unique_ptr<CreditCard> imported_credit_card; 2792 std::unique_ptr<CreditCard> imported_credit_card;
2793 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, false, 2793 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, false,
2794 &imported_credit_card)); 2794 &imported_credit_card));
2795 ASSERT_TRUE(imported_credit_card); 2795 ASSERT_TRUE(imported_credit_card);
2796 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2796 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2797 2797
2798 // Verify that the web database has been updated and the notification sent. 2798 // Verify that the web database has been updated and the notification sent.
2799 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2799 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2800 .WillOnce(QuitMainMessageLoop()); 2800 .WillOnce(QuitMainMessageLoop());
2801 base::RunLoop().Run(); 2801 base::RunLoop().Run();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2859 test::CreateTestFormField("Zip:", "zip", "20500", "text", &field); 2859 test::CreateTestFormField("Zip:", "zip", "20500", "text", &field);
2860 form.fields.push_back(field); 2860 form.fields.push_back(field);
2861 test::CreateTestFormField("Country:", "country", "USA", "text", &field); 2861 test::CreateTestFormField("Country:", "country", "USA", "text", &field);
2862 form.fields.push_back(field); 2862 form.fields.push_back(field);
2863 2863
2864 // Credit card section. 2864 // Credit card section.
2865 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", 2865 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01",
2866 "2999"); 2866 "2999");
2867 2867
2868 FormStructure form_structure(form); 2868 FormStructure form_structure(form);
2869 form_structure.DetermineHeuristicTypes(); 2869 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
2870 std::unique_ptr<CreditCard> imported_credit_card; 2870 std::unique_ptr<CreditCard> imported_credit_card;
2871 // Still returns true because the credit card import was successful. 2871 // Still returns true because the credit card import was successful.
2872 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, false, 2872 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, false,
2873 &imported_credit_card)); 2873 &imported_credit_card));
2874 ASSERT_TRUE(imported_credit_card); 2874 ASSERT_TRUE(imported_credit_card);
2875 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2875 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2876 2876
2877 // Verify that the web database has been updated and the notification sent. 2877 // Verify that the web database has been updated and the notification sent.
2878 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2878 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2879 .WillOnce(QuitMainMessageLoop()); 2879 .WillOnce(QuitMainMessageLoop());
(...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after
4135 form1.fields.push_back(field); 4135 form1.fields.push_back(field);
4136 test::CreateTestFormField("Card Number:", "card_number", "4012888888881881", 4136 test::CreateTestFormField("Card Number:", "card_number", "4012888888881881",
4137 "text", &field); 4137 "text", &field);
4138 form1.fields.push_back(field); 4138 form1.fields.push_back(field);
4139 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); 4139 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field);
4140 form1.fields.push_back(field); 4140 form1.fields.push_back(field);
4141 test::CreateTestFormField("Exp Year:", "exp_year", "2999", "text", &field); 4141 test::CreateTestFormField("Exp Year:", "exp_year", "2999", "text", &field);
4142 form1.fields.push_back(field); 4142 form1.fields.push_back(field);
4143 4143
4144 FormStructure form_structure1(form1); 4144 FormStructure form_structure1(form1);
4145 form_structure1.DetermineHeuristicTypes(); 4145 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
4146 std::unique_ptr<CreditCard> imported_credit_card; 4146 std::unique_ptr<CreditCard> imported_credit_card;
4147 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, false, 4147 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, false,
4148 &imported_credit_card)); 4148 &imported_credit_card));
4149 EXPECT_FALSE(imported_credit_card); 4149 EXPECT_FALSE(imported_credit_card);
4150 4150
4151 // A user re-types (or fills with) an unmasked card. Don't offer to save 4151 // A user re-types (or fills with) an unmasked card. Don't offer to save
4152 // here, either. Since it's unmasked, we know for certain that it's the same 4152 // here, either. Since it's unmasked, we know for certain that it's the same
4153 // card. 4153 // card.
4154 FormData form2; 4154 FormData form2;
4155 test::CreateTestFormField("Name on card:", "name_on_card", "Clyde Barrow", 4155 test::CreateTestFormField("Name on card:", "name_on_card", "Clyde Barrow",
4156 "text", &field); 4156 "text", &field);
4157 form2.fields.push_back(field); 4157 form2.fields.push_back(field);
4158 test::CreateTestFormField("Card Number:", "card_number", "347666888555", 4158 test::CreateTestFormField("Card Number:", "card_number", "347666888555",
4159 "text", &field); 4159 "text", &field);
4160 form2.fields.push_back(field); 4160 form2.fields.push_back(field);
4161 test::CreateTestFormField("Exp Month:", "exp_month", "04", "text", &field); 4161 test::CreateTestFormField("Exp Month:", "exp_month", "04", "text", &field);
4162 form2.fields.push_back(field); 4162 form2.fields.push_back(field);
4163 test::CreateTestFormField("Exp Year:", "exp_year", "2999", "text", &field); 4163 test::CreateTestFormField("Exp Year:", "exp_year", "2999", "text", &field);
4164 form2.fields.push_back(field); 4164 form2.fields.push_back(field);
4165 4165
4166 FormStructure form_structure2(form2); 4166 FormStructure form_structure2(form2);
4167 form_structure2.DetermineHeuristicTypes(); 4167 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
4168 std::unique_ptr<CreditCard> imported_credit_card2; 4168 std::unique_ptr<CreditCard> imported_credit_card2;
4169 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false, 4169 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false,
4170 &imported_credit_card2)); 4170 &imported_credit_card2));
4171 EXPECT_FALSE(imported_credit_card2); 4171 EXPECT_FALSE(imported_credit_card2);
4172 } 4172 }
4173 4173
4174 // Tests the SaveImportedProfile method with different profiles to make sure the 4174 // Tests the SaveImportedProfile method with different profiles to make sure the
4175 // merge logic works correctly. 4175 // merge logic works correctly.
4176 typedef struct { 4176 typedef struct {
4177 autofill::ServerFieldType field_type; 4177 autofill::ServerFieldType field_type;
(...skipping 2034 matching lines...) Expand 10 before | Expand all | Expand 10 after
6212 // to the converted address. 6212 // to the converted address.
6213 EXPECT_EQ(profiles[0]->guid(), 6213 EXPECT_EQ(profiles[0]->guid(),
6214 personal_data_->GetCreditCards()[0]->billing_address_id()); 6214 personal_data_->GetCreditCards()[0]->billing_address_id());
6215 // Make sure that the billing address id of the new server card still refers 6215 // Make sure that the billing address id of the new server card still refers
6216 // to the converted address. 6216 // to the converted address.
6217 EXPECT_EQ(profiles[0]->guid(), 6217 EXPECT_EQ(profiles[0]->guid(),
6218 personal_data_->GetCreditCards()[1]->billing_address_id()); 6218 personal_data_->GetCreditCards()[1]->billing_address_id());
6219 } 6219 }
6220 6220
6221 } // namespace autofill 6221 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/form_structure_unittest.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698