| OLD | NEW |
| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 MessageLoop::current()->Quit(); | 80 MessageLoop::current()->Quit(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 class PasswordTestProfileSyncService : public TestProfileSyncService { | 83 class PasswordTestProfileSyncService : public TestProfileSyncService { |
| 84 public: | 84 public: |
| 85 PasswordTestProfileSyncService( | 85 PasswordTestProfileSyncService( |
| 86 ProfileSyncComponentsFactory* factory, | 86 ProfileSyncComponentsFactory* factory, |
| 87 Profile* profile, | 87 Profile* profile, |
| 88 SigninManager* signin, | 88 SigninManager* signin, |
| 89 bool synchronous_backend_initialization, | 89 bool synchronous_backend_initialization, |
| 90 const base::Closure& initial_condition_setup_cb, | 90 const base::Callback<void(syncer::UserShare*)>& initial_setup_cb, |
| 91 const base::Closure& passphrase_accept_cb) | 91 const base::Closure& passphrase_accept_cb) |
| 92 : TestProfileSyncService(factory, | 92 : TestProfileSyncService(factory, |
| 93 profile, | 93 profile, |
| 94 signin, | 94 signin, |
| 95 ProfileSyncService::AUTO_START, | 95 ProfileSyncService::AUTO_START, |
| 96 synchronous_backend_initialization, | 96 synchronous_backend_initialization, |
| 97 initial_condition_setup_cb), | 97 initial_setup_cb), |
| 98 callback_(passphrase_accept_cb) {} | 98 callback_(passphrase_accept_cb) {} |
| 99 | 99 |
| 100 virtual ~PasswordTestProfileSyncService() {} | 100 virtual ~PasswordTestProfileSyncService() {} |
| 101 | 101 |
| 102 virtual void OnPassphraseAccepted() { | 102 virtual void OnPassphraseAccepted() { |
| 103 if (!callback_.is_null()) | 103 if (!callback_.is_null()) |
| 104 callback_.Run(); | 104 callback_.Run(); |
| 105 | 105 |
| 106 TestProfileSyncService::OnPassphraseAccepted(); | 106 TestProfileSyncService::OnPassphraseAccepted(); |
| 107 } | 107 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 160 } |
| 161 | 161 |
| 162 void FlushLastDBTask() { | 162 void FlushLastDBTask() { |
| 163 base::WaitableEvent done(false, false); | 163 base::WaitableEvent done(false, false); |
| 164 BrowserThread::PostTask( | 164 BrowserThread::PostTask( |
| 165 BrowserThread::DB, FROM_HERE, | 165 BrowserThread::DB, FROM_HERE, |
| 166 base::Bind(&ProfileSyncServicePasswordTest::SignalEvent, &done)); | 166 base::Bind(&ProfileSyncServicePasswordTest::SignalEvent, &done)); |
| 167 done.TimedWait(TestTimeouts::action_timeout()); | 167 done.TimedWait(TestTimeouts::action_timeout()); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void StartSyncService(const base::Closure& root_callback, | 170 void StartSyncService( |
| 171 const base::Closure& node_callback) { | 171 const base::Callback<void(syncer::UserShare*)>& root_callback, |
| 172 const base::Closure& node_callback) { |
| 172 if (!service_.get()) { | 173 if (!service_.get()) { |
| 173 SigninManager* signin = SigninManagerFactory::GetForProfile(&profile_); | 174 SigninManager* signin = SigninManagerFactory::GetForProfile(&profile_); |
| 174 signin->SetAuthenticatedUsername("test_user"); | 175 signin->SetAuthenticatedUsername("test_user"); |
| 175 token_service_ = static_cast<TokenService*>( | 176 token_service_ = static_cast<TokenService*>( |
| 176 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 177 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 177 &profile_, BuildTokenService)); | 178 &profile_, BuildTokenService)); |
| 178 ProfileSyncComponentsFactoryMock* factory = | 179 ProfileSyncComponentsFactoryMock* factory = |
| 179 new ProfileSyncComponentsFactoryMock(); | 180 new ProfileSyncComponentsFactoryMock(); |
| 180 service_.reset(new PasswordTestProfileSyncService( | 181 service_.reset(new PasswordTestProfileSyncService( |
| 181 factory, &profile_, signin, false, | 182 factory, &profile_, signin, false, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 content::NotificationRegistrar registrar_; | 271 content::NotificationRegistrar registrar_; |
| 271 }; | 272 }; |
| 272 | 273 |
| 273 void AddPasswordEntriesCallback(ProfileSyncServicePasswordTest* test, | 274 void AddPasswordEntriesCallback(ProfileSyncServicePasswordTest* test, |
| 274 const std::vector<PasswordForm>& entries) { | 275 const std::vector<PasswordForm>& entries) { |
| 275 for (size_t i = 0; i < entries.size(); ++i) | 276 for (size_t i = 0; i < entries.size(); ++i) |
| 276 test->AddPasswordSyncNode(entries[i]); | 277 test->AddPasswordSyncNode(entries[i]); |
| 277 } | 278 } |
| 278 | 279 |
| 279 TEST_F(ProfileSyncServicePasswordTest, FailModelAssociation) { | 280 TEST_F(ProfileSyncServicePasswordTest, FailModelAssociation) { |
| 280 StartSyncService(base::Closure(), base::Closure()); | 281 StartSyncService(TestProfileSyncService::NullCallback(), |
| 282 base::Closure()); |
| 281 EXPECT_TRUE(service_->HasUnrecoverableError()); | 283 EXPECT_TRUE(service_->HasUnrecoverableError()); |
| 282 } | 284 } |
| 283 | 285 |
| 284 TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) { | 286 TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) { |
| 285 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) | 287 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
| 286 .WillOnce(Return(true)); | 288 .WillOnce(Return(true)); |
| 287 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) | 289 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) |
| 288 .WillOnce(Return(true)); | 290 .WillOnce(Return(true)); |
| 289 SetIdleChangeProcessorExpectations(); | 291 SetIdleChangeProcessorExpectations(); |
| 290 CreateRootHelper create_root(this, syncer::PASSWORDS); | 292 CreateRootHelper create_root(this, syncer::PASSWORDS); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 CreateRootHelper create_root(this, syncer::PASSWORDS); | 567 CreateRootHelper create_root(this, syncer::PASSWORDS); |
| 566 StartSyncService(create_root.callback(), | 568 StartSyncService(create_root.callback(), |
| 567 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); | 569 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); |
| 568 | 570 |
| 569 std::vector<PasswordForm> new_sync_forms; | 571 std::vector<PasswordForm> new_sync_forms; |
| 570 GetPasswordEntriesFromSyncDB(&new_sync_forms); | 572 GetPasswordEntriesFromSyncDB(&new_sync_forms); |
| 571 | 573 |
| 572 EXPECT_EQ(1U, new_sync_forms.size()); | 574 EXPECT_EQ(1U, new_sync_forms.size()); |
| 573 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); | 575 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); |
| 574 } | 576 } |
| OLD | NEW |