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