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 6403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6414 // Make sure that the billing address id of the first server card still refers | 6414 // Make sure that the billing address id of the first server card still refers |
6415 // to the converted address. | 6415 // to the converted address. |
6416 EXPECT_EQ(profiles[0]->guid(), | 6416 EXPECT_EQ(profiles[0]->guid(), |
6417 personal_data_->GetCreditCards()[0]->billing_address_id()); | 6417 personal_data_->GetCreditCards()[0]->billing_address_id()); |
6418 // Make sure that the billing address id of the new server card still refers | 6418 // Make sure that the billing address id of the new server card still refers |
6419 // to the converted address. | 6419 // to the converted address. |
6420 EXPECT_EQ(profiles[0]->guid(), | 6420 EXPECT_EQ(profiles[0]->guid(), |
6421 personal_data_->GetCreditCards()[1]->billing_address_id()); | 6421 personal_data_->GetCreditCards()[1]->billing_address_id()); |
6422 } | 6422 } |
6423 | 6423 |
| 6424 TEST_F(PersonalDataManagerTest, RemoveByGUID_ResetsBillingAddress) { |
| 6425 /////////////////////////////////////////////////////////////////////// |
| 6426 // Setup. |
| 6427 /////////////////////////////////////////////////////////////////////// |
| 6428 EnableWalletCardImport(); |
| 6429 std::vector<CreditCard> server_cards; |
| 6430 |
| 6431 // Add two different profiles |
| 6432 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); |
| 6433 test::SetProfileInfo(&profile0, "Bob", "", "Doe", "", "Fox", "1212 Center.", |
| 6434 "Bld. 5", "Orlando", "FL", "32801", "US", "19482937549"); |
| 6435 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 6436 test::SetProfileInfo(&profile1, "Seb", "", "Doe", "", "ACME", |
| 6437 "1234 Evergreen Terrace", "Bld. 5", "Springfield", "IL", |
| 6438 "32801", "US", "15151231234"); |
| 6439 |
| 6440 // Add a local and a server card that have profile0 as their billing address. |
| 6441 CreditCard local_card0(base::GenerateGUID(), "https://www.example.com"); |
| 6442 test::SetCreditCardInfo(&local_card0, "John Dillinger", |
| 6443 "4111111111111111" /* Visa */, "01", "2999", |
| 6444 profile0.guid()); |
| 6445 CreditCard server_card0(CreditCard::FULL_SERVER_CARD, "c789"); |
| 6446 test::SetCreditCardInfo(&server_card0, "John Barrow", |
| 6447 "347666888555" /* American Express */, "04", "2999", |
| 6448 profile0.guid()); |
| 6449 server_cards.push_back(server_card0); |
| 6450 |
| 6451 // Do the same but for profile1. |
| 6452 CreditCard local_card1(base::GenerateGUID(), "https://www.example.com"); |
| 6453 test::SetCreditCardInfo(&local_card1, "Seb Dillinger", |
| 6454 "4111111111111111" /* Visa */, "01", "2999", |
| 6455 profile1.guid()); |
| 6456 CreditCard server_card1(CreditCard::FULL_SERVER_CARD, "c789"); |
| 6457 test::SetCreditCardInfo(&server_card1, "John Barrow", |
| 6458 "347666888555" /* American Express */, "04", "2999", |
| 6459 profile1.guid()); |
| 6460 server_cards.push_back(server_card1); |
| 6461 |
| 6462 // Add the data to the database. |
| 6463 personal_data_->AddProfile(profile0); |
| 6464 personal_data_->AddProfile(profile1); |
| 6465 personal_data_->AddCreditCard(local_card0); |
| 6466 personal_data_->AddCreditCard(local_card1); |
| 6467 test::SetServerCreditCards(autofill_table_, server_cards); |
| 6468 |
| 6469 personal_data_->Refresh(); |
| 6470 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 6471 .WillOnce(QuitMainMessageLoop()); |
| 6472 base::RunLoop().Run(); |
| 6473 |
| 6474 // Make sure everything was saved properly. |
| 6475 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 6476 EXPECT_EQ(4U, personal_data_->GetCreditCards().size()); |
| 6477 |
| 6478 /////////////////////////////////////////////////////////////////////// |
| 6479 // Tested method. |
| 6480 /////////////////////////////////////////////////////////////////////// |
| 6481 personal_data_->RemoveByGUID(profile0.guid()); |
| 6482 |
| 6483 /////////////////////////////////////////////////////////////////////// |
| 6484 // Validation. |
| 6485 /////////////////////////////////////////////////////////////////////// |
| 6486 |
| 6487 // Wait for the data to be refreshed. |
| 6488 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 6489 .WillOnce(QuitMainMessageLoop()); |
| 6490 base::RunLoop().Run(); |
| 6491 |
| 6492 // Make sure only profile0 was deleted. |
| 6493 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); |
| 6494 EXPECT_EQ(profile1.guid(), personal_data_->GetProfiles()[0]->guid()); |
| 6495 EXPECT_EQ(4U, personal_data_->GetCreditCards().size()); |
| 6496 |
| 6497 for (CreditCard* card : personal_data_->GetCreditCards()) { |
| 6498 if (card->guid() == local_card0.guid() || |
| 6499 card->guid() == server_card0.guid()) { |
| 6500 // The billing address id of local_card0 and server_card0 should have been |
| 6501 // reset. |
| 6502 EXPECT_EQ("", card->billing_address_id()); |
| 6503 } else { |
| 6504 // The billing address of local_card1 and server_card1 should still refer |
| 6505 // to profile1. |
| 6506 EXPECT_EQ(profile1.guid(), card->billing_address_id()); |
| 6507 } |
| 6508 } |
| 6509 } |
| 6510 |
6424 } // namespace autofill | 6511 } // namespace autofill |
OLD | NEW |