OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 #include "base/task.h" | 9 #include "base/task.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 WillRepeatedly(Return(password_store_.get())); | 178 WillRepeatedly(Return(password_store_.get())); |
179 | 179 |
180 EXPECT_CALL(observer_, | 180 EXPECT_CALL(observer_, |
181 Observe( | 181 Observe( |
182 NotificationType(NotificationType::SYNC_CONFIGURE_DONE),_,_)); | 182 NotificationType(NotificationType::SYNC_CONFIGURE_DONE),_,_)); |
183 | 183 |
184 service_->RegisterDataTypeController(data_type_controller); | 184 service_->RegisterDataTypeController(data_type_controller); |
185 service_->Initialize(); | 185 service_->Initialize(); |
186 MessageLoop::current()->Run(); | 186 MessageLoop::current()->Run(); |
187 | 187 |
188 // Only set the passphrase if we actually created the password and nigori | 188 |
189 // root nodes. | 189 EXPECT_CALL(observer_, |
190 if (root_task) { | 190 Observe( |
191 EXPECT_CALL(observer_, | 191 NotificationType(NotificationType::SYNC_PASSPHRASE_ACCEPTED), |
192 Observe( | 192 _,_)). |
193 NotificationType(NotificationType::SYNC_PASSPHRASE_ACCEPTED), | 193 WillOnce(InvokeTask(node_task)); |
194 _,_)). | 194 EXPECT_CALL(observer_, |
195 WillOnce(InvokeTask(node_task)); | 195 Observe( |
196 EXPECT_CALL(observer_, | 196 NotificationType(NotificationType::SYNC_CONFIGURE_DONE), |
197 Observe( | 197 _,_)). |
198 NotificationType(NotificationType::SYNC_CONFIGURE_DONE), | 198 WillOnce(QuitUIMessageLoop()); |
199 _,_)). | 199 service_->SetPassphrase("foo"); |
200 WillOnce(QuitUIMessageLoop()); | 200 MessageLoop::current()->Run(); |
201 service_->SetPassphrase("foo"); | 201 |
202 MessageLoop::current()->Run(); | |
203 } | |
204 } | 202 } |
205 } | 203 } |
206 | 204 |
207 void AddPasswordSyncNode(const PasswordForm& entry) { | 205 void AddPasswordSyncNode(const PasswordForm& entry) { |
208 sync_api::WriteTransaction trans( | 206 sync_api::WriteTransaction trans( |
209 service_->backend()->GetUserShareHandle()); | 207 service_->backend()->GetUserShareHandle()); |
210 sync_api::ReadNode password_root(&trans); | 208 sync_api::ReadNode password_root(&trans); |
211 ASSERT_TRUE(password_root.InitByTagLookup(browser_sync::kPasswordTag)); | 209 ASSERT_TRUE(password_root.InitByTagLookup(browser_sync::kPasswordTag)); |
212 | 210 |
213 sync_api::WriteNode node(&trans); | 211 sync_api::WriteNode node(&trans); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 261 |
264 friend class AddPasswordEntriesTask; | 262 friend class AddPasswordEntriesTask; |
265 | 263 |
266 BrowserThread db_thread_; | 264 BrowserThread db_thread_; |
267 scoped_refptr<ThreadNotificationService> notification_service_; | 265 scoped_refptr<ThreadNotificationService> notification_service_; |
268 NotificationObserverMock observer_; | 266 NotificationObserverMock observer_; |
269 ProfileMock profile_; | 267 ProfileMock profile_; |
270 scoped_refptr<MockPasswordStore> password_store_; | 268 scoped_refptr<MockPasswordStore> password_store_; |
271 NotificationRegistrar registrar_; | 269 NotificationRegistrar registrar_; |
272 | 270 |
273 TestIdFactory ids_; | |
274 }; | |
275 | |
276 class CreatePasswordRootTask : public Task { | |
277 public: | |
278 explicit CreatePasswordRootTask(AbstractProfileSyncServiceTest* test) | |
279 : test_(test) { | |
280 } | |
281 | |
282 virtual void Run() { | |
283 test_->CreateRoot(syncable::NIGORI); | |
284 test_->CreateRoot(syncable::PASSWORDS); | |
285 } | |
286 | |
287 private: | |
288 AbstractProfileSyncServiceTest* test_; | |
289 }; | 271 }; |
290 | 272 |
291 class AddPasswordEntriesTask : public Task { | 273 class AddPasswordEntriesTask : public Task { |
292 public: | 274 public: |
293 AddPasswordEntriesTask(ProfileSyncServicePasswordTest* test, | 275 AddPasswordEntriesTask(ProfileSyncServicePasswordTest* test, |
294 const std::vector<PasswordForm>& entries) | 276 const std::vector<PasswordForm>& entries) |
295 : test_(test), entries_(entries) { | 277 : test_(test), entries_(entries) { |
296 } | 278 } |
297 | 279 |
298 virtual void Run() { | 280 virtual void Run() { |
299 for (size_t i = 0; i < entries_.size(); ++i) { | 281 for (size_t i = 0; i < entries_.size(); ++i) { |
300 test_->AddPasswordSyncNode(entries_[i]); | 282 test_->AddPasswordSyncNode(entries_[i]); |
301 } | 283 } |
302 } | 284 } |
303 | 285 |
304 private: | 286 private: |
305 ProfileSyncServicePasswordTest* test_; | 287 ProfileSyncServicePasswordTest* test_; |
306 const std::vector<PasswordForm>& entries_; | 288 const std::vector<PasswordForm>& entries_; |
307 }; | 289 }; |
308 | 290 |
309 TEST_F(ProfileSyncServicePasswordTest, FailModelAssociation) { | 291 TEST_F(ProfileSyncServicePasswordTest, FailModelAssociation) { |
310 // Create the nigori root node so that password model association is | 292 StartSyncService(NULL, NULL, 1, 2); |
311 // attempted, but not the password root node so that it fails. | |
312 CreateRootTask task(this, syncable::NIGORI); | |
313 StartSyncService(&task, NULL, 1, 2); | |
314 EXPECT_TRUE(service_->unrecoverable_error_detected()); | 293 EXPECT_TRUE(service_->unrecoverable_error_detected()); |
315 } | 294 } |
316 | 295 |
317 TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) { | 296 TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) { |
318 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) | 297 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
319 .WillOnce(Return(true)); | 298 .WillOnce(Return(true)); |
320 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) | 299 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) |
321 .WillOnce(Return(true)); | 300 .WillOnce(Return(true)); |
322 SetIdleChangeProcessorExpectations(); | 301 SetIdleChangeProcessorExpectations(); |
323 CreatePasswordRootTask task(this); | 302 CreateRootTask task(this, syncable::PASSWORDS); |
324 StartSyncService(&task, NULL); | 303 StartSyncService(&task, NULL); |
325 std::vector<PasswordForm> sync_entries; | 304 std::vector<PasswordForm> sync_entries; |
326 GetPasswordEntriesFromSyncDB(&sync_entries); | 305 GetPasswordEntriesFromSyncDB(&sync_entries); |
327 EXPECT_EQ(0U, sync_entries.size()); | 306 EXPECT_EQ(0U, sync_entries.size()); |
328 } | 307 } |
329 | 308 |
330 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySync) { | 309 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySync) { |
331 std::vector<PasswordForm*> forms; | 310 std::vector<PasswordForm*> forms; |
332 std::vector<PasswordForm> expected_forms; | 311 std::vector<PasswordForm> expected_forms; |
333 PasswordForm* new_form = new PasswordForm; | 312 PasswordForm* new_form = new PasswordForm; |
334 new_form->scheme = PasswordForm::SCHEME_HTML; | 313 new_form->scheme = PasswordForm::SCHEME_HTML; |
335 new_form->signon_realm = "pie"; | 314 new_form->signon_realm = "pie"; |
336 new_form->origin = GURL("http://pie.com"); | 315 new_form->origin = GURL("http://pie.com"); |
337 new_form->action = GURL("http://pie.com/submit"); | 316 new_form->action = GURL("http://pie.com/submit"); |
338 new_form->username_element = UTF8ToUTF16("name"); | 317 new_form->username_element = UTF8ToUTF16("name"); |
339 new_form->username_value = UTF8ToUTF16("tom"); | 318 new_form->username_value = UTF8ToUTF16("tom"); |
340 new_form->password_element = UTF8ToUTF16("cork"); | 319 new_form->password_element = UTF8ToUTF16("cork"); |
341 new_form->password_value = UTF8ToUTF16("password1"); | 320 new_form->password_value = UTF8ToUTF16("password1"); |
342 new_form->ssl_valid = true; | 321 new_form->ssl_valid = true; |
343 new_form->preferred = false; | 322 new_form->preferred = false; |
344 new_form->date_created = base::Time::FromInternalValue(1234); | 323 new_form->date_created = base::Time::FromInternalValue(1234); |
345 new_form->blacklisted_by_user = false; | 324 new_form->blacklisted_by_user = false; |
346 forms.push_back(new_form); | 325 forms.push_back(new_form); |
347 expected_forms.push_back(*new_form); | 326 expected_forms.push_back(*new_form); |
348 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) | 327 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
349 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); | 328 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); |
350 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) | 329 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) |
351 .WillOnce(Return(true)); | 330 .WillOnce(Return(true)); |
352 SetIdleChangeProcessorExpectations(); | 331 SetIdleChangeProcessorExpectations(); |
353 CreatePasswordRootTask task(this); | 332 CreateRootTask task(this, syncable::PASSWORDS); |
354 StartSyncService(&task, NULL); | 333 StartSyncService(&task, NULL); |
355 std::vector<PasswordForm> sync_forms; | 334 std::vector<PasswordForm> sync_forms; |
356 GetPasswordEntriesFromSyncDB(&sync_forms); | 335 GetPasswordEntriesFromSyncDB(&sync_forms); |
357 ASSERT_EQ(1U, sync_forms.size()); | 336 ASSERT_EQ(1U, sync_forms.size()); |
358 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[0])); | 337 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[0])); |
359 } | 338 } |
360 | 339 |
361 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySyncSameUsername) { | 340 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySyncSameUsername) { |
362 std::vector<PasswordForm*> forms; | 341 std::vector<PasswordForm*> forms; |
363 std::vector<PasswordForm> expected_forms; | 342 std::vector<PasswordForm> expected_forms; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 new_form->blacklisted_by_user = false; | 374 new_form->blacklisted_by_user = false; |
396 forms.push_back(new_form); | 375 forms.push_back(new_form); |
397 expected_forms.push_back(*new_form); | 376 expected_forms.push_back(*new_form); |
398 } | 377 } |
399 | 378 |
400 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) | 379 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
401 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); | 380 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); |
402 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) | 381 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) |
403 .WillOnce(Return(true)); | 382 .WillOnce(Return(true)); |
404 SetIdleChangeProcessorExpectations(); | 383 SetIdleChangeProcessorExpectations(); |
405 CreatePasswordRootTask task(this); | 384 CreateRootTask task(this, syncable::PASSWORDS); |
406 StartSyncService(&task, NULL); | 385 StartSyncService(&task, NULL); |
407 std::vector<PasswordForm> sync_forms; | 386 std::vector<PasswordForm> sync_forms; |
408 GetPasswordEntriesFromSyncDB(&sync_forms); | 387 GetPasswordEntriesFromSyncDB(&sync_forms); |
409 ASSERT_EQ(2U, sync_forms.size()); | 388 ASSERT_EQ(2U, sync_forms.size()); |
410 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[1])); | 389 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[1])); |
411 EXPECT_TRUE(ComparePasswords(expected_forms[1], sync_forms[0])); | 390 EXPECT_TRUE(ComparePasswords(expected_forms[1], sync_forms[0])); |
412 } | 391 } |
413 | 392 |
414 TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncNoMerge) { | 393 TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncNoMerge) { |
415 std::vector<PasswordForm*> native_forms; | 394 std::vector<PasswordForm*> native_forms; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 new_form.blacklisted_by_user = false; | 429 new_form.blacklisted_by_user = false; |
451 sync_forms.push_back(new_form); | 430 sync_forms.push_back(new_form); |
452 expected_forms.push_back(new_form); | 431 expected_forms.push_back(new_form); |
453 } | 432 } |
454 | 433 |
455 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) | 434 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
456 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); | 435 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); |
457 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); | 436 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); |
458 EXPECT_CALL(*password_store_, AddLoginImpl(_)).Times(1); | 437 EXPECT_CALL(*password_store_, AddLoginImpl(_)).Times(1); |
459 | 438 |
460 CreatePasswordRootTask root_task(this); | 439 CreateRootTask root_task(this, syncable::PASSWORDS); |
461 AddPasswordEntriesTask node_task(this, sync_forms); | 440 AddPasswordEntriesTask node_task(this, sync_forms); |
462 StartSyncService(&root_task, &node_task); | 441 StartSyncService(&root_task, &node_task); |
463 | 442 |
464 std::vector<PasswordForm> new_sync_forms; | 443 std::vector<PasswordForm> new_sync_forms; |
465 GetPasswordEntriesFromSyncDB(&new_sync_forms); | 444 GetPasswordEntriesFromSyncDB(&new_sync_forms); |
466 | 445 |
467 EXPECT_EQ(2U, new_sync_forms.size()); | 446 EXPECT_EQ(2U, new_sync_forms.size()); |
468 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); | 447 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); |
469 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1])); | 448 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1])); |
470 } | 449 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 new_form.date_created = base::Time::FromInternalValue(12345); | 502 new_form.date_created = base::Time::FromInternalValue(12345); |
524 new_form.blacklisted_by_user = false; | 503 new_form.blacklisted_by_user = false; |
525 expected_forms.push_back(new_form); | 504 expected_forms.push_back(new_form); |
526 } | 505 } |
527 | 506 |
528 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) | 507 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
529 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); | 508 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); |
530 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); | 509 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); |
531 EXPECT_CALL(*password_store_, UpdateLoginImpl(_)).Times(1); | 510 EXPECT_CALL(*password_store_, UpdateLoginImpl(_)).Times(1); |
532 | 511 |
533 CreatePasswordRootTask root_task(this); | 512 CreateRootTask root_task(this, syncable::PASSWORDS); |
534 AddPasswordEntriesTask node_task(this, sync_forms); | 513 AddPasswordEntriesTask node_task(this, sync_forms); |
535 | 514 |
536 StartSyncService(&root_task, &node_task); | 515 StartSyncService(&root_task, &node_task); |
537 | 516 |
538 std::vector<PasswordForm> new_sync_forms; | 517 std::vector<PasswordForm> new_sync_forms; |
539 GetPasswordEntriesFromSyncDB(&new_sync_forms); | 518 GetPasswordEntriesFromSyncDB(&new_sync_forms); |
540 | 519 |
541 EXPECT_EQ(1U, new_sync_forms.size()); | 520 EXPECT_EQ(1U, new_sync_forms.size()); |
542 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); | 521 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); |
543 } | 522 } |
OLD | NEW |