 Chromium Code Reviews
 Chromium Code Reviews Issue 2855943002:
  Offer to save card locally if user manually enters same card number as  (Closed)
    
  
    Issue 2855943002:
  Offer to save card locally if user manually enters same card number as  (Closed) 
  | OLD | NEW | 
|---|---|
| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 | 241 | 
| 242 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 242 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 
| 243 } | 243 } | 
| 244 | 244 | 
| 245 // Helper methods that simply forward the call to the private member (to avoid | 245 // Helper methods that simply forward the call to the private member (to avoid | 
| 246 // having to friend every test that needs to access the private | 246 // having to friend every test that needs to access the private | 
| 247 // PersonalDataManager::ImportAddressProfile or ImportCreditCard). | 247 // PersonalDataManager::ImportAddressProfile or ImportCreditCard). | 
| 248 bool ImportAddressProfiles(const FormStructure& form) { | 248 bool ImportAddressProfiles(const FormStructure& form) { | 
| 249 return personal_data_->ImportAddressProfiles(form); | 249 return personal_data_->ImportAddressProfiles(form); | 
| 250 } | 250 } | 
| 251 bool ImportCreditCard(const FormStructure& form, | 251 bool ImportCreditCard( | 
| 252 bool should_return_local_card, | 252 const FormStructure& form, | 
| 253 std::unique_ptr<CreditCard>* imported_credit_card) { | 253 bool should_return_local_card, | 
| 254 return personal_data_->ImportCreditCard(form, should_return_local_card, | 254 std::unique_ptr<CreditCard>* imported_credit_card, | 
| 255 imported_credit_card); | 255 bool* imported_credit_card_matches_masked_server_credit_card) { | 
| 256 return personal_data_->ImportCreditCard( | |
| 257 form, should_return_local_card, imported_credit_card, | |
| 258 imported_credit_card_matches_masked_server_credit_card); | |
| 256 } | 259 } | 
| 257 | 260 | 
| 258 void SubmitFormAndExpectImportedCardWithData(const FormData& form, | 261 void SubmitFormAndExpectImportedCardWithData(const FormData& form, | 
| 259 const char* exp_name, | 262 const char* exp_name, | 
| 260 const char* exp_cc_num, | 263 const char* exp_cc_num, | 
| 261 const char* exp_cc_month, | 264 const char* exp_cc_month, | 
| 262 const char* exp_cc_year) { | 265 const char* exp_cc_year) { | 
| 263 FormStructure form_structure(form); | 266 FormStructure form_structure(form); | 
| 264 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 267 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 265 std::unique_ptr<CreditCard> imported_credit_card; | 268 std::unique_ptr<CreditCard> imported_credit_card; | 
| 266 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 269 bool imported_credit_card_matches_masked_server_credit_card; | 
| 270 EXPECT_TRUE(ImportCreditCard( | |
| 271 form_structure, false, &imported_credit_card, | |
| 272 &imported_credit_card_matches_masked_server_credit_card)); | |
| 267 ASSERT_TRUE(imported_credit_card); | 273 ASSERT_TRUE(imported_credit_card); | 
| 274 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); | |
| 268 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 275 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 
| 269 | 276 | 
| 270 // Verify that the web database has been updated and the notification sent. | 277 // Verify that the web database has been updated and the notification sent. | 
| 271 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 278 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 272 .WillOnce(QuitMainMessageLoop()); | 279 .WillOnce(QuitMainMessageLoop()); | 
| 273 base::RunLoop().Run(); | 280 base::RunLoop().Run(); | 
| 274 | 281 | 
| 275 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 282 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 
| 276 test::SetCreditCardInfo(&expected, exp_name, exp_cc_num, exp_cc_month, | 283 test::SetCreditCardInfo(&expected, exp_name, exp_cc_num, exp_cc_month, | 
| 277 exp_cc_year); | 284 exp_cc_year); | 
| (...skipping 1918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2196 // Tests that a valid credit card is extracted. | 2203 // Tests that a valid credit card is extracted. | 
| 2197 TEST_F(PersonalDataManagerTest, ImportCreditCard_Valid) { | 2204 TEST_F(PersonalDataManagerTest, ImportCreditCard_Valid) { | 
| 2198 // Add a single valid credit card form. | 2205 // Add a single valid credit card form. | 
| 2199 FormData form; | 2206 FormData form; | 
| 2200 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2207 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 
| 2201 "2999"); | 2208 "2999"); | 
| 2202 | 2209 | 
| 2203 FormStructure form_structure(form); | 2210 FormStructure form_structure(form); | 
| 2204 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2211 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2205 std::unique_ptr<CreditCard> imported_credit_card; | 2212 std::unique_ptr<CreditCard> imported_credit_card; | 
| 2206 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2213 bool imported_credit_card_matches_masked_server_credit_card; | 
| 2214 EXPECT_TRUE(ImportCreditCard( | |
| 2215 form_structure, false, &imported_credit_card, | |
| 2216 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2207 ASSERT_TRUE(imported_credit_card); | 2217 ASSERT_TRUE(imported_credit_card); | 
| 2218 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); | |
| 2208 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2219 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 
| 2209 | 2220 | 
| 2210 // Verify that the web database has been updated and the notification sent. | 2221 // Verify that the web database has been updated and the notification sent. | 
| 2211 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2222 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 2212 .WillOnce(QuitMainMessageLoop()); | 2223 .WillOnce(QuitMainMessageLoop()); | 
| 2213 base::RunLoop().Run(); | 2224 base::RunLoop().Run(); | 
| 2214 | 2225 | 
| 2215 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2226 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 
| 2216 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 2227 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 
| 2217 "2999"); | 2228 "2999"); | 
| 2218 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2229 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 
| 2219 ASSERT_EQ(1U, results.size()); | 2230 ASSERT_EQ(1U, results.size()); | 
| 2220 EXPECT_EQ(0, expected.Compare(*results[0])); | 2231 EXPECT_EQ(0, expected.Compare(*results[0])); | 
| 2221 } | 2232 } | 
| 2222 | 2233 | 
| 2223 // Tests that an invalid credit card is not extracted. | 2234 // Tests that an invalid credit card is not extracted. | 
| 2224 TEST_F(PersonalDataManagerTest, ImportCreditCard_Invalid) { | 2235 TEST_F(PersonalDataManagerTest, ImportCreditCard_Invalid) { | 
| 2225 FormData form; | 2236 FormData form; | 
| 2226 AddFullCreditCardForm(&form, "Jim Johansen", "1000000000000000", "02", | 2237 AddFullCreditCardForm(&form, "Jim Johansen", "1000000000000000", "02", | 
| 2227 "2999"); | 2238 "2999"); | 
| 2228 | 2239 | 
| 2229 FormStructure form_structure(form); | 2240 FormStructure form_structure(form); | 
| 2230 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2241 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2231 std::unique_ptr<CreditCard> imported_credit_card; | 2242 std::unique_ptr<CreditCard> imported_credit_card; | 
| 2232 EXPECT_FALSE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2243 bool imported_credit_card_matches_masked_server_credit_card; | 
| 2244 EXPECT_FALSE(ImportCreditCard( | |
| 2245 form_structure, false, &imported_credit_card, | |
| 2246 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2233 ASSERT_FALSE(imported_credit_card); | 2247 ASSERT_FALSE(imported_credit_card); | 
| 2234 | 2248 | 
| 2235 // Since no refresh is expected, reload the data from the database to make | 2249 // Since no refresh is expected, reload the data from the database to make | 
| 2236 // sure no changes were written out. | 2250 // sure no changes were written out. | 
| 2237 ResetPersonalDataManager(USER_MODE_NORMAL); | 2251 ResetPersonalDataManager(USER_MODE_NORMAL); | 
| 2238 | 2252 | 
| 2239 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2253 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 
| 2240 ASSERT_EQ(0U, results.size()); | 2254 ASSERT_EQ(0U, results.size()); | 
| 2241 } | 2255 } | 
| 2242 | 2256 | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 2256 std::vector<base::string16> contents; | 2270 std::vector<base::string16> contents; | 
| 2257 contents.push_back(base::ASCIIToUTF16("Jan (1)")); | 2271 contents.push_back(base::ASCIIToUTF16("Jan (1)")); | 
| 2258 contents.push_back(base::ASCIIToUTF16("Feb (2)")); | 2272 contents.push_back(base::ASCIIToUTF16("Feb (2)")); | 
| 2259 contents.push_back(base::ASCIIToUTF16("Mar (3)")); | 2273 contents.push_back(base::ASCIIToUTF16("Mar (3)")); | 
| 2260 form.fields[2].option_values = values; | 2274 form.fields[2].option_values = values; | 
| 2261 form.fields[2].option_contents = contents; | 2275 form.fields[2].option_contents = contents; | 
| 2262 | 2276 | 
| 2263 FormStructure form_structure(form); | 2277 FormStructure form_structure(form); | 
| 2264 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2278 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2265 std::unique_ptr<CreditCard> imported_credit_card; | 2279 std::unique_ptr<CreditCard> imported_credit_card; | 
| 2266 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2280 bool imported_credit_card_matches_masked_server_credit_card; | 
| 2281 EXPECT_TRUE(ImportCreditCard( | |
| 2282 form_structure, false, &imported_credit_card, | |
| 2283 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2267 ASSERT_TRUE(imported_credit_card); | 2284 ASSERT_TRUE(imported_credit_card); | 
| 2285 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); | |
| 2268 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2286 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 
| 2269 | 2287 | 
| 2270 // Verify that the web database has been updated and the notification sent. | 2288 // Verify that the web database has been updated and the notification sent. | 
| 2271 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2289 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 2272 .WillOnce(QuitMainMessageLoop()); | 2290 .WillOnce(QuitMainMessageLoop()); | 
| 2273 base::RunLoop().Run(); | 2291 base::RunLoop().Run(); | 
| 2274 | 2292 | 
| 2275 // See that the invalid option text was converted to the right value. | 2293 // See that the invalid option text was converted to the right value. | 
| 2276 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2294 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 
| 2277 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "02", | 2295 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "02", | 
| 2278 "2999"); | 2296 "2999"); | 
| 2279 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2297 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 
| 2280 ASSERT_EQ(1U, results.size()); | 2298 ASSERT_EQ(1U, results.size()); | 
| 2281 EXPECT_EQ(0, expected.Compare(*results[0])); | 2299 EXPECT_EQ(0, expected.Compare(*results[0])); | 
| 2282 } | 2300 } | 
| 2283 | 2301 | 
| 2284 TEST_F(PersonalDataManagerTest, ImportCreditCard_TwoValidCards) { | 2302 TEST_F(PersonalDataManagerTest, ImportCreditCard_TwoValidCards) { | 
| 2285 // Start with a single valid credit card form. | 2303 // Start with a single valid credit card form. | 
| 2286 FormData form1; | 2304 FormData form1; | 
| 2287 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2305 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 
| 2288 "2999"); | 2306 "2999"); | 
| 2289 | 2307 | 
| 2290 FormStructure form_structure1(form1); | 2308 FormStructure form_structure1(form1); | 
| 2291 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2309 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2292 std::unique_ptr<CreditCard> imported_credit_card; | 2310 std::unique_ptr<CreditCard> imported_credit_card; | 
| 2293 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2311 bool imported_credit_card_matches_masked_server_credit_card; | 
| 2312 EXPECT_TRUE(ImportCreditCard( | |
| 2313 form_structure1, false, &imported_credit_card, | |
| 2314 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2294 ASSERT_TRUE(imported_credit_card); | 2315 ASSERT_TRUE(imported_credit_card); | 
| 2316 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); | |
| 2295 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2317 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 
| 2296 | 2318 | 
| 2297 // Verify that the web database has been updated and the notification sent. | 2319 // Verify that the web database has been updated and the notification sent. | 
| 2298 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2320 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 2299 .WillOnce(QuitMainMessageLoop()); | 2321 .WillOnce(QuitMainMessageLoop()); | 
| 2300 base::RunLoop().Run(); | 2322 base::RunLoop().Run(); | 
| 2301 | 2323 | 
| 2302 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2324 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 
| 2303 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 2325 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 
| 2304 "2999"); | 2326 "2999"); | 
| 2305 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2327 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 
| 2306 ASSERT_EQ(1U, results.size()); | 2328 ASSERT_EQ(1U, results.size()); | 
| 2307 EXPECT_EQ(0, expected.Compare(*results[0])); | 2329 EXPECT_EQ(0, expected.Compare(*results[0])); | 
| 2308 | 2330 | 
| 2309 // Add a second different valid credit card. | 2331 // Add a second different valid credit card. | 
| 2310 FormData form2; | 2332 FormData form2; | 
| 2311 AddFullCreditCardForm(&form2, "", "5500 0000 0000 0004", "02", "2999"); | 2333 AddFullCreditCardForm(&form2, "", "5500 0000 0000 0004", "02", "2999"); | 
| 2312 | 2334 | 
| 2313 FormStructure form_structure2(form2); | 2335 FormStructure form_structure2(form2); | 
| 2314 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2336 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2315 std::unique_ptr<CreditCard> imported_credit_card2; | 2337 std::unique_ptr<CreditCard> imported_credit_card2; | 
| 2316 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2338 EXPECT_TRUE(ImportCreditCard( | 
| 2339 form_structure2, false, &imported_credit_card2, | |
| 2340 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2317 ASSERT_TRUE(imported_credit_card2); | 2341 ASSERT_TRUE(imported_credit_card2); | 
| 2342 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); | |
| 2318 personal_data_->SaveImportedCreditCard(*imported_credit_card2); | 2343 personal_data_->SaveImportedCreditCard(*imported_credit_card2); | 
| 2319 | 2344 | 
| 2320 // Verify that the web database has been updated and the notification sent. | 2345 // Verify that the web database has been updated and the notification sent. | 
| 2321 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2346 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 2322 .WillOnce(QuitMainMessageLoop()); | 2347 .WillOnce(QuitMainMessageLoop()); | 
| 2323 base::RunLoop().Run(); | 2348 base::RunLoop().Run(); | 
| 2324 | 2349 | 
| 2325 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2350 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 
| 2326 test::SetCreditCardInfo(&expected2, "", "5500000000000004", "02", "2999"); | 2351 test::SetCreditCardInfo(&expected2, "", "5500000000000004", "02", "2999"); | 
| 2327 std::vector<CreditCard*> cards; | 2352 std::vector<CreditCard*> cards; | 
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2421 // Type the same data as the masked card into a form. | 2446 // Type the same data as the masked card into a form. | 
| 2422 FormData form; | 2447 FormData form; | 
| 2423 AddFullCreditCardForm(&form, "John Dillinger", "4111111111111111", "01", | 2448 AddFullCreditCardForm(&form, "John Dillinger", "4111111111111111", "01", | 
| 2424 "2999"); | 2449 "2999"); | 
| 2425 | 2450 | 
| 2426 // The card should be offered to be saved locally because it only matches the | 2451 // The card should be offered to be saved locally because it only matches the | 
| 2427 // masked server card. | 2452 // masked server card. | 
| 2428 FormStructure form_structure(form); | 2453 FormStructure form_structure(form); | 
| 2429 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2454 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2430 std::unique_ptr<CreditCard> imported_credit_card; | 2455 std::unique_ptr<CreditCard> imported_credit_card; | 
| 2431 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2456 bool imported_credit_card_matches_masked_server_credit_card; | 
| 2457 EXPECT_TRUE(ImportCreditCard( | |
| 2458 form_structure, false, &imported_credit_card, | |
| 2459 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2432 ASSERT_TRUE(imported_credit_card); | 2460 ASSERT_TRUE(imported_credit_card); | 
| 2461 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); | |
| 2433 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2462 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 
| 2434 | 2463 | 
| 2435 // Verify that the web database has been updated and the notification sent. | 2464 // Verify that the web database has been updated and the notification sent. | 
| 2436 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2465 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 2437 .WillOnce(QuitMainMessageLoop()); | 2466 .WillOnce(QuitMainMessageLoop()); | 
| 2438 base::RunLoop().Run(); | 2467 base::RunLoop().Run(); | 
| 2439 } | 2468 } | 
| 2440 | 2469 | 
| 2441 // Tests that a credit card is not extracted because it matches a full server | 2470 // Tests that a credit card is not extracted because it matches a full server | 
| 2442 // card. | 2471 // card. | 
| 2443 TEST_F(PersonalDataManagerTest, | 2472 TEST_F(PersonalDataManagerTest, | 
| 2444 ImportCreditCard_DuplicateServerCards_FullCard) { | 2473 ImportCreditCard_DuplicateServerCards_FullCard) { | 
| 2445 // Add a full server card. | 2474 // Add a full server card. | 
| 2446 std::vector<CreditCard> server_cards; | 2475 std::vector<CreditCard> server_cards; | 
| 2447 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 2476 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 
| 2448 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 2477 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 
| 2449 "347666888555" /* American Express */, "04", "2999"); | 2478 "347666888555" /* American Express */, "04", "2999"); | 
| 2450 test::SetServerCreditCards(autofill_table_, server_cards); | 2479 test::SetServerCreditCards(autofill_table_, server_cards); | 
| 2451 | 2480 | 
| 2452 // Type the same data as the unmasked card into a form. | 2481 // Type the same data as the unmasked card into a form. | 
| 2453 FormData form; | 2482 FormData form; | 
| 2454 AddFullCreditCardForm(&form, "Clyde Barrow", "347666888555", "04", "2999"); | 2483 AddFullCreditCardForm(&form, "Clyde Barrow", "347666888555", "04", "2999"); | 
| 2455 | 2484 | 
| 2456 // The card should not be offered to be saved locally because it only matches | 2485 // The card should not be offered to be saved locally because it only matches | 
| 2457 // the full server card. | 2486 // the full server card. | 
| 2458 FormStructure form_structure(form); | 2487 FormStructure form_structure(form); | 
| 2459 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2488 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2460 std::unique_ptr<CreditCard> imported_credit_card; | 2489 std::unique_ptr<CreditCard> imported_credit_card; | 
| 2461 EXPECT_FALSE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2490 bool imported_credit_card_matches_masked_server_credit_card; | 
| 2491 EXPECT_FALSE(ImportCreditCard( | |
| 2492 form_structure, false, &imported_credit_card, | |
| 2493 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2462 ASSERT_FALSE(imported_credit_card); | 2494 ASSERT_FALSE(imported_credit_card); | 
| 2463 } | 2495 } | 
| 2464 | 2496 | 
| 2465 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCreditCardWithConflict) { | 2497 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCreditCardWithConflict) { | 
| 2466 // Start with a single valid credit card form. | 2498 // Start with a single valid credit card form. | 
| 2467 FormData form1; | 2499 FormData form1; | 
| 2468 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2500 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 
| 2469 "2998"); | 2501 "2998"); | 
| 2470 | 2502 | 
| 2471 FormStructure form_structure1(form1); | 2503 FormStructure form_structure1(form1); | 
| 2472 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2504 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2473 std::unique_ptr<CreditCard> imported_credit_card; | 2505 std::unique_ptr<CreditCard> imported_credit_card; | 
| 2474 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2506 bool imported_credit_card_matches_masked_server_credit_card; | 
| 2507 EXPECT_TRUE(ImportCreditCard( | |
| 2508 form_structure1, false, &imported_credit_card, | |
| 2509 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2475 ASSERT_TRUE(imported_credit_card); | 2510 ASSERT_TRUE(imported_credit_card); | 
| 2511 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); | |
| 2476 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2512 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 
| 2477 | 2513 | 
| 2478 // Verify that the web database has been updated and the notification sent. | 2514 // Verify that the web database has been updated and the notification sent. | 
| 2479 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2515 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 2480 .WillOnce(QuitMainMessageLoop()); | 2516 .WillOnce(QuitMainMessageLoop()); | 
| 2481 base::RunLoop().Run(); | 2517 base::RunLoop().Run(); | 
| 2482 | 2518 | 
| 2483 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2519 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 
| 2484 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 2520 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 
| 2485 "2998"); | 2521 "2998"); | 
| 2486 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2522 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 
| 2487 ASSERT_EQ(1U, results.size()); | 2523 ASSERT_EQ(1U, results.size()); | 
| 2488 EXPECT_EQ(0, expected.Compare(*results[0])); | 2524 EXPECT_EQ(0, expected.Compare(*results[0])); | 
| 2489 | 2525 | 
| 2490 // Add a second different valid credit card where the year is different but | 2526 // Add a second different valid credit card where the year is different but | 
| 2491 // the credit card number matches. | 2527 // the credit card number matches. | 
| 2492 FormData form2; | 2528 FormData form2; | 
| 2493 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", | 2529 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", | 
| 2494 /* different year */ "2999"); | 2530 /* different year */ "2999"); | 
| 2495 | 2531 | 
| 2496 FormStructure form_structure2(form2); | 2532 FormStructure form_structure2(form2); | 
| 2497 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2533 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2498 std::unique_ptr<CreditCard> imported_credit_card2; | 2534 std::unique_ptr<CreditCard> imported_credit_card2; | 
| 2499 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2535 EXPECT_TRUE(ImportCreditCard( | 
| 2536 form_structure2, false, &imported_credit_card2, | |
| 2537 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2500 EXPECT_FALSE(imported_credit_card2); | 2538 EXPECT_FALSE(imported_credit_card2); | 
| 2501 | 2539 | 
| 2502 // Verify that the web database has been updated and the notification sent. | 2540 // Verify that the web database has been updated and the notification sent. | 
| 2503 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2541 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 2504 .WillOnce(QuitMainMessageLoop()); | 2542 .WillOnce(QuitMainMessageLoop()); | 
| 2505 base::RunLoop().Run(); | 2543 base::RunLoop().Run(); | 
| 2506 | 2544 | 
| 2507 // Expect that the newer information is saved. In this case the year is | 2545 // Expect that the newer information is saved. In this case the year is | 
| 2508 // updated to "2999". | 2546 // updated to "2999". | 
| 2509 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2547 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 
| 2510 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", | 2548 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", | 
| 2511 "2999"); | 2549 "2999"); | 
| 2512 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2550 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 
| 2513 ASSERT_EQ(1U, results2.size()); | 2551 ASSERT_EQ(1U, results2.size()); | 
| 2514 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2552 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 
| 2515 } | 2553 } | 
| 2516 | 2554 | 
| 2517 TEST_F(PersonalDataManagerTest, ImportCreditCard_ShouldReturnLocalCard) { | 2555 TEST_F(PersonalDataManagerTest, ImportCreditCard_ShouldReturnLocalCard) { | 
| 2518 // Start with a single valid credit card form. | 2556 // Start with a single valid credit card form. | 
| 2519 FormData form1; | 2557 FormData form1; | 
| 2520 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2558 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 
| 2521 "2998"); | 2559 "2998"); | 
| 2522 | 2560 | 
| 2523 FormStructure form_structure1(form1); | 2561 FormStructure form_structure1(form1); | 
| 2524 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2562 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2525 std::unique_ptr<CreditCard> imported_credit_card; | 2563 std::unique_ptr<CreditCard> imported_credit_card; | 
| 2526 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2564 bool imported_credit_card_matches_masked_server_credit_card; | 
| 2565 EXPECT_TRUE(ImportCreditCard( | |
| 2566 form_structure1, false, &imported_credit_card, | |
| 2567 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2527 ASSERT_TRUE(imported_credit_card); | 2568 ASSERT_TRUE(imported_credit_card); | 
| 2569 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); | |
| 2528 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2570 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 
| 2529 | 2571 | 
| 2530 // Verify that the web database has been updated and the notification sent. | 2572 // Verify that the web database has been updated and the notification sent. | 
| 2531 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2573 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 2532 .WillOnce(QuitMainMessageLoop()); | 2574 .WillOnce(QuitMainMessageLoop()); | 
| 2533 base::RunLoop().Run(); | 2575 base::RunLoop().Run(); | 
| 2534 | 2576 | 
| 2535 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2577 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 
| 2536 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 2578 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 
| 2537 "2998"); | 2579 "2998"); | 
| 2538 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2580 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 
| 2539 ASSERT_EQ(1U, results.size()); | 2581 ASSERT_EQ(1U, results.size()); | 
| 2540 EXPECT_EQ(0, expected.Compare(*results[0])); | 2582 EXPECT_EQ(0, expected.Compare(*results[0])); | 
| 2541 | 2583 | 
| 2542 // Add a second different valid credit card where the year is different but | 2584 // Add a second different valid credit card where the year is different but | 
| 2543 // the credit card number matches. | 2585 // the credit card number matches. | 
| 2544 FormData form2; | 2586 FormData form2; | 
| 2545 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", | 2587 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", | 
| 2546 /* different year */ "2999"); | 2588 /* different year */ "2999"); | 
| 2547 | 2589 | 
| 2548 FormStructure form_structure2(form2); | 2590 FormStructure form_structure2(form2); | 
| 2549 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2591 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2550 std::unique_ptr<CreditCard> imported_credit_card2; | 2592 std::unique_ptr<CreditCard> imported_credit_card2; | 
| 2551 EXPECT_TRUE(ImportCreditCard(form_structure2, | 2593 EXPECT_TRUE(ImportCreditCard( | 
| 2552 /* should_return_local_card= */ true, | 2594 form_structure2, | 
| 2553 &imported_credit_card2)); | 2595 /* should_return_local_card= */ true, &imported_credit_card2, | 
| 2596 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2554 // The local card is returned after an update. | 2597 // The local card is returned after an update. | 
| 2555 EXPECT_TRUE(imported_credit_card2); | 2598 EXPECT_TRUE(imported_credit_card2); | 
| 2599 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); | |
| 2556 | 2600 | 
| 2557 // Verify that the web database has been updated and the notification sent. | 2601 // Verify that the web database has been updated and the notification sent. | 
| 2558 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2602 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 2559 .WillOnce(QuitMainMessageLoop()); | 2603 .WillOnce(QuitMainMessageLoop()); | 
| 2560 base::RunLoop().Run(); | 2604 base::RunLoop().Run(); | 
| 2561 | 2605 | 
| 2562 // Expect that the newer information is saved. In this case the year is | 2606 // Expect that the newer information is saved. In this case the year is | 
| 2563 // updated to "2999". | 2607 // updated to "2999". | 
| 2564 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2608 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 
| 2565 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", | 2609 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", | 
| 2566 "2999"); | 2610 "2999"); | 
| 2567 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2611 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 
| 2568 ASSERT_EQ(1U, results2.size()); | 2612 ASSERT_EQ(1U, results2.size()); | 
| 2569 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2613 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 
| 2570 } | 2614 } | 
| 2571 | 2615 | 
| 2572 TEST_F(PersonalDataManagerTest, ImportCreditCard_EmptyCardWithConflict) { | 2616 TEST_F(PersonalDataManagerTest, ImportCreditCard_EmptyCardWithConflict) { | 
| 2573 // Start with a single valid credit card form. | 2617 // Start with a single valid credit card form. | 
| 2574 FormData form1; | 2618 FormData form1; | 
| 2575 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2619 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 
| 2576 "2998"); | 2620 "2998"); | 
| 2577 | 2621 | 
| 2578 FormStructure form_structure1(form1); | 2622 FormStructure form_structure1(form1); | 
| 2579 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2623 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2580 std::unique_ptr<CreditCard> imported_credit_card; | 2624 std::unique_ptr<CreditCard> imported_credit_card; | 
| 2581 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2625 bool imported_credit_card_matches_masked_server_credit_card; | 
| 2626 EXPECT_TRUE(ImportCreditCard( | |
| 2627 form_structure1, false, &imported_credit_card, | |
| 2628 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2582 ASSERT_TRUE(imported_credit_card); | 2629 ASSERT_TRUE(imported_credit_card); | 
| 2630 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); | |
| 2583 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2631 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 
| 2584 | 2632 | 
| 2585 // Verify that the web database has been updated and the notification sent. | 2633 // Verify that the web database has been updated and the notification sent. | 
| 2586 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2634 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 2587 .WillOnce(QuitMainMessageLoop()); | 2635 .WillOnce(QuitMainMessageLoop()); | 
| 2588 base::RunLoop().Run(); | 2636 base::RunLoop().Run(); | 
| 2589 | 2637 | 
| 2590 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2638 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 
| 2591 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 2639 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 
| 2592 "2998"); | 2640 "2998"); | 
| 2593 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2641 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 
| 2594 ASSERT_EQ(1U, results.size()); | 2642 ASSERT_EQ(1U, results.size()); | 
| 2595 EXPECT_EQ(0, expected.Compare(*results[0])); | 2643 EXPECT_EQ(0, expected.Compare(*results[0])); | 
| 2596 | 2644 | 
| 2597 // Add a second credit card with no number. | 2645 // Add a second credit card with no number. | 
| 2598 FormData form2; | 2646 FormData form2; | 
| 2599 AddFullCreditCardForm(&form2, "Biggie Smalls", /* no number */ nullptr, "01", | 2647 AddFullCreditCardForm(&form2, "Biggie Smalls", /* no number */ nullptr, "01", | 
| 2600 "2999"); | 2648 "2999"); | 
| 2601 | 2649 | 
| 2602 FormStructure form_structure2(form2); | 2650 FormStructure form_structure2(form2); | 
| 2603 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2651 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2604 std::unique_ptr<CreditCard> imported_credit_card2; | 2652 std::unique_ptr<CreditCard> imported_credit_card2; | 
| 2605 EXPECT_FALSE( | 2653 EXPECT_FALSE(ImportCreditCard( | 
| 2606 ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2654 form_structure2, false, &imported_credit_card2, | 
| 2655 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2607 EXPECT_FALSE(imported_credit_card2); | 2656 EXPECT_FALSE(imported_credit_card2); | 
| 2608 | 2657 | 
| 2609 // Since no refresh is expected, reload the data from the database to make | 2658 // Since no refresh is expected, reload the data from the database to make | 
| 2610 // sure no changes were written out. | 2659 // sure no changes were written out. | 
| 2611 ResetPersonalDataManager(USER_MODE_NORMAL); | 2660 ResetPersonalDataManager(USER_MODE_NORMAL); | 
| 2612 | 2661 | 
| 2613 // No change is expected. | 2662 // No change is expected. | 
| 2614 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2663 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 
| 2615 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", | 2664 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", | 
| 2616 "2998"); | 2665 "2998"); | 
| 2617 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2666 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 
| 2618 ASSERT_EQ(1U, results2.size()); | 2667 ASSERT_EQ(1U, results2.size()); | 
| 2619 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2668 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 
| 2620 } | 2669 } | 
| 2621 | 2670 | 
| 2622 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInNew) { | 2671 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInNew) { | 
| 2623 // Start with a single valid credit card form. | 2672 // Start with a single valid credit card form. | 
| 2624 FormData form1; | 2673 FormData form1; | 
| 2625 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2674 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 
| 2626 "2999"); | 2675 "2999"); | 
| 2627 | 2676 | 
| 2628 FormStructure form_structure1(form1); | 2677 FormStructure form_structure1(form1); | 
| 2629 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2678 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2630 std::unique_ptr<CreditCard> imported_credit_card; | 2679 std::unique_ptr<CreditCard> imported_credit_card; | 
| 2631 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2680 bool imported_credit_card_matches_masked_server_credit_card; | 
| 2681 EXPECT_TRUE(ImportCreditCard( | |
| 2682 form_structure1, false, &imported_credit_card, | |
| 2683 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2632 ASSERT_TRUE(imported_credit_card); | 2684 ASSERT_TRUE(imported_credit_card); | 
| 2685 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); | |
| 2633 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2686 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 
| 2634 | 2687 | 
| 2635 // Verify that the web database has been updated and the notification sent. | 2688 // Verify that the web database has been updated and the notification sent. | 
| 2636 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2689 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 2637 .WillOnce(QuitMainMessageLoop()); | 2690 .WillOnce(QuitMainMessageLoop()); | 
| 2638 base::RunLoop().Run(); | 2691 base::RunLoop().Run(); | 
| 2639 | 2692 | 
| 2640 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2693 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 
| 2641 test::SetCreditCardInfo(&expected, | 2694 test::SetCreditCardInfo(&expected, | 
| 2642 "Biggie Smalls", "4111111111111111", "01", "2999"); | 2695 "Biggie Smalls", "4111111111111111", "01", "2999"); | 
| 2643 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2696 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 
| 2644 ASSERT_EQ(1U, results.size()); | 2697 ASSERT_EQ(1U, results.size()); | 
| 2645 EXPECT_EQ(0, expected.Compare(*results[0])); | 2698 EXPECT_EQ(0, expected.Compare(*results[0])); | 
| 2646 | 2699 | 
| 2647 // Add a second different valid credit card where the name is missing but | 2700 // Add a second different valid credit card where the name is missing but | 
| 2648 // the credit card number matches. | 2701 // the credit card number matches. | 
| 2649 FormData form2; | 2702 FormData form2; | 
| 2650 AddFullCreditCardForm(&form2, /* missing name */ nullptr, | 2703 AddFullCreditCardForm(&form2, /* missing name */ nullptr, | 
| 2651 "4111-1111-1111-1111", "01", "2999"); | 2704 "4111-1111-1111-1111", "01", "2999"); | 
| 2652 | 2705 | 
| 2653 FormStructure form_structure2(form2); | 2706 FormStructure form_structure2(form2); | 
| 2654 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2707 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2655 std::unique_ptr<CreditCard> imported_credit_card2; | 2708 std::unique_ptr<CreditCard> imported_credit_card2; | 
| 2656 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2709 EXPECT_TRUE(ImportCreditCard( | 
| 2710 form_structure2, false, &imported_credit_card2, | |
| 2711 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2657 EXPECT_FALSE(imported_credit_card2); | 2712 EXPECT_FALSE(imported_credit_card2); | 
| 2658 | 2713 | 
| 2659 // Since no refresh is expected, reload the data from the database to make | 2714 // Since no refresh is expected, reload the data from the database to make | 
| 2660 // sure no changes were written out. | 2715 // sure no changes were written out. | 
| 2661 ResetPersonalDataManager(USER_MODE_NORMAL); | 2716 ResetPersonalDataManager(USER_MODE_NORMAL); | 
| 2662 | 2717 | 
| 2663 // No change is expected. | 2718 // No change is expected. | 
| 2664 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2719 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 
| 2665 test::SetCreditCardInfo(&expected2, | 2720 test::SetCreditCardInfo(&expected2, | 
| 2666 "Biggie Smalls", "4111111111111111", "01", "2999"); | 2721 "Biggie Smalls", "4111111111111111", "01", "2999"); | 
| 2667 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2722 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 
| 2668 ASSERT_EQ(1U, results2.size()); | 2723 ASSERT_EQ(1U, results2.size()); | 
| 2669 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2724 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 
| 2670 | 2725 | 
| 2671 // Add a third credit card where the expiration date is missing. | 2726 // Add a third credit card where the expiration date is missing. | 
| 2672 FormData form3; | 2727 FormData form3; | 
| 2673 AddFullCreditCardForm(&form3, "Johnny McEnroe", "5555555555554444", | 2728 AddFullCreditCardForm(&form3, "Johnny McEnroe", "5555555555554444", | 
| 2674 /* no month */ nullptr, | 2729 /* no month */ nullptr, | 
| 2675 /* no year */ nullptr); | 2730 /* no year */ nullptr); | 
| 2676 | 2731 | 
| 2677 FormStructure form_structure3(form3); | 2732 FormStructure form_structure3(form3); | 
| 2678 form_structure3.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2733 form_structure3.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2679 std::unique_ptr<CreditCard> imported_credit_card3; | 2734 std::unique_ptr<CreditCard> imported_credit_card3; | 
| 2680 EXPECT_FALSE( | 2735 EXPECT_FALSE(ImportCreditCard( | 
| 2681 ImportCreditCard(form_structure3, false, &imported_credit_card3)); | 2736 form_structure3, false, &imported_credit_card3, | 
| 2737 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2682 ASSERT_FALSE(imported_credit_card3); | 2738 ASSERT_FALSE(imported_credit_card3); | 
| 2683 | 2739 | 
| 2684 // Since no refresh is expected, reload the data from the database to make | 2740 // Since no refresh is expected, reload the data from the database to make | 
| 2685 // sure no changes were written out. | 2741 // sure no changes were written out. | 
| 2686 ResetPersonalDataManager(USER_MODE_NORMAL); | 2742 ResetPersonalDataManager(USER_MODE_NORMAL); | 
| 2687 | 2743 | 
| 2688 // No change is expected. | 2744 // No change is expected. | 
| 2689 CreditCard expected3(base::GenerateGUID(), "https://www.example.com"); | 2745 CreditCard expected3(base::GenerateGUID(), "https://www.example.com"); | 
| 2690 test::SetCreditCardInfo(&expected3, | 2746 test::SetCreditCardInfo(&expected3, | 
| 2691 "Biggie Smalls", "4111111111111111", "01", "2999"); | 2747 "Biggie Smalls", "4111111111111111", "01", "2999"); | 
| (...skipping 21 matching lines...) Expand all Loading... | |
| 2713 | 2769 | 
| 2714 // Add a second different valid credit card where the year is different but | 2770 // Add a second different valid credit card where the year is different but | 
| 2715 // the credit card number matches. | 2771 // the credit card number matches. | 
| 2716 FormData form; | 2772 FormData form; | 
| 2717 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2773 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 
| 2718 /* different year */ "2999"); | 2774 /* different year */ "2999"); | 
| 2719 | 2775 | 
| 2720 FormStructure form_structure(form); | 2776 FormStructure form_structure(form); | 
| 2721 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2777 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2722 std::unique_ptr<CreditCard> imported_credit_card; | 2778 std::unique_ptr<CreditCard> imported_credit_card; | 
| 2723 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2779 bool imported_credit_card_matches_masked_server_credit_card; | 
| 2780 EXPECT_TRUE(ImportCreditCard( | |
| 2781 form_structure, false, &imported_credit_card, | |
| 2782 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2724 EXPECT_FALSE(imported_credit_card); | 2783 EXPECT_FALSE(imported_credit_card); | 
| 2725 | 2784 | 
| 2726 // Verify that the web database has been updated and the notification sent. | 2785 // Verify that the web database has been updated and the notification sent. | 
| 2727 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2786 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 2728 .WillOnce(QuitMainMessageLoop()); | 2787 .WillOnce(QuitMainMessageLoop()); | 
| 2729 base::RunLoop().Run(); | 2788 base::RunLoop().Run(); | 
| 2730 | 2789 | 
| 2731 // Expect that the newer information is saved. In this case the year is | 2790 // Expect that the newer information is saved. In this case the year is | 
| 2732 // added to the existing credit card. | 2791 // added to the existing credit card. | 
| 2733 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2792 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2758 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); | 2817 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); | 
| 2759 | 2818 | 
| 2760 // Import the same card info, but with different separators in the number. | 2819 // Import the same card info, but with different separators in the number. | 
| 2761 FormData form; | 2820 FormData form; | 
| 2762 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2821 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 
| 2763 "2999"); | 2822 "2999"); | 
| 2764 | 2823 | 
| 2765 FormStructure form_structure(form); | 2824 FormStructure form_structure(form); | 
| 2766 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2825 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2767 std::unique_ptr<CreditCard> imported_credit_card; | 2826 std::unique_ptr<CreditCard> imported_credit_card; | 
| 2768 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2827 bool imported_credit_card_matches_masked_server_credit_card; | 
| 2828 EXPECT_TRUE(ImportCreditCard( | |
| 2829 form_structure, false, &imported_credit_card, | |
| 2830 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2769 EXPECT_FALSE(imported_credit_card); | 2831 EXPECT_FALSE(imported_credit_card); | 
| 2770 | 2832 | 
| 2771 // Since no refresh is expected, reload the data from the database to make | 2833 // Since no refresh is expected, reload the data from the database to make | 
| 2772 // sure no changes were written out. | 2834 // sure no changes were written out. | 
| 2773 ResetPersonalDataManager(USER_MODE_NORMAL); | 2835 ResetPersonalDataManager(USER_MODE_NORMAL); | 
| 2774 | 2836 | 
| 2775 // Expect that no new card is saved. | 2837 // Expect that no new card is saved. | 
| 2776 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2838 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 
| 2777 ASSERT_EQ(1U, results2.size()); | 2839 ASSERT_EQ(1U, results2.size()); | 
| 2778 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); | 2840 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); | 
| (...skipping 18 matching lines...) Expand all Loading... | |
| 2797 base::RunLoop().Run(); | 2859 base::RunLoop().Run(); | 
| 2798 | 2860 | 
| 2799 // Simulate a form submission with conflicting expiration year. | 2861 // Simulate a form submission with conflicting expiration year. | 
| 2800 FormData form; | 2862 FormData form; | 
| 2801 AddFullCreditCardForm(&form, "Biggie Smalls", "4111 1111 1111 1111", "01", | 2863 AddFullCreditCardForm(&form, "Biggie Smalls", "4111 1111 1111 1111", "01", | 
| 2802 /* different year */ "2999"); | 2864 /* different year */ "2999"); | 
| 2803 | 2865 | 
| 2804 FormStructure form_structure(form); | 2866 FormStructure form_structure(form); | 
| 2805 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2867 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2806 std::unique_ptr<CreditCard> imported_credit_card; | 2868 std::unique_ptr<CreditCard> imported_credit_card; | 
| 2807 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2869 bool imported_credit_card_matches_masked_server_credit_card; | 
| 2870 EXPECT_TRUE(ImportCreditCard( | |
| 2871 form_structure, false, &imported_credit_card, | |
| 2872 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2808 ASSERT_FALSE(imported_credit_card); | 2873 ASSERT_FALSE(imported_credit_card); | 
| 2809 | 2874 | 
| 2810 // Since no refresh is expected, reload the data from the database to make | 2875 // Since no refresh is expected, reload the data from the database to make | 
| 2811 // sure no changes were written out. | 2876 // sure no changes were written out. | 
| 2812 ResetPersonalDataManager(USER_MODE_NORMAL); | 2877 ResetPersonalDataManager(USER_MODE_NORMAL); | 
| 2813 | 2878 | 
| 2814 // Expect that the saved credit card is not modified. | 2879 // Expect that the saved credit card is not modified. | 
| 2815 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2880 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 
| 2816 ASSERT_EQ(1U, results.size()); | 2881 ASSERT_EQ(1U, results.size()); | 
| 2817 EXPECT_EQ(0, credit_card.Compare(*results[0])); | 2882 EXPECT_EQ(0, credit_card.Compare(*results[0])); | 
| (...skipping 26 matching lines...) Expand all Loading... | |
| 2844 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | 2909 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | 
| 2845 form.fields.push_back(field); | 2910 form.fields.push_back(field); | 
| 2846 | 2911 | 
| 2847 // Credit card section. | 2912 // Credit card section. | 
| 2848 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2913 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 
| 2849 "2999"); | 2914 "2999"); | 
| 2850 | 2915 | 
| 2851 FormStructure form_structure(form); | 2916 FormStructure form_structure(form); | 
| 2852 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2917 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2853 std::unique_ptr<CreditCard> imported_credit_card; | 2918 std::unique_ptr<CreditCard> imported_credit_card; | 
| 2854 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, false, | 2919 bool imported_credit_card_matches_masked_server_credit_card; | 
| 2855 &imported_credit_card)); | 2920 EXPECT_TRUE(personal_data_->ImportFormData( | 
| 2921 form_structure, false, &imported_credit_card, | |
| 2922 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2856 ASSERT_TRUE(imported_credit_card); | 2923 ASSERT_TRUE(imported_credit_card); | 
| 2924 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); | |
| 2857 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2925 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 
| 2858 | 2926 | 
| 2859 // Verify that the web database has been updated and the notification sent. | 2927 // Verify that the web database has been updated and the notification sent. | 
| 2860 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2928 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 2861 .WillOnce(QuitMainMessageLoop()); | 2929 .WillOnce(QuitMainMessageLoop()); | 
| 2862 base::RunLoop().Run(); | 2930 base::RunLoop().Run(); | 
| 2863 | 2931 | 
| 2864 // Test that the address has been saved. | 2932 // Test that the address has been saved. | 
| 2865 AutofillProfile expected_address(base::GenerateGUID(), | 2933 AutofillProfile expected_address(base::GenerateGUID(), | 
| 2866 "https://www.example.com"); | 2934 "https://www.example.com"); | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2922 test::CreateTestFormField("Country:", "country", "USA", "text", &field); | 2990 test::CreateTestFormField("Country:", "country", "USA", "text", &field); | 
| 2923 form.fields.push_back(field); | 2991 form.fields.push_back(field); | 
| 2924 | 2992 | 
| 2925 // Credit card section. | 2993 // Credit card section. | 
| 2926 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2994 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 
| 2927 "2999"); | 2995 "2999"); | 
| 2928 | 2996 | 
| 2929 FormStructure form_structure(form); | 2997 FormStructure form_structure(form); | 
| 2930 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2998 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 2931 std::unique_ptr<CreditCard> imported_credit_card; | 2999 std::unique_ptr<CreditCard> imported_credit_card; | 
| 3000 bool imported_credit_card_matches_masked_server_credit_card; | |
| 2932 // Still returns true because the credit card import was successful. | 3001 // Still returns true because the credit card import was successful. | 
| 2933 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, false, | 3002 EXPECT_TRUE(personal_data_->ImportFormData( | 
| 2934 &imported_credit_card)); | 3003 form_structure, false, &imported_credit_card, | 
| 3004 &imported_credit_card_matches_masked_server_credit_card)); | |
| 2935 ASSERT_TRUE(imported_credit_card); | 3005 ASSERT_TRUE(imported_credit_card); | 
| 3006 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); | |
| 2936 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 3007 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 
| 2937 | 3008 | 
| 2938 // Verify that the web database has been updated and the notification sent. | 3009 // Verify that the web database has been updated and the notification sent. | 
| 2939 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3010 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 
| 2940 .WillOnce(QuitMainMessageLoop()); | 3011 .WillOnce(QuitMainMessageLoop()); | 
| 2941 base::RunLoop().Run(); | 3012 base::RunLoop().Run(); | 
| 2942 | 3013 | 
| 2943 // Test that both addresses have been saved. | 3014 // Test that both addresses have been saved. | 
| 2944 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 3015 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 
| 2945 | 3016 | 
| (...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4169 ResetPersonalDataManager(USER_MODE_NORMAL); | 4240 ResetPersonalDataManager(USER_MODE_NORMAL); | 
| 4170 EXPECT_FALSE(personal_data_->GetCreditCards().empty()); | 4241 EXPECT_FALSE(personal_data_->GetCreditCards().empty()); | 
| 4171 | 4242 | 
| 4172 personal_data_->ClearAllServerData(); | 4243 personal_data_->ClearAllServerData(); | 
| 4173 | 4244 | 
| 4174 // Reload the database, everything should be gone. | 4245 // Reload the database, everything should be gone. | 
| 4175 ResetPersonalDataManager(USER_MODE_NORMAL); | 4246 ResetPersonalDataManager(USER_MODE_NORMAL); | 
| 4176 EXPECT_TRUE(personal_data_->GetCreditCards().empty()); | 4247 EXPECT_TRUE(personal_data_->GetCreditCards().empty()); | 
| 4177 } | 4248 } | 
| 4178 | 4249 | 
| 4179 TEST_F(PersonalDataManagerTest, DontDuplicateServerCard) { | 4250 TEST_F(PersonalDataManagerTest, | 
| 4251 DuplicateMaskedServerCard_DontDuplicateFullServerCard) { | |
| 
sebsg
2017/05/03 17:23:30
Can you split this one in two? Like DontDuplicateF
 
csashi
2017/05/03 17:43:09
Done.
 | |
| 4180 EnableWalletCardImport(); | 4252 EnableWalletCardImport(); | 
| 4181 | 4253 | 
| 4182 std::vector<CreditCard> server_cards; | 4254 std::vector<CreditCard> server_cards; | 
| 4183 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 4255 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 
| 4184 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 4256 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 
| 4185 "1881" /* Visa */, "01", "2999"); | 4257 "1881" /* Visa */, "01", "2999"); | 
| 4186 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 4258 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 
| 4187 | 4259 | 
| 4188 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 4260 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 
| 4189 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 4261 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 
| (...skipping 18 matching lines...) Expand all Loading... | |
| 4208 "text", &field); | 4280 "text", &field); | 
| 4209 form1.fields.push_back(field); | 4281 form1.fields.push_back(field); | 
| 4210 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | 4282 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | 
| 4211 form1.fields.push_back(field); | 4283 form1.fields.push_back(field); | 
| 4212 test::CreateTestFormField("Exp Year:", "exp_year", "2999", "text", &field); | 4284 test::CreateTestFormField("Exp Year:", "exp_year", "2999", "text", &field); | 
| 4213 form1.fields.push_back(field); | 4285 form1.fields.push_back(field); | 
| 4214 | 4286 | 
| 4215 FormStructure form_structure1(form1); | 4287 FormStructure form_structure1(form1); | 
| 4216 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 4288 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 4217 std::unique_ptr<CreditCard> imported_credit_card; | 4289 std::unique_ptr<CreditCard> imported_credit_card; | 
| 4218 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, false, | 4290 bool imported_credit_card_matches_masked_server_credit_card; | 
| 4219 &imported_credit_card)); | 4291 EXPECT_TRUE(personal_data_->ImportFormData( | 
| 4220 EXPECT_FALSE(imported_credit_card); | 4292 form_structure1, false, &imported_credit_card, | 
| 4293 &imported_credit_card_matches_masked_server_credit_card)); | |
| 4294 ASSERT_TRUE(imported_credit_card); | |
| 4295 EXPECT_TRUE(imported_credit_card_matches_masked_server_credit_card); | |
| 4296 personal_data_->SaveImportedCreditCard(*imported_credit_card); | |
| 4297 | |
| 4298 // Verify that the web database has been updated and the notification sent. | |
| 4299 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | |
| 4300 .WillOnce(QuitMainMessageLoop()); | |
| 4301 base::RunLoop().Run(); | |
| 4302 | |
| 4303 CreditCard local_card(base::GenerateGUID(), "https://www.example.com"); | |
| 4304 test::SetCreditCardInfo(&local_card, "John Dillinger", "4012888888881881", | |
| 4305 "01", "2999"); | |
| 4306 const std::vector<CreditCard*>& results = | |
| 4307 personal_data_->GetLocalCreditCards(); | |
| 4308 ASSERT_EQ(1U, results.size()); | |
| 4309 EXPECT_EQ(0, local_card.Compare(*results[0])); | |
| 4310 EXPECT_EQ(3U, personal_data_->GetCreditCards().size()); | |
| 4221 | 4311 | 
| 4222 // A user re-types (or fills with) an unmasked card. Don't offer to save | 4312 // A user re-types (or fills with) an unmasked card. Don't offer to save | 
| 4223 // here, either. Since it's unmasked, we know for certain that it's the same | 4313 // here, either. Since it's unmasked, we know for certain that it's the same | 
| 4224 // card. | 4314 // card. | 
| 4225 FormData form2; | 4315 FormData form2; | 
| 4226 test::CreateTestFormField("Name on card:", "name_on_card", "Clyde Barrow", | 4316 test::CreateTestFormField("Name on card:", "name_on_card", "Clyde Barrow", | 
| 4227 "text", &field); | 4317 "text", &field); | 
| 4228 form2.fields.push_back(field); | 4318 form2.fields.push_back(field); | 
| 4229 test::CreateTestFormField("Card Number:", "card_number", "347666888555", | 4319 test::CreateTestFormField("Card Number:", "card_number", "347666888555", | 
| 4230 "text", &field); | 4320 "text", &field); | 
| 4231 form2.fields.push_back(field); | 4321 form2.fields.push_back(field); | 
| 4232 test::CreateTestFormField("Exp Month:", "exp_month", "04", "text", &field); | 4322 test::CreateTestFormField("Exp Month:", "exp_month", "04", "text", &field); | 
| 4233 form2.fields.push_back(field); | 4323 form2.fields.push_back(field); | 
| 4234 test::CreateTestFormField("Exp Year:", "exp_year", "2999", "text", &field); | 4324 test::CreateTestFormField("Exp Year:", "exp_year", "2999", "text", &field); | 
| 4235 form2.fields.push_back(field); | 4325 form2.fields.push_back(field); | 
| 4236 | 4326 | 
| 4237 FormStructure form_structure2(form2); | 4327 FormStructure form_structure2(form2); | 
| 4238 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 4328 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 
| 4239 std::unique_ptr<CreditCard> imported_credit_card2; | 4329 std::unique_ptr<CreditCard> imported_credit_card2; | 
| 4240 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false, | 4330 EXPECT_FALSE(personal_data_->ImportFormData( | 
| 4241 &imported_credit_card2)); | 4331 form_structure2, false, &imported_credit_card2, | 
| 4332 &imported_credit_card_matches_masked_server_credit_card)); | |
| 4242 EXPECT_FALSE(imported_credit_card2); | 4333 EXPECT_FALSE(imported_credit_card2); | 
| 4243 } | 4334 } | 
| 4244 | 4335 | 
| 4245 // Tests the SaveImportedProfile method with different profiles to make sure the | 4336 // Tests the SaveImportedProfile method with different profiles to make sure the | 
| 4246 // merge logic works correctly. | 4337 // merge logic works correctly. | 
| 4247 typedef struct { | 4338 typedef struct { | 
| 4248 autofill::ServerFieldType field_type; | 4339 autofill::ServerFieldType field_type; | 
| 4249 std::string field_value; | 4340 std::string field_value; | 
| 4250 } ProfileField; | 4341 } ProfileField; | 
| 4251 | 4342 | 
| (...skipping 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6283 // to the converted address. | 6374 // to the converted address. | 
| 6284 EXPECT_EQ(profiles[0]->guid(), | 6375 EXPECT_EQ(profiles[0]->guid(), | 
| 6285 personal_data_->GetCreditCards()[0]->billing_address_id()); | 6376 personal_data_->GetCreditCards()[0]->billing_address_id()); | 
| 6286 // Make sure that the billing address id of the new server card still refers | 6377 // Make sure that the billing address id of the new server card still refers | 
| 6287 // to the converted address. | 6378 // to the converted address. | 
| 6288 EXPECT_EQ(profiles[0]->guid(), | 6379 EXPECT_EQ(profiles[0]->guid(), | 
| 6289 personal_data_->GetCreditCards()[1]->billing_address_id()); | 6380 personal_data_->GetCreditCards()[1]->billing_address_id()); | 
| 6290 } | 6381 } | 
| 6291 | 6382 | 
| 6292 } // namespace autofill | 6383 } // namespace autofill | 
| OLD | NEW |