OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/password_manager/password_syncable_service.h" | 5 #include "chrome/browser/password_manager/password_syncable_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 void (const PasswordStoreChangeList&)); | 88 void (const PasswordStoreChangeList&)); |
89 }; | 89 }; |
90 | 90 |
91 // Class to verify the arguments passed to |PasswordStore|. | 91 // Class to verify the arguments passed to |PasswordStore|. |
92 class PasswordStoreDataVerifier { | 92 class PasswordStoreDataVerifier { |
93 public: | 93 public: |
94 PasswordStoreDataVerifier() {} | 94 PasswordStoreDataVerifier() {} |
95 ~PasswordStoreDataVerifier() { | 95 ~PasswordStoreDataVerifier() { |
96 EXPECT_TRUE(expected_db_add_changes_.empty()); | 96 EXPECT_TRUE(expected_db_add_changes_.empty()); |
97 EXPECT_TRUE(expected_db_update_changes_.empty()); | 97 EXPECT_TRUE(expected_db_update_changes_.empty()); |
98 EXPECT_TRUE(expected_db_delete_changes_.empty()); | |
98 } | 99 } |
99 | 100 |
100 class TestSyncChangeProcessor; | 101 class TestSyncChangeProcessor; |
101 | 102 |
102 // Sets expected changes to the password database. | 103 // Sets expected changes to the password database. |
103 void SetExpectedDBChanges( | 104 void SetExpectedDBChanges( |
104 const SyncDataList& add_forms, | 105 const SyncDataList& add_forms, |
105 const std::vector<autofill::PasswordForm*>& update_forms, | 106 const std::vector<autofill::PasswordForm*>& update_forms, |
107 const std::vector<autofill::PasswordForm*>& delete_forms, | |
106 MockPasswordStore* password_store); | 108 MockPasswordStore* password_store); |
107 // Sets expected changes to TestSyncChangeProcessor. | 109 // Sets expected changes to TestSyncChangeProcessor. |
108 void SetExpectedSyncChanges(SyncChangeList list); | 110 void SetExpectedSyncChanges(SyncChangeList list); |
109 | 111 |
110 private: | 112 private: |
111 // Checks that |change_list| matches |expected_sync_change_list_|. | 113 // Checks that |change_list| matches |expected_sync_change_list_|. |
112 SyncError TestSyncChanges(const SyncChangeList& change_list); | 114 SyncError TestSyncChanges(const SyncChangeList& change_list); |
113 | 115 |
114 // Verifies that the |password| is present in the |expected_db_add_changes_| | 116 // Verifies that the |password| is present in the |expected_db_add_changes_| |
115 // list. If found |password| would be removed from | 117 // list. If found |password| would be removed from |
116 // |expected_db_add_changes_| list. | 118 // |expected_db_add_changes_| list. |
117 PasswordStoreChangeList VerifyAdd(const autofill::PasswordForm& password) { | 119 PasswordStoreChangeList VerifyAdd(const autofill::PasswordForm& password) { |
118 return VerifyChange(PasswordStoreChange::ADD, password, | 120 return VerifyChange(PasswordStoreChange::ADD, password, |
119 &expected_db_add_changes_); | 121 &expected_db_add_changes_); |
120 } | 122 } |
121 | 123 |
122 // Verifies that the |password| is present in the | |
123 // |expected_db_update_changes_| list. | |
Ilya Sherman
2014/02/07 22:56:35
Rather than removing this comment, please expand i
vasilii
2014/02/10 19:06:50
Done.
| |
124 PasswordStoreChangeList VerifyUpdate(const autofill::PasswordForm& password) { | 124 PasswordStoreChangeList VerifyUpdate(const autofill::PasswordForm& password) { |
125 return VerifyChange(PasswordStoreChange::UPDATE, password, | 125 return VerifyChange(PasswordStoreChange::UPDATE, password, |
126 &expected_db_update_changes_); | 126 &expected_db_update_changes_); |
127 } | 127 } |
128 | 128 |
129 PasswordStoreChangeList VerifyDelete(const autofill::PasswordForm& password) { | |
130 return VerifyChange(PasswordStoreChange::REMOVE, password, | |
131 &expected_db_delete_changes_); | |
132 } | |
133 | |
129 static PasswordStoreChangeList VerifyChange( | 134 static PasswordStoreChangeList VerifyChange( |
130 PasswordStoreChange::Type type, | 135 PasswordStoreChange::Type type, |
131 const autofill::PasswordForm& password, | 136 const autofill::PasswordForm& password, |
132 std::vector<autofill::PasswordForm>* password_list); | 137 std::vector<autofill::PasswordForm>* password_list); |
133 | 138 |
134 std::vector<autofill::PasswordForm> expected_db_add_changes_; | 139 std::vector<autofill::PasswordForm> expected_db_add_changes_; |
135 std::vector<autofill::PasswordForm> expected_db_update_changes_; | 140 std::vector<autofill::PasswordForm> expected_db_update_changes_; |
141 std::vector<autofill::PasswordForm> expected_db_delete_changes_; | |
136 SyncChangeList expected_sync_change_list_; | 142 SyncChangeList expected_sync_change_list_; |
137 | 143 |
138 DISALLOW_COPY_AND_ASSIGN(PasswordStoreDataVerifier); | 144 DISALLOW_COPY_AND_ASSIGN(PasswordStoreDataVerifier); |
139 }; | 145 }; |
140 | 146 |
141 class PasswordStoreDataVerifier::TestSyncChangeProcessor | 147 class PasswordStoreDataVerifier::TestSyncChangeProcessor |
142 : public syncer::SyncChangeProcessor { | 148 : public syncer::SyncChangeProcessor { |
143 public: | 149 public: |
144 explicit TestSyncChangeProcessor(PasswordStoreDataVerifier* verifier) | 150 explicit TestSyncChangeProcessor(PasswordStoreDataVerifier* verifier) |
145 : verifier_(verifier) { | 151 : verifier_(verifier) { |
(...skipping 10 matching lines...) Expand all Loading... | |
156 } | 162 } |
157 private: | 163 private: |
158 PasswordStoreDataVerifier* verifier_; | 164 PasswordStoreDataVerifier* verifier_; |
159 | 165 |
160 DISALLOW_COPY_AND_ASSIGN(TestSyncChangeProcessor); | 166 DISALLOW_COPY_AND_ASSIGN(TestSyncChangeProcessor); |
161 }; | 167 }; |
162 | 168 |
163 void PasswordStoreDataVerifier::SetExpectedDBChanges( | 169 void PasswordStoreDataVerifier::SetExpectedDBChanges( |
164 const SyncDataList& add_forms, | 170 const SyncDataList& add_forms, |
165 const std::vector<autofill::PasswordForm*>& update_forms, | 171 const std::vector<autofill::PasswordForm*>& update_forms, |
172 const std::vector<autofill::PasswordForm*>& delete_forms, | |
166 MockPasswordStore* password_store) { | 173 MockPasswordStore* password_store) { |
167 DCHECK(expected_db_add_changes_.empty()); | 174 DCHECK(expected_db_add_changes_.empty()); |
168 DCHECK(expected_db_update_changes_.empty()); | 175 DCHECK(expected_db_update_changes_.empty()); |
169 DCHECK(password_store); | 176 DCHECK(password_store); |
170 | 177 |
171 for (SyncDataList::const_iterator i = add_forms.begin(); | 178 for (SyncDataList::const_iterator i = add_forms.begin(); |
172 i != add_forms.end(); ++i) { | 179 i != add_forms.end(); ++i) { |
173 autofill::PasswordForm form; | 180 autofill::PasswordForm form; |
174 PasswordFromSpecifics(GetPasswordSpecifics(*i), &form); | 181 PasswordFromSpecifics(GetPasswordSpecifics(*i), &form); |
175 expected_db_add_changes_.push_back(form); | 182 expected_db_add_changes_.push_back(form); |
(...skipping 11 matching lines...) Expand all Loading... | |
187 i != update_forms.end(); ++i) { | 194 i != update_forms.end(); ++i) { |
188 expected_db_update_changes_.push_back(**i); | 195 expected_db_update_changes_.push_back(**i); |
189 } | 196 } |
190 if (expected_db_update_changes_.empty()) { | 197 if (expected_db_update_changes_.empty()) { |
191 EXPECT_CALL(*password_store, UpdateLoginImpl(_)).Times(0); | 198 EXPECT_CALL(*password_store, UpdateLoginImpl(_)).Times(0); |
192 } else { | 199 } else { |
193 EXPECT_CALL(*password_store, UpdateLoginImpl(_)) | 200 EXPECT_CALL(*password_store, UpdateLoginImpl(_)) |
194 .Times(expected_db_update_changes_.size()) | 201 .Times(expected_db_update_changes_.size()) |
195 .WillRepeatedly(Invoke(this, &PasswordStoreDataVerifier::VerifyUpdate)); | 202 .WillRepeatedly(Invoke(this, &PasswordStoreDataVerifier::VerifyUpdate)); |
196 } | 203 } |
204 | |
205 for (std::vector<autofill::PasswordForm*>::const_iterator i = | |
Ilya Sherman
2014/02/07 22:56:35
nit: i -> it
vasilii
2014/02/10 19:06:50
Done.
| |
206 delete_forms.begin(); | |
207 i != delete_forms.end(); ++i) { | |
208 expected_db_delete_changes_.push_back(**i); | |
209 } | |
210 if (expected_db_delete_changes_.empty()) { | |
211 EXPECT_CALL(*password_store, RemoveLoginImpl(_)).Times(0); | |
212 } else { | |
213 EXPECT_CALL(*password_store, RemoveLoginImpl(_)) | |
214 .Times(expected_db_delete_changes_.size()) | |
215 .WillRepeatedly(Invoke(this, &PasswordStoreDataVerifier::VerifyDelete)); | |
216 } | |
197 } | 217 } |
198 | 218 |
199 void PasswordStoreDataVerifier::SetExpectedSyncChanges(SyncChangeList list) { | 219 void PasswordStoreDataVerifier::SetExpectedSyncChanges(SyncChangeList list) { |
200 expected_sync_change_list_.swap(list); | 220 expected_sync_change_list_.swap(list); |
201 } | 221 } |
202 | 222 |
203 SyncError PasswordStoreDataVerifier::TestSyncChanges( | 223 SyncError PasswordStoreDataVerifier::TestSyncChanges( |
204 const SyncChangeList& change_list) { | 224 const SyncChangeList& change_list) { |
205 for (SyncChangeList::const_iterator it = change_list.begin(); | 225 for (SyncChangeList::const_iterator it = change_list.begin(); |
206 it != change_list.end(); ++it) { | 226 it != change_list.end(); ++it) { |
(...skipping 27 matching lines...) Expand all Loading... | |
234 PasswordStoreChange::Type type, | 254 PasswordStoreChange::Type type, |
235 const autofill::PasswordForm& password, | 255 const autofill::PasswordForm& password, |
236 std::vector<autofill::PasswordForm>* password_list) { | 256 std::vector<autofill::PasswordForm>* password_list) { |
237 std::vector<autofill::PasswordForm>::iterator it = | 257 std::vector<autofill::PasswordForm>::iterator it = |
238 std::find(password_list->begin(), password_list->end(), password); | 258 std::find(password_list->begin(), password_list->end(), password); |
239 EXPECT_NE(password_list->end(), it); | 259 EXPECT_NE(password_list->end(), it); |
240 password_list->erase(it); | 260 password_list->erase(it); |
241 return PasswordStoreChangeList(1, PasswordStoreChange(type, password)); | 261 return PasswordStoreChangeList(1, PasswordStoreChange(type, password)); |
242 } | 262 } |
243 | 263 |
244 class PasswordSyncableServiceTest : public testing::Test { | 264 class PasswordSyncableServiceWrapper { |
245 public: | 265 public: |
246 PasswordSyncableServiceTest() {} | 266 PasswordSyncableServiceWrapper() {} |
247 virtual ~PasswordSyncableServiceTest() {} | 267 ~PasswordSyncableServiceWrapper() {} |
248 | 268 |
249 virtual void SetUp() OVERRIDE { | 269 void SetUp() { |
250 password_store_ = new MockPasswordStore; | 270 password_store_ = new MockPasswordStore; |
251 service_.reset(new MockPasswordSyncableService(password_store_)); | 271 service_.reset(new MockPasswordSyncableService(password_store_)); |
252 } | 272 } |
253 | 273 |
254 virtual void TearDown() OVERRIDE { | 274 void TearDown() { |
255 password_store_->Shutdown(); | 275 password_store_->Shutdown(); |
Nicolas Zea
2014/02/07 21:16:47
Can you move SetUp and TearDown into the construct
vasilii
2014/02/10 19:06:50
Done.
| |
256 } | 276 } |
257 | 277 |
278 MockPasswordStore* password_store() { | |
279 return password_store_; | |
280 } | |
281 | |
282 scoped_ptr<MockPasswordSyncableService>& service() { | |
Ilya Sherman
2014/02/07 22:56:35
Hmm, returning a scoped_ptr by reference is pretty
vasilii
2014/02/10 19:06:50
In PasswordSyncableServiceTest.MergeDataAndPushBac
Ilya Sherman
2014/02/11 07:59:45
I see. It would be better -- in that it's less su
vasilii
2014/02/11 12:23:33
Done.
| |
283 return service_; | |
284 } | |
285 | |
258 PasswordStoreDataVerifier* verifier() { | 286 PasswordStoreDataVerifier* verifier() { |
259 return &verifier_; | 287 return &verifier_; |
260 } | 288 } |
261 | 289 |
262 scoped_ptr<syncer::SyncChangeProcessor> ReleaseSyncChangeProcessor() { | 290 scoped_ptr<syncer::SyncChangeProcessor> ReleaseSyncChangeProcessor() { |
263 return make_scoped_ptr<syncer::SyncChangeProcessor>( | 291 return make_scoped_ptr<syncer::SyncChangeProcessor>( |
264 new PasswordStoreDataVerifier::TestSyncChangeProcessor(verifier())); | 292 new PasswordStoreDataVerifier::TestSyncChangeProcessor(verifier())); |
265 } | 293 } |
266 | 294 |
267 // Sets the data that will be returned to the caller accessing password store. | 295 // Sets the data that will be returned to the caller accessing password store. |
268 void SetPasswordStoreData(const std::vector<autofill::PasswordForm*>& forms) { | 296 void SetPasswordStoreData(const std::vector<autofill::PasswordForm*>& forms) { |
269 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) | 297 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
270 .WillOnce(DoAll(SetArgPointee<0>(forms), Return(true))); | 298 .WillOnce(DoAll(SetArgPointee<0>(forms), Return(true))) |
299 .RetiresOnSaturation(); | |
300 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) | |
301 .WillOnce(Return(true)) | |
302 .RetiresOnSaturation(); | |
271 } | 303 } |
272 | 304 |
273 protected: | 305 protected: |
274 scoped_refptr<MockPasswordStore> password_store_; | 306 scoped_refptr<MockPasswordStore> password_store_; |
275 scoped_ptr<MockPasswordSyncableService> service_; | 307 scoped_ptr<MockPasswordSyncableService> service_; |
276 PasswordStoreDataVerifier verifier_; | 308 PasswordStoreDataVerifier verifier_; |
309 | |
310 private: | |
311 DISALLOW_COPY_AND_ASSIGN(PasswordSyncableServiceWrapper); | |
312 }; | |
313 | |
314 class PasswordSyncableServiceTest : public testing::Test, | |
315 public PasswordSyncableServiceWrapper { | |
316 public: | |
317 PasswordSyncableServiceTest() {} | |
318 virtual ~PasswordSyncableServiceTest() {} | |
319 | |
320 virtual void SetUp() OVERRIDE { | |
321 PasswordSyncableServiceWrapper::SetUp(); | |
322 } | |
323 | |
324 virtual void TearDown() OVERRIDE { | |
325 PasswordSyncableServiceWrapper::TearDown(); | |
326 } | |
277 }; | 327 }; |
278 | 328 |
279 | 329 |
280 // Both sync and password db have data that are not present in the other. | 330 // Both sync and password db have data that are not present in the other. |
281 TEST_F(PasswordSyncableServiceTest, AdditionsInBoth) { | 331 TEST_F(PasswordSyncableServiceTest, AdditionsInBoth) { |
282 autofill::PasswordForm* form1 = new autofill::PasswordForm; | 332 autofill::PasswordForm* form1 = new autofill::PasswordForm; |
283 form1->signon_realm = "abc"; | 333 form1->signon_realm = "abc"; |
284 std::vector<autofill::PasswordForm*> forms; | 334 std::vector<autofill::PasswordForm*> forms; |
285 forms.push_back(form1); | 335 forms.push_back(form1); |
286 SetPasswordStoreData(forms); | 336 SetPasswordStoreData(forms); |
287 | 337 |
288 SyncData sync_data = CreateSyncData("def"); | 338 SyncData sync_data = CreateSyncData("def"); |
289 SyncDataList list; | 339 SyncDataList list; |
290 list.push_back(sync_data); | 340 list.push_back(sync_data); |
291 | 341 |
292 verifier()->SetExpectedDBChanges(list, | 342 verifier()->SetExpectedDBChanges(list, |
293 std::vector<autofill::PasswordForm*>(), | 343 std::vector<autofill::PasswordForm*>(), |
294 password_store_); | 344 std::vector<autofill::PasswordForm*>(), |
345 password_store()); | |
295 verifier()->SetExpectedSyncChanges( | 346 verifier()->SetExpectedSyncChanges( |
296 SyncChangeList(1, CreateSyncChange(*form1, SyncChange::ACTION_ADD))); | 347 SyncChangeList(1, CreateSyncChange(*form1, SyncChange::ACTION_ADD))); |
297 EXPECT_CALL(*service_, NotifyPasswordStoreOfLoginChanges(_)); | 348 EXPECT_CALL(*service(), NotifyPasswordStoreOfLoginChanges(_)); |
298 | 349 |
299 service_->MergeDataAndStartSyncing(syncer::PASSWORDS, | 350 service()->MergeDataAndStartSyncing(syncer::PASSWORDS, |
300 list, | 351 list, |
301 ReleaseSyncChangeProcessor(), | 352 ReleaseSyncChangeProcessor(), |
302 scoped_ptr<syncer::SyncErrorFactory>()); | 353 scoped_ptr<syncer::SyncErrorFactory>()); |
303 } | 354 } |
304 | 355 |
305 // Sync has data that is not present in the password db. | 356 // Sync has data that is not present in the password db. |
306 TEST_F(PasswordSyncableServiceTest, AdditionOnlyInSync) { | 357 TEST_F(PasswordSyncableServiceTest, AdditionOnlyInSync) { |
307 SetPasswordStoreData(std::vector<autofill::PasswordForm*>()); | 358 SetPasswordStoreData(std::vector<autofill::PasswordForm*>()); |
308 | 359 |
309 SyncData sync_data = CreateSyncData("def"); | 360 SyncData sync_data = CreateSyncData("def"); |
310 SyncDataList list; | 361 SyncDataList list; |
311 list.push_back(sync_data); | 362 list.push_back(sync_data); |
312 | 363 |
313 verifier()->SetExpectedDBChanges(list, | 364 verifier()->SetExpectedDBChanges(list, |
314 std::vector<autofill::PasswordForm*>(), | 365 std::vector<autofill::PasswordForm*>(), |
315 password_store_); | 366 std::vector<autofill::PasswordForm*>(), |
367 password_store()); | |
316 verifier()->SetExpectedSyncChanges(SyncChangeList()); | 368 verifier()->SetExpectedSyncChanges(SyncChangeList()); |
317 EXPECT_CALL(*service_, NotifyPasswordStoreOfLoginChanges(_)); | 369 EXPECT_CALL(*service(), NotifyPasswordStoreOfLoginChanges(_)); |
318 | 370 |
319 service_->MergeDataAndStartSyncing(syncer::PASSWORDS, | 371 service()->MergeDataAndStartSyncing(syncer::PASSWORDS, |
320 list, | 372 list, |
321 ReleaseSyncChangeProcessor(), | 373 ReleaseSyncChangeProcessor(), |
322 scoped_ptr<syncer::SyncErrorFactory>()); | 374 scoped_ptr<syncer::SyncErrorFactory>()); |
323 } | 375 } |
324 | 376 |
325 // Passwords db has data that is not present in sync. | 377 // Passwords db has data that is not present in sync. |
326 TEST_F(PasswordSyncableServiceTest, AdditionOnlyInPasswordStore) { | 378 TEST_F(PasswordSyncableServiceTest, AdditionOnlyInPasswordStore) { |
327 autofill::PasswordForm* form1 = new autofill::PasswordForm; | 379 autofill::PasswordForm* form1 = new autofill::PasswordForm; |
328 form1->signon_realm = "abc"; | 380 form1->signon_realm = "abc"; |
329 std::vector<autofill::PasswordForm*> forms; | 381 std::vector<autofill::PasswordForm*> forms; |
330 forms.push_back(form1); | 382 forms.push_back(form1); |
331 SetPasswordStoreData(forms); | 383 SetPasswordStoreData(forms); |
332 | 384 |
333 verifier()->SetExpectedDBChanges(SyncDataList(), | 385 verifier()->SetExpectedDBChanges(SyncDataList(), |
334 std::vector<autofill::PasswordForm*>(), | 386 std::vector<autofill::PasswordForm*>(), |
335 password_store_); | 387 std::vector<autofill::PasswordForm*>(), |
388 password_store()); | |
336 verifier()->SetExpectedSyncChanges( | 389 verifier()->SetExpectedSyncChanges( |
337 SyncChangeList(1, CreateSyncChange(*form1, SyncChange::ACTION_ADD))); | 390 SyncChangeList(1, CreateSyncChange(*form1, SyncChange::ACTION_ADD))); |
338 EXPECT_CALL(*service_, | 391 EXPECT_CALL(*service_, |
339 NotifyPasswordStoreOfLoginChanges(PasswordStoreChangeList())); | 392 NotifyPasswordStoreOfLoginChanges(PasswordStoreChangeList())); |
340 | 393 |
341 service_->MergeDataAndStartSyncing(syncer::PASSWORDS, | 394 service()->MergeDataAndStartSyncing(syncer::PASSWORDS, |
342 SyncDataList(), | 395 SyncDataList(), |
343 ReleaseSyncChangeProcessor(), | 396 ReleaseSyncChangeProcessor(), |
344 scoped_ptr<syncer::SyncErrorFactory>()); | 397 scoped_ptr<syncer::SyncErrorFactory>()); |
345 } | 398 } |
346 | 399 |
347 // Both passwords db and sync contain the same data. | 400 // Both passwords db and sync contain the same data. |
348 TEST_F(PasswordSyncableServiceTest, BothInSync) { | 401 TEST_F(PasswordSyncableServiceTest, BothInSync) { |
349 autofill::PasswordForm *form1 = new autofill::PasswordForm; | 402 autofill::PasswordForm *form1 = new autofill::PasswordForm; |
350 form1->signon_realm = "abc"; | 403 form1->signon_realm = "abc"; |
351 std::vector<autofill::PasswordForm*> forms; | 404 std::vector<autofill::PasswordForm*> forms; |
352 forms.push_back(form1); | 405 forms.push_back(form1); |
353 SetPasswordStoreData(forms); | 406 SetPasswordStoreData(forms); |
354 | 407 |
355 verifier()->SetExpectedDBChanges(SyncDataList(), | 408 verifier()->SetExpectedDBChanges(SyncDataList(), |
356 std::vector<autofill::PasswordForm*>(), | 409 std::vector<autofill::PasswordForm*>(), |
357 password_store_); | 410 std::vector<autofill::PasswordForm*>(), |
411 password_store()); | |
358 verifier()->SetExpectedSyncChanges(SyncChangeList()); | 412 verifier()->SetExpectedSyncChanges(SyncChangeList()); |
359 EXPECT_CALL(*service_, | 413 EXPECT_CALL(*service_, |
360 NotifyPasswordStoreOfLoginChanges(PasswordStoreChangeList())); | 414 NotifyPasswordStoreOfLoginChanges(PasswordStoreChangeList())); |
361 | 415 |
362 service_->MergeDataAndStartSyncing(syncer::PASSWORDS, | 416 service()->MergeDataAndStartSyncing(syncer::PASSWORDS, |
363 SyncDataList(1, CreateSyncData("abc")), | 417 SyncDataList(1, CreateSyncData("abc")), |
364 ReleaseSyncChangeProcessor(), | 418 ReleaseSyncChangeProcessor(), |
365 scoped_ptr<syncer::SyncErrorFactory>()); | 419 scoped_ptr<syncer::SyncErrorFactory>()); |
366 } | 420 } |
367 | 421 |
368 // Both passwords db and sync have the same data but they need to be merged | 422 // Both passwords db and sync have the same data but they need to be merged |
369 // as some fields of the data differ. | 423 // as some fields of the data differ. |
370 TEST_F(PasswordSyncableServiceTest, Merge) { | 424 TEST_F(PasswordSyncableServiceTest, Merge) { |
371 autofill::PasswordForm *form1 = new autofill::PasswordForm; | 425 autofill::PasswordForm *form1 = new autofill::PasswordForm; |
372 form1->signon_realm = "abc"; | 426 form1->signon_realm = "abc"; |
373 form1->action = GURL("http://pie.com"); | 427 form1->action = GURL("http://pie.com"); |
374 form1->date_created = base::Time::Now(); | 428 form1->date_created = base::Time::Now(); |
375 std::vector<autofill::PasswordForm*> forms; | 429 std::vector<autofill::PasswordForm*> forms; |
376 forms.push_back(form1); | 430 forms.push_back(form1); |
377 SetPasswordStoreData(forms); | 431 SetPasswordStoreData(forms); |
378 | 432 |
379 verifier()->SetExpectedDBChanges(SyncDataList(), | 433 verifier()->SetExpectedDBChanges(SyncDataList(), |
380 forms, | 434 forms, |
381 password_store_); | 435 std::vector<autofill::PasswordForm*>(), |
436 password_store()); | |
382 verifier()->SetExpectedSyncChanges( | 437 verifier()->SetExpectedSyncChanges( |
383 SyncChangeList(1, CreateSyncChange(*form1, SyncChange::ACTION_UPDATE))); | 438 SyncChangeList(1, CreateSyncChange(*form1, SyncChange::ACTION_UPDATE))); |
384 | 439 |
385 EXPECT_CALL(*service_, NotifyPasswordStoreOfLoginChanges(_)); | 440 EXPECT_CALL(*service(), NotifyPasswordStoreOfLoginChanges(_)); |
386 | 441 |
387 service_->MergeDataAndStartSyncing(syncer::PASSWORDS, | 442 service()->MergeDataAndStartSyncing(syncer::PASSWORDS, |
388 SyncDataList(1, CreateSyncData("abc")), | 443 SyncDataList(1, CreateSyncData("abc")), |
389 ReleaseSyncChangeProcessor(), | 444 ReleaseSyncChangeProcessor(), |
390 scoped_ptr<syncer::SyncErrorFactory>()); | 445 scoped_ptr<syncer::SyncErrorFactory>()); |
391 } | 446 } |
392 | 447 |
393 // Initiate sync due to local DB changes. | 448 // Initiate sync due to local DB changes. |
394 TEST_F(PasswordSyncableServiceTest, PasswordStoreChanges) { | 449 TEST_F(PasswordSyncableServiceTest, PasswordStoreChanges) { |
395 // Set the sync change processor first. | 450 // Set the sync change processor first. |
396 SetPasswordStoreData(std::vector<autofill::PasswordForm*>()); | 451 SetPasswordStoreData(std::vector<autofill::PasswordForm*>()); |
397 verifier()->SetExpectedSyncChanges(SyncChangeList()); | 452 verifier()->SetExpectedSyncChanges(SyncChangeList()); |
398 EXPECT_CALL(*service_, | 453 EXPECT_CALL(*service_, |
399 NotifyPasswordStoreOfLoginChanges(PasswordStoreChangeList())); | 454 NotifyPasswordStoreOfLoginChanges(PasswordStoreChangeList())); |
400 service_->MergeDataAndStartSyncing(syncer::PASSWORDS, | 455 service_->MergeDataAndStartSyncing(syncer::PASSWORDS, |
401 SyncDataList(), | 456 SyncDataList(), |
402 ReleaseSyncChangeProcessor(), | 457 ReleaseSyncChangeProcessor(), |
403 scoped_ptr<syncer::SyncErrorFactory>()); | 458 scoped_ptr<syncer::SyncErrorFactory>()); |
404 | 459 |
405 autofill::PasswordForm form1; | 460 autofill::PasswordForm form1; |
406 form1.signon_realm = "abc"; | 461 form1.signon_realm = "abc"; |
407 autofill::PasswordForm form2; | 462 autofill::PasswordForm form2; |
408 form2.signon_realm = "def"; | 463 form2.signon_realm = "def"; |
409 autofill::PasswordForm form3; | 464 autofill::PasswordForm form3; |
410 form3.signon_realm = "xyz"; | 465 form3.signon_realm = "xyz"; |
411 | 466 |
412 SyncChangeList sync_list; | 467 SyncChangeList sync_list; |
413 sync_list.push_back(CreateSyncChange(form1, SyncChange::ACTION_ADD)); | 468 sync_list.push_back(CreateSyncChange(form1, SyncChange::ACTION_ADD)); |
414 sync_list.push_back(CreateSyncChange(form2, SyncChange::ACTION_UPDATE)); | 469 sync_list.push_back(CreateSyncChange(form2, SyncChange::ACTION_UPDATE)); |
415 sync_list.push_back(CreateSyncChange(form3, SyncChange::ACTION_DELETE)); | 470 sync_list.push_back(CreateSyncChange(form3, SyncChange::ACTION_DELETE)); |
416 | 471 |
417 verifier()->SetExpectedDBChanges(SyncDataList(), | 472 verifier()->SetExpectedDBChanges(SyncDataList(), |
418 std::vector<autofill::PasswordForm*>(), | 473 std::vector<autofill::PasswordForm*>(), |
419 password_store_); | 474 std::vector<autofill::PasswordForm*>(), |
475 password_store()); | |
420 verifier()->SetExpectedSyncChanges(sync_list); | 476 verifier()->SetExpectedSyncChanges(sync_list); |
421 | 477 |
422 PasswordStoreChangeList list; | 478 PasswordStoreChangeList list; |
423 list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form1)); | 479 list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form1)); |
424 list.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form2)); | 480 list.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form2)); |
425 list.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form3)); | 481 list.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form3)); |
426 service_->ActOnPasswordStoreChanges(list); | 482 service()->ActOnPasswordStoreChanges(list); |
483 } | |
484 | |
485 // Process all types of changes from sync. | |
486 TEST_F(PasswordSyncableServiceTest, ProcessSyncChanges) { | |
487 autofill::PasswordForm *form1 = new autofill::PasswordForm; | |
Ilya Sherman
2014/02/07 22:56:35
nit: Please use a scoped_ptr here. If for some re
vasilii
2014/02/10 19:06:50
Done.
| |
488 form1->signon_realm = "abc"; | |
489 form1->action = GURL("http://foo.com"); | |
490 form1->date_created = base::Time::Now(); | |
491 autofill::PasswordForm *form2 = new autofill::PasswordForm; | |
Ilya Sherman
2014/02/07 22:56:35
Ditto.
vasilii
2014/02/10 19:06:50
Done.
| |
492 form2->signon_realm = "xyz"; | |
493 form2->action = GURL("http://bar.com"); | |
494 form2->date_created = base::Time::Now(); | |
495 std::vector<autofill::PasswordForm*> forms; | |
496 forms.push_back(form1); | |
497 forms.push_back(form2); | |
498 SetPasswordStoreData(forms); | |
499 | |
500 SyncData add_data = CreateSyncData("def"); | |
501 std::vector<autofill::PasswordForm*> updated_passwords(1, form1); | |
502 std::vector<autofill::PasswordForm*> deleted_passwords(1, form2); | |
503 verifier()->SetExpectedDBChanges(SyncDataList(1, add_data), | |
504 updated_passwords, | |
505 deleted_passwords, | |
506 password_store()); | |
507 EXPECT_CALL(*service(), NotifyPasswordStoreOfLoginChanges(_)); | |
Ilya Sherman
2014/02/07 22:56:35
nit: Please move this to be roughly right above th
vasilii
2014/02/10 19:06:50
Done.
| |
508 | |
509 SyncChangeList list; | |
510 list.push_back(SyncChange(FROM_HERE, | |
511 syncer::SyncChange::ACTION_ADD, | |
512 add_data)); | |
513 list.push_back(SyncChange(FROM_HERE, | |
514 syncer::SyncChange::ACTION_UPDATE, | |
515 CreateSyncData("abc"))); | |
516 list.push_back(CreateSyncChange(*form2, syncer::SyncChange::ACTION_DELETE)); | |
517 service()->ProcessSyncChanges(FROM_HERE, list); | |
518 } | |
519 | |
520 // Retrives sync data from the model. | |
521 TEST_F(PasswordSyncableServiceTest, GetAllSyncData) { | |
522 autofill::PasswordForm *form1 = new autofill::PasswordForm; | |
Ilya Sherman
2014/02/07 22:56:35
Ditto.
vasilii
2014/02/10 19:06:50
Done.
| |
523 form1->signon_realm = "abc"; | |
524 form1->action = GURL("http://foo.com"); | |
525 autofill::PasswordForm *form2 = new autofill::PasswordForm; | |
Ilya Sherman
2014/02/07 22:56:35
Ditto.
vasilii
2014/02/10 19:06:50
Done.
| |
526 form2->signon_realm = "xyz"; | |
527 form2->action = GURL("http://bar.com"); | |
528 std::vector<autofill::PasswordForm*> forms; | |
529 forms.push_back(form1); | |
530 forms.push_back(form2); | |
531 SetPasswordStoreData(forms); | |
532 | |
533 SyncDataList expected_list; | |
534 expected_list.push_back(SyncDataFromPassword(*form1)); | |
535 expected_list.push_back(SyncDataFromPassword(*form2)); | |
536 | |
537 verifier()->SetExpectedDBChanges(SyncDataList(), | |
538 std::vector<autofill::PasswordForm*>(), | |
539 std::vector<autofill::PasswordForm*>(), | |
540 password_store()); | |
541 | |
542 SyncDataList actual_list = service()->GetAllSyncData(syncer::PASSWORDS); | |
543 EXPECT_EQ(expected_list.size(), actual_list.size()); | |
544 for (SyncDataList::iterator i(actual_list.begin()), j(expected_list.begin()); | |
545 i != actual_list.end() && j != expected_list.end(); ++i, ++j) { | |
546 PasswordsEqual(GetPasswordSpecifics(*j), GetPasswordSpecifics(*i)); | |
547 } | |
548 } | |
549 | |
550 // Creates 2 PasswordSyncableService instances, merges the content of the first | |
551 // one to the second one and back. | |
552 TEST_F(PasswordSyncableServiceTest, MergeDataAndPushBack) { | |
Nicolas Zea
2014/02/07 21:16:47
Nice.
vasilii
2014/02/10 19:06:50
Done.
| |
553 autofill::PasswordForm *form1 = new autofill::PasswordForm; | |
Ilya Sherman
2014/02/07 22:56:35
Ditto.
vasilii
2014/02/10 19:06:50
Done.
| |
554 form1->signon_realm = "abc"; | |
555 form1->action = GURL("http://foo.com"); | |
556 SetPasswordStoreData(std::vector<autofill::PasswordForm*>(1, form1)); | |
557 | |
558 PasswordSyncableServiceWrapper other_service_wrapper; | |
559 other_service_wrapper.SetUp(); | |
560 autofill::PasswordForm *form2 = new autofill::PasswordForm; | |
561 form2->signon_realm = "xyz"; | |
562 form2->action = GURL("http://bar.com"); | |
563 // SetPasswordStoreData will be called twice: from GetAllSyncData() and | |
564 // ProcessSyncChanges(). | |
565 other_service_wrapper.SetPasswordStoreData( | |
566 std::vector<autofill::PasswordForm*>(1, form2)); | |
567 other_service_wrapper.SetPasswordStoreData( | |
568 std::vector<autofill::PasswordForm*>(1, | |
569 new autofill::PasswordForm(*form2))); | |
570 | |
571 verifier()->SetExpectedDBChanges( | |
572 SyncDataList(1, SyncDataFromPassword(*form2)), | |
573 std::vector<autofill::PasswordForm*>(), | |
574 std::vector<autofill::PasswordForm*>(), | |
575 password_store()); | |
576 other_service_wrapper.verifier()->SetExpectedDBChanges( | |
577 SyncDataList(1, SyncDataFromPassword(*form1)), | |
578 std::vector<autofill::PasswordForm*>(), | |
579 std::vector<autofill::PasswordForm*>(), | |
580 other_service_wrapper.password_store()); | |
581 EXPECT_CALL(*service(), NotifyPasswordStoreOfLoginChanges(_)); | |
582 EXPECT_CALL(*other_service_wrapper.service(), | |
583 NotifyPasswordStoreOfLoginChanges(_)); | |
584 | |
585 service()->MergeDataAndStartSyncing( | |
586 syncer::PASSWORDS, | |
587 other_service_wrapper.service()->GetAllSyncData(syncer::PASSWORDS), | |
588 other_service_wrapper.service().PassAs<syncer::SyncChangeProcessor>(), | |
589 scoped_ptr<syncer::SyncErrorFactory>()); | |
590 other_service_wrapper.TearDown(); | |
427 } | 591 } |
428 | 592 |
429 } // namespace | 593 } // namespace |
OLD | NEW |