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 "components/browser_sync/profile_sync_service.h" | 5 #include "components/browser_sync/profile_sync_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 TEST_F(ProfileSyncServiceTest, InitialState) { | 366 TEST_F(ProfileSyncServiceTest, InitialState) { |
367 CreateService(ProfileSyncService::AUTO_START); | 367 CreateService(ProfileSyncService::AUTO_START); |
368 InitializeForNthSync(); | 368 InitializeForNthSync(); |
369 const std::string& url = service()->sync_service_url().spec(); | 369 const std::string& url = service()->sync_service_url().spec(); |
370 EXPECT_TRUE(url == syncer::internal::kSyncServerUrl || | 370 EXPECT_TRUE(url == syncer::internal::kSyncServerUrl || |
371 url == syncer::internal::kSyncDevServerUrl); | 371 url == syncer::internal::kSyncDevServerUrl); |
372 } | 372 } |
373 | 373 |
374 // Verify a successful initialization. | 374 // Verify a successful initialization. |
375 TEST_F(ProfileSyncServiceTest, SuccessfulInitialization) { | 375 TEST_F(ProfileSyncServiceTest, SuccessfulInitialization) { |
376 prefs()->SetManagedPref(syncer::prefs::kSyncManaged, | 376 prefs()->SetManagedPref(syncer::prefs::kSyncManaged, new base::Value(false)); |
377 new base::FundamentalValue(false)); | |
378 IssueTestTokens(); | 377 IssueTestTokens(); |
379 CreateService(ProfileSyncService::AUTO_START); | 378 CreateService(ProfileSyncService::AUTO_START); |
380 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | 379 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); |
381 ExpectSyncEngineCreation(1); | 380 ExpectSyncEngineCreation(1); |
382 InitializeForNthSync(); | 381 InitializeForNthSync(); |
383 EXPECT_FALSE(service()->IsManaged()); | 382 EXPECT_FALSE(service()->IsManaged()); |
384 EXPECT_TRUE(service()->IsSyncActive()); | 383 EXPECT_TRUE(service()->IsSyncActive()); |
385 } | 384 } |
386 | 385 |
387 // Verify a successful initialization. | 386 // Verify a successful initialization. |
388 TEST_F(ProfileSyncServiceTest, SuccessfulLocalBackendInitialization) { | 387 TEST_F(ProfileSyncServiceTest, SuccessfulLocalBackendInitialization) { |
389 prefs()->SetManagedPref(syncer::prefs::kSyncManaged, | 388 prefs()->SetManagedPref(syncer::prefs::kSyncManaged, new base::Value(false)); |
390 new base::FundamentalValue(false)); | |
391 IssueTestTokens(); | 389 IssueTestTokens(); |
392 CreateServiceWithLocalSyncBackend(); | 390 CreateServiceWithLocalSyncBackend(); |
393 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | 391 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); |
394 ExpectSyncEngineCreation(1); | 392 ExpectSyncEngineCreation(1); |
395 InitializeForNthSync(); | 393 InitializeForNthSync(); |
396 EXPECT_FALSE(service()->IsManaged()); | 394 EXPECT_FALSE(service()->IsManaged()); |
397 EXPECT_TRUE(service()->IsSyncActive()); | 395 EXPECT_TRUE(service()->IsSyncActive()); |
398 } | 396 } |
399 | 397 |
400 // Verify that an initialization where first setup is not complete does not | 398 // Verify that an initialization where first setup is not complete does not |
401 // start up the backend. | 399 // start up the backend. |
402 TEST_F(ProfileSyncServiceTest, NeedsConfirmation) { | 400 TEST_F(ProfileSyncServiceTest, NeedsConfirmation) { |
403 prefs()->SetManagedPref(syncer::prefs::kSyncManaged, | 401 prefs()->SetManagedPref(syncer::prefs::kSyncManaged, new base::Value(false)); |
404 new base::FundamentalValue(false)); | |
405 IssueTestTokens(); | 402 IssueTestTokens(); |
406 CreateService(ProfileSyncService::MANUAL_START); | 403 CreateService(ProfileSyncService::MANUAL_START); |
407 syncer::SyncPrefs sync_prefs(prefs()); | 404 syncer::SyncPrefs sync_prefs(prefs()); |
408 base::Time now = base::Time::Now(); | 405 base::Time now = base::Time::Now(); |
409 sync_prefs.SetLastSyncedTime(now); | 406 sync_prefs.SetLastSyncedTime(now); |
410 sync_prefs.SetKeepEverythingSynced(true); | 407 sync_prefs.SetKeepEverythingSynced(true); |
411 service()->Initialize(); | 408 service()->Initialize(); |
412 EXPECT_FALSE(service()->IsSyncActive()); | 409 EXPECT_FALSE(service()->IsSyncActive()); |
413 | 410 |
414 // The last sync time shouldn't be cleared. | 411 // The last sync time shouldn't be cleared. |
(...skipping 14 matching lines...) Expand all Loading... |
429 auto sync_blocker = service()->GetSetupInProgressHandle(); | 426 auto sync_blocker = service()->GetSetupInProgressHandle(); |
430 EXPECT_TRUE(observer.setup_in_progress()); | 427 EXPECT_TRUE(observer.setup_in_progress()); |
431 sync_blocker.reset(); | 428 sync_blocker.reset(); |
432 EXPECT_FALSE(observer.setup_in_progress()); | 429 EXPECT_FALSE(observer.setup_in_progress()); |
433 | 430 |
434 service()->RemoveObserver(&observer); | 431 service()->RemoveObserver(&observer); |
435 } | 432 } |
436 | 433 |
437 // Verify that disable by enterprise policy works. | 434 // Verify that disable by enterprise policy works. |
438 TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) { | 435 TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) { |
439 prefs()->SetManagedPref(syncer::prefs::kSyncManaged, | 436 prefs()->SetManagedPref(syncer::prefs::kSyncManaged, new base::Value(true)); |
440 new base::FundamentalValue(true)); | |
441 IssueTestTokens(); | 437 IssueTestTokens(); |
442 CreateService(ProfileSyncService::AUTO_START); | 438 CreateService(ProfileSyncService::AUTO_START); |
443 InitializeForNthSync(); | 439 InitializeForNthSync(); |
444 EXPECT_TRUE(service()->IsManaged()); | 440 EXPECT_TRUE(service()->IsManaged()); |
445 EXPECT_FALSE(service()->IsSyncActive()); | 441 EXPECT_FALSE(service()->IsSyncActive()); |
446 } | 442 } |
447 | 443 |
448 // Verify that disable by enterprise policy works even after the backend has | 444 // Verify that disable by enterprise policy works even after the backend has |
449 // been initialized. | 445 // been initialized. |
450 TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) { | 446 TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) { |
451 IssueTestTokens(); | 447 IssueTestTokens(); |
452 CreateService(ProfileSyncService::AUTO_START); | 448 CreateService(ProfileSyncService::AUTO_START); |
453 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | 449 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); |
454 ExpectSyncEngineCreation(1); | 450 ExpectSyncEngineCreation(1); |
455 InitializeForNthSync(); | 451 InitializeForNthSync(); |
456 | 452 |
457 EXPECT_FALSE(service()->IsManaged()); | 453 EXPECT_FALSE(service()->IsManaged()); |
458 EXPECT_TRUE(service()->IsSyncActive()); | 454 EXPECT_TRUE(service()->IsSyncActive()); |
459 | 455 |
460 prefs()->SetManagedPref(syncer::prefs::kSyncManaged, | 456 prefs()->SetManagedPref(syncer::prefs::kSyncManaged, new base::Value(true)); |
461 new base::FundamentalValue(true)); | |
462 | 457 |
463 EXPECT_TRUE(service()->IsManaged()); | 458 EXPECT_TRUE(service()->IsManaged()); |
464 EXPECT_FALSE(service()->IsSyncActive()); | 459 EXPECT_FALSE(service()->IsSyncActive()); |
465 } | 460 } |
466 | 461 |
467 // Exercies the ProfileSyncService's code paths related to getting shut down | 462 // Exercies the ProfileSyncService's code paths related to getting shut down |
468 // before the backend initialize call returns. | 463 // before the backend initialize call returns. |
469 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { | 464 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { |
470 CreateService(ProfileSyncService::AUTO_START); | 465 CreateService(ProfileSyncService::AUTO_START); |
471 PrepareDelayedInitSyncEngine(); | 466 PrepareDelayedInitSyncEngine(); |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 // Progress the controller to RUNNING first, which is how the service | 961 // Progress the controller to RUNNING first, which is how the service |
967 // determines whether a type is enabled. | 962 // determines whether a type is enabled. |
968 controller->StartAssociating(base::Bind(&DoNothing)); | 963 controller->StartAssociating(base::Bind(&DoNothing)); |
969 controller->FinishStart(DataTypeController::OK_FIRST_RUN); | 964 controller->FinishStart(DataTypeController::OK_FIRST_RUN); |
970 service()->RegisterDataTypeController(std::move(controller)); | 965 service()->RegisterDataTypeController(std::move(controller)); |
971 EXPECT_NE(nullptr, service()->GetOpenTabsUIDelegate()); | 966 EXPECT_NE(nullptr, service()->GetOpenTabsUIDelegate()); |
972 } | 967 } |
973 | 968 |
974 } // namespace | 969 } // namespace |
975 } // namespace browser_sync | 970 } // namespace browser_sync |
OLD | NEW |