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 15 matching lines...) Expand all Loading... |
26 using testing::Invoke; | 26 using testing::Invoke; |
27 using testing::Return; | 27 using testing::Return; |
28 using testing::SetArgPointee; | 28 using testing::SetArgPointee; |
29 using testing::_; | 29 using testing::_; |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 typedef std::vector<SyncChange> SyncChangeList; | 33 typedef std::vector<SyncChange> SyncChangeList; |
34 | 34 |
35 const sync_pb::PasswordSpecificsData& GetPasswordSpecifics( | 35 const sync_pb::PasswordSpecificsData& GetPasswordSpecifics( |
36 const syncer::SyncData& sync_change) { | 36 const syncer::SyncData& sync_data) { |
37 const sync_pb::EntitySpecifics& specifics = sync_change.GetSpecifics(); | 37 const sync_pb::EntitySpecifics& specifics = sync_data.GetSpecifics(); |
38 return specifics.password().client_only_encrypted_data(); | 38 return specifics.password().client_only_encrypted_data(); |
39 } | 39 } |
40 | 40 |
41 void PasswordsEqual(const sync_pb::PasswordSpecificsData& expected_password, | 41 void PasswordsEqual(const sync_pb::PasswordSpecificsData& expected_password, |
42 const sync_pb::PasswordSpecificsData& actual_password) { | 42 const sync_pb::PasswordSpecificsData& actual_password) { |
43 EXPECT_EQ(expected_password.scheme(), actual_password.scheme()); | 43 EXPECT_EQ(expected_password.scheme(), actual_password.scheme()); |
44 EXPECT_EQ(expected_password.signon_realm(), actual_password.signon_realm()); | 44 EXPECT_EQ(expected_password.signon_realm(), actual_password.signon_realm()); |
45 EXPECT_EQ(expected_password.origin(), actual_password.origin()); | 45 EXPECT_EQ(expected_password.origin(), actual_password.origin()); |
46 EXPECT_EQ(expected_password.action(), actual_password.action()); | 46 EXPECT_EQ(expected_password.action(), actual_password.action()); |
47 EXPECT_EQ(expected_password.username_element(), | 47 EXPECT_EQ(expected_password.username_element(), |
(...skipping 40 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 it = add_forms.begin(); |
172 i != add_forms.end(); ++i) { | 185 it != add_forms.end(); ++it) { |
173 autofill::PasswordForm form; | 186 autofill::PasswordForm form; |
174 PasswordFromSpecifics(GetPasswordSpecifics(*i), &form); | 187 PasswordFromSpecifics(GetPasswordSpecifics(*it), &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 it = |
| 212 delete_forms.begin(); |
| 213 it != delete_forms.end(); ++it) { |
| 214 expected_db_delete_changes_.push_back(**it); |
| 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 MockPasswordSyncableService* service() { |
| 286 return service_.get(); |
| 287 } |
| 288 |
| 289 // Returnes the scoped_ptr to |service_| thus NULLing out it. |
| 290 scoped_ptr<syncer::SyncChangeProcessor> ReleaseSyncableService() { |
| 291 return service_.PassAs<syncer::SyncChangeProcessor>(); |
| 292 } |
| 293 |
258 PasswordStoreDataVerifier* verifier() { | 294 PasswordStoreDataVerifier* verifier() { |
259 return &verifier_; | 295 return &verifier_; |
260 } | 296 } |
261 | 297 |
262 scoped_ptr<syncer::SyncChangeProcessor> ReleaseSyncChangeProcessor() { | 298 scoped_ptr<syncer::SyncChangeProcessor> CreateSyncChangeProcessor() { |
263 return make_scoped_ptr<syncer::SyncChangeProcessor>( | 299 return make_scoped_ptr<syncer::SyncChangeProcessor>( |
264 new PasswordStoreDataVerifier::TestSyncChangeProcessor(verifier())); | 300 new PasswordStoreDataVerifier::TestSyncChangeProcessor(verifier())); |
265 } | 301 } |
266 | 302 |
267 // Sets the data that will be returned to the caller accessing password store. | 303 // Sets the data that will be returned to the caller accessing password store. |
268 void SetPasswordStoreData(const std::vector<autofill::PasswordForm*>& forms) { | 304 void SetPasswordStoreData( |
| 305 const std::vector<autofill::PasswordForm*>& forms, |
| 306 const std::vector<autofill::PasswordForm*>& blacklist_forms) { |
269 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) | 307 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
270 .WillOnce(DoAll(SetArgPointee<0>(forms), Return(true))); | 308 .WillOnce(Invoke(AppendVector(forms))) |
| 309 .RetiresOnSaturation(); |
| 310 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) |
| 311 .WillOnce(Invoke(AppendVector(blacklist_forms))) |
| 312 .RetiresOnSaturation(); |
271 } | 313 } |
272 | 314 |
273 protected: | 315 protected: |
274 scoped_refptr<MockPasswordStore> password_store_; | 316 scoped_refptr<MockPasswordStore> password_store_; |
275 scoped_ptr<MockPasswordSyncableService> service_; | 317 scoped_ptr<MockPasswordSyncableService> service_; |
276 PasswordStoreDataVerifier verifier_; | 318 PasswordStoreDataVerifier verifier_; |
| 319 |
| 320 private: |
| 321 struct AppendVector { |
| 322 explicit AppendVector( |
| 323 const std::vector<autofill::PasswordForm*>& append_forms) |
| 324 : append_forms_(append_forms) { |
| 325 } |
| 326 |
| 327 ~AppendVector() {} |
| 328 |
| 329 bool operator()(std::vector<autofill::PasswordForm*>* forms) const { |
| 330 forms->insert(forms->end(), append_forms_.begin(), append_forms_.end()); |
| 331 return true; |
| 332 } |
| 333 |
| 334 std::vector<autofill::PasswordForm*> append_forms_; |
| 335 }; |
| 336 |
| 337 DISALLOW_COPY_AND_ASSIGN(PasswordSyncableServiceWrapper); |
| 338 }; |
| 339 |
| 340 class PasswordSyncableServiceTest : public testing::Test, |
| 341 public PasswordSyncableServiceWrapper { |
| 342 public: |
| 343 PasswordSyncableServiceTest() {} |
| 344 virtual ~PasswordSyncableServiceTest() {} |
277 }; | 345 }; |
278 | 346 |
279 | 347 |
280 // Both sync and password db have data that are not present in the other. | 348 // Both sync and password db have data that are not present in the other. |
281 TEST_F(PasswordSyncableServiceTest, AdditionsInBoth) { | 349 TEST_F(PasswordSyncableServiceTest, AdditionsInBoth) { |
282 autofill::PasswordForm* form1 = new autofill::PasswordForm; | 350 scoped_ptr<autofill::PasswordForm> form1(new autofill::PasswordForm); |
283 form1->signon_realm = "abc"; | 351 form1->signon_realm = "abc"; |
284 std::vector<autofill::PasswordForm*> forms; | 352 std::vector<autofill::PasswordForm*> forms; |
285 forms.push_back(form1); | 353 forms.push_back(form1.release()); |
286 SetPasswordStoreData(forms); | 354 SetPasswordStoreData(forms, std::vector<autofill::PasswordForm*>()); |
287 | 355 |
288 SyncData sync_data = CreateSyncData("def"); | 356 SyncData sync_data = CreateSyncData("def"); |
289 SyncDataList list; | 357 SyncDataList list; |
290 list.push_back(sync_data); | 358 list.push_back(sync_data); |
291 | 359 |
292 verifier()->SetExpectedDBChanges(list, | 360 verifier()->SetExpectedDBChanges(list, |
293 std::vector<autofill::PasswordForm*>(), | 361 std::vector<autofill::PasswordForm*>(), |
294 password_store_); | 362 std::vector<autofill::PasswordForm*>(), |
| 363 password_store()); |
295 verifier()->SetExpectedSyncChanges( | 364 verifier()->SetExpectedSyncChanges( |
296 SyncChangeList(1, CreateSyncChange(*form1, SyncChange::ACTION_ADD))); | 365 SyncChangeList(1, CreateSyncChange(*forms[0], SyncChange::ACTION_ADD))); |
297 EXPECT_CALL(*service_, NotifyPasswordStoreOfLoginChanges(_)); | 366 EXPECT_CALL(*service(), NotifyPasswordStoreOfLoginChanges(_)); |
298 | 367 |
299 service_->MergeDataAndStartSyncing(syncer::PASSWORDS, | 368 service()->MergeDataAndStartSyncing(syncer::PASSWORDS, |
300 list, | 369 list, |
301 ReleaseSyncChangeProcessor(), | 370 CreateSyncChangeProcessor(), |
302 scoped_ptr<syncer::SyncErrorFactory>()); | 371 scoped_ptr<syncer::SyncErrorFactory>()); |
303 } | 372 } |
304 | 373 |
305 // Sync has data that is not present in the password db. | 374 // Sync has data that is not present in the password db. |
306 TEST_F(PasswordSyncableServiceTest, AdditionOnlyInSync) { | 375 TEST_F(PasswordSyncableServiceTest, AdditionOnlyInSync) { |
307 SetPasswordStoreData(std::vector<autofill::PasswordForm*>()); | 376 SetPasswordStoreData(std::vector<autofill::PasswordForm*>(), |
| 377 std::vector<autofill::PasswordForm*>()); |
308 | 378 |
309 SyncData sync_data = CreateSyncData("def"); | 379 SyncData sync_data = CreateSyncData("def"); |
310 SyncDataList list; | 380 SyncDataList list; |
311 list.push_back(sync_data); | 381 list.push_back(sync_data); |
312 | 382 |
313 verifier()->SetExpectedDBChanges(list, | 383 verifier()->SetExpectedDBChanges(list, |
314 std::vector<autofill::PasswordForm*>(), | 384 std::vector<autofill::PasswordForm*>(), |
315 password_store_); | 385 std::vector<autofill::PasswordForm*>(), |
| 386 password_store()); |
316 verifier()->SetExpectedSyncChanges(SyncChangeList()); | 387 verifier()->SetExpectedSyncChanges(SyncChangeList()); |
317 EXPECT_CALL(*service_, NotifyPasswordStoreOfLoginChanges(_)); | 388 EXPECT_CALL(*service(), NotifyPasswordStoreOfLoginChanges(_)); |
318 | 389 |
319 service_->MergeDataAndStartSyncing(syncer::PASSWORDS, | 390 service()->MergeDataAndStartSyncing(syncer::PASSWORDS, |
320 list, | 391 list, |
321 ReleaseSyncChangeProcessor(), | 392 CreateSyncChangeProcessor(), |
322 scoped_ptr<syncer::SyncErrorFactory>()); | 393 scoped_ptr<syncer::SyncErrorFactory>()); |
323 } | 394 } |
324 | 395 |
325 // Passwords db has data that is not present in sync. | 396 // Passwords db has data that is not present in sync. |
326 TEST_F(PasswordSyncableServiceTest, AdditionOnlyInPasswordStore) { | 397 TEST_F(PasswordSyncableServiceTest, AdditionOnlyInPasswordStore) { |
327 autofill::PasswordForm* form1 = new autofill::PasswordForm; | 398 scoped_ptr<autofill::PasswordForm> form1(new autofill::PasswordForm); |
328 form1->signon_realm = "abc"; | 399 form1->signon_realm = "abc"; |
329 std::vector<autofill::PasswordForm*> forms; | 400 std::vector<autofill::PasswordForm*> forms; |
330 forms.push_back(form1); | 401 forms.push_back(form1.release()); |
331 SetPasswordStoreData(forms); | 402 SetPasswordStoreData(forms, std::vector<autofill::PasswordForm*>()); |
332 | 403 |
333 verifier()->SetExpectedDBChanges(SyncDataList(), | 404 verifier()->SetExpectedDBChanges(SyncDataList(), |
334 std::vector<autofill::PasswordForm*>(), | 405 std::vector<autofill::PasswordForm*>(), |
335 password_store_); | 406 std::vector<autofill::PasswordForm*>(), |
| 407 password_store()); |
336 verifier()->SetExpectedSyncChanges( | 408 verifier()->SetExpectedSyncChanges( |
337 SyncChangeList(1, CreateSyncChange(*form1, SyncChange::ACTION_ADD))); | 409 SyncChangeList(1, CreateSyncChange(*forms[0], SyncChange::ACTION_ADD))); |
338 EXPECT_CALL(*service_, | 410 EXPECT_CALL(*service_, |
339 NotifyPasswordStoreOfLoginChanges(PasswordStoreChangeList())); | 411 NotifyPasswordStoreOfLoginChanges(PasswordStoreChangeList())); |
340 | 412 |
341 service_->MergeDataAndStartSyncing(syncer::PASSWORDS, | 413 service()->MergeDataAndStartSyncing(syncer::PASSWORDS, |
342 SyncDataList(), | 414 SyncDataList(), |
343 ReleaseSyncChangeProcessor(), | 415 CreateSyncChangeProcessor(), |
344 scoped_ptr<syncer::SyncErrorFactory>()); | 416 scoped_ptr<syncer::SyncErrorFactory>()); |
345 } | 417 } |
346 | 418 |
347 // Both passwords db and sync contain the same data. | 419 // Both passwords db and sync contain the same data. |
348 TEST_F(PasswordSyncableServiceTest, BothInSync) { | 420 TEST_F(PasswordSyncableServiceTest, BothInSync) { |
349 autofill::PasswordForm *form1 = new autofill::PasswordForm; | 421 scoped_ptr<autofill::PasswordForm> form1(new autofill::PasswordForm); |
350 form1->signon_realm = "abc"; | 422 form1->signon_realm = "abc"; |
351 std::vector<autofill::PasswordForm*> forms; | 423 std::vector<autofill::PasswordForm*> forms; |
352 forms.push_back(form1); | 424 forms.push_back(form1.release()); |
353 SetPasswordStoreData(forms); | 425 SetPasswordStoreData(forms, std::vector<autofill::PasswordForm*>()); |
354 | 426 |
355 verifier()->SetExpectedDBChanges(SyncDataList(), | 427 verifier()->SetExpectedDBChanges(SyncDataList(), |
356 std::vector<autofill::PasswordForm*>(), | 428 std::vector<autofill::PasswordForm*>(), |
357 password_store_); | 429 std::vector<autofill::PasswordForm*>(), |
| 430 password_store()); |
358 verifier()->SetExpectedSyncChanges(SyncChangeList()); | 431 verifier()->SetExpectedSyncChanges(SyncChangeList()); |
359 EXPECT_CALL(*service_, | 432 EXPECT_CALL(*service_, |
360 NotifyPasswordStoreOfLoginChanges(PasswordStoreChangeList())); | 433 NotifyPasswordStoreOfLoginChanges(PasswordStoreChangeList())); |
361 | 434 |
362 service_->MergeDataAndStartSyncing(syncer::PASSWORDS, | 435 service()->MergeDataAndStartSyncing(syncer::PASSWORDS, |
363 SyncDataList(1, CreateSyncData("abc")), | 436 SyncDataList(1, CreateSyncData("abc")), |
364 ReleaseSyncChangeProcessor(), | 437 CreateSyncChangeProcessor(), |
365 scoped_ptr<syncer::SyncErrorFactory>()); | 438 scoped_ptr<syncer::SyncErrorFactory>()); |
366 } | 439 } |
367 | 440 |
368 // Both passwords db and sync have the same data but they need to be merged | 441 // Both passwords db and sync have the same data but they need to be merged |
369 // as some fields of the data differ. | 442 // as some fields of the data differ. |
370 TEST_F(PasswordSyncableServiceTest, Merge) { | 443 TEST_F(PasswordSyncableServiceTest, Merge) { |
371 autofill::PasswordForm *form1 = new autofill::PasswordForm; | 444 scoped_ptr<autofill::PasswordForm> form1(new autofill::PasswordForm); |
372 form1->signon_realm = "abc"; | 445 form1->signon_realm = "abc"; |
373 form1->action = GURL("http://pie.com"); | 446 form1->action = GURL("http://pie.com"); |
374 form1->date_created = base::Time::Now(); | 447 form1->date_created = base::Time::Now(); |
375 std::vector<autofill::PasswordForm*> forms; | 448 std::vector<autofill::PasswordForm*> forms; |
376 forms.push_back(form1); | 449 forms.push_back(form1.release()); |
377 SetPasswordStoreData(forms); | 450 SetPasswordStoreData(forms, std::vector<autofill::PasswordForm*>()); |
378 | 451 |
379 verifier()->SetExpectedDBChanges(SyncDataList(), | 452 verifier()->SetExpectedDBChanges(SyncDataList(), |
380 forms, | 453 std::vector<autofill::PasswordForm*>(), |
381 password_store_); | 454 std::vector<autofill::PasswordForm*>(), |
| 455 password_store()); |
382 verifier()->SetExpectedSyncChanges( | 456 verifier()->SetExpectedSyncChanges( |
383 SyncChangeList(1, CreateSyncChange(*form1, SyncChange::ACTION_UPDATE))); | 457 SyncChangeList(1, CreateSyncChange(*forms[0], |
| 458 SyncChange::ACTION_UPDATE))); |
384 | 459 |
385 EXPECT_CALL(*service_, NotifyPasswordStoreOfLoginChanges(_)); | 460 EXPECT_CALL(*service(), NotifyPasswordStoreOfLoginChanges(_)); |
386 | 461 |
387 service_->MergeDataAndStartSyncing(syncer::PASSWORDS, | 462 service()->MergeDataAndStartSyncing(syncer::PASSWORDS, |
388 SyncDataList(1, CreateSyncData("abc")), | 463 SyncDataList(1, CreateSyncData("abc")), |
389 ReleaseSyncChangeProcessor(), | 464 CreateSyncChangeProcessor(), |
390 scoped_ptr<syncer::SyncErrorFactory>()); | 465 scoped_ptr<syncer::SyncErrorFactory>()); |
391 } | 466 } |
392 | 467 |
393 // Initiate sync due to local DB changes. | 468 // Initiate sync due to local DB changes. |
394 TEST_F(PasswordSyncableServiceTest, PasswordStoreChanges) { | 469 TEST_F(PasswordSyncableServiceTest, PasswordStoreChanges) { |
395 // Set the sync change processor first. | 470 // Set the sync change processor first. |
396 SetPasswordStoreData(std::vector<autofill::PasswordForm*>()); | 471 SetPasswordStoreData(std::vector<autofill::PasswordForm*>(), |
| 472 std::vector<autofill::PasswordForm*>()); |
397 verifier()->SetExpectedSyncChanges(SyncChangeList()); | 473 verifier()->SetExpectedSyncChanges(SyncChangeList()); |
398 EXPECT_CALL(*service_, | 474 EXPECT_CALL(*service_, |
399 NotifyPasswordStoreOfLoginChanges(PasswordStoreChangeList())); | 475 NotifyPasswordStoreOfLoginChanges(PasswordStoreChangeList())); |
400 service_->MergeDataAndStartSyncing(syncer::PASSWORDS, | 476 service_->MergeDataAndStartSyncing(syncer::PASSWORDS, |
401 SyncDataList(), | 477 SyncDataList(), |
402 ReleaseSyncChangeProcessor(), | 478 CreateSyncChangeProcessor(), |
403 scoped_ptr<syncer::SyncErrorFactory>()); | 479 scoped_ptr<syncer::SyncErrorFactory>()); |
404 | 480 |
405 autofill::PasswordForm form1; | 481 autofill::PasswordForm form1; |
406 form1.signon_realm = "abc"; | 482 form1.signon_realm = "abc"; |
407 autofill::PasswordForm form2; | 483 autofill::PasswordForm form2; |
408 form2.signon_realm = "def"; | 484 form2.signon_realm = "def"; |
409 autofill::PasswordForm form3; | 485 autofill::PasswordForm form3; |
410 form3.signon_realm = "xyz"; | 486 form3.signon_realm = "xyz"; |
411 | 487 |
412 SyncChangeList sync_list; | 488 SyncChangeList sync_list; |
413 sync_list.push_back(CreateSyncChange(form1, SyncChange::ACTION_ADD)); | 489 sync_list.push_back(CreateSyncChange(form1, SyncChange::ACTION_ADD)); |
414 sync_list.push_back(CreateSyncChange(form2, SyncChange::ACTION_UPDATE)); | 490 sync_list.push_back(CreateSyncChange(form2, SyncChange::ACTION_UPDATE)); |
415 sync_list.push_back(CreateSyncChange(form3, SyncChange::ACTION_DELETE)); | 491 sync_list.push_back(CreateSyncChange(form3, SyncChange::ACTION_DELETE)); |
416 | 492 |
417 verifier()->SetExpectedDBChanges(SyncDataList(), | 493 verifier()->SetExpectedDBChanges(SyncDataList(), |
418 std::vector<autofill::PasswordForm*>(), | 494 std::vector<autofill::PasswordForm*>(), |
419 password_store_); | 495 std::vector<autofill::PasswordForm*>(), |
| 496 password_store()); |
420 verifier()->SetExpectedSyncChanges(sync_list); | 497 verifier()->SetExpectedSyncChanges(sync_list); |
421 | 498 |
422 PasswordStoreChangeList list; | 499 PasswordStoreChangeList list; |
423 list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form1)); | 500 list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form1)); |
424 list.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form2)); | 501 list.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form2)); |
425 list.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form3)); | 502 list.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form3)); |
426 service_->ActOnPasswordStoreChanges(list); | 503 service()->ActOnPasswordStoreChanges(list); |
| 504 } |
| 505 |
| 506 // Process all types of changes from sync. |
| 507 TEST_F(PasswordSyncableServiceTest, ProcessSyncChanges) { |
| 508 scoped_ptr<autofill::PasswordForm> form1(new autofill::PasswordForm); |
| 509 form1->signon_realm = "abc"; |
| 510 form1->action = GURL("http://foo.com"); |
| 511 scoped_ptr<autofill::PasswordForm> form2(new autofill::PasswordForm); |
| 512 form2->signon_realm = "xyz"; |
| 513 form2->action = GURL("http://bar.com"); |
| 514 form2->date_created = base::Time::Now(); |
| 515 form2->blacklisted_by_user = true; |
| 516 std::vector<autofill::PasswordForm*> forms(1, form1.release()); |
| 517 std::vector<autofill::PasswordForm*> blacklist_forms(1, form2.release()); |
| 518 SetPasswordStoreData(forms, blacklist_forms); |
| 519 |
| 520 SyncData add_data = CreateSyncData("def"); |
| 521 autofill::PasswordForm updated_form = *forms[0]; |
| 522 updated_form.date_created = base::Time::Now(); |
| 523 std::vector<autofill::PasswordForm*> updated_passwords(1, &updated_form); |
| 524 std::vector<autofill::PasswordForm*> deleted_passwords(1, blacklist_forms[0]); |
| 525 verifier()->SetExpectedDBChanges(SyncDataList(1, add_data), |
| 526 updated_passwords, |
| 527 deleted_passwords, |
| 528 password_store()); |
| 529 |
| 530 SyncChangeList list; |
| 531 list.push_back(SyncChange(FROM_HERE, |
| 532 syncer::SyncChange::ACTION_ADD, |
| 533 add_data)); |
| 534 list.push_back(SyncChange(FROM_HERE, |
| 535 syncer::SyncChange::ACTION_UPDATE, |
| 536 SyncDataFromPassword(updated_form))); |
| 537 list.push_back(CreateSyncChange(*blacklist_forms[0], |
| 538 syncer::SyncChange::ACTION_DELETE)); |
| 539 EXPECT_CALL(*service(), NotifyPasswordStoreOfLoginChanges(_)); |
| 540 service()->ProcessSyncChanges(FROM_HERE, list); |
| 541 } |
| 542 |
| 543 // Retrives sync data from the model. |
| 544 TEST_F(PasswordSyncableServiceTest, GetAllSyncData) { |
| 545 scoped_ptr<autofill::PasswordForm> form1(new autofill::PasswordForm); |
| 546 form1->signon_realm = "abc"; |
| 547 form1->action = GURL("http://foo.com"); |
| 548 scoped_ptr<autofill::PasswordForm> form2(new autofill::PasswordForm); |
| 549 form2->signon_realm = "xyz"; |
| 550 form2->action = GURL("http://bar.com"); |
| 551 form2->blacklisted_by_user = true; |
| 552 std::vector<autofill::PasswordForm*> forms(1, form1.release()); |
| 553 std::vector<autofill::PasswordForm*> blacklist_forms(1, form2.release()); |
| 554 SetPasswordStoreData(forms, blacklist_forms); |
| 555 |
| 556 SyncDataList expected_list; |
| 557 expected_list.push_back(SyncDataFromPassword(*forms[0])); |
| 558 expected_list.push_back(SyncDataFromPassword(*blacklist_forms[0])); |
| 559 |
| 560 verifier()->SetExpectedDBChanges(SyncDataList(), |
| 561 std::vector<autofill::PasswordForm*>(), |
| 562 std::vector<autofill::PasswordForm*>(), |
| 563 password_store()); |
| 564 |
| 565 SyncDataList actual_list = service()->GetAllSyncData(syncer::PASSWORDS); |
| 566 EXPECT_EQ(expected_list.size(), actual_list.size()); |
| 567 for (SyncDataList::iterator i(actual_list.begin()), j(expected_list.begin()); |
| 568 i != actual_list.end() && j != expected_list.end(); ++i, ++j) { |
| 569 PasswordsEqual(GetPasswordSpecifics(*j), GetPasswordSpecifics(*i)); |
| 570 } |
| 571 } |
| 572 |
| 573 // Creates 2 PasswordSyncableService instances, merges the content of the first |
| 574 // one to the second one and back. |
| 575 TEST_F(PasswordSyncableServiceTest, MergeDataAndPushBack) { |
| 576 scoped_ptr<autofill::PasswordForm> form1(new autofill::PasswordForm); |
| 577 form1->signon_realm = "abc"; |
| 578 form1->action = GURL("http://foo.com"); |
| 579 std::vector<autofill::PasswordForm*> forms(1, form1.release()); |
| 580 SetPasswordStoreData(forms, std::vector<autofill::PasswordForm*>()); |
| 581 |
| 582 PasswordSyncableServiceWrapper other_service_wrapper; |
| 583 scoped_ptr<autofill::PasswordForm> form2(new autofill::PasswordForm); |
| 584 form2->signon_realm = "xyz"; |
| 585 form2->action = GURL("http://bar.com"); |
| 586 syncer::SyncData form2_sync_data = SyncDataFromPassword(*form2); |
| 587 other_service_wrapper.SetPasswordStoreData( |
| 588 std::vector<autofill::PasswordForm*>(1, form2.release()), |
| 589 std::vector<autofill::PasswordForm*>()); |
| 590 |
| 591 verifier()->SetExpectedDBChanges(SyncDataList(1, form2_sync_data), |
| 592 std::vector<autofill::PasswordForm*>(), |
| 593 std::vector<autofill::PasswordForm*>(), |
| 594 password_store()); |
| 595 other_service_wrapper.verifier()->SetExpectedDBChanges( |
| 596 SyncDataList(1, SyncDataFromPassword(*forms[0])), |
| 597 std::vector<autofill::PasswordForm*>(), |
| 598 std::vector<autofill::PasswordForm*>(), |
| 599 other_service_wrapper.password_store()); |
| 600 EXPECT_CALL(*service(), NotifyPasswordStoreOfLoginChanges(_)); |
| 601 EXPECT_CALL(*other_service_wrapper.service(), |
| 602 NotifyPasswordStoreOfLoginChanges(_)); |
| 603 |
| 604 syncer::SyncDataList other_service_data = |
| 605 other_service_wrapper.service()->GetAllSyncData(syncer::PASSWORDS); |
| 606 service()->MergeDataAndStartSyncing( |
| 607 syncer::PASSWORDS, |
| 608 other_service_data, |
| 609 other_service_wrapper.ReleaseSyncableService(), |
| 610 scoped_ptr<syncer::SyncErrorFactory>()); |
427 } | 611 } |
428 | 612 |
429 } // namespace | 613 } // namespace |
OLD | NEW |