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

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

Issue 14141006: [components] Switch {RefCounted}ProfileKeyedService to use BrowserContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for review Created 7 years, 8 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/signin/fake_signin_manager.h" 10 #include "chrome/browser/signin/fake_signin_manager.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 sync_->signin()->SetAuthenticatedUsername("test_user"); 105 sync_->signin()->SetAuthenticatedUsername("test_user");
106 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 106 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
107 "test_user"); 107 "test_user");
108 GoogleServiceSigninSuccessDetails details("test_user", ""); 108 GoogleServiceSigninSuccessDetails details("test_user", "");
109 content::NotificationService::current()->Notify( 109 content::NotificationService::current()->Notify(
110 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 110 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
111 content::Source<Profile>(profile_.get()), 111 content::Source<Profile>(profile_.get()),
112 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); 112 content::Details<const GoogleServiceSigninSuccessDetails>(&details));
113 } 113 }
114 114
115 static ProfileKeyedService* BuildService(Profile* profile) { 115 static ProfileKeyedService* BuildService(content::BrowserContext* profile) {
116 SigninManagerBase* signin = static_cast<SigninManagerBase*>( 116 SigninManagerBase* signin = static_cast<SigninManagerBase*>(
117 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( 117 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
118 profile, FakeSigninManagerBase::Build)); 118 profile, FakeSigninManagerBase::Build));
119 signin->SetAuthenticatedUsername("test_user"); 119 signin->SetAuthenticatedUsername("test_user");
120 return new TestProfileSyncService( 120 return new TestProfileSyncService(
121 new ProfileSyncComponentsFactoryMock(), 121 new ProfileSyncComponentsFactoryMock(),
122 profile, 122 static_cast<Profile*>(profile),
123 signin, 123 signin,
124 ProfileSyncService::MANUAL_START, 124 ProfileSyncService::MANUAL_START,
125 true); 125 true);
126 } 126 }
127 127
128 protected: 128 protected:
129 // Overridden below by ProfileSyncServiceStartupCrosTest. 129 // Overridden below by ProfileSyncServiceStartupCrosTest.
130 virtual void CreateSyncService() { 130 virtual void CreateSyncService() {
131 sync_ = static_cast<TestProfileSyncService*>( 131 sync_ = static_cast<TestProfileSyncService*>(
132 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 132 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
(...skipping 13 matching lines...) Expand all
146 content::TestBrowserThread db_thread_; 146 content::TestBrowserThread db_thread_;
147 content::TestBrowserThread file_thread_; 147 content::TestBrowserThread file_thread_;
148 content::TestBrowserThread io_thread_; 148 content::TestBrowserThread io_thread_;
149 scoped_ptr<TestingProfile> profile_; 149 scoped_ptr<TestingProfile> profile_;
150 TestProfileSyncService* sync_; 150 TestProfileSyncService* sync_;
151 ProfileSyncServiceObserverMock observer_; 151 ProfileSyncServiceObserverMock observer_;
152 }; 152 };
153 153
154 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest { 154 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest {
155 public: 155 public:
156 static ProfileKeyedService* BuildCrosService(Profile* profile) { 156 static ProfileKeyedService* BuildCrosService(
157 SigninManagerBase* signin = 157 content::BrowserContext* context) {
158 SigninManagerFactory::GetForProfile(profile); 158 Profile* profile = static_cast<Profile*>(context);
159 signin->SetAuthenticatedUsername("test_user"); 159 SigninManagerBase* signin =
160 return new TestProfileSyncService( 160 SigninManagerFactory::GetForProfile(profile);
161 new ProfileSyncComponentsFactoryMock(), 161 signin->SetAuthenticatedUsername("test_user");
162 profile, 162 return new TestProfileSyncService(
163 signin, 163 new ProfileSyncComponentsFactoryMock(),
164 ProfileSyncService::AUTO_START, 164 profile,
165 true); 165 signin,
166 } 166 ProfileSyncService::AUTO_START,
167 true);
168 }
167 169
168 protected: 170 protected:
169 virtual void CreateSyncService() OVERRIDE { 171 virtual void CreateSyncService() OVERRIDE {
170 sync_ = static_cast<TestProfileSyncService*>( 172 sync_ = static_cast<TestProfileSyncService*>(
171 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 173 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
172 profile_.get(), BuildCrosService)); 174 profile_.get(), BuildCrosService));
173 } 175 }
174 }; 176 };
175 177
176 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { 178 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
(...skipping 29 matching lines...) Expand all
206 sync_->SetSetupInProgress(true); 208 sync_->SetSetupInProgress(true);
207 Signin(); 209 Signin();
208 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 210 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
209 GaiaConstants::kSyncService, "sync_token"); 211 GaiaConstants::kSyncService, "sync_token");
210 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 212 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
211 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); 213 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
212 sync_->SetSetupInProgress(false); 214 sync_->SetSetupInProgress(false);
213 EXPECT_TRUE(sync_->ShouldPushChanges()); 215 EXPECT_TRUE(sync_->ShouldPushChanges());
214 } 216 }
215 217
216 ProfileKeyedService* BuildFakeTokenService(Profile* profile) { 218 ProfileKeyedService* BuildFakeTokenService(content::BrowserContext* profile) {
217 return new FakeTokenService(); 219 return new FakeTokenService();
218 } 220 }
219 221
220 TEST_F(ProfileSyncServiceStartupTest, StartNoCredentials) { 222 TEST_F(ProfileSyncServiceStartupTest, StartNoCredentials) {
221 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 223 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
222 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0); 224 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0);
223 TokenService* token_service = static_cast<TokenService*>( 225 TokenService* token_service = static_cast<TokenService*>(
224 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( 226 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse(
225 profile_.get(), BuildFakeTokenService)); 227 profile_.get(), BuildFakeTokenService));
226 228
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 481
480 // Preload the tokens. 482 // Preload the tokens.
481 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 483 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
482 GaiaConstants::kSyncService, "sync_token"); 484 GaiaConstants::kSyncService, "sync_token");
483 sync_->fail_initial_download(); 485 sync_->fail_initial_download();
484 486
485 sync_->Initialize(); 487 sync_->Initialize();
486 EXPECT_FALSE(sync_->sync_initialized()); 488 EXPECT_FALSE(sync_->sync_initialized());
487 EXPECT_FALSE(sync_->GetBackendForTest()); 489 EXPECT_FALSE(sync_->GetBackendForTest());
488 } 490 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698