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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/files/scoped_temp_dir.h" |
8 #include "base/guid.h" | 9 #include "base/guid.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
11 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
14 #include "chrome/test/base/testing_profile.h" | |
15 #include "components/autofill/core/browser/autofill_metrics.h" | 15 #include "components/autofill/core/browser/autofill_metrics.h" |
16 #include "components/autofill/core/browser/autofill_profile.h" | 16 #include "components/autofill/core/browser/autofill_profile.h" |
17 #include "components/autofill/core/browser/autofill_test_utils.h" | 17 #include "components/autofill/core/browser/autofill_test_utils.h" |
18 #include "components/autofill/core/browser/form_structure.h" | 18 #include "components/autofill/core/browser/form_structure.h" |
19 #include "components/autofill/core/browser/personal_data_manager.h" | 19 #include "components/autofill/core/browser/personal_data_manager.h" |
20 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 20 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
21 #include "components/autofill/core/browser/webdata/autofill_table.h" | 21 #include "components/autofill/core/browser/webdata/autofill_table.h" |
22 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 22 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
23 #include "components/autofill/core/common/autofill_pref_names.h" | 23 #include "components/autofill/core/common/autofill_pref_names.h" |
24 #include "components/autofill/core/common/form_data.h" | 24 #include "components/autofill/core/common/form_data.h" |
25 #include "components/webdata/common/web_data_service_base.h" | 25 #include "components/webdata/common/web_data_service_base.h" |
26 #include "components/webdata/common/web_database_service.h" | 26 #include "components/webdata/common/web_database_service.h" |
27 #include "content/public/test/test_browser_thread.h" | |
28 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
30 | 29 |
31 using base::ASCIIToUTF16; | 30 using base::ASCIIToUTF16; |
32 | 31 |
33 using content::BrowserThread; | |
34 | |
35 namespace autofill { | 32 namespace autofill { |
36 namespace { | 33 namespace { |
37 | 34 |
38 ACTION(QuitUIMessageLoop) { | 35 enum UserMode { USER_MODE_NORMAL, USER_MODE_INCOGNITO }; |
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 36 |
40 base::MessageLoop::current()->Quit(); | 37 ACTION(QuitMainMessageLoop) { base::MessageLoop::current()->Quit(); } |
41 } | |
42 | 38 |
43 class PersonalDataLoadedObserverMock : public PersonalDataManagerObserver { | 39 class PersonalDataLoadedObserverMock : public PersonalDataManagerObserver { |
44 public: | 40 public: |
45 PersonalDataLoadedObserverMock() {} | 41 PersonalDataLoadedObserverMock() {} |
46 virtual ~PersonalDataLoadedObserverMock() {} | 42 virtual ~PersonalDataLoadedObserverMock() {} |
47 | 43 |
48 MOCK_METHOD0(OnPersonalDataChanged, void()); | 44 MOCK_METHOD0(OnPersonalDataChanged, void()); |
49 }; | 45 }; |
50 | 46 |
51 // Unlike the base AutofillMetrics, exposes copy and assignment constructors, | 47 // Unlike the base AutofillMetrics, exposes copy and assignment constructors, |
52 // which are handy for briefer test code. The AutofillMetrics class is | 48 // which are handy for briefer test code. The AutofillMetrics class is |
53 // stateless, so this is safe. | 49 // stateless, so this is safe. |
54 class TestAutofillMetrics : public AutofillMetrics { | 50 class TestAutofillMetrics : public AutofillMetrics { |
55 public: | 51 public: |
56 TestAutofillMetrics() {} | 52 TestAutofillMetrics() {} |
57 virtual ~TestAutofillMetrics() {} | 53 virtual ~TestAutofillMetrics() {} |
58 }; | 54 }; |
59 | 55 |
60 } // anonymous namespace | 56 } // anonymous namespace |
61 | 57 |
62 class PersonalDataManagerTest : public testing::Test { | 58 class PersonalDataManagerTest : public testing::Test { |
63 protected: | 59 protected: |
64 PersonalDataManagerTest() | 60 PersonalDataManagerTest() {} |
65 : ui_thread_(BrowserThread::UI, &message_loop_), | |
66 db_thread_(BrowserThread::DB) { | |
67 } | |
68 | 61 |
69 virtual void SetUp() { | 62 virtual void SetUp() { |
70 db_thread_.Start(); | |
71 | 63 |
| 64 prefs_ = test::PrefServiceForTesting(); |
72 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 65 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
73 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); | 66 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); |
74 web_database_ = new WebDatabaseService( | 67 web_database_ = new WebDatabaseService(path, |
75 path, | 68 base::MessageLoopProxy::current(), |
76 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), | 69 base::MessageLoopProxy::current()); |
77 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)); | |
78 web_database_->AddTable( | 70 web_database_->AddTable( |
79 scoped_ptr<WebDatabaseTable>(new AutofillTable("en-US"))); | 71 scoped_ptr<WebDatabaseTable>(new AutofillTable("en-US"))); |
80 web_database_->LoadDatabase(); | 72 web_database_->LoadDatabase(); |
81 autofill_database_service_ = new AutofillWebDataService( | 73 autofill_database_service_ = |
82 web_database_, | 74 new AutofillWebDataService(web_database_, |
83 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), | 75 base::MessageLoopProxy::current(), |
84 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 76 base::MessageLoopProxy::current(), |
85 WebDataServiceBase::ProfileErrorCallback()); | 77 WebDataServiceBase::ProfileErrorCallback()); |
86 autofill_database_service_->Init(); | 78 autofill_database_service_->Init(); |
87 | 79 |
88 profile_.reset(new TestingProfile); | 80 test::DisableSystemServices(prefs_.get()); |
89 profile_->CreateWebDataService(); | 81 ResetPersonalDataManager(USER_MODE_NORMAL); |
90 | |
91 test::DisableSystemServices(profile_.get()); | |
92 ResetPersonalDataManager(); | |
93 } | 82 } |
94 | 83 |
95 virtual void TearDown() { | 84 virtual void TearDown() { |
96 // Destruction order is imposed explicitly here. | 85 // Destruction order is imposed explicitly here. |
97 personal_data_.reset(NULL); | 86 personal_data_.reset(NULL); |
98 profile_.reset(NULL); | |
99 | 87 |
100 autofill_database_service_->ShutdownOnUIThread(); | 88 autofill_database_service_->ShutdownOnUIThread(); |
101 web_database_->ShutdownDatabase(); | 89 web_database_->ShutdownDatabase(); |
102 autofill_database_service_ = NULL; | 90 autofill_database_service_ = NULL; |
103 web_database_ = NULL; | 91 web_database_ = NULL; |
104 | |
105 // Schedule another task on the DB thread to notify us that it's safe to | |
106 // stop the thread. | |
107 base::WaitableEvent done(false, false); | |
108 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | |
109 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | |
110 done.Wait(); | |
111 base::MessageLoop::current()->PostTask(FROM_HERE, | |
112 base::MessageLoop::QuitClosure()); | |
113 base::MessageLoop::current()->Run(); | |
114 db_thread_.Stop(); | |
115 } | 92 } |
116 | 93 |
117 void ResetPersonalDataManager() { | 94 void ResetPersonalDataManager(UserMode user_mode) { |
| 95 bool is_incognito = (user_mode == USER_MODE_INCOGNITO); |
118 personal_data_.reset(new PersonalDataManager("en-US")); | 96 personal_data_.reset(new PersonalDataManager("en-US")); |
119 personal_data_->Init( | 97 personal_data_->Init( |
120 scoped_refptr<AutofillWebDataService>(autofill_database_service_), | 98 scoped_refptr<AutofillWebDataService>(autofill_database_service_), |
121 profile_->GetPrefs(), | 99 prefs_.get(), |
122 profile_->IsOffTheRecord()); | 100 is_incognito); |
123 personal_data_->AddObserver(&personal_data_observer_); | 101 personal_data_->AddObserver(&personal_data_observer_); |
124 | 102 |
125 // Verify that the web database has been updated and the notification sent. | 103 // Verify that the web database has been updated and the notification sent. |
126 EXPECT_CALL(personal_data_observer_, | 104 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
127 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 105 .WillOnce(QuitMainMessageLoop()); |
128 base::MessageLoop::current()->Run(); | 106 base::MessageLoop::current()->Run(); |
129 } | 107 } |
130 | 108 |
131 void MakeProfileIncognito() { | |
132 // Switch to an incognito profile. | |
133 profile_->ForceIncognito(true); | |
134 DCHECK(profile_->IsOffTheRecord()); | |
135 } | |
136 | |
137 base::MessageLoopForUI message_loop_; | 109 base::MessageLoopForUI message_loop_; |
138 content::TestBrowserThread ui_thread_; | 110 scoped_ptr<PrefService> prefs_; |
139 content::TestBrowserThread db_thread_; | |
140 scoped_ptr<TestingProfile> profile_; | |
141 scoped_refptr<AutofillWebDataService> autofill_database_service_; | 111 scoped_refptr<AutofillWebDataService> autofill_database_service_; |
142 scoped_refptr<WebDatabaseService> web_database_; | 112 scoped_refptr<WebDatabaseService> web_database_; |
143 base::ScopedTempDir temp_dir_; | 113 base::ScopedTempDir temp_dir_; |
144 scoped_ptr<PersonalDataManager> personal_data_; | 114 scoped_ptr<PersonalDataManager> personal_data_; |
145 PersonalDataLoadedObserverMock personal_data_observer_; | 115 PersonalDataLoadedObserverMock personal_data_observer_; |
146 }; | 116 }; |
147 | 117 |
148 TEST_F(PersonalDataManagerTest, AddProfile) { | 118 TEST_F(PersonalDataManagerTest, AddProfile) { |
149 // Add profile0 to the database. | 119 // Add profile0 to the database. |
150 AutofillProfile profile0(autofill::test::GetFullProfile()); | 120 AutofillProfile profile0(autofill::test::GetFullProfile()); |
151 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); | 121 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); |
152 personal_data_->AddProfile(profile0); | 122 personal_data_->AddProfile(profile0); |
153 | 123 |
154 // Reload the database. | 124 // Reload the database. |
155 ResetPersonalDataManager(); | 125 ResetPersonalDataManager(USER_MODE_NORMAL); |
156 | 126 |
157 // Verify the addition. | 127 // Verify the addition. |
158 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | 128 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
159 ASSERT_EQ(1U, results1.size()); | 129 ASSERT_EQ(1U, results1.size()); |
160 EXPECT_EQ(0, profile0.Compare(*results1[0])); | 130 EXPECT_EQ(0, profile0.Compare(*results1[0])); |
161 | 131 |
162 // Add profile with identical values. Duplicates should not get saved. | 132 // Add profile with identical values. Duplicates should not get saved. |
163 AutofillProfile profile0a = profile0; | 133 AutofillProfile profile0a = profile0; |
164 profile0a.set_guid(base::GenerateGUID()); | 134 profile0a.set_guid(base::GenerateGUID()); |
165 personal_data_->AddProfile(profile0a); | 135 personal_data_->AddProfile(profile0a); |
166 | 136 |
167 // Reload the database. | 137 // Reload the database. |
168 ResetPersonalDataManager(); | 138 ResetPersonalDataManager(USER_MODE_NORMAL); |
169 | 139 |
170 // Verify the non-addition. | 140 // Verify the non-addition. |
171 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 141 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
172 ASSERT_EQ(1U, results2.size()); | 142 ASSERT_EQ(1U, results2.size()); |
173 EXPECT_EQ(0, profile0.Compare(*results2[0])); | 143 EXPECT_EQ(0, profile0.Compare(*results2[0])); |
174 | 144 |
175 // New profile with different email. | 145 // New profile with different email. |
176 AutofillProfile profile1 = profile0; | 146 AutofillProfile profile1 = profile0; |
177 profile1.set_guid(base::GenerateGUID()); | 147 profile1.set_guid(base::GenerateGUID()); |
178 profile1.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("john@smith.com")); | 148 profile1.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("john@smith.com")); |
179 | 149 |
180 // Add the different profile. This should save as a separate profile. | 150 // Add the different profile. This should save as a separate profile. |
181 // Note that if this same profile was "merged" it would collapse to one | 151 // Note that if this same profile was "merged" it would collapse to one |
182 // profile with a multi-valued entry for email. | 152 // profile with a multi-valued entry for email. |
183 personal_data_->AddProfile(profile1); | 153 personal_data_->AddProfile(profile1); |
184 | 154 |
185 // Reload the database. | 155 // Reload the database. |
186 ResetPersonalDataManager(); | 156 ResetPersonalDataManager(USER_MODE_NORMAL); |
187 | 157 |
188 // Verify the addition. | 158 // Verify the addition. |
189 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); | 159 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); |
190 ASSERT_EQ(2U, results3.size()); | 160 ASSERT_EQ(2U, results3.size()); |
191 EXPECT_EQ(0, profile0.Compare(*results3[0])); | 161 EXPECT_EQ(0, profile0.Compare(*results3[0])); |
192 EXPECT_EQ(0, profile1.Compare(*results3[1])); | 162 EXPECT_EQ(0, profile1.Compare(*results3[1])); |
193 } | 163 } |
194 | 164 |
195 TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) { | 165 TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) { |
196 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | 166 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); |
(...skipping 12 matching lines...) Expand all Loading... |
209 test::SetProfileInfo(&profile2, | 179 test::SetProfileInfo(&profile2, |
210 "Josephine", "Alicia", "Saenz", | 180 "Josephine", "Alicia", "Saenz", |
211 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | 181 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", |
212 "32801", "US", "19482937549"); | 182 "32801", "US", "19482937549"); |
213 | 183 |
214 // Add two test profiles to the database. | 184 // Add two test profiles to the database. |
215 personal_data_->AddProfile(profile0); | 185 personal_data_->AddProfile(profile0); |
216 personal_data_->AddProfile(profile1); | 186 personal_data_->AddProfile(profile1); |
217 | 187 |
218 // Verify that the web database has been updated and the notification sent. | 188 // Verify that the web database has been updated and the notification sent. |
219 EXPECT_CALL(personal_data_observer_, | 189 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
220 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 190 .WillOnce(QuitMainMessageLoop()); |
221 base::MessageLoop::current()->Run(); | 191 base::MessageLoop::current()->Run(); |
222 | 192 |
223 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | 193 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
224 ASSERT_EQ(2U, results1.size()); | 194 ASSERT_EQ(2U, results1.size()); |
225 EXPECT_EQ(0, profile0.Compare(*results1[0])); | 195 EXPECT_EQ(0, profile0.Compare(*results1[0])); |
226 EXPECT_EQ(0, profile1.Compare(*results1[1])); | 196 EXPECT_EQ(0, profile1.Compare(*results1[1])); |
227 | 197 |
228 // Update, remove, and add. | 198 // Update, remove, and add. |
229 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); | 199 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); |
230 personal_data_->UpdateProfile(profile0); | 200 personal_data_->UpdateProfile(profile0); |
231 personal_data_->RemoveByGUID(profile1.guid()); | 201 personal_data_->RemoveByGUID(profile1.guid()); |
232 personal_data_->AddProfile(profile2); | 202 personal_data_->AddProfile(profile2); |
233 | 203 |
234 // Verify that the web database has been updated and the notification sent. | 204 // Verify that the web database has been updated and the notification sent. |
235 EXPECT_CALL(personal_data_observer_, | 205 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
236 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 206 .WillOnce(QuitMainMessageLoop()); |
237 base::MessageLoop::current()->Run(); | 207 base::MessageLoop::current()->Run(); |
238 | 208 |
239 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 209 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
240 ASSERT_EQ(2U, results2.size()); | 210 ASSERT_EQ(2U, results2.size()); |
241 EXPECT_EQ(0, profile0.Compare(*results2[0])); | 211 EXPECT_EQ(0, profile0.Compare(*results2[0])); |
242 EXPECT_EQ(0, profile2.Compare(*results2[1])); | 212 EXPECT_EQ(0, profile2.Compare(*results2[1])); |
243 | 213 |
244 // Reset the PersonalDataManager. This tests that the personal data was saved | 214 // Reset the PersonalDataManager. This tests that the personal data was saved |
245 // to the web database, and that we can load the profiles from the web | 215 // to the web database, and that we can load the profiles from the web |
246 // database. | 216 // database. |
247 ResetPersonalDataManager(); | 217 ResetPersonalDataManager(USER_MODE_NORMAL); |
248 | 218 |
249 // Verify that we've loaded the profiles from the web database. | 219 // Verify that we've loaded the profiles from the web database. |
250 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); | 220 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); |
251 ASSERT_EQ(2U, results3.size()); | 221 ASSERT_EQ(2U, results3.size()); |
252 EXPECT_EQ(0, profile0.Compare(*results3[0])); | 222 EXPECT_EQ(0, profile0.Compare(*results3[0])); |
253 EXPECT_EQ(0, profile2.Compare(*results3[1])); | 223 EXPECT_EQ(0, profile2.Compare(*results3[1])); |
254 } | 224 } |
255 | 225 |
256 TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) { | 226 TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) { |
257 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | 227 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); |
258 test::SetCreditCardInfo(&credit_card0, | 228 test::SetCreditCardInfo(&credit_card0, |
259 "John Dillinger", "423456789012" /* Visa */, "01", "2010"); | 229 "John Dillinger", "423456789012" /* Visa */, "01", "2010"); |
260 | 230 |
261 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); | 231 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); |
262 test::SetCreditCardInfo(&credit_card1, | 232 test::SetCreditCardInfo(&credit_card1, |
263 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012"); | 233 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012"); |
264 | 234 |
265 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); | 235 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); |
266 test::SetCreditCardInfo(&credit_card2, | 236 test::SetCreditCardInfo(&credit_card2, |
267 "Clyde Barrow", "347666888555" /* American Express */, "04", "2015"); | 237 "Clyde Barrow", "347666888555" /* American Express */, "04", "2015"); |
268 | 238 |
269 // Add two test credit cards to the database. | 239 // Add two test credit cards to the database. |
270 personal_data_->AddCreditCard(credit_card0); | 240 personal_data_->AddCreditCard(credit_card0); |
271 personal_data_->AddCreditCard(credit_card1); | 241 personal_data_->AddCreditCard(credit_card1); |
272 | 242 |
273 // Verify that the web database has been updated and the notification sent. | 243 // Verify that the web database has been updated and the notification sent. |
274 EXPECT_CALL(personal_data_observer_, | 244 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
275 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 245 .WillOnce(QuitMainMessageLoop()); |
276 base::MessageLoop::current()->Run(); | 246 base::MessageLoop::current()->Run(); |
277 | 247 |
278 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); | 248 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); |
279 ASSERT_EQ(2U, results1.size()); | 249 ASSERT_EQ(2U, results1.size()); |
280 EXPECT_EQ(0, credit_card0.Compare(*results1[0])); | 250 EXPECT_EQ(0, credit_card0.Compare(*results1[0])); |
281 EXPECT_EQ(0, credit_card1.Compare(*results1[1])); | 251 EXPECT_EQ(0, credit_card1.Compare(*results1[1])); |
282 | 252 |
283 // Update, remove, and add. | 253 // Update, remove, and add. |
284 credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe")); | 254 credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe")); |
285 personal_data_->UpdateCreditCard(credit_card0); | 255 personal_data_->UpdateCreditCard(credit_card0); |
286 personal_data_->RemoveByGUID(credit_card1.guid()); | 256 personal_data_->RemoveByGUID(credit_card1.guid()); |
287 personal_data_->AddCreditCard(credit_card2); | 257 personal_data_->AddCreditCard(credit_card2); |
288 | 258 |
289 // Verify that the web database has been updated and the notification sent. | 259 // Verify that the web database has been updated and the notification sent. |
290 EXPECT_CALL(personal_data_observer_, | 260 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
291 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 261 .WillOnce(QuitMainMessageLoop()); |
292 base::MessageLoop::current()->Run(); | 262 base::MessageLoop::current()->Run(); |
293 | 263 |
294 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 264 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
295 ASSERT_EQ(2U, results2.size()); | 265 ASSERT_EQ(2U, results2.size()); |
296 EXPECT_EQ(credit_card0, *results2[0]); | 266 EXPECT_EQ(credit_card0, *results2[0]); |
297 EXPECT_EQ(credit_card2, *results2[1]); | 267 EXPECT_EQ(credit_card2, *results2[1]); |
298 | 268 |
299 // Reset the PersonalDataManager. This tests that the personal data was saved | 269 // Reset the PersonalDataManager. This tests that the personal data was saved |
300 // to the web database, and that we can load the credit cards from the web | 270 // to the web database, and that we can load the credit cards from the web |
301 // database. | 271 // database. |
302 ResetPersonalDataManager(); | 272 ResetPersonalDataManager(USER_MODE_NORMAL); |
303 | 273 |
304 // Verify that we've loaded the credit cards from the web database. | 274 // Verify that we've loaded the credit cards from the web database. |
305 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); | 275 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); |
306 ASSERT_EQ(2U, results3.size()); | 276 ASSERT_EQ(2U, results3.size()); |
307 EXPECT_EQ(credit_card0, *results3[0]); | 277 EXPECT_EQ(credit_card0, *results3[0]); |
308 EXPECT_EQ(credit_card2, *results3[1]); | 278 EXPECT_EQ(credit_card2, *results3[1]); |
309 } | 279 } |
310 | 280 |
311 TEST_F(PersonalDataManagerTest, UpdateUnverifiedProfilesAndCreditCards) { | 281 TEST_F(PersonalDataManagerTest, UpdateUnverifiedProfilesAndCreditCards) { |
312 // Start with unverified data. | 282 // Start with unverified data. |
313 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); | 283 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); |
314 test::SetProfileInfo(&profile, | 284 test::SetProfileInfo(&profile, |
315 "Marion", "Mitchell", "Morrison", | 285 "Marion", "Mitchell", "Morrison", |
316 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 286 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
317 "91601", "US", "12345678910"); | 287 "91601", "US", "12345678910"); |
318 EXPECT_FALSE(profile.IsVerified()); | 288 EXPECT_FALSE(profile.IsVerified()); |
319 | 289 |
320 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); | 290 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); |
321 test::SetCreditCardInfo(&credit_card, | 291 test::SetCreditCardInfo(&credit_card, |
322 "John Dillinger", "423456789012" /* Visa */, "01", "2010"); | 292 "John Dillinger", "423456789012" /* Visa */, "01", "2010"); |
323 EXPECT_FALSE(credit_card.IsVerified()); | 293 EXPECT_FALSE(credit_card.IsVerified()); |
324 | 294 |
325 // Add the data to the database. | 295 // Add the data to the database. |
326 personal_data_->AddProfile(profile); | 296 personal_data_->AddProfile(profile); |
327 personal_data_->AddCreditCard(credit_card); | 297 personal_data_->AddCreditCard(credit_card); |
328 | 298 |
329 // Verify that the web database has been updated and the notification sent. | 299 // Verify that the web database has been updated and the notification sent. |
330 EXPECT_CALL(personal_data_observer_, | 300 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
331 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 301 .WillOnce(QuitMainMessageLoop()); |
332 base::MessageLoop::current()->Run(); | 302 base::MessageLoop::current()->Run(); |
333 | 303 |
334 const std::vector<AutofillProfile*>& profiles1 = | 304 const std::vector<AutofillProfile*>& profiles1 = |
335 personal_data_->GetProfiles(); | 305 personal_data_->GetProfiles(); |
336 const std::vector<CreditCard*>& cards1 = personal_data_->GetCreditCards(); | 306 const std::vector<CreditCard*>& cards1 = personal_data_->GetCreditCards(); |
337 ASSERT_EQ(1U, profiles1.size()); | 307 ASSERT_EQ(1U, profiles1.size()); |
338 ASSERT_EQ(1U, cards1.size()); | 308 ASSERT_EQ(1U, cards1.size()); |
339 EXPECT_EQ(0, profile.Compare(*profiles1[0])); | 309 EXPECT_EQ(0, profile.Compare(*profiles1[0])); |
340 EXPECT_EQ(0, credit_card.Compare(*cards1[0])); | 310 EXPECT_EQ(0, credit_card.Compare(*cards1[0])); |
341 | 311 |
(...skipping 22 matching lines...) Expand all Loading... |
364 EXPECT_EQ(original_credit_card.origin(), cards2[0]->origin()); | 334 EXPECT_EQ(original_credit_card.origin(), cards2[0]->origin()); |
365 | 335 |
366 // Try to update with data changed as well. | 336 // Try to update with data changed as well. |
367 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); | 337 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); |
368 credit_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe")); | 338 credit_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe")); |
369 | 339 |
370 personal_data_->UpdateProfile(profile); | 340 personal_data_->UpdateProfile(profile); |
371 personal_data_->UpdateCreditCard(credit_card); | 341 personal_data_->UpdateCreditCard(credit_card); |
372 | 342 |
373 // Verify that the web database has been updated and the notification sent. | 343 // Verify that the web database has been updated and the notification sent. |
374 EXPECT_CALL(personal_data_observer_, | 344 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
375 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 345 .WillOnce(QuitMainMessageLoop()); |
376 base::MessageLoop::current()->Run(); | 346 base::MessageLoop::current()->Run(); |
377 | 347 |
378 const std::vector<AutofillProfile*>& profiles3 = | 348 const std::vector<AutofillProfile*>& profiles3 = |
379 personal_data_->GetProfiles(); | 349 personal_data_->GetProfiles(); |
380 const std::vector<CreditCard*>& cards3 = personal_data_->GetCreditCards(); | 350 const std::vector<CreditCard*>& cards3 = personal_data_->GetCreditCards(); |
381 ASSERT_EQ(1U, profiles3.size()); | 351 ASSERT_EQ(1U, profiles3.size()); |
382 ASSERT_EQ(1U, cards3.size()); | 352 ASSERT_EQ(1U, cards3.size()); |
383 EXPECT_EQ(0, profile.Compare(*profiles3[0])); | 353 EXPECT_EQ(0, profile.Compare(*profiles3[0])); |
384 EXPECT_EQ(0, credit_card.Compare(*cards3[0])); | 354 EXPECT_EQ(0, credit_card.Compare(*cards3[0])); |
385 EXPECT_EQ(profile.origin(), profiles3[0]->origin()); | 355 EXPECT_EQ(profile.origin(), profiles3[0]->origin()); |
(...skipping 19 matching lines...) Expand all Loading... |
405 | 375 |
406 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); | 376 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); |
407 test::SetCreditCardInfo(&credit_card1, | 377 test::SetCreditCardInfo(&credit_card1, |
408 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012"); | 378 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012"); |
409 | 379 |
410 // Add two test profiles to the database. | 380 // Add two test profiles to the database. |
411 personal_data_->AddProfile(profile0); | 381 personal_data_->AddProfile(profile0); |
412 personal_data_->AddProfile(profile1); | 382 personal_data_->AddProfile(profile1); |
413 | 383 |
414 // Verify that the web database has been updated and the notification sent. | 384 // Verify that the web database has been updated and the notification sent. |
415 EXPECT_CALL(personal_data_observer_, | 385 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
416 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 386 .WillOnce(QuitMainMessageLoop()); |
417 base::MessageLoop::current()->Run(); | 387 base::MessageLoop::current()->Run(); |
418 | 388 |
419 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | 389 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
420 ASSERT_EQ(2U, results1.size()); | 390 ASSERT_EQ(2U, results1.size()); |
421 EXPECT_EQ(0, profile0.Compare(*results1[0])); | 391 EXPECT_EQ(0, profile0.Compare(*results1[0])); |
422 EXPECT_EQ(0, profile1.Compare(*results1[1])); | 392 EXPECT_EQ(0, profile1.Compare(*results1[1])); |
423 | 393 |
424 // Add two test credit cards to the database. | 394 // Add two test credit cards to the database. |
425 personal_data_->AddCreditCard(credit_card0); | 395 personal_data_->AddCreditCard(credit_card0); |
426 personal_data_->AddCreditCard(credit_card1); | 396 personal_data_->AddCreditCard(credit_card1); |
427 | 397 |
428 // Verify that the web database has been updated and the notification sent. | 398 // Verify that the web database has been updated and the notification sent. |
429 EXPECT_CALL(personal_data_observer_, | 399 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
430 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 400 .WillOnce(QuitMainMessageLoop()); |
431 base::MessageLoop::current()->Run(); | 401 base::MessageLoop::current()->Run(); |
432 | 402 |
433 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 403 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
434 ASSERT_EQ(2U, results2.size()); | 404 ASSERT_EQ(2U, results2.size()); |
435 EXPECT_EQ(credit_card0, *results2[0]); | 405 EXPECT_EQ(credit_card0, *results2[0]); |
436 EXPECT_EQ(credit_card1, *results2[1]); | 406 EXPECT_EQ(credit_card1, *results2[1]); |
437 | 407 |
438 // Determine uniqueness by inserting all of the GUIDs into a set and verifying | 408 // Determine uniqueness by inserting all of the GUIDs into a set and verifying |
439 // the size of the set matches the number of GUIDs. | 409 // the size of the set matches the number of GUIDs. |
440 std::set<std::string> guids; | 410 std::set<std::string> guids; |
441 guids.insert(profile0.guid()); | 411 guids.insert(profile0.guid()); |
442 guids.insert(profile1.guid()); | 412 guids.insert(profile1.guid()); |
443 guids.insert(credit_card0.guid()); | 413 guids.insert(credit_card0.guid()); |
444 guids.insert(credit_card1.guid()); | 414 guids.insert(credit_card1.guid()); |
445 EXPECT_EQ(4U, guids.size()); | 415 EXPECT_EQ(4U, guids.size()); |
446 } | 416 } |
447 | 417 |
448 // Test for http://crbug.com/50047. Makes sure that guids are populated | 418 // Test for http://crbug.com/50047. Makes sure that guids are populated |
449 // correctly on load. | 419 // correctly on load. |
450 TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) { | 420 TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) { |
451 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | 421 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); |
452 test::SetProfileInfo(&profile0, | 422 test::SetProfileInfo(&profile0, |
453 "y", "", "", "", "", "", "", "", "", "", "", ""); | 423 "y", "", "", "", "", "", "", "", "", "", "", ""); |
454 | 424 |
455 // Add the profile0 to the db. | 425 // Add the profile0 to the db. |
456 personal_data_->AddProfile(profile0); | 426 personal_data_->AddProfile(profile0); |
457 | 427 |
458 // Verify that the web database has been updated and the notification sent. | 428 // Verify that the web database has been updated and the notification sent. |
459 EXPECT_CALL(personal_data_observer_, | 429 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
460 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 430 .WillOnce(QuitMainMessageLoop()); |
461 base::MessageLoop::current()->Run(); | 431 base::MessageLoop::current()->Run(); |
462 | 432 |
463 // Verify that we've loaded the profiles from the web database. | 433 // Verify that we've loaded the profiles from the web database. |
464 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 434 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
465 ASSERT_EQ(1U, results2.size()); | 435 ASSERT_EQ(1U, results2.size()); |
466 EXPECT_EQ(0, profile0.Compare(*results2[0])); | 436 EXPECT_EQ(0, profile0.Compare(*results2[0])); |
467 | 437 |
468 // Add a new profile. | 438 // Add a new profile. |
469 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 439 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
470 test::SetProfileInfo(&profile1, | 440 test::SetProfileInfo(&profile1, |
471 "z", "", "", "", "", "", "", "", "", "", "", ""); | 441 "z", "", "", "", "", "", "", "", "", "", "", ""); |
472 personal_data_->AddProfile(profile1); | 442 personal_data_->AddProfile(profile1); |
473 | 443 |
474 // Verify that the web database has been updated and the notification sent. | 444 // Verify that the web database has been updated and the notification sent. |
475 EXPECT_CALL(personal_data_observer_, | 445 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
476 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 446 .WillOnce(QuitMainMessageLoop()); |
477 base::MessageLoop::current()->Run(); | 447 base::MessageLoop::current()->Run(); |
478 | 448 |
479 // Make sure the two profiles have different GUIDs, both valid. | 449 // Make sure the two profiles have different GUIDs, both valid. |
480 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); | 450 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); |
481 ASSERT_EQ(2U, results3.size()); | 451 ASSERT_EQ(2U, results3.size()); |
482 EXPECT_NE(results3[0]->guid(), results3[1]->guid()); | 452 EXPECT_NE(results3[0]->guid(), results3[1]->guid()); |
483 EXPECT_TRUE(base::IsValidGUID(results3[0]->guid())); | 453 EXPECT_TRUE(base::IsValidGUID(results3[0]->guid())); |
484 EXPECT_TRUE(base::IsValidGUID(results3[1]->guid())); | 454 EXPECT_TRUE(base::IsValidGUID(results3[1]->guid())); |
485 } | 455 } |
486 | 456 |
487 TEST_F(PersonalDataManagerTest, SetEmptyProfile) { | 457 TEST_F(PersonalDataManagerTest, SetEmptyProfile) { |
488 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | 458 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); |
489 test::SetProfileInfo(&profile0, | 459 test::SetProfileInfo(&profile0, |
490 "", "", "", "", "", "", "", "", "", "", "", ""); | 460 "", "", "", "", "", "", "", "", "", "", "", ""); |
491 | 461 |
492 // Add the empty profile to the database. | 462 // Add the empty profile to the database. |
493 personal_data_->AddProfile(profile0); | 463 personal_data_->AddProfile(profile0); |
494 | 464 |
495 // Note: no refresh here. | 465 // Note: no refresh here. |
496 | 466 |
497 // Reset the PersonalDataManager. This tests that the personal data was saved | 467 // Reset the PersonalDataManager. This tests that the personal data was saved |
498 // to the web database, and that we can load the profiles from the web | 468 // to the web database, and that we can load the profiles from the web |
499 // database. | 469 // database. |
500 ResetPersonalDataManager(); | 470 ResetPersonalDataManager(USER_MODE_NORMAL); |
501 | 471 |
502 // Verify that we've loaded the profiles from the web database. | 472 // Verify that we've loaded the profiles from the web database. |
503 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 473 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
504 ASSERT_EQ(0U, results2.size()); | 474 ASSERT_EQ(0U, results2.size()); |
505 } | 475 } |
506 | 476 |
507 TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) { | 477 TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) { |
508 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | 478 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); |
509 test::SetCreditCardInfo(&credit_card0, "", "", "", ""); | 479 test::SetCreditCardInfo(&credit_card0, "", "", "", ""); |
510 | 480 |
511 // Add the empty credit card to the database. | 481 // Add the empty credit card to the database. |
512 personal_data_->AddCreditCard(credit_card0); | 482 personal_data_->AddCreditCard(credit_card0); |
513 | 483 |
514 // Note: no refresh here. | 484 // Note: no refresh here. |
515 | 485 |
516 // Reset the PersonalDataManager. This tests that the personal data was saved | 486 // Reset the PersonalDataManager. This tests that the personal data was saved |
517 // to the web database, and that we can load the credit cards from the web | 487 // to the web database, and that we can load the credit cards from the web |
518 // database. | 488 // database. |
519 ResetPersonalDataManager(); | 489 ResetPersonalDataManager(USER_MODE_NORMAL); |
520 | 490 |
521 // Verify that we've loaded the credit cards from the web database. | 491 // Verify that we've loaded the credit cards from the web database. |
522 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 492 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
523 ASSERT_EQ(0U, results2.size()); | 493 ASSERT_EQ(0U, results2.size()); |
524 } | 494 } |
525 | 495 |
526 TEST_F(PersonalDataManagerTest, Refresh) { | 496 TEST_F(PersonalDataManagerTest, Refresh) { |
527 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | 497 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); |
528 test::SetProfileInfo(&profile0, | 498 test::SetProfileInfo(&profile0, |
529 "Marion", "Mitchell", "Morrison", | 499 "Marion", "Mitchell", "Morrison", |
530 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 500 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
531 "91601", "US", "12345678910"); | 501 "91601", "US", "12345678910"); |
532 | 502 |
533 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 503 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
534 test::SetProfileInfo(&profile1, | 504 test::SetProfileInfo(&profile1, |
535 "Josephine", "Alicia", "Saenz", | 505 "Josephine", "Alicia", "Saenz", |
536 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", | 506 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", |
537 "US", "19482937549"); | 507 "US", "19482937549"); |
538 | 508 |
539 // Add the test profiles to the database. | 509 // Add the test profiles to the database. |
540 personal_data_->AddProfile(profile0); | 510 personal_data_->AddProfile(profile0); |
541 personal_data_->AddProfile(profile1); | 511 personal_data_->AddProfile(profile1); |
542 | 512 |
543 // Verify that the web database has been updated and the notification sent. | 513 // Verify that the web database has been updated and the notification sent. |
544 EXPECT_CALL(personal_data_observer_, | 514 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
545 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 515 .WillOnce(QuitMainMessageLoop()); |
546 base::MessageLoop::current()->Run(); | 516 base::MessageLoop::current()->Run(); |
547 | 517 |
548 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | 518 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
549 ASSERT_EQ(2U, results1.size()); | 519 ASSERT_EQ(2U, results1.size()); |
550 EXPECT_EQ(profile0, *results1[0]); | 520 EXPECT_EQ(profile0, *results1[0]); |
551 EXPECT_EQ(profile1, *results1[1]); | 521 EXPECT_EQ(profile1, *results1[1]); |
552 | 522 |
553 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 523 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
554 test::SetProfileInfo(&profile2, | 524 test::SetProfileInfo(&profile2, |
555 "Josephine", "Alicia", "Saenz", | 525 "Josephine", "Alicia", "Saenz", |
556 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | 526 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", |
557 "32801", "US", "19482937549"); | 527 "32801", "US", "19482937549"); |
558 | 528 |
559 autofill_database_service_->AddAutofillProfile(profile2); | 529 autofill_database_service_->AddAutofillProfile(profile2); |
560 | 530 |
561 personal_data_->Refresh(); | 531 personal_data_->Refresh(); |
562 | 532 |
563 // Verify that the web database has been updated and the notification sent. | 533 // Verify that the web database has been updated and the notification sent. |
564 EXPECT_CALL(personal_data_observer_, | 534 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
565 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 535 .WillOnce(QuitMainMessageLoop()); |
566 base::MessageLoop::current()->Run(); | 536 base::MessageLoop::current()->Run(); |
567 | 537 |
568 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 538 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
569 ASSERT_EQ(3U, results2.size()); | 539 ASSERT_EQ(3U, results2.size()); |
570 EXPECT_EQ(profile0, *results2[0]); | 540 EXPECT_EQ(profile0, *results2[0]); |
571 EXPECT_EQ(profile1, *results2[1]); | 541 EXPECT_EQ(profile1, *results2[1]); |
572 EXPECT_EQ(profile2, *results2[2]); | 542 EXPECT_EQ(profile2, *results2[2]); |
573 | 543 |
574 autofill_database_service_->RemoveAutofillProfile(profile1.guid()); | 544 autofill_database_service_->RemoveAutofillProfile(profile1.guid()); |
575 autofill_database_service_->RemoveAutofillProfile(profile2.guid()); | 545 autofill_database_service_->RemoveAutofillProfile(profile2.guid()); |
576 | 546 |
577 // Before telling the PDM to refresh, simulate an edit to one of the deleted | 547 // Before telling the PDM to refresh, simulate an edit to one of the deleted |
578 // profiles via a SetProfile update (this would happen if the Autofill window | 548 // profiles via a SetProfile update (this would happen if the Autofill window |
579 // was open with a previous snapshot of the profiles, and something | 549 // was open with a previous snapshot of the profiles, and something |
580 // [e.g. sync] removed a profile from the browser. In this edge case, we will | 550 // [e.g. sync] removed a profile from the browser. In this edge case, we will |
581 // end up in a consistent state by dropping the write). | 551 // end up in a consistent state by dropping the write). |
582 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Mar")); | 552 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Mar")); |
583 profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jo")); | 553 profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jo")); |
584 personal_data_->UpdateProfile(profile0); | 554 personal_data_->UpdateProfile(profile0); |
585 personal_data_->AddProfile(profile1); | 555 personal_data_->AddProfile(profile1); |
586 personal_data_->AddProfile(profile2); | 556 personal_data_->AddProfile(profile2); |
587 | 557 |
588 // Verify that the web database has been updated and the notification sent. | 558 // Verify that the web database has been updated and the notification sent. |
589 EXPECT_CALL(personal_data_observer_, | 559 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
590 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 560 .WillOnce(QuitMainMessageLoop()); |
591 base::MessageLoop::current()->Run(); | 561 base::MessageLoop::current()->Run(); |
592 | 562 |
593 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); | 563 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); |
594 ASSERT_EQ(1U, results3.size()); | 564 ASSERT_EQ(1U, results3.size()); |
595 EXPECT_EQ(profile0, *results2[0]); | 565 EXPECT_EQ(profile0, *results2[0]); |
596 } | 566 } |
597 | 567 |
598 TEST_F(PersonalDataManagerTest, ImportFormData) { | 568 TEST_F(PersonalDataManagerTest, ImportFormData) { |
599 FormData form; | 569 FormData form; |
600 FormFieldData field; | 570 FormFieldData field; |
(...skipping 16 matching lines...) Expand all Loading... |
617 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | 587 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
618 form.fields.push_back(field); | 588 form.fields.push_back(field); |
619 FormStructure form_structure(form); | 589 FormStructure form_structure(form); |
620 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 590 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
621 scoped_ptr<CreditCard> imported_credit_card; | 591 scoped_ptr<CreditCard> imported_credit_card; |
622 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | 592 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
623 &imported_credit_card)); | 593 &imported_credit_card)); |
624 ASSERT_FALSE(imported_credit_card); | 594 ASSERT_FALSE(imported_credit_card); |
625 | 595 |
626 // Verify that the web database has been updated and the notification sent. | 596 // Verify that the web database has been updated and the notification sent. |
627 EXPECT_CALL(personal_data_observer_, | 597 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
628 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 598 .WillOnce(QuitMainMessageLoop()); |
629 base::MessageLoop::current()->Run(); | 599 base::MessageLoop::current()->Run(); |
630 | 600 |
631 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | 601 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); |
632 test::SetProfileInfo(&expected, "George", NULL, | 602 test::SetProfileInfo(&expected, "George", NULL, |
633 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, | 603 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, |
634 "San Francisco", "California", "94102", NULL, NULL); | 604 "San Francisco", "California", "94102", NULL, NULL); |
635 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | 605 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
636 ASSERT_EQ(1U, results.size()); | 606 ASSERT_EQ(1U, results.size()); |
637 EXPECT_EQ(0, expected.Compare(*results[0])); | 607 EXPECT_EQ(0, expected.Compare(*results[0])); |
638 } | 608 } |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | 832 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
863 form.fields.push_back(field); | 833 form.fields.push_back(field); |
864 FormStructure form_structure(form); | 834 FormStructure form_structure(form); |
865 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 835 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
866 scoped_ptr<CreditCard> imported_credit_card; | 836 scoped_ptr<CreditCard> imported_credit_card; |
867 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | 837 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
868 &imported_credit_card)); | 838 &imported_credit_card)); |
869 ASSERT_FALSE(imported_credit_card); | 839 ASSERT_FALSE(imported_credit_card); |
870 | 840 |
871 // Verify that the web database has been updated and the notification sent. | 841 // Verify that the web database has been updated and the notification sent. |
872 EXPECT_CALL(personal_data_observer_, | 842 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
873 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 843 .WillOnce(QuitMainMessageLoop()); |
874 base::MessageLoop::current()->Run(); | 844 base::MessageLoop::current()->Run(); |
875 | 845 |
876 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | 846 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); |
877 test::SetProfileInfo(&expected, "George", NULL, | 847 test::SetProfileInfo(&expected, "George", NULL, |
878 "Washington", NULL, NULL, "21 Laussat St", NULL, | 848 "Washington", NULL, NULL, "21 Laussat St", NULL, |
879 "San Francisco", "California", "94102", NULL, "(650) 555-0000"); | 849 "San Francisco", "California", "94102", NULL, "(650) 555-0000"); |
880 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | 850 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
881 ASSERT_EQ(1U, results.size()); | 851 ASSERT_EQ(1U, results.size()); |
882 EXPECT_EQ(0, expected.Compare(*results[0])); | 852 EXPECT_EQ(0, expected.Compare(*results[0])); |
883 } | 853 } |
(...skipping 25 matching lines...) Expand all Loading... |
909 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | 879 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
910 form.fields.push_back(field); | 880 form.fields.push_back(field); |
911 FormStructure form_structure(form); | 881 FormStructure form_structure(form); |
912 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 882 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
913 scoped_ptr<CreditCard> imported_credit_card; | 883 scoped_ptr<CreditCard> imported_credit_card; |
914 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | 884 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
915 &imported_credit_card)); | 885 &imported_credit_card)); |
916 ASSERT_FALSE(imported_credit_card); | 886 ASSERT_FALSE(imported_credit_card); |
917 | 887 |
918 // Verify that the web database has been updated and the notification sent. | 888 // Verify that the web database has been updated and the notification sent. |
919 EXPECT_CALL(personal_data_observer_, | 889 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
920 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 890 .WillOnce(QuitMainMessageLoop()); |
921 base::MessageLoop::current()->Run(); | 891 base::MessageLoop::current()->Run(); |
922 | 892 |
923 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | 893 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); |
924 test::SetProfileInfo(&expected, "George", NULL, | 894 test::SetProfileInfo(&expected, "George", NULL, |
925 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", "Apt. #42", | 895 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", "Apt. #42", |
926 "San Francisco", "California", "94102", NULL, NULL); | 896 "San Francisco", "California", "94102", NULL, NULL); |
927 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | 897 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
928 ASSERT_EQ(1U, results.size()); | 898 ASSERT_EQ(1U, results.size()); |
929 EXPECT_EQ(0, expected.Compare(*results[0])); | 899 EXPECT_EQ(0, expected.Compare(*results[0])); |
930 } | 900 } |
(...skipping 16 matching lines...) Expand all Loading... |
947 personal_data_->AddCreditCard(credit_card0); | 917 personal_data_->AddCreditCard(credit_card0); |
948 personal_data_->AddCreditCard(credit_card1); | 918 personal_data_->AddCreditCard(credit_card1); |
949 personal_data_->AddCreditCard(credit_card2); | 919 personal_data_->AddCreditCard(credit_card2); |
950 personal_data_->AddCreditCard(credit_card3); | 920 personal_data_->AddCreditCard(credit_card3); |
951 personal_data_->AddCreditCard(credit_card4); | 921 personal_data_->AddCreditCard(credit_card4); |
952 personal_data_->AddCreditCard(credit_card5); | 922 personal_data_->AddCreditCard(credit_card5); |
953 | 923 |
954 // Reset the PersonalDataManager. This tests that the personal data was saved | 924 // Reset the PersonalDataManager. This tests that the personal data was saved |
955 // to the web database, and that we can load the credit cards from the web | 925 // to the web database, and that we can load the credit cards from the web |
956 // database. | 926 // database. |
957 ResetPersonalDataManager(); | 927 ResetPersonalDataManager(USER_MODE_NORMAL); |
958 | 928 |
959 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 929 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
960 ASSERT_EQ(6U, results.size()); | 930 ASSERT_EQ(6U, results.size()); |
961 EXPECT_EQ(credit_card0.guid(), results[0]->guid()); | 931 EXPECT_EQ(credit_card0.guid(), results[0]->guid()); |
962 EXPECT_EQ(credit_card1.guid(), results[1]->guid()); | 932 EXPECT_EQ(credit_card1.guid(), results[1]->guid()); |
963 EXPECT_EQ(credit_card2.guid(), results[2]->guid()); | 933 EXPECT_EQ(credit_card2.guid(), results[2]->guid()); |
964 EXPECT_EQ(credit_card3.guid(), results[3]->guid()); | 934 EXPECT_EQ(credit_card3.guid(), results[3]->guid()); |
965 EXPECT_EQ(credit_card4.guid(), results[4]->guid()); | 935 EXPECT_EQ(credit_card4.guid(), results[4]->guid()); |
966 EXPECT_EQ(credit_card5.guid(), results[5]->guid()); | 936 EXPECT_EQ(credit_card5.guid(), results[5]->guid()); |
967 } | 937 } |
(...skipping 21 matching lines...) Expand all Loading... |
989 form1.fields.push_back(field); | 959 form1.fields.push_back(field); |
990 | 960 |
991 FormStructure form_structure1(form1); | 961 FormStructure form_structure1(form1); |
992 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | 962 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
993 scoped_ptr<CreditCard> imported_credit_card; | 963 scoped_ptr<CreditCard> imported_credit_card; |
994 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | 964 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
995 &imported_credit_card)); | 965 &imported_credit_card)); |
996 ASSERT_FALSE(imported_credit_card); | 966 ASSERT_FALSE(imported_credit_card); |
997 | 967 |
998 // Verify that the web database has been updated and the notification sent. | 968 // Verify that the web database has been updated and the notification sent. |
999 EXPECT_CALL(personal_data_observer_, | 969 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1000 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 970 .WillOnce(QuitMainMessageLoop()); |
1001 base::MessageLoop::current()->Run(); | 971 base::MessageLoop::current()->Run(); |
1002 | 972 |
1003 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | 973 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); |
1004 test::SetProfileInfo(&expected, "George", NULL, | 974 test::SetProfileInfo(&expected, "George", NULL, |
1005 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, | 975 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, |
1006 "San Francisco", "California", "94102", NULL, NULL); | 976 "San Francisco", "California", "94102", NULL, NULL); |
1007 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | 977 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
1008 ASSERT_EQ(1U, results1.size()); | 978 ASSERT_EQ(1U, results1.size()); |
1009 EXPECT_EQ(0, expected.Compare(*results1[0])); | 979 EXPECT_EQ(0, expected.Compare(*results1[0])); |
1010 | 980 |
(...skipping 18 matching lines...) Expand all Loading... |
1029 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | 999 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
1030 form2.fields.push_back(field); | 1000 form2.fields.push_back(field); |
1031 | 1001 |
1032 FormStructure form_structure2(form2); | 1002 FormStructure form_structure2(form2); |
1033 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1003 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
1034 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | 1004 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
1035 &imported_credit_card)); | 1005 &imported_credit_card)); |
1036 ASSERT_FALSE(imported_credit_card); | 1006 ASSERT_FALSE(imported_credit_card); |
1037 | 1007 |
1038 // Verify that the web database has been updated and the notification sent. | 1008 // Verify that the web database has been updated and the notification sent. |
1039 EXPECT_CALL(personal_data_observer_, | 1009 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1040 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1010 .WillOnce(QuitMainMessageLoop()); |
1041 base::MessageLoop::current()->Run(); | 1011 base::MessageLoop::current()->Run(); |
1042 | 1012 |
1043 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 1013 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
1044 | 1014 |
1045 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com"); | 1015 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com"); |
1046 test::SetProfileInfo(&expected2, "John", NULL, | 1016 test::SetProfileInfo(&expected2, "John", NULL, |
1047 "Adams", "second@gmail.com", NULL, "22 Laussat St", NULL, | 1017 "Adams", "second@gmail.com", NULL, "22 Laussat St", NULL, |
1048 "San Francisco", "California", "94102", NULL, NULL); | 1018 "San Francisco", "California", "94102", NULL, NULL); |
1049 ASSERT_EQ(2U, results2.size()); | 1019 ASSERT_EQ(2U, results2.size()); |
1050 EXPECT_EQ(0, expected.Compare(*results2[0])); | 1020 EXPECT_EQ(0, expected.Compare(*results2[0])); |
(...skipping 23 matching lines...) Expand all Loading... |
1074 form1.fields.push_back(field); | 1044 form1.fields.push_back(field); |
1075 | 1045 |
1076 FormStructure form_structure1(form1); | 1046 FormStructure form_structure1(form1); |
1077 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | 1047 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
1078 scoped_ptr<CreditCard> imported_credit_card; | 1048 scoped_ptr<CreditCard> imported_credit_card; |
1079 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | 1049 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
1080 &imported_credit_card)); | 1050 &imported_credit_card)); |
1081 ASSERT_FALSE(imported_credit_card); | 1051 ASSERT_FALSE(imported_credit_card); |
1082 | 1052 |
1083 // Verify that the web database has been updated and the notification sent. | 1053 // Verify that the web database has been updated and the notification sent. |
1084 EXPECT_CALL(personal_data_observer_, | 1054 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1085 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1055 .WillOnce(QuitMainMessageLoop()); |
1086 base::MessageLoop::current()->Run(); | 1056 base::MessageLoop::current()->Run(); |
1087 | 1057 |
1088 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | 1058 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); |
1089 test::SetProfileInfo(&expected, "George", NULL, | 1059 test::SetProfileInfo(&expected, "George", NULL, |
1090 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, | 1060 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, |
1091 "San Francisco", "California", "94102", NULL, NULL); | 1061 "San Francisco", "California", "94102", NULL, NULL); |
1092 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | 1062 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
1093 ASSERT_EQ(1U, results1.size()); | 1063 ASSERT_EQ(1U, results1.size()); |
1094 EXPECT_EQ(0, expected.Compare(*results1[0])); | 1064 EXPECT_EQ(0, expected.Compare(*results1[0])); |
1095 | 1065 |
(...skipping 17 matching lines...) Expand all Loading... |
1113 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | 1083 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
1114 form2.fields.push_back(field); | 1084 form2.fields.push_back(field); |
1115 | 1085 |
1116 FormStructure form_structure2(form2); | 1086 FormStructure form_structure2(form2); |
1117 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1087 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
1118 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | 1088 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
1119 &imported_credit_card)); | 1089 &imported_credit_card)); |
1120 ASSERT_FALSE(imported_credit_card); | 1090 ASSERT_FALSE(imported_credit_card); |
1121 | 1091 |
1122 // Verify that the web database has been updated and the notification sent. | 1092 // Verify that the web database has been updated and the notification sent. |
1123 EXPECT_CALL(personal_data_observer_, | 1093 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1124 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1094 .WillOnce(QuitMainMessageLoop()); |
1125 base::MessageLoop::current()->Run(); | 1095 base::MessageLoop::current()->Run(); |
1126 | 1096 |
1127 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 1097 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
1128 | 1098 |
1129 // Modify expected to include multi-valued fields. | 1099 // Modify expected to include multi-valued fields. |
1130 std::vector<base::string16> values; | 1100 std::vector<base::string16> values; |
1131 expected.GetRawMultiInfo(NAME_FULL, &values); | 1101 expected.GetRawMultiInfo(NAME_FULL, &values); |
1132 values.push_back(ASCIIToUTF16("John Adams")); | 1102 values.push_back(ASCIIToUTF16("John Adams")); |
1133 expected.SetRawMultiInfo(NAME_FULL, values); | 1103 expected.SetRawMultiInfo(NAME_FULL, values); |
1134 expected.GetRawMultiInfo(EMAIL_ADDRESS, &values); | 1104 expected.GetRawMultiInfo(EMAIL_ADDRESS, &values); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 form1.fields.push_back(field); | 1137 form1.fields.push_back(field); |
1168 | 1138 |
1169 FormStructure form_structure1(form1); | 1139 FormStructure form_structure1(form1); |
1170 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | 1140 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
1171 scoped_ptr<CreditCard> imported_credit_card; | 1141 scoped_ptr<CreditCard> imported_credit_card; |
1172 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | 1142 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
1173 &imported_credit_card)); | 1143 &imported_credit_card)); |
1174 ASSERT_FALSE(imported_credit_card); | 1144 ASSERT_FALSE(imported_credit_card); |
1175 | 1145 |
1176 // Verify that the web database has been updated and the notification sent. | 1146 // Verify that the web database has been updated and the notification sent. |
1177 EXPECT_CALL(personal_data_observer_, | 1147 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1178 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1148 .WillOnce(QuitMainMessageLoop()); |
1179 base::MessageLoop::current()->Run(); | 1149 base::MessageLoop::current()->Run(); |
1180 | 1150 |
1181 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | 1151 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); |
1182 test::SetProfileInfo( | 1152 test::SetProfileInfo( |
1183 &expected, "George", NULL, "Washington", "theprez@gmail.com", NULL, | 1153 &expected, "George", NULL, "Washington", "theprez@gmail.com", NULL, |
1184 "1600 Pennsylvania Avenue", "Suite A", "San Francisco", "California", | 1154 "1600 Pennsylvania Avenue", "Suite A", "San Francisco", "California", |
1185 "94102", NULL, "(650) 555-6666"); | 1155 "94102", NULL, "(650) 555-6666"); |
1186 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | 1156 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
1187 ASSERT_EQ(1U, results1.size()); | 1157 ASSERT_EQ(1U, results1.size()); |
1188 EXPECT_EQ(0, expected.Compare(*results1[0])); | 1158 EXPECT_EQ(0, expected.Compare(*results1[0])); |
(...skipping 28 matching lines...) Expand all Loading... |
1217 test::CreateTestFormField("Phone:", "phone", "6502231234", "text", &field); | 1187 test::CreateTestFormField("Phone:", "phone", "6502231234", "text", &field); |
1218 form2.fields.push_back(field); | 1188 form2.fields.push_back(field); |
1219 | 1189 |
1220 FormStructure form_structure2(form2); | 1190 FormStructure form_structure2(form2); |
1221 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1191 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
1222 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | 1192 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
1223 &imported_credit_card)); | 1193 &imported_credit_card)); |
1224 ASSERT_FALSE(imported_credit_card); | 1194 ASSERT_FALSE(imported_credit_card); |
1225 | 1195 |
1226 // Verify that the web database has been updated and the notification sent. | 1196 // Verify that the web database has been updated and the notification sent. |
1227 EXPECT_CALL(personal_data_observer_, | 1197 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1228 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1198 .WillOnce(QuitMainMessageLoop()); |
1229 base::MessageLoop::current()->Run(); | 1199 base::MessageLoop::current()->Run(); |
1230 | 1200 |
1231 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 1201 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
1232 | 1202 |
1233 // Add multi-valued phone number to expectation. Also, country gets added. | 1203 // Add multi-valued phone number to expectation. Also, country gets added. |
1234 std::vector<base::string16> values; | 1204 std::vector<base::string16> values; |
1235 expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); | 1205 expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); |
1236 values.push_back(ASCIIToUTF16("(650) 223-1234")); | 1206 values.push_back(ASCIIToUTF16("(650) 223-1234")); |
1237 expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); | 1207 expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); |
1238 expected.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); | 1208 expected.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); |
(...skipping 21 matching lines...) Expand all Loading... |
1260 form1.fields.push_back(field); | 1230 form1.fields.push_back(field); |
1261 | 1231 |
1262 FormStructure form_structure1(form1); | 1232 FormStructure form_structure1(form1); |
1263 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | 1233 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
1264 scoped_ptr<CreditCard> imported_credit_card; | 1234 scoped_ptr<CreditCard> imported_credit_card; |
1265 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | 1235 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
1266 &imported_credit_card)); | 1236 &imported_credit_card)); |
1267 EXPECT_FALSE(imported_credit_card); | 1237 EXPECT_FALSE(imported_credit_card); |
1268 | 1238 |
1269 // Verify that the web database has been updated and the notification sent. | 1239 // Verify that the web database has been updated and the notification sent. |
1270 EXPECT_CALL(personal_data_observer_, | 1240 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1271 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1241 .WillOnce(QuitMainMessageLoop()); |
1272 base::MessageLoop::current()->Run(); | 1242 base::MessageLoop::current()->Run(); |
1273 | 1243 |
1274 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | 1244 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); |
1275 test::SetProfileInfo(&expected, "George", NULL, | 1245 test::SetProfileInfo(&expected, "George", NULL, |
1276 "Washington", NULL, NULL, "190 High Street", NULL, | 1246 "Washington", NULL, NULL, "190 High Street", NULL, |
1277 "Philadelphia", "Pennsylvania", "19106", NULL, NULL); | 1247 "Philadelphia", "Pennsylvania", "19106", NULL, NULL); |
1278 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | 1248 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
1279 ASSERT_EQ(1U, results1.size()); | 1249 ASSERT_EQ(1U, results1.size()); |
1280 EXPECT_EQ(0, expected.Compare(*results1[0])); | 1250 EXPECT_EQ(0, expected.Compare(*results1[0])); |
1281 | 1251 |
(...skipping 18 matching lines...) Expand all Loading... |
1300 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); | 1270 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); |
1301 form2.fields.push_back(field); | 1271 form2.fields.push_back(field); |
1302 | 1272 |
1303 FormStructure form_structure2(form2); | 1273 FormStructure form_structure2(form2); |
1304 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1274 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
1305 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | 1275 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
1306 &imported_credit_card)); | 1276 &imported_credit_card)); |
1307 ASSERT_FALSE(imported_credit_card); | 1277 ASSERT_FALSE(imported_credit_card); |
1308 | 1278 |
1309 // Verify that the web database has been updated and the notification sent. | 1279 // Verify that the web database has been updated and the notification sent. |
1310 EXPECT_CALL(personal_data_observer_, | 1280 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1311 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1281 .WillOnce(QuitMainMessageLoop()); |
1312 base::MessageLoop::current()->Run(); | 1282 base::MessageLoop::current()->Run(); |
1313 | 1283 |
1314 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 1284 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
1315 | 1285 |
1316 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com"); | 1286 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com"); |
1317 test::SetProfileInfo(&expected2, "George", NULL, | 1287 test::SetProfileInfo(&expected2, "George", NULL, |
1318 "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL, | 1288 "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL, |
1319 "Philadelphia", "Pennsylvania", "19106", NULL, NULL); | 1289 "Philadelphia", "Pennsylvania", "19106", NULL, NULL); |
1320 ASSERT_EQ(1U, results2.size()); | 1290 ASSERT_EQ(1U, results2.size()); |
1321 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 1291 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
(...skipping 25 matching lines...) Expand all Loading... |
1347 form1.fields.push_back(field); | 1317 form1.fields.push_back(field); |
1348 | 1318 |
1349 FormStructure form_structure1(form1); | 1319 FormStructure form_structure1(form1); |
1350 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | 1320 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
1351 scoped_ptr<CreditCard> imported_credit_card; | 1321 scoped_ptr<CreditCard> imported_credit_card; |
1352 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | 1322 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
1353 &imported_credit_card)); | 1323 &imported_credit_card)); |
1354 ASSERT_FALSE(imported_credit_card); | 1324 ASSERT_FALSE(imported_credit_card); |
1355 | 1325 |
1356 // Verify that the web database has been updated and the notification sent. | 1326 // Verify that the web database has been updated and the notification sent. |
1357 EXPECT_CALL(personal_data_observer_, | 1327 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1358 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1328 .WillOnce(QuitMainMessageLoop()); |
1359 base::MessageLoop::current()->Run(); | 1329 base::MessageLoop::current()->Run(); |
1360 | 1330 |
1361 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | 1331 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); |
1362 test::SetProfileInfo(&expected, "George", NULL, | 1332 test::SetProfileInfo(&expected, "George", NULL, |
1363 "Washington", "theprez@gmail.com", "Government", "190 High Street", NULL, | 1333 "Washington", "theprez@gmail.com", "Government", "190 High Street", NULL, |
1364 "Philadelphia", "Pennsylvania", "19106", NULL, NULL); | 1334 "Philadelphia", "Pennsylvania", "19106", NULL, NULL); |
1365 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | 1335 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
1366 ASSERT_EQ(1U, results1.size()); | 1336 ASSERT_EQ(1U, results1.size()); |
1367 EXPECT_EQ(0, expected.Compare(*results1[0])); | 1337 EXPECT_EQ(0, expected.Compare(*results1[0])); |
1368 | 1338 |
(...skipping 19 matching lines...) Expand all Loading... |
1388 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); | 1358 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); |
1389 form2.fields.push_back(field); | 1359 form2.fields.push_back(field); |
1390 | 1360 |
1391 FormStructure form_structure2(form2); | 1361 FormStructure form_structure2(form2); |
1392 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1362 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
1393 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | 1363 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
1394 &imported_credit_card)); | 1364 &imported_credit_card)); |
1395 ASSERT_FALSE(imported_credit_card); | 1365 ASSERT_FALSE(imported_credit_card); |
1396 | 1366 |
1397 // Verify that the web database has been updated and the notification sent. | 1367 // Verify that the web database has been updated and the notification sent. |
1398 EXPECT_CALL(personal_data_observer_, | 1368 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1399 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1369 .WillOnce(QuitMainMessageLoop()); |
1400 base::MessageLoop::current()->Run(); | 1370 base::MessageLoop::current()->Run(); |
1401 | 1371 |
1402 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 1372 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
1403 | 1373 |
1404 // Expect no change. | 1374 // Expect no change. |
1405 ASSERT_EQ(1U, results2.size()); | 1375 ASSERT_EQ(1U, results2.size()); |
1406 EXPECT_EQ(0, expected.Compare(*results2[0])); | 1376 EXPECT_EQ(0, expected.Compare(*results2[0])); |
1407 } | 1377 } |
1408 | 1378 |
1409 TEST_F(PersonalDataManagerTest, AggregateProfileWithInsufficientAddress) { | 1379 TEST_F(PersonalDataManagerTest, AggregateProfileWithInsufficientAddress) { |
(...skipping 19 matching lines...) Expand all Loading... |
1429 | 1399 |
1430 FormStructure form_structure1(form1); | 1400 FormStructure form_structure1(form1); |
1431 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | 1401 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
1432 scoped_ptr<CreditCard> imported_credit_card; | 1402 scoped_ptr<CreditCard> imported_credit_card; |
1433 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, | 1403 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, |
1434 &imported_credit_card)); | 1404 &imported_credit_card)); |
1435 ASSERT_FALSE(imported_credit_card); | 1405 ASSERT_FALSE(imported_credit_card); |
1436 | 1406 |
1437 // Since no refresh is expected, reload the data from the database to make | 1407 // Since no refresh is expected, reload the data from the database to make |
1438 // sure no changes were written out. | 1408 // sure no changes were written out. |
1439 ResetPersonalDataManager(); | 1409 ResetPersonalDataManager(USER_MODE_NORMAL); |
1440 | 1410 |
1441 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | 1411 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
1442 ASSERT_EQ(0U, profiles.size()); | 1412 ASSERT_EQ(0U, profiles.size()); |
1443 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); | 1413 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); |
1444 ASSERT_EQ(0U, cards.size()); | 1414 ASSERT_EQ(0U, cards.size()); |
1445 } | 1415 } |
1446 | 1416 |
1447 TEST_F(PersonalDataManagerTest, AggregateExistingAuxiliaryProfile) { | 1417 TEST_F(PersonalDataManagerTest, AggregateExistingAuxiliaryProfile) { |
1448 // Simulate having access to an auxiliary profile. | 1418 // Simulate having access to an auxiliary profile. |
1449 // |auxiliary_profile| will be owned by |personal_data_|. | 1419 // |auxiliary_profile| will be owned by |personal_data_|. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 | 1486 |
1517 FormStructure form_structure1(form1); | 1487 FormStructure form_structure1(form1); |
1518 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | 1488 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
1519 scoped_ptr<CreditCard> imported_credit_card; | 1489 scoped_ptr<CreditCard> imported_credit_card; |
1520 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | 1490 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
1521 &imported_credit_card)); | 1491 &imported_credit_card)); |
1522 ASSERT_TRUE(imported_credit_card); | 1492 ASSERT_TRUE(imported_credit_card); |
1523 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 1493 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
1524 | 1494 |
1525 // Verify that the web database has been updated and the notification sent. | 1495 // Verify that the web database has been updated and the notification sent. |
1526 EXPECT_CALL(personal_data_observer_, | 1496 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1527 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1497 .WillOnce(QuitMainMessageLoop()); |
1528 base::MessageLoop::current()->Run(); | 1498 base::MessageLoop::current()->Run(); |
1529 | 1499 |
1530 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 1500 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
1531 test::SetCreditCardInfo(&expected, | 1501 test::SetCreditCardInfo(&expected, |
1532 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1502 "Biggie Smalls", "4111111111111111", "01", "2011"); |
1533 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 1503 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
1534 ASSERT_EQ(1U, results.size()); | 1504 ASSERT_EQ(1U, results.size()); |
1535 EXPECT_EQ(0, expected.Compare(*results[0])); | 1505 EXPECT_EQ(0, expected.Compare(*results[0])); |
1536 | 1506 |
1537 // Add a second different valid credit card. | 1507 // Add a second different valid credit card. |
(...skipping 10 matching lines...) Expand all Loading... |
1548 form2.fields.push_back(field); | 1518 form2.fields.push_back(field); |
1549 | 1519 |
1550 FormStructure form_structure2(form2); | 1520 FormStructure form_structure2(form2); |
1551 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1521 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
1552 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | 1522 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
1553 &imported_credit_card)); | 1523 &imported_credit_card)); |
1554 ASSERT_TRUE(imported_credit_card); | 1524 ASSERT_TRUE(imported_credit_card); |
1555 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 1525 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
1556 | 1526 |
1557 // Verify that the web database has been updated and the notification sent. | 1527 // Verify that the web database has been updated and the notification sent. |
1558 EXPECT_CALL(personal_data_observer_, | 1528 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1559 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1529 .WillOnce(QuitMainMessageLoop()); |
1560 base::MessageLoop::current()->Run(); | 1530 base::MessageLoop::current()->Run(); |
1561 | 1531 |
1562 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 1532 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
1563 test::SetCreditCardInfo(&expected2,"", "5500000000000004", "02", "2012"); | 1533 test::SetCreditCardInfo(&expected2,"", "5500000000000004", "02", "2012"); |
1564 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 1534 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
1565 ASSERT_EQ(2U, results2.size()); | 1535 ASSERT_EQ(2U, results2.size()); |
1566 EXPECT_EQ(0, expected.Compare(*results2[0])); | 1536 EXPECT_EQ(0, expected.Compare(*results2[0])); |
1567 EXPECT_EQ(0, expected2.Compare(*results2[1])); | 1537 EXPECT_EQ(0, expected2.Compare(*results2[1])); |
1568 } | 1538 } |
1569 | 1539 |
(...skipping 15 matching lines...) Expand all Loading... |
1585 | 1555 |
1586 FormStructure form_structure1(form1); | 1556 FormStructure form_structure1(form1); |
1587 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | 1557 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
1588 scoped_ptr<CreditCard> imported_credit_card; | 1558 scoped_ptr<CreditCard> imported_credit_card; |
1589 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | 1559 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
1590 &imported_credit_card)); | 1560 &imported_credit_card)); |
1591 ASSERT_TRUE(imported_credit_card); | 1561 ASSERT_TRUE(imported_credit_card); |
1592 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 1562 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
1593 | 1563 |
1594 // Verify that the web database has been updated and the notification sent. | 1564 // Verify that the web database has been updated and the notification sent. |
1595 EXPECT_CALL(personal_data_observer_, | 1565 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1596 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1566 .WillOnce(QuitMainMessageLoop()); |
1597 base::MessageLoop::current()->Run(); | 1567 base::MessageLoop::current()->Run(); |
1598 | 1568 |
1599 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 1569 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
1600 test::SetCreditCardInfo(&expected, | 1570 test::SetCreditCardInfo(&expected, |
1601 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1571 "Biggie Smalls", "4111111111111111", "01", "2011"); |
1602 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 1572 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
1603 ASSERT_EQ(1U, results.size()); | 1573 ASSERT_EQ(1U, results.size()); |
1604 EXPECT_EQ(0, expected.Compare(*results[0])); | 1574 EXPECT_EQ(0, expected.Compare(*results[0])); |
1605 | 1575 |
1606 // Add a second different invalid credit card. | 1576 // Add a second different invalid credit card. |
(...skipping 10 matching lines...) Expand all Loading... |
1617 form2.fields.push_back(field); | 1587 form2.fields.push_back(field); |
1618 | 1588 |
1619 FormStructure form_structure2(form2); | 1589 FormStructure form_structure2(form2); |
1620 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1590 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
1621 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, | 1591 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, |
1622 &imported_credit_card)); | 1592 &imported_credit_card)); |
1623 ASSERT_FALSE(imported_credit_card); | 1593 ASSERT_FALSE(imported_credit_card); |
1624 | 1594 |
1625 // Since no refresh is expected, reload the data from the database to make | 1595 // Since no refresh is expected, reload the data from the database to make |
1626 // sure no changes were written out. | 1596 // sure no changes were written out. |
1627 ResetPersonalDataManager(); | 1597 ResetPersonalDataManager(USER_MODE_NORMAL); |
1628 | 1598 |
1629 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 1599 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
1630 ASSERT_EQ(1U, results2.size()); | 1600 ASSERT_EQ(1U, results2.size()); |
1631 EXPECT_EQ(0, expected.Compare(*results2[0])); | 1601 EXPECT_EQ(0, expected.Compare(*results2[0])); |
1632 } | 1602 } |
1633 | 1603 |
1634 TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithConflict) { | 1604 TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithConflict) { |
1635 FormData form1; | 1605 FormData form1; |
1636 | 1606 |
1637 // Start with a single valid credit card form. | 1607 // Start with a single valid credit card form. |
(...skipping 11 matching lines...) Expand all Loading... |
1649 | 1619 |
1650 FormStructure form_structure1(form1); | 1620 FormStructure form_structure1(form1); |
1651 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | 1621 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
1652 scoped_ptr<CreditCard> imported_credit_card; | 1622 scoped_ptr<CreditCard> imported_credit_card; |
1653 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | 1623 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
1654 &imported_credit_card)); | 1624 &imported_credit_card)); |
1655 ASSERT_TRUE(imported_credit_card); | 1625 ASSERT_TRUE(imported_credit_card); |
1656 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 1626 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
1657 | 1627 |
1658 // Verify that the web database has been updated and the notification sent. | 1628 // Verify that the web database has been updated and the notification sent. |
1659 EXPECT_CALL(personal_data_observer_, | 1629 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1660 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1630 .WillOnce(QuitMainMessageLoop()); |
1661 base::MessageLoop::current()->Run(); | 1631 base::MessageLoop::current()->Run(); |
1662 | 1632 |
1663 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 1633 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
1664 test::SetCreditCardInfo(&expected, | 1634 test::SetCreditCardInfo(&expected, |
1665 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1635 "Biggie Smalls", "4111111111111111", "01", "2011"); |
1666 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 1636 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
1667 ASSERT_EQ(1U, results.size()); | 1637 ASSERT_EQ(1U, results.size()); |
1668 EXPECT_EQ(0, expected.Compare(*results[0])); | 1638 EXPECT_EQ(0, expected.Compare(*results[0])); |
1669 | 1639 |
1670 // Add a second different valid credit card where the year is different but | 1640 // Add a second different valid credit card where the year is different but |
(...skipping 10 matching lines...) Expand all Loading... |
1681 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); | 1651 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); |
1682 form2.fields.push_back(field); | 1652 form2.fields.push_back(field); |
1683 | 1653 |
1684 FormStructure form_structure2(form2); | 1654 FormStructure form_structure2(form2); |
1685 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1655 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
1686 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | 1656 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
1687 &imported_credit_card)); | 1657 &imported_credit_card)); |
1688 EXPECT_FALSE(imported_credit_card); | 1658 EXPECT_FALSE(imported_credit_card); |
1689 | 1659 |
1690 // Verify that the web database has been updated and the notification sent. | 1660 // Verify that the web database has been updated and the notification sent. |
1691 EXPECT_CALL(personal_data_observer_, | 1661 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1692 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1662 .WillOnce(QuitMainMessageLoop()); |
1693 base::MessageLoop::current()->Run(); | 1663 base::MessageLoop::current()->Run(); |
1694 | 1664 |
1695 // Expect that the newer information is saved. In this case the year is | 1665 // Expect that the newer information is saved. In this case the year is |
1696 // updated to "2012". | 1666 // updated to "2012". |
1697 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 1667 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
1698 test::SetCreditCardInfo(&expected2, | 1668 test::SetCreditCardInfo(&expected2, |
1699 "Biggie Smalls", "4111111111111111", "01", "2012"); | 1669 "Biggie Smalls", "4111111111111111", "01", "2012"); |
1700 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 1670 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
1701 ASSERT_EQ(1U, results2.size()); | 1671 ASSERT_EQ(1U, results2.size()); |
1702 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 1672 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
(...skipping 17 matching lines...) Expand all Loading... |
1720 | 1690 |
1721 FormStructure form_structure1(form1); | 1691 FormStructure form_structure1(form1); |
1722 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | 1692 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
1723 scoped_ptr<CreditCard> imported_credit_card; | 1693 scoped_ptr<CreditCard> imported_credit_card; |
1724 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | 1694 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
1725 &imported_credit_card)); | 1695 &imported_credit_card)); |
1726 ASSERT_TRUE(imported_credit_card); | 1696 ASSERT_TRUE(imported_credit_card); |
1727 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 1697 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
1728 | 1698 |
1729 // Verify that the web database has been updated and the notification sent. | 1699 // Verify that the web database has been updated and the notification sent. |
1730 EXPECT_CALL(personal_data_observer_, | 1700 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1731 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1701 .WillOnce(QuitMainMessageLoop()); |
1732 base::MessageLoop::current()->Run(); | 1702 base::MessageLoop::current()->Run(); |
1733 | 1703 |
1734 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 1704 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
1735 test::SetCreditCardInfo(&expected, | 1705 test::SetCreditCardInfo(&expected, |
1736 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1706 "Biggie Smalls", "4111111111111111", "01", "2011"); |
1737 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 1707 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
1738 ASSERT_EQ(1U, results.size()); | 1708 ASSERT_EQ(1U, results.size()); |
1739 EXPECT_EQ(0, expected.Compare(*results[0])); | 1709 EXPECT_EQ(0, expected.Compare(*results[0])); |
1740 | 1710 |
1741 // Add a second credit card with no number. | 1711 // Add a second credit card with no number. |
1742 FormData form2; | 1712 FormData form2; |
1743 test::CreateTestFormField( | 1713 test::CreateTestFormField( |
1744 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | 1714 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
1745 form2.fields.push_back(field); | 1715 form2.fields.push_back(field); |
1746 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | 1716 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
1747 form2.fields.push_back(field); | 1717 form2.fields.push_back(field); |
1748 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); | 1718 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); |
1749 form2.fields.push_back(field); | 1719 form2.fields.push_back(field); |
1750 | 1720 |
1751 FormStructure form_structure2(form2); | 1721 FormStructure form_structure2(form2); |
1752 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1722 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
1753 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, | 1723 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, |
1754 &imported_credit_card)); | 1724 &imported_credit_card)); |
1755 EXPECT_FALSE(imported_credit_card); | 1725 EXPECT_FALSE(imported_credit_card); |
1756 | 1726 |
1757 // Since no refresh is expected, reload the data from the database to make | 1727 // Since no refresh is expected, reload the data from the database to make |
1758 // sure no changes were written out. | 1728 // sure no changes were written out. |
1759 ResetPersonalDataManager(); | 1729 ResetPersonalDataManager(USER_MODE_NORMAL); |
1760 | 1730 |
1761 // No change is expected. | 1731 // No change is expected. |
1762 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 1732 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
1763 test::SetCreditCardInfo(&expected2, | 1733 test::SetCreditCardInfo(&expected2, |
1764 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1734 "Biggie Smalls", "4111111111111111", "01", "2011"); |
1765 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 1735 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
1766 ASSERT_EQ(1U, results2.size()); | 1736 ASSERT_EQ(1U, results2.size()); |
1767 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 1737 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
1768 } | 1738 } |
1769 | 1739 |
(...skipping 15 matching lines...) Expand all Loading... |
1785 | 1755 |
1786 FormStructure form_structure1(form1); | 1756 FormStructure form_structure1(form1); |
1787 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | 1757 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
1788 scoped_ptr<CreditCard> imported_credit_card; | 1758 scoped_ptr<CreditCard> imported_credit_card; |
1789 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | 1759 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
1790 &imported_credit_card)); | 1760 &imported_credit_card)); |
1791 ASSERT_TRUE(imported_credit_card); | 1761 ASSERT_TRUE(imported_credit_card); |
1792 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 1762 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
1793 | 1763 |
1794 // Verify that the web database has been updated and the notification sent. | 1764 // Verify that the web database has been updated and the notification sent. |
1795 EXPECT_CALL(personal_data_observer_, | 1765 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1796 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1766 .WillOnce(QuitMainMessageLoop()); |
1797 base::MessageLoop::current()->Run(); | 1767 base::MessageLoop::current()->Run(); |
1798 | 1768 |
1799 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 1769 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
1800 test::SetCreditCardInfo(&expected, | 1770 test::SetCreditCardInfo(&expected, |
1801 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1771 "Biggie Smalls", "4111111111111111", "01", "2011"); |
1802 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 1772 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
1803 ASSERT_EQ(1U, results.size()); | 1773 ASSERT_EQ(1U, results.size()); |
1804 EXPECT_EQ(0, expected.Compare(*results[0])); | 1774 EXPECT_EQ(0, expected.Compare(*results[0])); |
1805 | 1775 |
1806 // Add a second different valid credit card where the name is missing but | 1776 // Add a second different valid credit card where the name is missing but |
1807 // the credit card number matches. | 1777 // the credit card number matches. |
1808 FormData form2; | 1778 FormData form2; |
1809 // Note missing name. | 1779 // Note missing name. |
1810 test::CreateTestFormField( | 1780 test::CreateTestFormField( |
1811 "Card Number:", "card_number", "4111111111111111", "text", &field); | 1781 "Card Number:", "card_number", "4111111111111111", "text", &field); |
1812 form2.fields.push_back(field); | 1782 form2.fields.push_back(field); |
1813 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | 1783 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
1814 form2.fields.push_back(field); | 1784 form2.fields.push_back(field); |
1815 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); | 1785 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); |
1816 form2.fields.push_back(field); | 1786 form2.fields.push_back(field); |
1817 | 1787 |
1818 FormStructure form_structure2(form2); | 1788 FormStructure form_structure2(form2); |
1819 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1789 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
1820 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | 1790 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
1821 &imported_credit_card)); | 1791 &imported_credit_card)); |
1822 EXPECT_FALSE(imported_credit_card); | 1792 EXPECT_FALSE(imported_credit_card); |
1823 | 1793 |
1824 // Since no refresh is expected, reload the data from the database to make | 1794 // Since no refresh is expected, reload the data from the database to make |
1825 // sure no changes were written out. | 1795 // sure no changes were written out. |
1826 ResetPersonalDataManager(); | 1796 ResetPersonalDataManager(USER_MODE_NORMAL); |
1827 | 1797 |
1828 // No change is expected. | 1798 // No change is expected. |
1829 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 1799 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
1830 test::SetCreditCardInfo(&expected2, | 1800 test::SetCreditCardInfo(&expected2, |
1831 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1801 "Biggie Smalls", "4111111111111111", "01", "2011"); |
1832 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 1802 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
1833 ASSERT_EQ(1U, results2.size()); | 1803 ASSERT_EQ(1U, results2.size()); |
1834 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 1804 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
1835 | 1805 |
1836 // Add a third credit card where the expiration date is missing. | 1806 // Add a third credit card where the expiration date is missing. |
1837 FormData form3; | 1807 FormData form3; |
1838 test::CreateTestFormField( | 1808 test::CreateTestFormField( |
1839 "Name on card:", "name_on_card", "Johnny McEnroe", "text", &field); | 1809 "Name on card:", "name_on_card", "Johnny McEnroe", "text", &field); |
1840 form3.fields.push_back(field); | 1810 form3.fields.push_back(field); |
1841 test::CreateTestFormField( | 1811 test::CreateTestFormField( |
1842 "Card Number:", "card_number", "5555555555554444", "text", &field); | 1812 "Card Number:", "card_number", "5555555555554444", "text", &field); |
1843 form3.fields.push_back(field); | 1813 form3.fields.push_back(field); |
1844 // Note missing expiration month and year.. | 1814 // Note missing expiration month and year.. |
1845 | 1815 |
1846 FormStructure form_structure3(form3); | 1816 FormStructure form_structure3(form3); |
1847 form_structure3.DetermineHeuristicTypes(TestAutofillMetrics()); | 1817 form_structure3.DetermineHeuristicTypes(TestAutofillMetrics()); |
1848 EXPECT_FALSE(personal_data_->ImportFormData(form_structure3, | 1818 EXPECT_FALSE(personal_data_->ImportFormData(form_structure3, |
1849 &imported_credit_card)); | 1819 &imported_credit_card)); |
1850 ASSERT_FALSE(imported_credit_card); | 1820 ASSERT_FALSE(imported_credit_card); |
1851 | 1821 |
1852 // Since no refresh is expected, reload the data from the database to make | 1822 // Since no refresh is expected, reload the data from the database to make |
1853 // sure no changes were written out. | 1823 // sure no changes were written out. |
1854 ResetPersonalDataManager(); | 1824 ResetPersonalDataManager(USER_MODE_NORMAL); |
1855 | 1825 |
1856 // No change is expected. | 1826 // No change is expected. |
1857 CreditCard expected3(base::GenerateGUID(), "https://www.example.com"); | 1827 CreditCard expected3(base::GenerateGUID(), "https://www.example.com"); |
1858 test::SetCreditCardInfo(&expected3, | 1828 test::SetCreditCardInfo(&expected3, |
1859 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1829 "Biggie Smalls", "4111111111111111", "01", "2011"); |
1860 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); | 1830 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); |
1861 ASSERT_EQ(1U, results3.size()); | 1831 ASSERT_EQ(1U, results3.size()); |
1862 EXPECT_EQ(0, expected3.Compare(*results3[0])); | 1832 EXPECT_EQ(0, expected3.Compare(*results3[0])); |
1863 } | 1833 } |
1864 | 1834 |
1865 TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInOld) { | 1835 TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInOld) { |
1866 // Start with a single valid credit card stored via the preferences. | 1836 // Start with a single valid credit card stored via the preferences. |
1867 // Note the empty name. | 1837 // Note the empty name. |
1868 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); | 1838 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); |
1869 test::SetCreditCardInfo(&saved_credit_card, | 1839 test::SetCreditCardInfo(&saved_credit_card, |
1870 "", "4111111111111111" /* Visa */, "01", "2011"); | 1840 "", "4111111111111111" /* Visa */, "01", "2011"); |
1871 personal_data_->AddCreditCard(saved_credit_card); | 1841 personal_data_->AddCreditCard(saved_credit_card); |
1872 | 1842 |
1873 // Verify that the web database has been updated and the notification sent. | 1843 // Verify that the web database has been updated and the notification sent. |
1874 EXPECT_CALL(personal_data_observer_, | 1844 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1875 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1845 .WillOnce(QuitMainMessageLoop()); |
1876 base::MessageLoop::current()->Run(); | 1846 base::MessageLoop::current()->Run(); |
1877 | 1847 |
1878 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); | 1848 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); |
1879 ASSERT_EQ(1U, results1.size()); | 1849 ASSERT_EQ(1U, results1.size()); |
1880 EXPECT_EQ(saved_credit_card, *results1[0]); | 1850 EXPECT_EQ(saved_credit_card, *results1[0]); |
1881 | 1851 |
1882 | 1852 |
1883 // Add a second different valid credit card where the year is different but | 1853 // Add a second different valid credit card where the year is different but |
1884 // the credit card number matches. | 1854 // the credit card number matches. |
1885 FormData form; | 1855 FormData form; |
(...skipping 10 matching lines...) Expand all Loading... |
1896 form.fields.push_back(field); | 1866 form.fields.push_back(field); |
1897 | 1867 |
1898 FormStructure form_structure(form); | 1868 FormStructure form_structure(form); |
1899 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 1869 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
1900 scoped_ptr<CreditCard> imported_credit_card; | 1870 scoped_ptr<CreditCard> imported_credit_card; |
1901 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | 1871 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
1902 &imported_credit_card)); | 1872 &imported_credit_card)); |
1903 EXPECT_FALSE(imported_credit_card); | 1873 EXPECT_FALSE(imported_credit_card); |
1904 | 1874 |
1905 // Verify that the web database has been updated and the notification sent. | 1875 // Verify that the web database has been updated and the notification sent. |
1906 EXPECT_CALL(personal_data_observer_, | 1876 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1907 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1877 .WillOnce(QuitMainMessageLoop()); |
1908 base::MessageLoop::current()->Run(); | 1878 base::MessageLoop::current()->Run(); |
1909 | 1879 |
1910 // Expect that the newer information is saved. In this case the year is | 1880 // Expect that the newer information is saved. In this case the year is |
1911 // added to the existing credit card. | 1881 // added to the existing credit card. |
1912 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 1882 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
1913 test::SetCreditCardInfo(&expected2, | 1883 test::SetCreditCardInfo(&expected2, |
1914 "Biggie Smalls", "4111111111111111", "01", "2012"); | 1884 "Biggie Smalls", "4111111111111111", "01", "2012"); |
1915 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 1885 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
1916 ASSERT_EQ(1U, results2.size()); | 1886 ASSERT_EQ(1U, results2.size()); |
1917 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 1887 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
1918 } | 1888 } |
1919 | 1889 |
1920 // We allow the user to store a credit card number with separators via the UI. | 1890 // We allow the user to store a credit card number with separators via the UI. |
1921 // We should not try to re-aggregate the same card with the separators stripped. | 1891 // We should not try to re-aggregate the same card with the separators stripped. |
1922 TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithSeparators) { | 1892 TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithSeparators) { |
1923 // Start with a single valid credit card stored via the preferences. | 1893 // Start with a single valid credit card stored via the preferences. |
1924 // Note the separators in the credit card number. | 1894 // Note the separators in the credit card number. |
1925 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); | 1895 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); |
1926 test::SetCreditCardInfo(&saved_credit_card, | 1896 test::SetCreditCardInfo(&saved_credit_card, |
1927 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011"); | 1897 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011"); |
1928 personal_data_->AddCreditCard(saved_credit_card); | 1898 personal_data_->AddCreditCard(saved_credit_card); |
1929 | 1899 |
1930 // Verify that the web database has been updated and the notification sent. | 1900 // Verify that the web database has been updated and the notification sent. |
1931 EXPECT_CALL(personal_data_observer_, | 1901 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1932 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1902 .WillOnce(QuitMainMessageLoop()); |
1933 base::MessageLoop::current()->Run(); | 1903 base::MessageLoop::current()->Run(); |
1934 | 1904 |
1935 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); | 1905 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); |
1936 ASSERT_EQ(1U, results1.size()); | 1906 ASSERT_EQ(1U, results1.size()); |
1937 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); | 1907 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); |
1938 | 1908 |
1939 // Import the same card info, but with different separators in the number. | 1909 // Import the same card info, but with different separators in the number. |
1940 FormData form; | 1910 FormData form; |
1941 FormFieldData field; | 1911 FormFieldData field; |
1942 test::CreateTestFormField( | 1912 test::CreateTestFormField( |
1943 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | 1913 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
1944 form.fields.push_back(field); | 1914 form.fields.push_back(field); |
1945 test::CreateTestFormField( | 1915 test::CreateTestFormField( |
1946 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); | 1916 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
1947 form.fields.push_back(field); | 1917 form.fields.push_back(field); |
1948 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | 1918 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
1949 form.fields.push_back(field); | 1919 form.fields.push_back(field); |
1950 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); | 1920 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); |
1951 form.fields.push_back(field); | 1921 form.fields.push_back(field); |
1952 | 1922 |
1953 FormStructure form_structure(form); | 1923 FormStructure form_structure(form); |
1954 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 1924 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
1955 scoped_ptr<CreditCard> imported_credit_card; | 1925 scoped_ptr<CreditCard> imported_credit_card; |
1956 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | 1926 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
1957 &imported_credit_card)); | 1927 &imported_credit_card)); |
1958 EXPECT_FALSE(imported_credit_card); | 1928 EXPECT_FALSE(imported_credit_card); |
1959 | 1929 |
1960 // Since no refresh is expected, reload the data from the database to make | 1930 // Since no refresh is expected, reload the data from the database to make |
1961 // sure no changes were written out. | 1931 // sure no changes were written out. |
1962 ResetPersonalDataManager(); | 1932 ResetPersonalDataManager(USER_MODE_NORMAL); |
1963 | 1933 |
1964 // Expect that no new card is saved. | 1934 // Expect that no new card is saved. |
1965 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 1935 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
1966 ASSERT_EQ(1U, results2.size()); | 1936 ASSERT_EQ(1U, results2.size()); |
1967 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); | 1937 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); |
1968 } | 1938 } |
1969 | 1939 |
1970 // Ensure that if a verified profile already exists, aggregated profiles cannot | 1940 // Ensure that if a verified profile already exists, aggregated profiles cannot |
1971 // modify it in any way. | 1941 // modify it in any way. |
1972 TEST_F(PersonalDataManagerTest, AggregateExistingVerifiedProfileWithConflict) { | 1942 TEST_F(PersonalDataManagerTest, AggregateExistingVerifiedProfileWithConflict) { |
1973 // Start with a verified profile. | 1943 // Start with a verified profile. |
1974 AutofillProfile profile(base::GenerateGUID(), "Chrome settings"); | 1944 AutofillProfile profile(base::GenerateGUID(), "Chrome settings"); |
1975 test::SetProfileInfo(&profile, | 1945 test::SetProfileInfo(&profile, |
1976 "Marion", "Mitchell", "Morrison", | 1946 "Marion", "Mitchell", "Morrison", |
1977 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 1947 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
1978 "91601", "US", "12345678910"); | 1948 "91601", "US", "12345678910"); |
1979 EXPECT_TRUE(profile.IsVerified()); | 1949 EXPECT_TRUE(profile.IsVerified()); |
1980 | 1950 |
1981 // Add the profile to the database. | 1951 // Add the profile to the database. |
1982 personal_data_->AddProfile(profile); | 1952 personal_data_->AddProfile(profile); |
1983 | 1953 |
1984 // Verify that the web database has been updated and the notification sent. | 1954 // Verify that the web database has been updated and the notification sent. |
1985 EXPECT_CALL(personal_data_observer_, | 1955 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
1986 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1956 .WillOnce(QuitMainMessageLoop()); |
1987 base::MessageLoop::current()->Run(); | 1957 base::MessageLoop::current()->Run(); |
1988 | 1958 |
1989 // Simulate a form submission with conflicting info. | 1959 // Simulate a form submission with conflicting info. |
1990 FormData form; | 1960 FormData form; |
1991 FormFieldData field; | 1961 FormFieldData field; |
1992 test::CreateTestFormField( | 1962 test::CreateTestFormField( |
1993 "First name:", "first_name", "Marion", "text", &field); | 1963 "First name:", "first_name", "Marion", "text", &field); |
1994 form.fields.push_back(field); | 1964 form.fields.push_back(field); |
1995 test::CreateTestFormField( | 1965 test::CreateTestFormField( |
1996 "Last name:", "last_name", "Morrison", "text", &field); | 1966 "Last name:", "last_name", "Morrison", "text", &field); |
(...skipping 12 matching lines...) Expand all Loading... |
2009 form.fields.push_back(field); | 1979 form.fields.push_back(field); |
2010 | 1980 |
2011 FormStructure form_structure(form); | 1981 FormStructure form_structure(form); |
2012 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 1982 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
2013 scoped_ptr<CreditCard> imported_credit_card; | 1983 scoped_ptr<CreditCard> imported_credit_card; |
2014 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | 1984 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
2015 &imported_credit_card)); | 1985 &imported_credit_card)); |
2016 EXPECT_FALSE(imported_credit_card); | 1986 EXPECT_FALSE(imported_credit_card); |
2017 | 1987 |
2018 // Wait for the refresh, which in this case is a no-op. | 1988 // Wait for the refresh, which in this case is a no-op. |
2019 EXPECT_CALL(personal_data_observer_, | 1989 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
2020 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1990 .WillOnce(QuitMainMessageLoop()); |
2021 base::MessageLoop::current()->Run(); | 1991 base::MessageLoop::current()->Run(); |
2022 | 1992 |
2023 // Expect that no new profile is saved. | 1993 // Expect that no new profile is saved. |
2024 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | 1994 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
2025 ASSERT_EQ(1U, results.size()); | 1995 ASSERT_EQ(1U, results.size()); |
2026 EXPECT_EQ(0, profile.Compare(*results[0])); | 1996 EXPECT_EQ(0, profile.Compare(*results[0])); |
2027 } | 1997 } |
2028 | 1998 |
2029 // Ensure that if a verified credit card already exists, aggregated credit cards | 1999 // Ensure that if a verified credit card already exists, aggregated credit cards |
2030 // cannot modify it in any way. | 2000 // cannot modify it in any way. |
2031 TEST_F(PersonalDataManagerTest, | 2001 TEST_F(PersonalDataManagerTest, |
2032 AggregateExistingVerifiedCreditCardWithConflict) { | 2002 AggregateExistingVerifiedCreditCardWithConflict) { |
2033 // Start with a verified credit card. | 2003 // Start with a verified credit card. |
2034 CreditCard credit_card(base::GenerateGUID(), "Chrome settings"); | 2004 CreditCard credit_card(base::GenerateGUID(), "Chrome settings"); |
2035 test::SetCreditCardInfo(&credit_card, | 2005 test::SetCreditCardInfo(&credit_card, |
2036 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011"); | 2006 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011"); |
2037 EXPECT_TRUE(credit_card.IsVerified()); | 2007 EXPECT_TRUE(credit_card.IsVerified()); |
2038 | 2008 |
2039 // Add the credit card to the database. | 2009 // Add the credit card to the database. |
2040 personal_data_->AddCreditCard(credit_card); | 2010 personal_data_->AddCreditCard(credit_card); |
2041 | 2011 |
2042 // Verify that the web database has been updated and the notification sent. | 2012 // Verify that the web database has been updated and the notification sent. |
2043 EXPECT_CALL(personal_data_observer_, | 2013 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
2044 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 2014 .WillOnce(QuitMainMessageLoop()); |
2045 base::MessageLoop::current()->Run(); | 2015 base::MessageLoop::current()->Run(); |
2046 | 2016 |
2047 // Simulate a form submission with conflicting expiration year. | 2017 // Simulate a form submission with conflicting expiration year. |
2048 FormData form; | 2018 FormData form; |
2049 FormFieldData field; | 2019 FormFieldData field; |
2050 test::CreateTestFormField( | 2020 test::CreateTestFormField( |
2051 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | 2021 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
2052 form.fields.push_back(field); | 2022 form.fields.push_back(field); |
2053 test::CreateTestFormField( | 2023 test::CreateTestFormField( |
2054 "Card Number:", "card_number", "4111 1111 1111 1111", "text", &field); | 2024 "Card Number:", "card_number", "4111 1111 1111 1111", "text", &field); |
2055 form.fields.push_back(field); | 2025 form.fields.push_back(field); |
2056 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | 2026 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
2057 form.fields.push_back(field); | 2027 form.fields.push_back(field); |
2058 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); | 2028 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); |
2059 form.fields.push_back(field); | 2029 form.fields.push_back(field); |
2060 | 2030 |
2061 FormStructure form_structure(form); | 2031 FormStructure form_structure(form); |
2062 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 2032 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
2063 scoped_ptr<CreditCard> imported_credit_card; | 2033 scoped_ptr<CreditCard> imported_credit_card; |
2064 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | 2034 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
2065 &imported_credit_card)); | 2035 &imported_credit_card)); |
2066 ASSERT_FALSE(imported_credit_card); | 2036 ASSERT_FALSE(imported_credit_card); |
2067 | 2037 |
2068 // Since no refresh is expected, reload the data from the database to make | 2038 // Since no refresh is expected, reload the data from the database to make |
2069 // sure no changes were written out. | 2039 // sure no changes were written out. |
2070 ResetPersonalDataManager(); | 2040 ResetPersonalDataManager(USER_MODE_NORMAL); |
2071 | 2041 |
2072 // Expect that the saved credit card is not modified. | 2042 // Expect that the saved credit card is not modified. |
2073 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2043 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
2074 ASSERT_EQ(1U, results.size()); | 2044 ASSERT_EQ(1U, results.size()); |
2075 EXPECT_EQ(0, credit_card.Compare(*results[0])); | 2045 EXPECT_EQ(0, credit_card.Compare(*results[0])); |
2076 } | 2046 } |
2077 | 2047 |
2078 // Ensure that verified profiles can be saved via SaveImportedProfile, | 2048 // Ensure that verified profiles can be saved via SaveImportedProfile, |
2079 // overwriting existing unverified profiles. | 2049 // overwriting existing unverified profiles. |
2080 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithVerifiedData) { | 2050 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithVerifiedData) { |
2081 // Start with an unverified profile. | 2051 // Start with an unverified profile. |
2082 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); | 2052 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); |
2083 test::SetProfileInfo(&profile, | 2053 test::SetProfileInfo(&profile, |
2084 "Marion", "Mitchell", "Morrison", | 2054 "Marion", "Mitchell", "Morrison", |
2085 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 2055 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
2086 "91601", "US", "12345678910"); | 2056 "91601", "US", "12345678910"); |
2087 EXPECT_FALSE(profile.IsVerified()); | 2057 EXPECT_FALSE(profile.IsVerified()); |
2088 | 2058 |
2089 // Add the profile to the database. | 2059 // Add the profile to the database. |
2090 personal_data_->AddProfile(profile); | 2060 personal_data_->AddProfile(profile); |
2091 | 2061 |
2092 // Verify that the web database has been updated and the notification sent. | 2062 // Verify that the web database has been updated and the notification sent. |
2093 EXPECT_CALL(personal_data_observer_, | 2063 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
2094 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 2064 .WillOnce(QuitMainMessageLoop()); |
2095 base::MessageLoop::current()->Run(); | 2065 base::MessageLoop::current()->Run(); |
2096 | 2066 |
2097 AutofillProfile new_verified_profile = profile; | 2067 AutofillProfile new_verified_profile = profile; |
2098 new_verified_profile.set_guid(base::GenerateGUID()); | 2068 new_verified_profile.set_guid(base::GenerateGUID()); |
2099 new_verified_profile.set_origin("Chrome settings"); | 2069 new_verified_profile.set_origin("Chrome settings"); |
2100 new_verified_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Fizzbang, Inc.")); | 2070 new_verified_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Fizzbang, Inc.")); |
2101 EXPECT_TRUE(new_verified_profile.IsVerified()); | 2071 EXPECT_TRUE(new_verified_profile.IsVerified()); |
2102 | 2072 |
2103 personal_data_->SaveImportedProfile(new_verified_profile); | 2073 personal_data_->SaveImportedProfile(new_verified_profile); |
2104 | 2074 |
2105 // Verify that the web database has been updated and the notification sent. | 2075 // Verify that the web database has been updated and the notification sent. |
2106 EXPECT_CALL(personal_data_observer_, | 2076 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
2107 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 2077 .WillOnce(QuitMainMessageLoop()); |
2108 base::MessageLoop::current()->Run(); | 2078 base::MessageLoop::current()->Run(); |
2109 | 2079 |
2110 // Expect that the existing profile is not modified, and instead the new | 2080 // Expect that the existing profile is not modified, and instead the new |
2111 // profile is added. | 2081 // profile is added. |
2112 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | 2082 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
2113 ASSERT_EQ(1U, results.size()); | 2083 ASSERT_EQ(1U, results.size()); |
2114 EXPECT_EQ(0, new_verified_profile.Compare(*results[0])); | 2084 EXPECT_EQ(0, new_verified_profile.Compare(*results[0])); |
2115 } | 2085 } |
2116 | 2086 |
2117 // Ensure that verified profiles can be saved via SaveImportedProfile, | 2087 // Ensure that verified profiles can be saved via SaveImportedProfile, |
2118 // overwriting existing verified profiles as well. | 2088 // overwriting existing verified profiles as well. |
2119 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithExistingVerifiedData) { | 2089 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithExistingVerifiedData) { |
2120 // Start with a verified profile. | 2090 // Start with a verified profile. |
2121 AutofillProfile profile(base::GenerateGUID(), "Chrome settings"); | 2091 AutofillProfile profile(base::GenerateGUID(), "Chrome settings"); |
2122 test::SetProfileInfo(&profile, | 2092 test::SetProfileInfo(&profile, |
2123 "Marion", "Mitchell", "Morrison", | 2093 "Marion", "Mitchell", "Morrison", |
2124 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 2094 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
2125 "91601", "US", "12345678910"); | 2095 "91601", "US", "12345678910"); |
2126 EXPECT_TRUE(profile.IsVerified()); | 2096 EXPECT_TRUE(profile.IsVerified()); |
2127 | 2097 |
2128 // Add the profile to the database. | 2098 // Add the profile to the database. |
2129 personal_data_->AddProfile(profile); | 2099 personal_data_->AddProfile(profile); |
2130 | 2100 |
2131 // Verify that the web database has been updated and the notification sent. | 2101 // Verify that the web database has been updated and the notification sent. |
2132 EXPECT_CALL(personal_data_observer_, | 2102 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
2133 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 2103 .WillOnce(QuitMainMessageLoop()); |
2134 base::MessageLoop::current()->Run(); | 2104 base::MessageLoop::current()->Run(); |
2135 | 2105 |
2136 AutofillProfile new_verified_profile = profile; | 2106 AutofillProfile new_verified_profile = profile; |
2137 new_verified_profile.set_guid(base::GenerateGUID()); | 2107 new_verified_profile.set_guid(base::GenerateGUID()); |
2138 new_verified_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Fizzbang, Inc.")); | 2108 new_verified_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Fizzbang, Inc.")); |
2139 new_verified_profile.SetRawInfo(NAME_MIDDLE, base::string16()); | 2109 new_verified_profile.SetRawInfo(NAME_MIDDLE, base::string16()); |
2140 EXPECT_TRUE(new_verified_profile.IsVerified()); | 2110 EXPECT_TRUE(new_verified_profile.IsVerified()); |
2141 | 2111 |
2142 personal_data_->SaveImportedProfile(new_verified_profile); | 2112 personal_data_->SaveImportedProfile(new_verified_profile); |
2143 | 2113 |
2144 // Verify that the web database has been updated and the notification sent. | 2114 // Verify that the web database has been updated and the notification sent. |
2145 EXPECT_CALL(personal_data_observer_, | 2115 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
2146 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 2116 .WillOnce(QuitMainMessageLoop()); |
2147 base::MessageLoop::current()->Run(); | 2117 base::MessageLoop::current()->Run(); |
2148 | 2118 |
2149 // The new profile should be merged into the existing one. | 2119 // The new profile should be merged into the existing one. |
2150 AutofillProfile expected_profile = new_verified_profile; | 2120 AutofillProfile expected_profile = new_verified_profile; |
2151 expected_profile.set_guid(profile.guid()); | 2121 expected_profile.set_guid(profile.guid()); |
2152 std::vector<base::string16> names; | 2122 std::vector<base::string16> names; |
2153 expected_profile.GetRawMultiInfo(NAME_FULL, &names); | 2123 expected_profile.GetRawMultiInfo(NAME_FULL, &names); |
2154 names.insert(names.begin(), ASCIIToUTF16("Marion Mitchell Morrison")); | 2124 names.insert(names.begin(), ASCIIToUTF16("Marion Mitchell Morrison")); |
2155 expected_profile.SetRawMultiInfo(NAME_FULL, names); | 2125 expected_profile.SetRawMultiInfo(NAME_FULL, names); |
2156 | 2126 |
2157 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | 2127 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
2158 ASSERT_EQ(1U, results.size()); | 2128 ASSERT_EQ(1U, results.size()); |
2159 EXPECT_EQ(expected_profile, *results[0]); | 2129 EXPECT_EQ(expected_profile, *results[0]); |
2160 } | 2130 } |
2161 | 2131 |
2162 // Ensure that verified credit cards can be saved via SaveImportedCreditCard. | 2132 // Ensure that verified credit cards can be saved via SaveImportedCreditCard. |
2163 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) { | 2133 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) { |
2164 // Start with a verified credit card. | 2134 // Start with a verified credit card. |
2165 CreditCard credit_card(base::GenerateGUID(), "Chrome settings"); | 2135 CreditCard credit_card(base::GenerateGUID(), "Chrome settings"); |
2166 test::SetCreditCardInfo(&credit_card, | 2136 test::SetCreditCardInfo(&credit_card, |
2167 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011"); | 2137 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011"); |
2168 EXPECT_TRUE(credit_card.IsVerified()); | 2138 EXPECT_TRUE(credit_card.IsVerified()); |
2169 | 2139 |
2170 // Add the credit card to the database. | 2140 // Add the credit card to the database. |
2171 personal_data_->AddCreditCard(credit_card); | 2141 personal_data_->AddCreditCard(credit_card); |
2172 | 2142 |
2173 // Verify that the web database has been updated and the notification sent. | 2143 // Verify that the web database has been updated and the notification sent. |
2174 EXPECT_CALL(personal_data_observer_, | 2144 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
2175 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 2145 .WillOnce(QuitMainMessageLoop()); |
2176 base::MessageLoop::current()->Run(); | 2146 base::MessageLoop::current()->Run(); |
2177 | 2147 |
2178 CreditCard new_verified_card = credit_card; | 2148 CreditCard new_verified_card = credit_card; |
2179 new_verified_card.set_guid(base::GenerateGUID()); | 2149 new_verified_card.set_guid(base::GenerateGUID()); |
2180 new_verified_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("B. Small")); | 2150 new_verified_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("B. Small")); |
2181 EXPECT_TRUE(new_verified_card.IsVerified()); | 2151 EXPECT_TRUE(new_verified_card.IsVerified()); |
2182 | 2152 |
2183 personal_data_->SaveImportedCreditCard(new_verified_card); | 2153 personal_data_->SaveImportedCreditCard(new_verified_card); |
2184 | 2154 |
2185 // Verify that the web database has been updated and the notification sent. | 2155 // Verify that the web database has been updated and the notification sent. |
2186 EXPECT_CALL(personal_data_observer_, | 2156 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
2187 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 2157 .WillOnce(QuitMainMessageLoop()); |
2188 base::MessageLoop::current()->Run(); | 2158 base::MessageLoop::current()->Run(); |
2189 | 2159 |
2190 // Expect that the saved credit card is updated. | 2160 // Expect that the saved credit card is updated. |
2191 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2161 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
2192 ASSERT_EQ(1U, results.size()); | 2162 ASSERT_EQ(1U, results.size()); |
2193 EXPECT_EQ(ASCIIToUTF16("B. Small"), results[0]->GetRawInfo(CREDIT_CARD_NAME)); | 2163 EXPECT_EQ(ASCIIToUTF16("B. Small"), results[0]->GetRawInfo(CREDIT_CARD_NAME)); |
2194 } | 2164 } |
2195 | 2165 |
2196 TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) { | 2166 TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) { |
2197 // Check that there are no available types with no profiles stored. | 2167 // Check that there are no available types with no profiles stored. |
2198 ServerFieldTypeSet non_empty_types; | 2168 ServerFieldTypeSet non_empty_types; |
2199 personal_data_->GetNonEmptyTypes(&non_empty_types); | 2169 personal_data_->GetNonEmptyTypes(&non_empty_types); |
2200 EXPECT_EQ(0U, non_empty_types.size()); | 2170 EXPECT_EQ(0U, non_empty_types.size()); |
2201 | 2171 |
2202 // Test with one profile stored. | 2172 // Test with one profile stored. |
2203 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | 2173 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); |
2204 test::SetProfileInfo(&profile0, | 2174 test::SetProfileInfo(&profile0, |
2205 "Marion", NULL, "Morrison", | 2175 "Marion", NULL, "Morrison", |
2206 "johnwayne@me.xyz", NULL, "123 Zoo St.", NULL, "Hollywood", "CA", | 2176 "johnwayne@me.xyz", NULL, "123 Zoo St.", NULL, "Hollywood", "CA", |
2207 "91601", "US", "14155678910"); | 2177 "91601", "US", "14155678910"); |
2208 | 2178 |
2209 personal_data_->AddProfile(profile0); | 2179 personal_data_->AddProfile(profile0); |
2210 | 2180 |
2211 // Verify that the web database has been updated and the notification sent. | 2181 // Verify that the web database has been updated and the notification sent. |
2212 EXPECT_CALL(personal_data_observer_, | 2182 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
2213 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 2183 .WillOnce(QuitMainMessageLoop()); |
2214 base::MessageLoop::current()->Run(); | 2184 base::MessageLoop::current()->Run(); |
2215 | 2185 |
2216 personal_data_->GetNonEmptyTypes(&non_empty_types); | 2186 personal_data_->GetNonEmptyTypes(&non_empty_types); |
2217 EXPECT_EQ(15U, non_empty_types.size()); | 2187 EXPECT_EQ(15U, non_empty_types.size()); |
2218 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); | 2188 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); |
2219 EXPECT_TRUE(non_empty_types.count(NAME_LAST)); | 2189 EXPECT_TRUE(non_empty_types.count(NAME_LAST)); |
2220 EXPECT_TRUE(non_empty_types.count(NAME_FULL)); | 2190 EXPECT_TRUE(non_empty_types.count(NAME_FULL)); |
2221 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); | 2191 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); |
2222 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1)); | 2192 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1)); |
2223 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STREET_ADDRESS)); | 2193 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STREET_ADDRESS)); |
(...skipping 17 matching lines...) Expand all Loading... |
2241 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 2211 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
2242 test::SetProfileInfo(&profile2, | 2212 test::SetProfileInfo(&profile2, |
2243 "Josephine", "Alicia", "Saenz", | 2213 "Josephine", "Alicia", "Saenz", |
2244 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | 2214 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", |
2245 "32801", "US", "16502937549"); | 2215 "32801", "US", "16502937549"); |
2246 | 2216 |
2247 personal_data_->AddProfile(profile1); | 2217 personal_data_->AddProfile(profile1); |
2248 personal_data_->AddProfile(profile2); | 2218 personal_data_->AddProfile(profile2); |
2249 | 2219 |
2250 // Verify that the web database has been updated and the notification sent. | 2220 // Verify that the web database has been updated and the notification sent. |
2251 EXPECT_CALL(personal_data_observer_, | 2221 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
2252 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 2222 .WillOnce(QuitMainMessageLoop()); |
2253 base::MessageLoop::current()->Run(); | 2223 base::MessageLoop::current()->Run(); |
2254 | 2224 |
2255 personal_data_->GetNonEmptyTypes(&non_empty_types); | 2225 personal_data_->GetNonEmptyTypes(&non_empty_types); |
2256 EXPECT_EQ(19U, non_empty_types.size()); | 2226 EXPECT_EQ(19U, non_empty_types.size()); |
2257 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); | 2227 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); |
2258 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE)); | 2228 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE)); |
2259 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL)); | 2229 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL)); |
2260 EXPECT_TRUE(non_empty_types.count(NAME_LAST)); | 2230 EXPECT_TRUE(non_empty_types.count(NAME_LAST)); |
2261 EXPECT_TRUE(non_empty_types.count(NAME_FULL)); | 2231 EXPECT_TRUE(non_empty_types.count(NAME_FULL)); |
2262 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); | 2232 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); |
(...skipping 12 matching lines...) Expand all Loading... |
2275 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER)); | 2245 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER)); |
2276 | 2246 |
2277 // Test with credit card information also stored. | 2247 // Test with credit card information also stored. |
2278 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); | 2248 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); |
2279 test::SetCreditCardInfo(&credit_card, | 2249 test::SetCreditCardInfo(&credit_card, |
2280 "John Dillinger", "423456789012" /* Visa */, | 2250 "John Dillinger", "423456789012" /* Visa */, |
2281 "01", "2010"); | 2251 "01", "2010"); |
2282 personal_data_->AddCreditCard(credit_card); | 2252 personal_data_->AddCreditCard(credit_card); |
2283 | 2253 |
2284 // Verify that the web database has been updated and the notification sent. | 2254 // Verify that the web database has been updated and the notification sent. |
2285 EXPECT_CALL(personal_data_observer_, | 2255 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
2286 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 2256 .WillOnce(QuitMainMessageLoop()); |
2287 base::MessageLoop::current()->Run(); | 2257 base::MessageLoop::current()->Run(); |
2288 | 2258 |
2289 personal_data_->GetNonEmptyTypes(&non_empty_types); | 2259 personal_data_->GetNonEmptyTypes(&non_empty_types); |
2290 EXPECT_EQ(27U, non_empty_types.size()); | 2260 EXPECT_EQ(27U, non_empty_types.size()); |
2291 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); | 2261 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); |
2292 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE)); | 2262 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE)); |
2293 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL)); | 2263 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL)); |
2294 EXPECT_TRUE(non_empty_types.count(NAME_LAST)); | 2264 EXPECT_TRUE(non_empty_types.count(NAME_LAST)); |
2295 EXPECT_TRUE(non_empty_types.count(NAME_FULL)); | 2265 EXPECT_TRUE(non_empty_types.count(NAME_FULL)); |
2296 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); | 2266 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2345 form1.fields.push_back(field); | 2315 form1.fields.push_back(field); |
2346 | 2316 |
2347 FormStructure form_structure1(form1); | 2317 FormStructure form_structure1(form1); |
2348 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | 2318 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
2349 scoped_ptr<CreditCard> imported_credit_card; | 2319 scoped_ptr<CreditCard> imported_credit_card; |
2350 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | 2320 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
2351 &imported_credit_card)); | 2321 &imported_credit_card)); |
2352 ASSERT_FALSE(imported_credit_card); | 2322 ASSERT_FALSE(imported_credit_card); |
2353 | 2323 |
2354 // Verify that the web database has been updated and the notification sent. | 2324 // Verify that the web database has been updated and the notification sent. |
2355 EXPECT_CALL(personal_data_observer_, | 2325 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
2356 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 2326 .WillOnce(QuitMainMessageLoop()); |
2357 base::MessageLoop::current()->Run(); | 2327 base::MessageLoop::current()->Run(); |
2358 | 2328 |
2359 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | 2329 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); |
2360 test::SetProfileInfo(&expected, "George", NULL, | 2330 test::SetProfileInfo(&expected, "George", NULL, |
2361 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, | 2331 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, |
2362 "San Francisco", "California", "94102", NULL, "(817) 555-6789"); | 2332 "San Francisco", "California", "94102", NULL, "(817) 555-6789"); |
2363 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | 2333 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
2364 ASSERT_EQ(1U, results1.size()); | 2334 ASSERT_EQ(1U, results1.size()); |
2365 EXPECT_EQ(0, expected.Compare(*results1[0])); | 2335 EXPECT_EQ(0, expected.Compare(*results1[0])); |
2366 | 2336 |
(...skipping 21 matching lines...) Expand all Loading... |
2388 "Phone number:", "phone_number", "214-555-1234", "text", &field); | 2358 "Phone number:", "phone_number", "214-555-1234", "text", &field); |
2389 form2.fields.push_back(field); | 2359 form2.fields.push_back(field); |
2390 | 2360 |
2391 FormStructure form_structure2(form2); | 2361 FormStructure form_structure2(form2); |
2392 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 2362 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
2393 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | 2363 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
2394 &imported_credit_card)); | 2364 &imported_credit_card)); |
2395 ASSERT_FALSE(imported_credit_card); | 2365 ASSERT_FALSE(imported_credit_card); |
2396 | 2366 |
2397 // Verify that the web database has been updated and the notification sent. | 2367 // Verify that the web database has been updated and the notification sent. |
2398 EXPECT_CALL(personal_data_observer_, | 2368 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
2399 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 2369 .WillOnce(QuitMainMessageLoop()); |
2400 base::MessageLoop::current()->Run(); | 2370 base::MessageLoop::current()->Run(); |
2401 | 2371 |
2402 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 2372 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
2403 | 2373 |
2404 // Modify expected to include multi-valued fields. | 2374 // Modify expected to include multi-valued fields. |
2405 std::vector<base::string16> values; | 2375 std::vector<base::string16> values; |
2406 expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); | 2376 expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); |
2407 values.push_back(ASCIIToUTF16("(214) 555-1234")); | 2377 values.push_back(ASCIIToUTF16("(214) 555-1234")); |
2408 expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); | 2378 expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); |
2409 | 2379 |
2410 ASSERT_EQ(1U, results2.size()); | 2380 ASSERT_EQ(1U, results2.size()); |
2411 EXPECT_EQ(0, expected.Compare(*results2[0])); | 2381 EXPECT_EQ(0, expected.Compare(*results2[0])); |
2412 } | 2382 } |
2413 | 2383 |
2414 TEST_F(PersonalDataManagerTest, IncognitoReadOnly) { | 2384 TEST_F(PersonalDataManagerTest, IncognitoReadOnly) { |
2415 ASSERT_TRUE(personal_data_->GetProfiles().empty()); | 2385 ASSERT_TRUE(personal_data_->GetProfiles().empty()); |
2416 ASSERT_TRUE(personal_data_->GetCreditCards().empty()); | 2386 ASSERT_TRUE(personal_data_->GetCreditCards().empty()); |
2417 | 2387 |
2418 AutofillProfile steve_jobs(base::GenerateGUID(), "https://www.example.com"); | 2388 AutofillProfile steve_jobs(base::GenerateGUID(), "https://www.example.com"); |
2419 test::SetProfileInfo(&steve_jobs, "Steven", "Paul", "Jobs", "sjobs@apple.com", | 2389 test::SetProfileInfo(&steve_jobs, "Steven", "Paul", "Jobs", "sjobs@apple.com", |
2420 "Apple Computer, Inc.", "1 Infinite Loop", "", "Cupertino", "CA", "95014", | 2390 "Apple Computer, Inc.", "1 Infinite Loop", "", "Cupertino", "CA", "95014", |
2421 "US", "(800) 275-2273"); | 2391 "US", "(800) 275-2273"); |
2422 personal_data_->AddProfile(steve_jobs); | 2392 personal_data_->AddProfile(steve_jobs); |
2423 | 2393 |
2424 CreditCard bill_gates(base::GenerateGUID(), "https://www.example.com"); | 2394 CreditCard bill_gates(base::GenerateGUID(), "https://www.example.com"); |
2425 test::SetCreditCardInfo( | 2395 test::SetCreditCardInfo( |
2426 &bill_gates, "William H. Gates", "5555555555554444", "1", "2020"); | 2396 &bill_gates, "William H. Gates", "5555555555554444", "1", "2020"); |
2427 personal_data_->AddCreditCard(bill_gates); | 2397 personal_data_->AddCreditCard(bill_gates); |
2428 | 2398 |
2429 MakeProfileIncognito(); | |
2430 | |
2431 // The personal data manager should be able to read existing profiles in an | 2399 // The personal data manager should be able to read existing profiles in an |
2432 // off-the-record context. | 2400 // off-the-record context. |
2433 ResetPersonalDataManager(); | 2401 ResetPersonalDataManager(USER_MODE_INCOGNITO); |
2434 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); | 2402 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); |
2435 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); | 2403 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); |
2436 | 2404 |
2437 // No adds, saves, or updates should take effect. | 2405 // No adds, saves, or updates should take effect. |
2438 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0); | 2406 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0); |
2439 | 2407 |
2440 // Add profiles or credit card shouldn't work. | 2408 // Add profiles or credit card shouldn't work. |
2441 personal_data_->AddProfile(test::GetFullProfile()); | 2409 personal_data_->AddProfile(test::GetFullProfile()); |
2442 | 2410 |
2443 CreditCard larry_page(base::GenerateGUID(), "https://www.example.com"); | 2411 CreditCard larry_page(base::GenerateGUID(), "https://www.example.com"); |
2444 test::SetCreditCardInfo( | 2412 test::SetCreditCardInfo( |
2445 &larry_page, "Lawrence Page", "4111111111111111", "10", "2025"); | 2413 &larry_page, "Lawrence Page", "4111111111111111", "10", "2025"); |
2446 personal_data_->AddCreditCard(larry_page); | 2414 personal_data_->AddCreditCard(larry_page); |
2447 | 2415 |
2448 ResetPersonalDataManager(); | 2416 ResetPersonalDataManager(USER_MODE_INCOGNITO); |
2449 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); | 2417 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); |
2450 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); | 2418 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); |
2451 | 2419 |
2452 // Saving or creating profiles from imported profiles shouldn't work. | 2420 // Saving or creating profiles from imported profiles shouldn't work. |
2453 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); | 2421 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); |
2454 personal_data_->SaveImportedProfile(steve_jobs); | 2422 personal_data_->SaveImportedProfile(steve_jobs); |
2455 | 2423 |
2456 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates")); | 2424 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates")); |
2457 personal_data_->SaveImportedCreditCard(bill_gates); | 2425 personal_data_->SaveImportedCreditCard(bill_gates); |
2458 | 2426 |
2459 ResetPersonalDataManager(); | 2427 ResetPersonalDataManager(USER_MODE_INCOGNITO); |
2460 EXPECT_EQ(ASCIIToUTF16("Steven"), | 2428 EXPECT_EQ(ASCIIToUTF16("Steven"), |
2461 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); | 2429 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); |
2462 EXPECT_EQ(ASCIIToUTF16("William H. Gates"), | 2430 EXPECT_EQ(ASCIIToUTF16("William H. Gates"), |
2463 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME)); | 2431 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME)); |
2464 | 2432 |
2465 // Updating existing profiles shouldn't work. | 2433 // Updating existing profiles shouldn't work. |
2466 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); | 2434 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); |
2467 personal_data_->UpdateProfile(steve_jobs); | 2435 personal_data_->UpdateProfile(steve_jobs); |
2468 | 2436 |
2469 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates")); | 2437 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates")); |
2470 personal_data_->UpdateCreditCard(bill_gates); | 2438 personal_data_->UpdateCreditCard(bill_gates); |
2471 | 2439 |
2472 ResetPersonalDataManager(); | 2440 ResetPersonalDataManager(USER_MODE_INCOGNITO); |
2473 EXPECT_EQ(ASCIIToUTF16("Steven"), | 2441 EXPECT_EQ(ASCIIToUTF16("Steven"), |
2474 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); | 2442 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); |
2475 EXPECT_EQ(ASCIIToUTF16("William H. Gates"), | 2443 EXPECT_EQ(ASCIIToUTF16("William H. Gates"), |
2476 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME)); | 2444 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME)); |
2477 | 2445 |
2478 // Removing shouldn't work. | 2446 // Removing shouldn't work. |
2479 personal_data_->RemoveByGUID(steve_jobs.guid()); | 2447 personal_data_->RemoveByGUID(steve_jobs.guid()); |
2480 personal_data_->RemoveByGUID(bill_gates.guid()); | 2448 personal_data_->RemoveByGUID(bill_gates.guid()); |
2481 | 2449 |
2482 ResetPersonalDataManager(); | 2450 ResetPersonalDataManager(USER_MODE_INCOGNITO); |
2483 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); | 2451 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); |
2484 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); | 2452 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); |
2485 } | 2453 } |
2486 | 2454 |
2487 TEST_F(PersonalDataManagerTest, DefaultCountryCodeIsCached) { | 2455 TEST_F(PersonalDataManagerTest, DefaultCountryCodeIsCached) { |
2488 // The return value should always be some country code, no matter what. | 2456 // The return value should always be some country code, no matter what. |
2489 std::string default_country = | 2457 std::string default_country = |
2490 personal_data_->GetDefaultCountryCodeForNewAddress(); | 2458 personal_data_->GetDefaultCountryCodeForNewAddress(); |
2491 EXPECT_EQ(2U, default_country.size()); | 2459 EXPECT_EQ(2U, default_country.size()); |
2492 | 2460 |
2493 AutofillProfile moose(base::GenerateGUID(), "Chrome settings"); | 2461 AutofillProfile moose(base::GenerateGUID(), "Chrome settings"); |
2494 test::SetProfileInfo(&moose, "Moose", "P", "McMahon", "mpm@example.com", | 2462 test::SetProfileInfo(&moose, "Moose", "P", "McMahon", "mpm@example.com", |
2495 "", "1 Taiga TKTR", "", "Calgary", "AB", "T2B 2K2", | 2463 "", "1 Taiga TKTR", "", "Calgary", "AB", "T2B 2K2", |
2496 "CA", "(800) 555-9000"); | 2464 "CA", "(800) 555-9000"); |
2497 personal_data_->AddProfile(moose); | 2465 personal_data_->AddProfile(moose); |
2498 EXPECT_CALL(personal_data_observer_, | 2466 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
2499 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 2467 .WillOnce(QuitMainMessageLoop()); |
2500 base::MessageLoop::current()->Run(); | 2468 base::MessageLoop::current()->Run(); |
2501 // The value is cached and doesn't change even after adding an address. | 2469 // The value is cached and doesn't change even after adding an address. |
2502 EXPECT_EQ(default_country, | 2470 EXPECT_EQ(default_country, |
2503 personal_data_->GetDefaultCountryCodeForNewAddress()); | 2471 personal_data_->GetDefaultCountryCodeForNewAddress()); |
2504 | 2472 |
2505 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(2); | 2473 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(2); |
2506 | 2474 |
2507 // Disabling Autofill blows away this cache and shouldn't account for Autofill | 2475 // Disabling Autofill blows away this cache and shouldn't account for Autofill |
2508 // profiles. | 2476 // profiles. |
2509 profile_->GetPrefs()->SetBoolean(prefs::kAutofillEnabled, false); | 2477 prefs_->SetBoolean(prefs::kAutofillEnabled, false); |
2510 EXPECT_EQ(default_country, | 2478 EXPECT_EQ(default_country, |
2511 personal_data_->GetDefaultCountryCodeForNewAddress()); | 2479 personal_data_->GetDefaultCountryCodeForNewAddress()); |
2512 | 2480 |
2513 // Enabling Autofill blows away the cached value and should reflect the new | 2481 // Enabling Autofill blows away the cached value and should reflect the new |
2514 // value (accounting for profiles). | 2482 // value (accounting for profiles). |
2515 profile_->GetPrefs()->SetBoolean(prefs::kAutofillEnabled, true); | 2483 prefs_->SetBoolean(prefs::kAutofillEnabled, true); |
2516 EXPECT_EQ(base::UTF16ToUTF8(moose.GetRawInfo(ADDRESS_HOME_COUNTRY)), | 2484 EXPECT_EQ(base::UTF16ToUTF8(moose.GetRawInfo(ADDRESS_HOME_COUNTRY)), |
2517 personal_data_->GetDefaultCountryCodeForNewAddress()); | 2485 personal_data_->GetDefaultCountryCodeForNewAddress()); |
2518 } | 2486 } |
2519 | 2487 |
2520 TEST_F(PersonalDataManagerTest, DefaultCountryCodeComesFromProfiles) { | 2488 TEST_F(PersonalDataManagerTest, DefaultCountryCodeComesFromProfiles) { |
2521 AutofillProfile moose(base::GenerateGUID(), "Chrome settings"); | 2489 AutofillProfile moose(base::GenerateGUID(), "Chrome settings"); |
2522 test::SetProfileInfo(&moose, "Moose", "P", "McMahon", "mpm@example.com", | 2490 test::SetProfileInfo(&moose, "Moose", "P", "McMahon", "mpm@example.com", |
2523 "", "1 Taiga TKTR", "", "Calgary", "AB", "T2B 2K2", | 2491 "", "1 Taiga TKTR", "", "Calgary", "AB", "T2B 2K2", |
2524 "CA", "(800) 555-9000"); | 2492 "CA", "(800) 555-9000"); |
2525 personal_data_->AddProfile(moose); | 2493 personal_data_->AddProfile(moose); |
2526 ResetPersonalDataManager(); | 2494 ResetPersonalDataManager(USER_MODE_NORMAL); |
2527 EXPECT_EQ("CA", personal_data_->GetDefaultCountryCodeForNewAddress()); | 2495 EXPECT_EQ("CA", personal_data_->GetDefaultCountryCodeForNewAddress()); |
2528 | 2496 |
2529 // Multiple profiles cast votes. | 2497 // Multiple profiles cast votes. |
2530 AutofillProfile armadillo(base::GenerateGUID(), "Chrome settings"); | 2498 AutofillProfile armadillo(base::GenerateGUID(), "Chrome settings"); |
2531 test::SetProfileInfo(&armadillo, "Armin", "Dill", "Oh", "ado@example.com", | 2499 test::SetProfileInfo(&armadillo, "Armin", "Dill", "Oh", "ado@example.com", |
2532 "", "1 Speed Bump", "", "Lubbock", "TX", "77500", | 2500 "", "1 Speed Bump", "", "Lubbock", "TX", "77500", |
2533 "MX", "(800) 555-9000"); | 2501 "MX", "(800) 555-9000"); |
2534 AutofillProfile armadillo2(base::GenerateGUID(), "Chrome settings"); | 2502 AutofillProfile armadillo2(base::GenerateGUID(), "Chrome settings"); |
2535 test::SetProfileInfo(&armadillo2, "Armin", "Dill", "Oh", "ado@example.com", | 2503 test::SetProfileInfo(&armadillo2, "Armin", "Dill", "Oh", "ado@example.com", |
2536 "", "2 Speed Bump", "", "Lubbock", "TX", "77500", | 2504 "", "2 Speed Bump", "", "Lubbock", "TX", "77500", |
2537 "MX", "(800) 555-9000"); | 2505 "MX", "(800) 555-9000"); |
2538 personal_data_->AddProfile(armadillo); | 2506 personal_data_->AddProfile(armadillo); |
2539 personal_data_->AddProfile(armadillo2); | 2507 personal_data_->AddProfile(armadillo2); |
2540 ResetPersonalDataManager(); | 2508 ResetPersonalDataManager(USER_MODE_NORMAL); |
2541 EXPECT_EQ("MX", personal_data_->GetDefaultCountryCodeForNewAddress()); | 2509 EXPECT_EQ("MX", personal_data_->GetDefaultCountryCodeForNewAddress()); |
2542 | 2510 |
2543 personal_data_->RemoveByGUID(armadillo.guid()); | 2511 personal_data_->RemoveByGUID(armadillo.guid()); |
2544 personal_data_->RemoveByGUID(armadillo2.guid()); | 2512 personal_data_->RemoveByGUID(armadillo2.guid()); |
2545 ResetPersonalDataManager(); | 2513 ResetPersonalDataManager(USER_MODE_NORMAL); |
2546 // Verified profiles count more. | 2514 // Verified profiles count more. |
2547 armadillo.set_origin("http://randomwebsite.com"); | 2515 armadillo.set_origin("http://randomwebsite.com"); |
2548 armadillo2.set_origin("http://randomwebsite.com"); | 2516 armadillo2.set_origin("http://randomwebsite.com"); |
2549 personal_data_->AddProfile(armadillo); | 2517 personal_data_->AddProfile(armadillo); |
2550 personal_data_->AddProfile(armadillo2); | 2518 personal_data_->AddProfile(armadillo2); |
2551 ResetPersonalDataManager(); | 2519 ResetPersonalDataManager(USER_MODE_NORMAL); |
2552 EXPECT_EQ("CA", personal_data_->GetDefaultCountryCodeForNewAddress()); | 2520 EXPECT_EQ("CA", personal_data_->GetDefaultCountryCodeForNewAddress()); |
2553 | 2521 |
2554 personal_data_->RemoveByGUID(armadillo.guid()); | 2522 personal_data_->RemoveByGUID(armadillo.guid()); |
2555 ResetPersonalDataManager(); | 2523 ResetPersonalDataManager(USER_MODE_NORMAL); |
2556 // But unverified profiles can be a tie breaker. | 2524 // But unverified profiles can be a tie breaker. |
2557 armadillo.set_origin("Chrome settings"); | 2525 armadillo.set_origin("Chrome settings"); |
2558 personal_data_->AddProfile(armadillo); | 2526 personal_data_->AddProfile(armadillo); |
2559 ResetPersonalDataManager(); | 2527 ResetPersonalDataManager(USER_MODE_NORMAL); |
2560 EXPECT_EQ("MX", personal_data_->GetDefaultCountryCodeForNewAddress()); | 2528 EXPECT_EQ("MX", personal_data_->GetDefaultCountryCodeForNewAddress()); |
2561 | 2529 |
2562 // Invalid country codes are ignored. | 2530 // Invalid country codes are ignored. |
2563 personal_data_->RemoveByGUID(armadillo.guid()); | 2531 personal_data_->RemoveByGUID(armadillo.guid()); |
2564 personal_data_->RemoveByGUID(moose.guid()); | 2532 personal_data_->RemoveByGUID(moose.guid()); |
2565 AutofillProfile space_invader(base::GenerateGUID(), "Chrome settings"); | 2533 AutofillProfile space_invader(base::GenerateGUID(), "Chrome settings"); |
2566 test::SetProfileInfo(&space_invader, "Marty", "", "Martian", | 2534 test::SetProfileInfo(&space_invader, "Marty", "", "Martian", |
2567 "mm@example.com", "", "1 Flying Object", "", "Valles Marineris", "", | 2535 "mm@example.com", "", "1 Flying Object", "", "Valles Marineris", "", |
2568 "", "XX", ""); | 2536 "", "XX", ""); |
2569 personal_data_->AddProfile(moose); | 2537 personal_data_->AddProfile(moose); |
2570 ResetPersonalDataManager(); | 2538 ResetPersonalDataManager(USER_MODE_NORMAL); |
2571 EXPECT_EQ("MX", personal_data_->GetDefaultCountryCodeForNewAddress()); | 2539 EXPECT_EQ("MX", personal_data_->GetDefaultCountryCodeForNewAddress()); |
2572 } | 2540 } |
2573 | 2541 |
2574 } // namespace autofill | 2542 } // namespace autofill |
OLD | NEW |