| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 123 |
| 124 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles(); | 124 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles(); |
| 125 ASSERT_EQ(2U, results1.size()); | 125 ASSERT_EQ(2U, results1.size()); |
| 126 EXPECT_EQ(0, profile0.Compare(*results1.at(0))); | 126 EXPECT_EQ(0, profile0.Compare(*results1.at(0))); |
| 127 EXPECT_EQ(0, profile1.Compare(*results1.at(1))); | 127 EXPECT_EQ(0, profile1.Compare(*results1.at(1))); |
| 128 | 128 |
| 129 // Three operations in one: | 129 // Three operations in one: |
| 130 // - Update profile0 | 130 // - Update profile0 |
| 131 // - Remove profile1 | 131 // - Remove profile1 |
| 132 // - Add profile2 | 132 // - Add profile2 |
| 133 profile0.SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("John")); | 133 profile0.SetInfo(NAME_FIRST, ASCIIToUTF16("John")); |
| 134 update.clear(); | 134 update.clear(); |
| 135 update.push_back(profile0); | 135 update.push_back(profile0); |
| 136 update.push_back(profile2); | 136 update.push_back(profile2); |
| 137 personal_data_->SetProfiles(&update); | 137 personal_data_->SetProfiles(&update); |
| 138 | 138 |
| 139 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles(); | 139 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles(); |
| 140 ASSERT_EQ(2U, results2.size()); | 140 ASSERT_EQ(2U, results2.size()); |
| 141 EXPECT_EQ(0, profile0.Compare(*results2.at(0))); | 141 EXPECT_EQ(0, profile0.Compare(*results2.at(0))); |
| 142 EXPECT_EQ(0, profile2.Compare(*results2.at(1))); | 142 EXPECT_EQ(0, profile2.Compare(*results2.at(1))); |
| 143 | 143 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 191 |
| 192 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards(); | 192 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards(); |
| 193 ASSERT_EQ(2U, results1.size()); | 193 ASSERT_EQ(2U, results1.size()); |
| 194 EXPECT_EQ(0, creditcard0.Compare(*results1.at(0))); | 194 EXPECT_EQ(0, creditcard0.Compare(*results1.at(0))); |
| 195 EXPECT_EQ(0, creditcard1.Compare(*results1.at(1))); | 195 EXPECT_EQ(0, creditcard1.Compare(*results1.at(1))); |
| 196 | 196 |
| 197 // Three operations in one: | 197 // Three operations in one: |
| 198 // - Update creditcard0 | 198 // - Update creditcard0 |
| 199 // - Remove creditcard1 | 199 // - Remove creditcard1 |
| 200 // - Add creditcard2 | 200 // - Add creditcard2 |
| 201 creditcard0.SetInfo(AutofillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); | 201 creditcard0.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe")); |
| 202 update.clear(); | 202 update.clear(); |
| 203 update.push_back(creditcard0); | 203 update.push_back(creditcard0); |
| 204 update.push_back(creditcard2); | 204 update.push_back(creditcard2); |
| 205 personal_data_->SetCreditCards(&update); | 205 personal_data_->SetCreditCards(&update); |
| 206 | 206 |
| 207 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 207 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 208 ASSERT_EQ(2U, results2.size()); | 208 ASSERT_EQ(2U, results2.size()); |
| 209 EXPECT_EQ(creditcard0, *results2.at(0)); | 209 EXPECT_EQ(creditcard0, *results2.at(0)); |
| 210 EXPECT_EQ(creditcard2, *results2.at(1)); | 210 EXPECT_EQ(creditcard2, *results2.at(1)); |
| 211 | 211 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 EXPECT_EQ(profile2, *results2.at(2)); | 492 EXPECT_EQ(profile2, *results2.at(2)); |
| 493 | 493 |
| 494 wds->RemoveAutofillProfile(profile1.guid()); | 494 wds->RemoveAutofillProfile(profile1.guid()); |
| 495 wds->RemoveAutofillProfile(profile2.guid()); | 495 wds->RemoveAutofillProfile(profile2.guid()); |
| 496 | 496 |
| 497 // Before telling the PDM to refresh, simulate an edit to one of the profiles | 497 // Before telling the PDM to refresh, simulate an edit to one of the profiles |
| 498 // via a SetProfile update (this would happen if the AutoFill window was | 498 // via a SetProfile update (this would happen if the AutoFill window was |
| 499 // open with a previous snapshot of the profiles, and something [e.g. sync] | 499 // open with a previous snapshot of the profiles, and something [e.g. sync] |
| 500 // removed a profile from the browser. In this edge case, we will end up | 500 // removed a profile from the browser. In this edge case, we will end up |
| 501 // in a consistent state by dropping the write). | 501 // in a consistent state by dropping the write). |
| 502 profile2.SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Jo")); | 502 profile2.SetInfo(NAME_FIRST, ASCIIToUTF16("Jo")); |
| 503 update.clear(); | 503 update.clear(); |
| 504 update.push_back(profile0); | 504 update.push_back(profile0); |
| 505 update.push_back(profile1); | 505 update.push_back(profile1); |
| 506 update.push_back(profile2); | 506 update.push_back(profile2); |
| 507 personal_data_->SetProfiles(&update); | 507 personal_data_->SetProfiles(&update); |
| 508 | 508 |
| 509 // Wait for the refresh. | 509 // Wait for the refresh. |
| 510 EXPECT_CALL(personal_data_observer_, | 510 EXPECT_CALL(personal_data_observer_, |
| 511 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); | 511 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); |
| 512 | 512 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 autofill_test::SetProfileInfo(&expected, "George", NULL, | 694 autofill_test::SetProfileInfo(&expected, "George", NULL, |
| 695 "Washington", NULL, NULL, "21 Laussat St", NULL, | 695 "Washington", NULL, NULL, "21 Laussat St", NULL, |
| 696 "San Francisco", "California", "94102", NULL, "6505550000", NULL); | 696 "San Francisco", "California", "94102", NULL, "6505550000", NULL); |
| 697 const std::vector<AutofillProfile*>& results = personal_data_->profiles(); | 697 const std::vector<AutofillProfile*>& results = personal_data_->profiles(); |
| 698 ASSERT_EQ(1U, results.size()); | 698 ASSERT_EQ(1U, results.size()); |
| 699 EXPECT_EQ(0, expected.Compare(*results[0])); | 699 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 700 } | 700 } |
| 701 | 701 |
| 702 TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) { | 702 TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) { |
| 703 CreditCard credit_card0; | 703 CreditCard credit_card0; |
| 704 credit_card0.SetInfo(AutofillType(CREDIT_CARD_NAME), ASCIIToUTF16("John")); | 704 credit_card0.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("John")); |
| 705 CreditCard credit_card1; | 705 CreditCard credit_card1; |
| 706 credit_card1.SetInfo(AutofillType(CREDIT_CARD_NAME), ASCIIToUTF16("Paul")); | 706 credit_card1.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Paul")); |
| 707 CreditCard credit_card2; | 707 CreditCard credit_card2; |
| 708 credit_card2.SetInfo(AutofillType(CREDIT_CARD_NAME), ASCIIToUTF16("Ringo")); | 708 credit_card2.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ringo")); |
| 709 CreditCard credit_card3; | 709 CreditCard credit_card3; |
| 710 credit_card3.SetInfo(AutofillType(CREDIT_CARD_NAME), ASCIIToUTF16("Other")); | 710 credit_card3.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Other")); |
| 711 CreditCard credit_card4; | 711 CreditCard credit_card4; |
| 712 credit_card4.SetInfo(AutofillType(CREDIT_CARD_NAME), ASCIIToUTF16("Ozzy")); | 712 credit_card4.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ozzy")); |
| 713 CreditCard credit_card5; | 713 CreditCard credit_card5; |
| 714 credit_card5.SetInfo(AutofillType(CREDIT_CARD_NAME), ASCIIToUTF16("Dio")); | 714 credit_card5.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Dio")); |
| 715 | 715 |
| 716 // This will verify that the web database has been loaded and the notification | 716 // This will verify that the web database has been loaded and the notification |
| 717 // sent out. | 717 // sent out. |
| 718 EXPECT_CALL(personal_data_observer_, | 718 EXPECT_CALL(personal_data_observer_, |
| 719 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); | 719 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); |
| 720 | 720 |
| 721 // The message loop will exit when the mock observer is notified. | 721 // The message loop will exit when the mock observer is notified. |
| 722 MessageLoop::current()->Run(); | 722 MessageLoop::current()->Run(); |
| 723 | 723 |
| 724 // Add the test credit cards to the database. | 724 // Add the test credit cards to the database. |
| (...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 | 1640 |
| 1641 // Expect that the newer information is saved. In this case the year is | 1641 // Expect that the newer information is saved. In this case the year is |
| 1642 // added to the existing credit card. | 1642 // added to the existing credit card. |
| 1643 CreditCard expected2; | 1643 CreditCard expected2; |
| 1644 autofill_test::SetCreditCardInfo(&expected2, | 1644 autofill_test::SetCreditCardInfo(&expected2, |
| 1645 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1645 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 1646 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 1646 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 1647 ASSERT_EQ(1U, results2.size()); | 1647 ASSERT_EQ(1U, results2.size()); |
| 1648 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 1648 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 1649 } | 1649 } |
| OLD | NEW |