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

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

Issue 162443004: sync: final pieces to sync deferred initialization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 6 years, 9 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/invalidation/invalidation_service_factory.h" 10 #include "chrome/browser/invalidation/invalidation_service_factory.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 service_.reset(); 111 service_.reset();
112 profile_.reset(); 112 profile_.reset();
113 } 113 }
114 114
115 void IssueTestTokens() { 115 void IssueTestTokens() {
116 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()) 116 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get())
117 ->UpdateCredentials("test", "oauth2_login_token"); 117 ->UpdateCredentials("test", "oauth2_login_token");
118 } 118 }
119 119
120 void CreateService(ProfileSyncService::StartBehavior behavior) { 120 void CreateService(ProfileSyncServiceStartBehavior behavior) {
121 SigninManagerBase* signin = 121 SigninManagerBase* signin =
122 SigninManagerFactory::GetForProfile(profile_.get()); 122 SigninManagerFactory::GetForProfile(profile_.get());
123 signin->SetAuthenticatedUsername("test"); 123 signin->SetAuthenticatedUsername("test");
124 ProfileOAuth2TokenService* oauth2_token_service = 124 ProfileOAuth2TokenService* oauth2_token_service =
125 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); 125 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get());
126 components_factory_ = new StrictMock<ProfileSyncComponentsFactoryMock>(); 126 components_factory_ = new StrictMock<ProfileSyncComponentsFactoryMock>();
127 service_.reset(new ProfileSyncService( 127 service_.reset(new ProfileSyncService(
128 components_factory_, 128 components_factory_,
129 profile_.get(), 129 profile_.get(),
130 new ManagedUserSigninManagerWrapper(signin), 130 new ManagedUserSigninManagerWrapper(signin),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 scoped_ptr<ProfileSyncService> service_; 174 scoped_ptr<ProfileSyncService> service_;
175 175
176 // Pointer to the components factory. Not owned. May be null. 176 // Pointer to the components factory. Not owned. May be null.
177 ProfileSyncComponentsFactoryMock* components_factory_; 177 ProfileSyncComponentsFactoryMock* components_factory_;
178 178
179 content::TestBrowserThreadBundle thread_bundle_; 179 content::TestBrowserThreadBundle thread_bundle_;
180 }; 180 };
181 181
182 // Verify that the server URLs are sane. 182 // Verify that the server URLs are sane.
183 TEST_F(ProfileSyncServiceTest, InitialState) { 183 TEST_F(ProfileSyncServiceTest, InitialState) {
184 CreateService(ProfileSyncService::AUTO_START); 184 CreateService(browser_sync::AUTO_START);
185 Initialize(); 185 Initialize();
186 const std::string& url = service()->sync_service_url().spec(); 186 const std::string& url = service()->sync_service_url().spec();
187 EXPECT_TRUE(url == ProfileSyncService::kSyncServerUrl || 187 EXPECT_TRUE(url == ProfileSyncService::kSyncServerUrl ||
188 url == ProfileSyncService::kDevServerUrl); 188 url == ProfileSyncService::kDevServerUrl);
189 } 189 }
190 190
191 // Verify a successful initialization. 191 // Verify a successful initialization.
192 TEST_F(ProfileSyncServiceTest, SuccessfulInitialization) { 192 TEST_F(ProfileSyncServiceTest, SuccessfulInitialization) {
193 profile()->GetTestingPrefService()->SetManagedPref( 193 profile()->GetTestingPrefService()->SetManagedPref(
194 prefs::kSyncManaged, 194 prefs::kSyncManaged,
195 base::Value::CreateBooleanValue(false)); 195 base::Value::CreateBooleanValue(false));
196 IssueTestTokens(); 196 IssueTestTokens();
197 CreateService(ProfileSyncService::AUTO_START); 197 CreateService(browser_sync::AUTO_START);
198 ExpectDataTypeManagerCreation(); 198 ExpectDataTypeManagerCreation();
199 ExpectSyncBackendHostCreation(); 199 ExpectSyncBackendHostCreation();
200 Initialize(); 200 Initialize();
201 EXPECT_FALSE(service()->IsManaged()); 201 EXPECT_FALSE(service()->IsManaged());
202 EXPECT_TRUE(service()->sync_initialized()); 202 EXPECT_TRUE(service()->sync_initialized());
203 } 203 }
204 204
205 205
206 // Verify that the SetSetupInProgress function call updates state 206 // Verify that the SetSetupInProgress function call updates state
207 // and notifies observers. 207 // and notifies observers.
208 TEST_F(ProfileSyncServiceTest, SetupInProgress) { 208 TEST_F(ProfileSyncServiceTest, SetupInProgress) {
209 CreateService(ProfileSyncService::MANUAL_START); 209 CreateService(browser_sync::AUTO_START);
210 Initialize(); 210 Initialize();
211 211
212 TestProfileSyncServiceObserver observer(service()); 212 TestProfileSyncServiceObserver observer(service());
213 service()->AddObserver(&observer); 213 service()->AddObserver(&observer);
214 214
215 service()->SetSetupInProgress(true); 215 service()->SetSetupInProgress(true);
216 EXPECT_TRUE(observer.first_setup_in_progress()); 216 EXPECT_TRUE(observer.first_setup_in_progress());
217 service()->SetSetupInProgress(false); 217 service()->SetSetupInProgress(false);
218 EXPECT_FALSE(observer.first_setup_in_progress()); 218 EXPECT_FALSE(observer.first_setup_in_progress());
219 219
220 service()->RemoveObserver(&observer); 220 service()->RemoveObserver(&observer);
221 } 221 }
222 222
223 // Verify that disable by enterprise policy works. 223 // Verify that disable by enterprise policy works.
224 TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) { 224 TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) {
225 profile()->GetTestingPrefService()->SetManagedPref( 225 profile()->GetTestingPrefService()->SetManagedPref(
226 prefs::kSyncManaged, 226 prefs::kSyncManaged,
227 base::Value::CreateBooleanValue(true)); 227 base::Value::CreateBooleanValue(true));
228 IssueTestTokens(); 228 IssueTestTokens();
229 CreateService(ProfileSyncService::AUTO_START); 229 CreateService(browser_sync::AUTO_START);
230 Initialize(); 230 Initialize();
231 EXPECT_TRUE(service()->IsManaged()); 231 EXPECT_TRUE(service()->IsManaged());
232 EXPECT_FALSE(service()->sync_initialized()); 232 EXPECT_FALSE(service()->sync_initialized());
233 } 233 }
234 234
235 // Verify that disable by enterprise policy works even after the backend has 235 // Verify that disable by enterprise policy works even after the backend has
236 // been initialized. 236 // been initialized.
237 TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) { 237 TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) {
238 IssueTestTokens(); 238 IssueTestTokens();
239 CreateService(ProfileSyncService::AUTO_START); 239 CreateService(browser_sync::AUTO_START);
240 ExpectDataTypeManagerCreation(); 240 ExpectDataTypeManagerCreation();
241 ExpectSyncBackendHostCreation(); 241 ExpectSyncBackendHostCreation();
242 Initialize(); 242 Initialize();
243 243
244 EXPECT_FALSE(service()->IsManaged()); 244 EXPECT_FALSE(service()->IsManaged());
245 EXPECT_TRUE(service()->sync_initialized()); 245 EXPECT_TRUE(service()->sync_initialized());
246 246
247 profile()->GetTestingPrefService()->SetManagedPref( 247 profile()->GetTestingPrefService()->SetManagedPref(
248 prefs::kSyncManaged, 248 prefs::kSyncManaged,
249 base::Value::CreateBooleanValue(true)); 249 base::Value::CreateBooleanValue(true));
250 250
251 EXPECT_TRUE(service()->IsManaged()); 251 EXPECT_TRUE(service()->IsManaged());
252 EXPECT_FALSE(service()->sync_initialized()); 252 EXPECT_FALSE(service()->sync_initialized());
253 } 253 }
254 254
255 // Exercies the ProfileSyncService's code paths related to getting shut down 255 // Exercies the ProfileSyncService's code paths related to getting shut down
256 // before the backend initialize call returns. 256 // before the backend initialize call returns.
257 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { 257 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) {
258 CreateService(ProfileSyncService::AUTO_START); 258 CreateService(browser_sync::AUTO_START);
259 PrepareDelayedInitSyncBackendHost(); 259 PrepareDelayedInitSyncBackendHost();
260 260
261 IssueTestTokens(); 261 IssueTestTokens();
262 Initialize(); 262 Initialize();
263 EXPECT_FALSE(service()->sync_initialized()); 263 EXPECT_FALSE(service()->sync_initialized());
264 264
265 ShutdownAndDeleteService(); 265 ShutdownAndDeleteService();
266 } 266 }
267 267
268 // Test StopAndSuppress() before we've initialized the backend. 268 // Test StopAndSuppress() before we've initialized the backend.
269 TEST_F(ProfileSyncServiceTest, EarlyStopAndSuppress) { 269 TEST_F(ProfileSyncServiceTest, EarlyStopAndSuppress) {
270 CreateService(ProfileSyncService::AUTO_START); 270 CreateService(browser_sync::AUTO_START);
271 IssueTestTokens(); 271 IssueTestTokens();
272 272
273 service()->StopAndSuppress(); 273 service()->StopAndSuppress();
274 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); 274 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart));
275 275
276 // Because of supression, this should fail. 276 // Because of supression, this should fail.
277 Initialize(); 277 Initialize();
278 EXPECT_FALSE(service()->sync_initialized()); 278 EXPECT_FALSE(service()->sync_initialized());
279 279
280 // Remove suppression. This should be enough to allow init to happen. 280 // Remove suppression. This should be enough to allow init to happen.
281 ExpectDataTypeManagerCreation(); 281 ExpectDataTypeManagerCreation();
282 ExpectSyncBackendHostCreation(); 282 ExpectSyncBackendHostCreation();
283 service()->UnsuppressAndStart(); 283 service()->UnsuppressAndStart();
284 EXPECT_TRUE(service()->sync_initialized()); 284 EXPECT_TRUE(service()->sync_initialized());
285 EXPECT_FALSE( 285 EXPECT_FALSE(
286 profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); 286 profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart));
287 } 287 }
288 288
289 // Test StopAndSuppress() after we've initialized the backend. 289 // Test StopAndSuppress() after we've initialized the backend.
290 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { 290 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) {
291 CreateService(ProfileSyncService::AUTO_START); 291 CreateService(browser_sync::AUTO_START);
292 IssueTestTokens(); 292 IssueTestTokens();
293 ExpectDataTypeManagerCreation(); 293 ExpectDataTypeManagerCreation();
294 ExpectSyncBackendHostCreation(); 294 ExpectSyncBackendHostCreation();
295 Initialize(); 295 Initialize();
296 296
297 EXPECT_TRUE(service()->sync_initialized()); 297 EXPECT_TRUE(service()->sync_initialized());
298 EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); 298 EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart));
299 299
300 testing::Mock::VerifyAndClearExpectations(components_factory()); 300 testing::Mock::VerifyAndClearExpectations(components_factory());
301 301
302 service()->StopAndSuppress(); 302 service()->StopAndSuppress();
303 EXPECT_FALSE(service()->sync_initialized()); 303 EXPECT_FALSE(service()->sync_initialized());
304 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); 304 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart));
305 305
306 ExpectDataTypeManagerCreation(); 306 ExpectDataTypeManagerCreation();
307 ExpectSyncBackendHostCreation(); 307 ExpectSyncBackendHostCreation();
308 308
309 service()->UnsuppressAndStart(); 309 service()->UnsuppressAndStart();
310 EXPECT_TRUE(service()->sync_initialized()); 310 EXPECT_TRUE(service()->sync_initialized());
311 EXPECT_FALSE( 311 EXPECT_FALSE(
312 profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); 312 profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart));
313 } 313 }
314 314
315 // Certain ProfileSyncService tests don't apply to Chrome OS, for example 315 // Certain ProfileSyncService tests don't apply to Chrome OS, for example
316 // things that deal with concepts like "signing out" and policy. 316 // things that deal with concepts like "signing out" and policy.
317 #if !defined (OS_CHROMEOS) 317 #if !defined (OS_CHROMEOS)
318 318
319 TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) { 319 TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) {
320 CreateService(ProfileSyncService::AUTO_START); 320 CreateService(browser_sync::AUTO_START);
321 ExpectDataTypeManagerCreation(); 321 ExpectDataTypeManagerCreation();
322 ExpectSyncBackendHostCreation(); 322 ExpectSyncBackendHostCreation();
323 IssueTestTokens(); 323 IssueTestTokens();
324 Initialize(); 324 Initialize();
325 325
326 EXPECT_TRUE(service()->sync_initialized()); 326 EXPECT_TRUE(service()->sync_initialized());
327 EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); 327 EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart));
328 328
329 SigninManagerFactory::GetForProfile(profile())->SignOut(); 329 SigninManagerFactory::GetForProfile(profile())->SignOut();
330 EXPECT_FALSE(service()->sync_initialized()); 330 EXPECT_FALSE(service()->sync_initialized());
331 } 331 }
332 332
333 #endif // !defined(OS_CHROMEOS) 333 #endif // !defined(OS_CHROMEOS)
334 334
335 TEST_F(ProfileSyncServiceTest, GetSyncTokenStatus) { 335 TEST_F(ProfileSyncServiceTest, GetSyncTokenStatus) {
336 CreateService(ProfileSyncService::AUTO_START); 336 CreateService(browser_sync::AUTO_START);
337 IssueTestTokens(); 337 IssueTestTokens();
338 ExpectDataTypeManagerCreation(); 338 ExpectDataTypeManagerCreation();
339 ExpectSyncBackendHostCreation(); 339 ExpectSyncBackendHostCreation();
340 Initialize(); 340 Initialize();
341 341
342 // Initial status. 342 // Initial status.
343 ProfileSyncService::SyncTokenStatus token_status = 343 ProfileSyncService::SyncTokenStatus token_status =
344 service()->GetSyncTokenStatus(); 344 service()->GetSyncTokenStatus();
345 EXPECT_EQ(syncer::CONNECTION_NOT_ATTEMPTED, token_status.connection_status); 345 EXPECT_EQ(syncer::CONNECTION_NOT_ATTEMPTED, token_status.connection_status);
346 EXPECT_TRUE(token_status.connection_status_update_time.is_null()); 346 EXPECT_TRUE(token_status.connection_status_update_time.is_null());
(...skipping 17 matching lines...) Expand all
364 EXPECT_TRUE(token_status.next_token_request_time.is_null()); 364 EXPECT_TRUE(token_status.next_token_request_time.is_null());
365 365
366 // Simulate successful connection. 366 // Simulate successful connection.
367 service()->OnConnectionStatusChange(syncer::CONNECTION_OK); 367 service()->OnConnectionStatusChange(syncer::CONNECTION_OK);
368 token_status = service()->GetSyncTokenStatus(); 368 token_status = service()->GetSyncTokenStatus();
369 EXPECT_EQ(syncer::CONNECTION_OK, token_status.connection_status); 369 EXPECT_EQ(syncer::CONNECTION_OK, token_status.connection_status);
370 } 370 }
371 371
372 } // namespace 372 } // namespace
373 } // namespace browser_sync 373 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_startup_unittest.cc ('k') | chrome/browser/sync/startup_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698