| 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/memory/ptr_util.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "components/sync/base/sync_prefs.h" | 13 #include "components/sync/base/sync_prefs.h" |
| 14 #include "components/sync/driver/sync_driver_switches.h" | 14 #include "components/sync/driver/sync_driver_switches.h" |
| 15 #include "components/sync_preferences/testing_pref_service_syncable.h" | 15 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace syncer { | 18 namespace syncer { |
| 19 | 19 |
| 20 // These are coupled to the implementation of StartupController's | 20 // These are coupled to the implementation of StartupController's |
| 21 // GetBackendInitializationStateString which is used by about:sync. We use it | 21 // GetEngineInitializationStateString which is used by about:sync. We use it |
| 22 // 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 |
| 23 // outputting the correct values for the debug string. | 23 // outputting the correct values for the debug string. |
| 24 static const char kStateStringStarted[] = "Started"; | 24 static const char kStateStringStarted[] = "Started"; |
| 25 static const char kStateStringDeferred[] = "Deferred"; | 25 static const char kStateStringDeferred[] = "Deferred"; |
| 26 static const char kStateStringNotStarted[] = "Not started"; | 26 static const char kStateStringNotStarted[] = "Not started"; |
| 27 | 27 |
| 28 class StartupControllerTest : public testing::Test { | 28 class StartupControllerTest : public testing::Test { |
| 29 public: | 29 public: |
| 30 StartupControllerTest() : can_start_(false), started_(false) {} | 30 StartupControllerTest() : can_start_(false), started_(false) {} |
| 31 | 31 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 47 void SetCanStart(bool can_start) { can_start_ = can_start; } | 47 void SetCanStart(bool can_start) { can_start_ = can_start; } |
| 48 | 48 |
| 49 void FakeStartBackend() { | 49 void FakeStartBackend() { |
| 50 started_ = true; | 50 started_ = true; |
| 51 sync_prefs()->SetFirstSetupComplete(); | 51 sync_prefs()->SetFirstSetupComplete(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void ExpectStarted() { | 54 void ExpectStarted() { |
| 55 EXPECT_TRUE(started()); | 55 EXPECT_TRUE(started()); |
| 56 EXPECT_EQ(kStateStringStarted, | 56 EXPECT_EQ(kStateStringStarted, |
| 57 controller()->GetBackendInitializationStateString()); | 57 controller()->GetEngineInitializationStateString()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void ExpectStartDeferred() { | 60 void ExpectStartDeferred() { |
| 61 const bool deferred_start = | 61 const bool deferred_start = |
| 62 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 62 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 63 switches::kSyncDisableDeferredStartup); | 63 switches::kSyncDisableDeferredStartup); |
| 64 EXPECT_EQ(!deferred_start, started()); | 64 EXPECT_EQ(!deferred_start, started()); |
| 65 EXPECT_EQ(deferred_start ? kStateStringDeferred : kStateStringStarted, | 65 EXPECT_EQ(deferred_start ? kStateStringDeferred : kStateStringStarted, |
| 66 controller()->GetBackendInitializationStateString()); | 66 controller()->GetEngineInitializationStateString()); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void ExpectNotStarted() { | 69 void ExpectNotStarted() { |
| 70 EXPECT_FALSE(started()); | 70 EXPECT_FALSE(started()); |
| 71 EXPECT_EQ(kStateStringNotStarted, | 71 EXPECT_EQ(kStateStringNotStarted, |
| 72 controller()->GetBackendInitializationStateString()); | 72 controller()->GetEngineInitializationStateString()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 bool started() const { return started_; } | 75 bool started() const { return started_; } |
| 76 void clear_started() { started_ = false; } | 76 void clear_started() { started_ = false; } |
| 77 StartupController* controller() { return controller_.get(); } | 77 StartupController* controller() { return controller_.get(); } |
| 78 SyncPrefs* sync_prefs() { return sync_prefs_.get(); } | 78 SyncPrefs* sync_prefs() { return sync_prefs_.get(); } |
| 79 | 79 |
| 80 private: | 80 private: |
| 81 bool can_start_; | 81 bool can_start_; |
| 82 bool started_; | 82 bool started_; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 controller()->SetSetupInProgress(true); | 204 controller()->SetSetupInProgress(true); |
| 205 | 205 |
| 206 // 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. |
| 207 controller()->Reset(UserTypes()); | 207 controller()->Reset(UserTypes()); |
| 208 | 208 |
| 209 // 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. |
| 210 EXPECT_TRUE(controller()->IsSetupInProgress()); | 210 EXPECT_TRUE(controller()->IsSetupInProgress()); |
| 211 } | 211 } |
| 212 | 212 |
| 213 } // namespace syncer | 213 } // namespace syncer |
| OLD | NEW |