Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Side by Side Diff: chrome/browser/sync/profile_sync_service_password_unittest.cc

Issue 16290004: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 171
172 virtual void SetUp() { 172 virtual void SetUp() {
173 AbstractProfileSyncServiceTest::SetUp(); 173 AbstractProfileSyncServiceTest::SetUp();
174 profile_.CreateRequestContext(); 174 profile_.CreateRequestContext();
175 password_store_ = static_cast<MockPasswordStore*>( 175 password_store_ = static_cast<MockPasswordStore*>(
176 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( 176 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse(
177 &profile_, MockPasswordStore::Build).get()); 177 &profile_, MockPasswordStore::Build).get());
178 } 178 }
179 179
180 virtual void TearDown() { 180 virtual void TearDown() {
181 if (password_store_) 181 if (password_store_.get())
182 password_store_->ShutdownOnUIThread(); 182 password_store_->ShutdownOnUIThread();
183 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory( 183 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(
184 &profile_, NULL); 184 &profile_, NULL);
185 profile_.ResetRequestContext(); 185 profile_.ResetRequestContext();
186 AbstractProfileSyncServiceTest::TearDown(); 186 AbstractProfileSyncServiceTest::TearDown();
187 } 187 }
188 188
189 static void SignalEvent(base::WaitableEvent* done) { 189 static void SignalEvent(base::WaitableEvent* done) {
190 done->Signal(); 190 done->Signal();
191 } 191 }
(...skipping 28 matching lines...) Expand all
220 syncer::ModelTypeSet preferred_types = 220 syncer::ModelTypeSet preferred_types =
221 sync_service_->GetPreferredDataTypes(); 221 sync_service_->GetPreferredDataTypes();
222 preferred_types.Put(syncer::PASSWORDS); 222 preferred_types.Put(syncer::PASSWORDS);
223 sync_service_->ChangePreferredDataTypes(preferred_types); 223 sync_service_->ChangePreferredDataTypes(preferred_types);
224 PasswordDataTypeController* data_type_controller = 224 PasswordDataTypeController* data_type_controller =
225 new PasswordDataTypeController(sync_service_->factory(), 225 new PasswordDataTypeController(sync_service_->factory(),
226 &profile_, 226 &profile_,
227 sync_service_); 227 sync_service_);
228 ProfileSyncComponentsFactoryMock* components = 228 ProfileSyncComponentsFactoryMock* components =
229 sync_service_->components_factory_mock(); 229 sync_service_->components_factory_mock();
230 if (password_store_) { 230 if (password_store_.get()) {
231 EXPECT_CALL(*components, CreatePasswordSyncComponents(_, _, _)). 231 EXPECT_CALL(*components, CreatePasswordSyncComponents(_, _, _))
232 Times(AtLeast(1)). // Can be more if we hit NEEDS_CRYPTO. 232 .Times(AtLeast(1)). // Can be more if we hit NEEDS_CRYPTO.
233 WillRepeatedly(MakePasswordSyncComponents(sync_service_, 233 WillRepeatedly(MakePasswordSyncComponents(
234 password_store_.get(), 234 sync_service_, password_store_.get(), data_type_controller));
235 data_type_controller));
236 } else { 235 } else {
237 // When the password store is unavailable, password sync components must 236 // When the password store is unavailable, password sync components must
238 // not be created. 237 // not be created.
239 EXPECT_CALL(*components, CreatePasswordSyncComponents(_, _, _)) 238 EXPECT_CALL(*components, CreatePasswordSyncComponents(_, _, _))
240 .Times(0); 239 .Times(0);
241 } 240 }
242 EXPECT_CALL(*components, CreateDataTypeManager(_, _, _, _, _)). 241 EXPECT_CALL(*components, CreateDataTypeManager(_, _, _, _, _)).
243 WillOnce(ReturnNewDataTypeManager()); 242 WillOnce(ReturnNewDataTypeManager());
244 243
245 // We need tokens to get the tests going 244 // We need tokens to get the tests going
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 lhs.username_value == rhs.username_value && 312 lhs.username_value == rhs.username_value &&
314 lhs.password_element == rhs.password_element && 313 lhs.password_element == rhs.password_element &&
315 lhs.password_value == rhs.password_value && 314 lhs.password_value == rhs.password_value &&
316 lhs.ssl_valid == rhs.ssl_valid && 315 lhs.ssl_valid == rhs.ssl_valid &&
317 lhs.preferred == rhs.preferred && 316 lhs.preferred == rhs.preferred &&
318 lhs.date_created == rhs.date_created && 317 lhs.date_created == rhs.date_created &&
319 lhs.blacklisted_by_user == rhs.blacklisted_by_user; 318 lhs.blacklisted_by_user == rhs.blacklisted_by_user;
320 } 319 }
321 320
322 void SetIdleChangeProcessorExpectations() { 321 void SetIdleChangeProcessorExpectations() {
323 EXPECT_CALL(*password_store_, AddLoginImpl(_)).Times(0); 322 EXPECT_CALL(*password_store_.get(), AddLoginImpl(_)).Times(0);
324 EXPECT_CALL(*password_store_, UpdateLoginImpl(_)).Times(0); 323 EXPECT_CALL(*password_store_.get(), UpdateLoginImpl(_)).Times(0);
325 EXPECT_CALL(*password_store_, RemoveLoginImpl(_)).Times(0); 324 EXPECT_CALL(*password_store_.get(), RemoveLoginImpl(_)).Times(0);
326 } 325 }
327 326
328 content::MockNotificationObserver observer_; 327 content::MockNotificationObserver observer_;
329 ProfileMock profile_; 328 ProfileMock profile_;
330 scoped_refptr<MockPasswordStore> password_store_; 329 scoped_refptr<MockPasswordStore> password_store_;
331 content::NotificationRegistrar registrar_; 330 content::NotificationRegistrar registrar_;
332 }; 331 };
333 332
334 void AddPasswordEntriesCallback(ProfileSyncServicePasswordTest* test, 333 void AddPasswordEntriesCallback(ProfileSyncServicePasswordTest* test,
335 const std::vector<PasswordForm>& entries) { 334 const std::vector<PasswordForm>& entries) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( 369 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse(
371 &profile_, NullPasswordStore::Build).get()); 370 &profile_, NullPasswordStore::Build).get());
372 StartSyncService(base::Closure(), base::Closure()); 371 StartSyncService(base::Closure(), base::Closure());
373 EXPECT_FALSE(sync_service_->HasUnrecoverableError()); 372 EXPECT_FALSE(sync_service_->HasUnrecoverableError());
374 syncer::ModelTypeSet failed_types = 373 syncer::ModelTypeSet failed_types =
375 sync_service_->failed_datatypes_handler().GetFailedTypes(); 374 sync_service_->failed_datatypes_handler().GetFailedTypes();
376 EXPECT_TRUE(failed_types.Equals(syncer::ModelTypeSet(syncer::PASSWORDS))); 375 EXPECT_TRUE(failed_types.Equals(syncer::ModelTypeSet(syncer::PASSWORDS)));
377 } 376 }
378 377
379 TEST_F(ProfileSyncServicePasswordTest, MAYBE_EmptyNativeEmptySync) { 378 TEST_F(ProfileSyncServicePasswordTest, MAYBE_EmptyNativeEmptySync) {
380 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 379 EXPECT_CALL(*password_store_.get(), FillAutofillableLogins(_))
381 .WillOnce(Return(true)); 380 .WillOnce(Return(true));
382 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) 381 EXPECT_CALL(*password_store_.get(), FillBlacklistLogins(_))
383 .WillOnce(Return(true)); 382 .WillOnce(Return(true));
384 SetIdleChangeProcessorExpectations(); 383 SetIdleChangeProcessorExpectations();
385 CreateRootHelper create_root(this, syncer::PASSWORDS); 384 CreateRootHelper create_root(this, syncer::PASSWORDS);
386 StartSyncService(create_root.callback(), base::Closure()); 385 StartSyncService(create_root.callback(), base::Closure());
387 std::vector<PasswordForm> sync_entries; 386 std::vector<PasswordForm> sync_entries;
388 GetPasswordEntriesFromSyncDB(&sync_entries); 387 GetPasswordEntriesFromSyncDB(&sync_entries);
389 EXPECT_EQ(0U, sync_entries.size()); 388 EXPECT_EQ(0U, sync_entries.size());
390 } 389 }
391 390
392 TEST_F(ProfileSyncServicePasswordTest, MAYBE_HasNativeEntriesEmptySync) { 391 TEST_F(ProfileSyncServicePasswordTest, MAYBE_HasNativeEntriesEmptySync) {
393 std::vector<PasswordForm*> forms; 392 std::vector<PasswordForm*> forms;
394 std::vector<PasswordForm> expected_forms; 393 std::vector<PasswordForm> expected_forms;
395 PasswordForm* new_form = new PasswordForm; 394 PasswordForm* new_form = new PasswordForm;
396 new_form->scheme = PasswordForm::SCHEME_HTML; 395 new_form->scheme = PasswordForm::SCHEME_HTML;
397 new_form->signon_realm = "pie"; 396 new_form->signon_realm = "pie";
398 new_form->origin = GURL("http://pie.com"); 397 new_form->origin = GURL("http://pie.com");
399 new_form->action = GURL("http://pie.com/submit"); 398 new_form->action = GURL("http://pie.com/submit");
400 new_form->username_element = UTF8ToUTF16("name"); 399 new_form->username_element = UTF8ToUTF16("name");
401 new_form->username_value = UTF8ToUTF16("tom"); 400 new_form->username_value = UTF8ToUTF16("tom");
402 new_form->password_element = UTF8ToUTF16("cork"); 401 new_form->password_element = UTF8ToUTF16("cork");
403 new_form->password_value = UTF8ToUTF16("password1"); 402 new_form->password_value = UTF8ToUTF16("password1");
404 new_form->ssl_valid = true; 403 new_form->ssl_valid = true;
405 new_form->preferred = false; 404 new_form->preferred = false;
406 new_form->date_created = base::Time::FromInternalValue(1234); 405 new_form->date_created = base::Time::FromInternalValue(1234);
407 new_form->blacklisted_by_user = false; 406 new_form->blacklisted_by_user = false;
408 forms.push_back(new_form); 407 forms.push_back(new_form);
409 expected_forms.push_back(*new_form); 408 expected_forms.push_back(*new_form);
410 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 409 EXPECT_CALL(*password_store_.get(), FillAutofillableLogins(_))
411 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); 410 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true)));
412 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) 411 EXPECT_CALL(*password_store_.get(), FillBlacklistLogins(_))
413 .WillOnce(Return(true)); 412 .WillOnce(Return(true));
414 SetIdleChangeProcessorExpectations(); 413 SetIdleChangeProcessorExpectations();
415 CreateRootHelper create_root(this, syncer::PASSWORDS); 414 CreateRootHelper create_root(this, syncer::PASSWORDS);
416 StartSyncService(create_root.callback(), base::Closure()); 415 StartSyncService(create_root.callback(), base::Closure());
417 std::vector<PasswordForm> sync_forms; 416 std::vector<PasswordForm> sync_forms;
418 GetPasswordEntriesFromSyncDB(&sync_forms); 417 GetPasswordEntriesFromSyncDB(&sync_forms);
419 ASSERT_EQ(1U, sync_forms.size()); 418 ASSERT_EQ(1U, sync_forms.size());
420 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[0])); 419 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[0]));
421 } 420 }
422 421
(...skipping 30 matching lines...) Expand all
453 new_form->password_element = UTF8ToUTF16("cork"); 452 new_form->password_element = UTF8ToUTF16("cork");
454 new_form->password_value = UTF8ToUTF16("password2"); 453 new_form->password_value = UTF8ToUTF16("password2");
455 new_form->ssl_valid = true; 454 new_form->ssl_valid = true;
456 new_form->preferred = false; 455 new_form->preferred = false;
457 new_form->date_created = base::Time::FromInternalValue(1234); 456 new_form->date_created = base::Time::FromInternalValue(1234);
458 new_form->blacklisted_by_user = false; 457 new_form->blacklisted_by_user = false;
459 forms.push_back(new_form); 458 forms.push_back(new_form);
460 expected_forms.push_back(*new_form); 459 expected_forms.push_back(*new_form);
461 } 460 }
462 461
463 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 462 EXPECT_CALL(*password_store_.get(), FillAutofillableLogins(_))
464 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); 463 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true)));
465 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) 464 EXPECT_CALL(*password_store_.get(), FillBlacklistLogins(_))
466 .WillOnce(Return(true)); 465 .WillOnce(Return(true));
467 SetIdleChangeProcessorExpectations(); 466 SetIdleChangeProcessorExpectations();
468 CreateRootHelper create_root(this, syncer::PASSWORDS); 467 CreateRootHelper create_root(this, syncer::PASSWORDS);
469 StartSyncService(create_root.callback(), base::Closure()); 468 StartSyncService(create_root.callback(), base::Closure());
470 std::vector<PasswordForm> sync_forms; 469 std::vector<PasswordForm> sync_forms;
471 GetPasswordEntriesFromSyncDB(&sync_forms); 470 GetPasswordEntriesFromSyncDB(&sync_forms);
472 ASSERT_EQ(2U, sync_forms.size()); 471 ASSERT_EQ(2U, sync_forms.size());
473 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[1])); 472 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[1]));
474 EXPECT_TRUE(ComparePasswords(expected_forms[1], sync_forms[0])); 473 EXPECT_TRUE(ComparePasswords(expected_forms[1], sync_forms[0]));
475 } 474 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 new_form.password_element = UTF8ToUTF16("cork2"); 507 new_form.password_element = UTF8ToUTF16("cork2");
509 new_form.password_value = UTF8ToUTF16("password12"); 508 new_form.password_value = UTF8ToUTF16("password12");
510 new_form.ssl_valid = false; 509 new_form.ssl_valid = false;
511 new_form.preferred = true; 510 new_form.preferred = true;
512 new_form.date_created = base::Time::FromInternalValue(12345); 511 new_form.date_created = base::Time::FromInternalValue(12345);
513 new_form.blacklisted_by_user = false; 512 new_form.blacklisted_by_user = false;
514 sync_forms.push_back(new_form); 513 sync_forms.push_back(new_form);
515 expected_forms.push_back(new_form); 514 expected_forms.push_back(new_form);
516 } 515 }
517 516
518 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 517 EXPECT_CALL(*password_store_.get(), FillAutofillableLogins(_))
519 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); 518 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true)));
520 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); 519 EXPECT_CALL(*password_store_.get(), FillBlacklistLogins(_))
521 EXPECT_CALL(*password_store_, AddLoginImpl(_)).Times(1); 520 .WillOnce(Return(true));
521 EXPECT_CALL(*password_store_.get(), AddLoginImpl(_)).Times(1);
522 522
523 CreateRootHelper create_root(this, syncer::PASSWORDS); 523 CreateRootHelper create_root(this, syncer::PASSWORDS);
524 StartSyncService(create_root.callback(), 524 StartSyncService(create_root.callback(),
525 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); 525 base::Bind(&AddPasswordEntriesCallback, this, sync_forms));
526 526
527 std::vector<PasswordForm> new_sync_forms; 527 std::vector<PasswordForm> new_sync_forms;
528 GetPasswordEntriesFromSyncDB(&new_sync_forms); 528 GetPasswordEntriesFromSyncDB(&new_sync_forms);
529 529
530 EXPECT_EQ(2U, new_sync_forms.size()); 530 EXPECT_EQ(2U, new_sync_forms.size());
531 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); 531 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0]));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 new_form.password_element = UTF8ToUTF16("cork2"); 568 new_form.password_element = UTF8ToUTF16("cork2");
569 new_form.password_value = UTF8ToUTF16("password12"); 569 new_form.password_value = UTF8ToUTF16("password12");
570 new_form.ssl_valid = false; 570 new_form.ssl_valid = false;
571 new_form.preferred = true; 571 new_form.preferred = true;
572 new_form.date_created = base::Time::FromInternalValue(12345); 572 new_form.date_created = base::Time::FromInternalValue(12345);
573 new_form.blacklisted_by_user = false; 573 new_form.blacklisted_by_user = false;
574 sync_forms.push_back(new_form); 574 sync_forms.push_back(new_form);
575 expected_forms.push_back(new_form); 575 expected_forms.push_back(new_form);
576 } 576 }
577 577
578 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 578 EXPECT_CALL(*password_store_.get(), FillAutofillableLogins(_))
579 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), 579 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms),
580 AcquireSyncTransaction(this), 580 AcquireSyncTransaction(this),
581 Return(true))); 581 Return(true)));
582 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) 582 EXPECT_CALL(*password_store_.get(), FillBlacklistLogins(_))
583 .WillOnce(DoAll(AcquireSyncTransaction(this), 583 .WillOnce(DoAll(AcquireSyncTransaction(this), Return(true)));
584 Return(true))); 584 EXPECT_CALL(*password_store_.get(), AddLoginImpl(_))
585 EXPECT_CALL(*password_store_, AddLoginImpl(_))
586 .WillOnce(AcquireSyncTransaction(this)); 585 .WillOnce(AcquireSyncTransaction(this));
587 586
588 CreateRootHelper create_root(this, syncer::PASSWORDS); 587 CreateRootHelper create_root(this, syncer::PASSWORDS);
589 StartSyncService(create_root.callback(), 588 StartSyncService(create_root.callback(),
590 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); 589 base::Bind(&AddPasswordEntriesCallback, this, sync_forms));
591 590
592 std::vector<PasswordForm> new_sync_forms; 591 std::vector<PasswordForm> new_sync_forms;
593 GetPasswordEntriesFromSyncDB(&new_sync_forms); 592 GetPasswordEntriesFromSyncDB(&new_sync_forms);
594 593
595 EXPECT_EQ(2U, new_sync_forms.size()); 594 EXPECT_EQ(2U, new_sync_forms.size());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 new_form.username_value = UTF8ToUTF16("tom"); 645 new_form.username_value = UTF8ToUTF16("tom");
647 new_form.password_element = UTF8ToUTF16("cork"); 646 new_form.password_element = UTF8ToUTF16("cork");
648 new_form.password_value = UTF8ToUTF16("password12"); 647 new_form.password_value = UTF8ToUTF16("password12");
649 new_form.ssl_valid = false; 648 new_form.ssl_valid = false;
650 new_form.preferred = true; 649 new_form.preferred = true;
651 new_form.date_created = base::Time::FromInternalValue(12345); 650 new_form.date_created = base::Time::FromInternalValue(12345);
652 new_form.blacklisted_by_user = false; 651 new_form.blacklisted_by_user = false;
653 expected_forms.push_back(new_form); 652 expected_forms.push_back(new_form);
654 } 653 }
655 654
656 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 655 EXPECT_CALL(*password_store_.get(), FillAutofillableLogins(_))
657 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); 656 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true)));
658 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); 657 EXPECT_CALL(*password_store_.get(), FillBlacklistLogins(_))
659 EXPECT_CALL(*password_store_, UpdateLoginImpl(_)).Times(1); 658 .WillOnce(Return(true));
659 EXPECT_CALL(*password_store_.get(), UpdateLoginImpl(_)).Times(1);
660 660
661 CreateRootHelper create_root(this, syncer::PASSWORDS); 661 CreateRootHelper create_root(this, syncer::PASSWORDS);
662 StartSyncService(create_root.callback(), 662 StartSyncService(create_root.callback(),
663 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); 663 base::Bind(&AddPasswordEntriesCallback, this, sync_forms));
664 664
665 std::vector<PasswordForm> new_sync_forms; 665 std::vector<PasswordForm> new_sync_forms;
666 GetPasswordEntriesFromSyncDB(&new_sync_forms); 666 GetPasswordEntriesFromSyncDB(&new_sync_forms);
667 667
668 EXPECT_EQ(1U, new_sync_forms.size()); 668 EXPECT_EQ(1U, new_sync_forms.size());
669 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); 669 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0]));
670 } 670 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_components_factory_impl.cc ('k') | chrome/browser/sync/test/integration/autofill_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698