| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sync/driver/startup_controller.h" | 5 #include "components/sync/driver/startup_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 12 #include "components/sync/base/sync_prefs.h" | 13 #include "components/sync/base/sync_prefs.h" |
| 13 #include "components/sync/driver/sync_driver_switches.h" | 14 #include "components/sync/driver/sync_driver_switches.h" |
| 14 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 15 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace syncer { | 18 namespace syncer { |
| 18 | 19 |
| 19 // These are coupled to the implementation of StartupController's | 20 // These are coupled to the implementation of StartupController's |
| 20 // GetBackendInitializationStateString which is used by about:sync. We use it | 21 // GetBackendInitializationStateString which is used by about:sync. We use it |
| 21 // as a convenient way to verify internal state and that the class is | 22 // as a convenient way to verify internal state and that the class is |
| 22 // outputting the correct values for the debug string. | 23 // outputting the correct values for the debug string. |
| 23 static const char kStateStringStarted[] = "Started"; | 24 static const char kStateStringStarted[] = "Started"; |
| 24 static const char kStateStringDeferred[] = "Deferred"; | 25 static const char kStateStringDeferred[] = "Deferred"; |
| 25 static const char kStateStringNotStarted[] = "Not started"; | 26 static const char kStateStringNotStarted[] = "Not started"; |
| 26 | 27 |
| 27 class StartupControllerTest : public testing::Test { | 28 class StartupControllerTest : public testing::Test { |
| 28 public: | 29 public: |
| 29 StartupControllerTest() : can_start_(false), started_(false) {} | 30 StartupControllerTest() : can_start_(false), started_(false) {} |
| 30 | 31 |
| 31 void SetUp() override { | 32 void SetUp() override { |
| 32 SyncPrefs::RegisterProfilePrefs(pref_service_.registry()); | 33 SyncPrefs::RegisterProfilePrefs(pref_service_.registry()); |
| 33 sync_prefs_.reset(new SyncPrefs(&pref_service_)); | 34 sync_prefs_ = base::MakeUnique<SyncPrefs>(&pref_service_); |
| 34 controller_.reset(new StartupController( | 35 controller_ = base::MakeUnique<StartupController>( |
| 35 sync_prefs_.get(), | 36 sync_prefs_.get(), |
| 36 base::Bind(&StartupControllerTest::CanStart, base::Unretained(this)), | 37 base::Bind(&StartupControllerTest::CanStart, base::Unretained(this)), |
| 37 base::Bind(&StartupControllerTest::FakeStartBackend, | 38 base::Bind(&StartupControllerTest::FakeStartBackend, |
| 38 base::Unretained(this)))); | 39 base::Unretained(this))); |
| 39 controller_->Reset(UserTypes()); | 40 controller_->Reset(UserTypes()); |
| 40 controller_->OverrideFallbackTimeoutForTest( | 41 controller_->OverrideFallbackTimeoutForTest( |
| 41 base::TimeDelta::FromSeconds(0)); | 42 base::TimeDelta::FromSeconds(0)); |
| 42 } | 43 } |
| 43 | 44 |
| 44 bool CanStart() { return can_start_; } | 45 bool CanStart() { return can_start_; } |
| 45 | 46 |
| 46 void SetCanStart(bool can_start) { can_start_ = can_start; } | 47 void SetCanStart(bool can_start) { can_start_ = can_start; } |
| 47 | 48 |
| 48 void FakeStartBackend() { | 49 void FakeStartBackend() { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 controller()->SetSetupInProgress(true); | 204 controller()->SetSetupInProgress(true); |
| 204 | 205 |
| 205 // This could happen if the UI triggers a stop-syncing permanently call. | 206 // This could happen if the UI triggers a stop-syncing permanently call. |
| 206 controller()->Reset(UserTypes()); | 207 controller()->Reset(UserTypes()); |
| 207 | 208 |
| 208 // From the UI's point of view, setup is still in progress. | 209 // From the UI's point of view, setup is still in progress. |
| 209 EXPECT_TRUE(controller()->IsSetupInProgress()); | 210 EXPECT_TRUE(controller()->IsSetupInProgress()); |
| 210 } | 211 } |
| 211 | 212 |
| 212 } // namespace syncer | 213 } // namespace syncer |
| OLD | NEW |