| 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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 MessageLoopForUI message_loop_; | 80 MessageLoopForUI message_loop_; |
| 81 BrowserThread ui_thread_; | 81 BrowserThread ui_thread_; |
| 82 BrowserThread db_thread_; | 82 BrowserThread db_thread_; |
| 83 scoped_ptr<TestingProfile> profile_; | 83 scoped_ptr<TestingProfile> profile_; |
| 84 scoped_refptr<PersonalDataManager> personal_data_; | 84 scoped_refptr<PersonalDataManager> personal_data_; |
| 85 NotificationRegistrar registrar_; | 85 NotificationRegistrar registrar_; |
| 86 NotificationObserverMock observer_; | 86 NotificationObserverMock observer_; |
| 87 PersonalDataLoadedObserverMock personal_data_observer_; | 87 PersonalDataLoadedObserverMock personal_data_observer_; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 TEST_F(PersonalDataManagerTest, AddProfile) { |
| 91 // This will verify that the web database has been loaded and the notification |
| 92 // sent out. |
| 93 EXPECT_CALL(personal_data_observer_, |
| 94 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); |
| 95 |
| 96 // The message loop will exit when the mock observer is notified. |
| 97 MessageLoop::current()->Run(); |
| 98 |
| 99 AutofillProfile profile0; |
| 100 autofill_test::SetProfileInfo(&profile0, |
| 101 "John", "Mitchell", "Smith", |
| 102 "j@s.com", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA", |
| 103 "94102", "USA", "4158889999", "4152223333"); |
| 104 |
| 105 // Add profile0 to the database. |
| 106 personal_data_->AddProfile(profile0); |
| 107 |
| 108 // Reload the database. |
| 109 ResetPersonalDataManager(); |
| 110 EXPECT_CALL(personal_data_observer_, |
| 111 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); |
| 112 MessageLoop::current()->Run(); |
| 113 |
| 114 // Verify the addition. |
| 115 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles(); |
| 116 ASSERT_EQ(1U, results1.size()); |
| 117 EXPECT_EQ(0, profile0.CompareMulti(*results1.at(0))); |
| 118 |
| 119 // Add profile with identical values. Duplicates should not get saved. |
| 120 AutofillProfile profile0a = profile0; |
| 121 profile0a.set_guid(guid::GenerateGUID()); |
| 122 personal_data_->AddProfile(profile0a); |
| 123 |
| 124 // Reload the database. |
| 125 ResetPersonalDataManager(); |
| 126 EXPECT_CALL(personal_data_observer_, |
| 127 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); |
| 128 MessageLoop::current()->Run(); |
| 129 |
| 130 // Verify the non-addition. |
| 131 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles(); |
| 132 ASSERT_EQ(1U, results2.size()); |
| 133 EXPECT_EQ(0, profile0.CompareMulti(*results2.at(0))); |
| 134 |
| 135 // New profile with different email. |
| 136 AutofillProfile profile1 = profile0; |
| 137 profile1.set_guid(guid::GenerateGUID()); |
| 138 profile1.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("john@smith.com")); |
| 139 |
| 140 // Add the different profile. This should save as a separate profile. |
| 141 // Note that if this same profile was "merged" it would collapse to one |
| 142 // profile with a multi-valued entry for email. |
| 143 personal_data_->AddProfile(profile1); |
| 144 |
| 145 // Reload the database. |
| 146 ResetPersonalDataManager(); |
| 147 EXPECT_CALL(personal_data_observer_, |
| 148 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); |
| 149 MessageLoop::current()->Run(); |
| 150 |
| 151 // Verify the addition. |
| 152 const std::vector<AutofillProfile*>& results3 = personal_data_->profiles(); |
| 153 ASSERT_EQ(2U, results3.size()); |
| 154 EXPECT_EQ(0, profile0.CompareMulti(*results3.at(0))); |
| 155 EXPECT_EQ(0, profile1.CompareMulti(*results3.at(1))); |
| 156 } |
| 157 |
| 90 // TODO(jhawkins): Test SetProfiles w/out a WebDataService in the profile. | 158 // TODO(jhawkins): Test SetProfiles w/out a WebDataService in the profile. |
| 91 TEST_F(PersonalDataManagerTest, SetProfiles) { | 159 TEST_F(PersonalDataManagerTest, SetProfiles) { |
| 92 AutofillProfile profile0; | 160 AutofillProfile profile0; |
| 93 autofill_test::SetProfileInfo(&profile0, | 161 autofill_test::SetProfileInfo(&profile0, |
| 94 "Marion", "Mitchell", "Morrison", | 162 "Marion", "Mitchell", "Morrison", |
| 95 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 163 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| 96 "91601", "US", "12345678910", "01987654321"); | 164 "91601", "US", "12345678910", "01987654321"); |
| 97 | 165 |
| 98 AutofillProfile profile1; | 166 AutofillProfile profile1; |
| 99 autofill_test::SetProfileInfo(&profile1, | 167 autofill_test::SetProfileInfo(&profile1, |
| (...skipping 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1735 | 1803 |
| 1736 // Expect that the newer information is saved. In this case the year is | 1804 // Expect that the newer information is saved. In this case the year is |
| 1737 // added to the existing credit card. | 1805 // added to the existing credit card. |
| 1738 CreditCard expected2; | 1806 CreditCard expected2; |
| 1739 autofill_test::SetCreditCardInfo(&expected2, | 1807 autofill_test::SetCreditCardInfo(&expected2, |
| 1740 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1808 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 1741 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 1809 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 1742 ASSERT_EQ(1U, results2.size()); | 1810 ASSERT_EQ(1U, results2.size()); |
| 1743 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 1811 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 1744 } | 1812 } |
| OLD | NEW |