Chromium Code Reviews| 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 <utility> | 5 #include <utility> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 return new FakeDataTypeManager(configure_called); | 85 return new FakeDataTypeManager(configure_called); |
| 86 } | 86 } |
| 87 | 87 |
| 88 using testing::Return; | 88 using testing::Return; |
| 89 using testing::StrictMock; | 89 using testing::StrictMock; |
| 90 using testing::_; | 90 using testing::_; |
| 91 | 91 |
| 92 class TestSyncServiceObserver : public sync_driver::SyncServiceObserver { | 92 class TestSyncServiceObserver : public sync_driver::SyncServiceObserver { |
| 93 public: | 93 public: |
| 94 explicit TestSyncServiceObserver(ProfileSyncService* service) | 94 explicit TestSyncServiceObserver(ProfileSyncService* service) |
| 95 : service_(service), first_setup_in_progress_(false) {} | 95 : service_(service), setup_in_progress_(false) {} |
| 96 void OnStateChanged() override { | 96 void OnStateChanged() override { |
| 97 first_setup_in_progress_ = service_->IsFirstSetupInProgress(); | 97 setup_in_progress_ = service_->IsSetupInProgress(); |
| 98 } | 98 } |
| 99 bool first_setup_in_progress() const { return first_setup_in_progress_; } | 99 bool setup_in_progress() const { return setup_in_progress_; } |
| 100 private: | 100 private: |
| 101 ProfileSyncService* service_; | 101 ProfileSyncService* service_; |
| 102 bool first_setup_in_progress_; | 102 bool setup_in_progress_; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 // A variant of the SyncBackendHostMock that won't automatically | 105 // A variant of the SyncBackendHostMock that won't automatically |
| 106 // call back when asked to initialized. Allows us to test things | 106 // call back when asked to initialized. Allows us to test things |
| 107 // that could happen while backend init is in progress. | 107 // that could happen while backend init is in progress. |
| 108 class SyncBackendHostNoReturn : public SyncBackendHostMock { | 108 class SyncBackendHostNoReturn : public SyncBackendHostMock { |
| 109 void Initialize( | 109 void Initialize( |
| 110 sync_driver::SyncFrontend* frontend, | 110 sync_driver::SyncFrontend* frontend, |
| 111 scoped_ptr<base::Thread> sync_thread, | 111 scoped_ptr<base::Thread> sync_thread, |
| 112 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, | 112 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 #endif | 258 #endif |
| 259 | 259 |
| 260 void ShutdownAndDeleteService() { | 260 void ShutdownAndDeleteService() { |
| 261 if (service_) | 261 if (service_) |
| 262 service_->Shutdown(); | 262 service_->Shutdown(); |
| 263 service_.reset(); | 263 service_.reset(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void InitializeForNthSync() { | 266 void InitializeForNthSync() { |
| 267 // Set first sync time before initialize to simulate a complete sync setup. | 267 // Set first sync time before initialize to simulate a complete sync setup. |
| 268 sync_driver::SyncPrefs sync_prefs( | 268 sync_driver::SyncPrefs sync_prefs(prefs()); |
| 269 service_->GetSyncClient()->GetPrefService()); | |
| 270 sync_prefs.SetFirstSyncTime(base::Time::Now()); | 269 sync_prefs.SetFirstSyncTime(base::Time::Now()); |
| 271 sync_prefs.SetFirstSetupComplete(); | 270 sync_prefs.SetFirstSetupComplete(); |
| 272 sync_prefs.SetKeepEverythingSynced(true); | 271 sync_prefs.SetKeepEverythingSynced(true); |
| 273 service_->Initialize(); | 272 service_->Initialize(); |
| 274 } | 273 } |
| 275 | 274 |
| 276 void InitializeForFirstSync() { | 275 void InitializeForFirstSync() { |
| 277 service_->Initialize(); | 276 service_->Initialize(); |
| 278 } | 277 } |
| 279 | 278 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 // Verify that the SetSetupInProgress function call updates state | 415 // Verify that the SetSetupInProgress function call updates state |
| 417 // and notifies observers. | 416 // and notifies observers. |
| 418 TEST_F(ProfileSyncServiceTest, SetupInProgress) { | 417 TEST_F(ProfileSyncServiceTest, SetupInProgress) { |
| 419 CreateService(browser_sync::AUTO_START); | 418 CreateService(browser_sync::AUTO_START); |
| 420 InitializeForFirstSync(); | 419 InitializeForFirstSync(); |
| 421 | 420 |
| 422 TestSyncServiceObserver observer(service()); | 421 TestSyncServiceObserver observer(service()); |
| 423 service()->AddObserver(&observer); | 422 service()->AddObserver(&observer); |
| 424 | 423 |
| 425 service()->SetSetupInProgress(true); | 424 service()->SetSetupInProgress(true); |
| 426 EXPECT_TRUE(observer.first_setup_in_progress()); | 425 EXPECT_TRUE(observer.setup_in_progress()); |
| 427 service()->SetSetupInProgress(false); | 426 service()->SetSetupInProgress(false); |
| 428 EXPECT_FALSE(observer.first_setup_in_progress()); | 427 EXPECT_FALSE(observer.setup_in_progress()); |
| 429 | 428 |
| 430 service()->RemoveObserver(&observer); | 429 service()->RemoveObserver(&observer); |
| 431 } | 430 } |
| 432 | 431 |
| 433 // Verify that disable by enterprise policy works. | 432 // Verify that disable by enterprise policy works. |
| 434 TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) { | 433 TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) { |
| 435 prefs()->SetManagedPref(sync_driver::prefs::kSyncManaged, | 434 prefs()->SetManagedPref(sync_driver::prefs::kSyncManaged, |
| 436 new base::FundamentalValue(true)); | 435 new base::FundamentalValue(true)); |
| 437 IssueTestTokens(); | 436 IssueTestTokens(); |
| 438 CreateService(browser_sync::AUTO_START); | 437 CreateService(browser_sync::AUTO_START); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 InitializeForNthSync(); | 469 InitializeForNthSync(); |
| 471 EXPECT_FALSE(service()->IsSyncActive()); | 470 EXPECT_FALSE(service()->IsSyncActive()); |
| 472 | 471 |
| 473 ShutdownAndDeleteService(); | 472 ShutdownAndDeleteService(); |
| 474 } | 473 } |
| 475 | 474 |
| 476 // Test RequestStop() before we've initialized the backend. | 475 // Test RequestStop() before we've initialized the backend. |
| 477 TEST_F(ProfileSyncServiceTest, EarlyRequestStop) { | 476 TEST_F(ProfileSyncServiceTest, EarlyRequestStop) { |
| 478 CreateService(browser_sync::AUTO_START); | 477 CreateService(browser_sync::AUTO_START); |
| 479 IssueTestTokens(); | 478 IssueTestTokens(); |
| 479 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
| 480 ExpectSyncBackendHostCreation(1); | |
| 480 | 481 |
| 481 service()->RequestStop(ProfileSyncService::KEEP_DATA); | 482 service()->RequestStop(ProfileSyncService::KEEP_DATA); |
| 482 EXPECT_TRUE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart)); | 483 EXPECT_FALSE(service()->IsSyncRequested()); |
| 483 | 484 |
| 484 // Because of suppression, this should fail. | 485 // Because sync is not requested, this should fail. |
| 485 sync_driver::SyncPrefs sync_prefs( | 486 InitializeForNthSync(); |
| 486 service()->GetSyncClient()->GetPrefService()); | |
| 487 sync_prefs.SetFirstSyncTime(base::Time::Now()); | |
| 488 service()->Initialize(); | |
| 489 EXPECT_FALSE(service()->IsSyncActive()); | 487 EXPECT_FALSE(service()->IsSyncActive()); |
|
Nicolas Zea
2016/02/29 21:21:55
Verify IsSyncRequested?
maxbogue
2016/03/09 02:00:59
Done.
| |
| 490 | 488 |
| 491 // Request start. This should be enough to allow init to happen. | 489 // Request start. This should be enough to allow init to happen. |
| 492 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
| 493 ExpectSyncBackendHostCreation(1); | |
| 494 service()->RequestStart(); | 490 service()->RequestStart(); |
| 491 EXPECT_TRUE(service()->IsSyncRequested()); | |
| 495 EXPECT_TRUE(service()->IsSyncActive()); | 492 EXPECT_TRUE(service()->IsSyncActive()); |
| 496 EXPECT_FALSE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart)); | |
| 497 } | 493 } |
| 498 | 494 |
| 499 // Test RequestStop() after we've initialized the backend. | 495 // Test RequestStop() after we've initialized the backend. |
| 500 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { | 496 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { |
| 501 CreateService(browser_sync::AUTO_START); | 497 CreateService(browser_sync::AUTO_START); |
| 502 IssueTestTokens(); | 498 IssueTestTokens(); |
| 503 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | 499 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); |
| 504 ExpectSyncBackendHostCreation(1); | 500 ExpectSyncBackendHostCreation(1); |
| 505 InitializeForNthSync(); | 501 InitializeForNthSync(); |
| 506 | 502 |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 908 // dereferenced in OnSyncCycleCompleted. The fix is to use find() to check if | 904 // dereferenced in OnSyncCycleCompleted. The fix is to use find() to check if |
| 909 // entry for sessions exists in map. | 905 // entry for sessions exists in map. |
| 910 TEST_F(ProfileSyncServiceTest, ValidPointersInDTCMap) { | 906 TEST_F(ProfileSyncServiceTest, ValidPointersInDTCMap) { |
| 911 CreateService(browser_sync::AUTO_START); | 907 CreateService(browser_sync::AUTO_START); |
| 912 service()->OnSessionRestoreComplete(); | 908 service()->OnSessionRestoreComplete(); |
| 913 service()->OnSyncCycleCompleted(); | 909 service()->OnSyncCycleCompleted(); |
| 914 } | 910 } |
| 915 | 911 |
| 916 } // namespace | 912 } // namespace |
| 917 } // namespace browser_sync | 913 } // namespace browser_sync |
| OLD | NEW |