| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 content::BrowserContext* profile) { | 85 content::BrowserContext* profile) { |
| 86 return scoped_refptr<RefcountedBrowserContextKeyedService>(); | 86 return scoped_refptr<RefcountedBrowserContextKeyedService>(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 protected: | 89 protected: |
| 90 virtual ~NullPasswordStore() {} | 90 virtual ~NullPasswordStore() {} |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 class PasswordTestProfileSyncService : public TestProfileSyncService { | 93 class PasswordTestProfileSyncService : public TestProfileSyncService { |
| 94 public: | 94 public: |
| 95 PasswordTestProfileSyncService(ProfileSyncComponentsFactory* factory, | 95 PasswordTestProfileSyncService( |
| 96 Profile* profile, | 96 ProfileSyncComponentsFactory* factory, |
| 97 SigninManagerBase* signin, | 97 Profile* profile, |
| 98 OAuth2TokenService* oauth2_token_service) | 98 SigninManagerBase* signin, |
| 99 ProfileOAuth2TokenService* oauth2_token_service) |
| 99 : TestProfileSyncService(factory, | 100 : TestProfileSyncService(factory, |
| 100 profile, | 101 profile, |
| 101 signin, | 102 signin, |
| 102 oauth2_token_service, | 103 oauth2_token_service, |
| 103 ProfileSyncService::AUTO_START, | 104 ProfileSyncService::AUTO_START, |
| 104 false) {} | 105 false) {} |
| 105 | 106 |
| 106 virtual ~PasswordTestProfileSyncService() {} | 107 virtual ~PasswordTestProfileSyncService() {} |
| 107 | 108 |
| 108 virtual void OnPassphraseAccepted() OVERRIDE { | 109 virtual void OnPassphraseAccepted() OVERRIDE { |
| 109 if (!callback_.is_null()) | 110 if (!callback_.is_null()) |
| 110 callback_.Run(); | 111 callback_.Run(); |
| 111 | 112 |
| 112 TestProfileSyncService::OnPassphraseAccepted(); | 113 TestProfileSyncService::OnPassphraseAccepted(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 static BrowserContextKeyedService* Build(content::BrowserContext* context) { | 116 static BrowserContextKeyedService* Build(content::BrowserContext* context) { |
| 116 Profile* profile = static_cast<Profile*>(context); | 117 Profile* profile = static_cast<Profile*>(context); |
| 117 SigninManagerBase* signin = | 118 SigninManagerBase* signin = |
| 118 SigninManagerFactory::GetForProfile(profile); | 119 SigninManagerFactory::GetForProfile(profile); |
| 119 OAuth2TokenService* oauth2_token_service = | 120 ProfileOAuth2TokenService* oauth2_token_service = |
| 120 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 121 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 121 ProfileSyncComponentsFactoryMock* factory = | 122 ProfileSyncComponentsFactoryMock* factory = |
| 122 new ProfileSyncComponentsFactoryMock(); | 123 new ProfileSyncComponentsFactoryMock(); |
| 123 return new PasswordTestProfileSyncService( | 124 return new PasswordTestProfileSyncService( |
| 124 factory, profile, signin, oauth2_token_service); | 125 factory, profile, signin, oauth2_token_service); |
| 125 } | 126 } |
| 126 | 127 |
| 127 void set_passphrase_accept_callback(const base::Closure& callback) { | 128 void set_passphrase_accept_callback(const base::Closure& callback) { |
| 128 callback_ = callback; | 129 callback_ = callback; |
| 129 } | 130 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } else { | 227 } else { |
| 227 // When the password store is unavailable, password sync components must | 228 // When the password store is unavailable, password sync components must |
| 228 // not be created. | 229 // not be created. |
| 229 EXPECT_CALL(*components, CreatePasswordSyncComponents(_, _, _)) | 230 EXPECT_CALL(*components, CreatePasswordSyncComponents(_, _, _)) |
| 230 .Times(0); | 231 .Times(0); |
| 231 } | 232 } |
| 232 EXPECT_CALL(*components, CreateDataTypeManager(_, _, _, _, _, _)). | 233 EXPECT_CALL(*components, CreateDataTypeManager(_, _, _, _, _, _)). |
| 233 WillOnce(ReturnNewDataTypeManager()); | 234 WillOnce(ReturnNewDataTypeManager()); |
| 234 | 235 |
| 235 // We need tokens to get the tests going | 236 // We need tokens to get the tests going |
| 236 token_service_->IssueAuthTokenForTest( | 237 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()) |
| 237 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); | 238 ->UpdateCredentials("test_user@gmail.com", "oauth2_login_token"); |
| 238 token_service_->IssueAuthTokenForTest( | 239 token_service_->IssueAuthTokenForTest(GaiaConstants::kSyncService, |
| 239 GaiaConstants::kSyncService, "token"); | 240 "token"); |
| 240 | 241 |
| 241 sync_service_->RegisterDataTypeController(data_type_controller); | 242 sync_service_->RegisterDataTypeController(data_type_controller); |
| 242 sync_service_->Initialize(); | 243 sync_service_->Initialize(); |
| 243 base::MessageLoop::current()->Run(); | 244 base::MessageLoop::current()->Run(); |
| 244 FlushLastDBTask(); | 245 FlushLastDBTask(); |
| 245 | 246 |
| 246 sync_service_->SetEncryptionPassphrase("foo", | 247 sync_service_->SetEncryptionPassphrase("foo", |
| 247 ProfileSyncService::IMPLICIT); | 248 ProfileSyncService::IMPLICIT); |
| 248 base::MessageLoop::current()->Run(); | 249 base::MessageLoop::current()->Run(); |
| 249 } | 250 } |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 CreateRootHelper create_root(this, syncer::PASSWORDS); | 653 CreateRootHelper create_root(this, syncer::PASSWORDS); |
| 653 StartSyncService(create_root.callback(), | 654 StartSyncService(create_root.callback(), |
| 654 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); | 655 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); |
| 655 | 656 |
| 656 std::vector<PasswordForm> new_sync_forms; | 657 std::vector<PasswordForm> new_sync_forms; |
| 657 GetPasswordEntriesFromSyncDB(&new_sync_forms); | 658 GetPasswordEntriesFromSyncDB(&new_sync_forms); |
| 658 | 659 |
| 659 EXPECT_EQ(1U, new_sync_forms.size()); | 660 EXPECT_EQ(1U, new_sync_forms.size()); |
| 660 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); | 661 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); |
| 661 } | 662 } |
| OLD | NEW |