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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 | 79 |
80 private: | 80 private: |
81 bool can_start_; | 81 bool can_start_; |
82 bool started_; | 82 bool started_; |
83 base::MessageLoop message_loop_; | 83 base::MessageLoop message_loop_; |
84 syncable_prefs::TestingPrefServiceSyncable pref_service_; | 84 syncable_prefs::TestingPrefServiceSyncable pref_service_; |
85 std::unique_ptr<sync_driver::SyncPrefs> sync_prefs_; | 85 std::unique_ptr<sync_driver::SyncPrefs> sync_prefs_; |
86 std::unique_ptr<StartupController> controller_; | 86 std::unique_ptr<StartupController> controller_; |
87 }; | 87 }; |
88 | 88 |
89 // Test that sync doesn't start until all conditions are met. | 89 // Test that sync doesn't start if setup is not in progress or complete. |
90 TEST_F(StartupControllerTest, Basic) { | 90 TEST_F(StartupControllerTest, NoSetupComplete) { |
91 controller()->TryStart(); | 91 controller()->TryStart(); |
92 ExpectNotStarted(); | 92 ExpectNotStarted(); |
93 | 93 |
94 SetCanStart(true); | 94 SetCanStart(true); |
95 controller()->TryStart(); | 95 controller()->TryStart(); |
96 ExpectStarted(); | 96 ExpectNotStarted(); |
97 } | 97 } |
98 | 98 |
99 // Test that sync defers if first setup is complete. | 99 // Test that sync defers if first setup is complete. |
100 TEST_F(StartupControllerTest, DefersAfterFirstSetupComplete) { | 100 TEST_F(StartupControllerTest, DefersAfterFirstSetupComplete) { |
101 sync_prefs()->SetFirstSetupComplete(); | 101 sync_prefs()->SetFirstSetupComplete(); |
102 SetCanStart(true); | 102 SetCanStart(true); |
103 controller()->TryStart(); | 103 controller()->TryStart(); |
104 ExpectStartDeferred(); | 104 ExpectStartDeferred(); |
105 } | 105 } |
106 | 106 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 TEST_F(StartupControllerTest, SetupInProgressTriggerInterruptsDeferral) { | 182 TEST_F(StartupControllerTest, SetupInProgressTriggerInterruptsDeferral) { |
183 sync_prefs()->SetFirstSetupComplete(); | 183 sync_prefs()->SetFirstSetupComplete(); |
184 SetCanStart(true); | 184 SetCanStart(true); |
185 controller()->TryStart(); | 185 controller()->TryStart(); |
186 ExpectStartDeferred(); | 186 ExpectStartDeferred(); |
187 | 187 |
188 controller()->SetSetupInProgress(true); | 188 controller()->SetSetupInProgress(true); |
189 ExpectStarted(); | 189 ExpectStarted(); |
190 } | 190 } |
191 | 191 |
192 // Test that start isn't deferred on the first start but is on restarts. | 192 // Test that immediate startup can be forced. |
193 TEST_F(StartupControllerTest, DeferralOnRestart) { | 193 TEST_F(StartupControllerTest, ForceImmediateStartup) { |
194 sync_prefs()->SetFirstSetupComplete(); | |
maxbogue
2016/07/15 23:45:15
Remove this line. The test needs to pass without i
Nicolas Zea
2016/07/15 23:49:11
Good catch! done.
| |
194 SetCanStart(true); | 195 SetCanStart(true); |
195 controller()->TryStart(); | 196 controller()->TryStartImmediately(); |
196 ExpectStarted(); | 197 ExpectStarted(); |
197 | |
198 clear_started(); | |
199 controller()->Reset(syncer::UserTypes()); | |
200 ExpectNotStarted(); | |
201 controller()->TryStart(); | |
202 ExpectStartDeferred(); | |
203 } | 198 } |
204 | 199 |
205 // Test that setup-in-progress tracking is persistent across a Reset. | 200 // Test that setup-in-progress tracking is persistent across a Reset. |
206 TEST_F(StartupControllerTest, ResetDuringSetup) { | 201 TEST_F(StartupControllerTest, ResetDuringSetup) { |
207 SetCanStart(true); | 202 SetCanStart(true); |
208 | 203 |
209 // Simulate UI telling us setup is in progress. | 204 // Simulate UI telling us setup is in progress. |
210 controller()->SetSetupInProgress(true); | 205 controller()->SetSetupInProgress(true); |
211 | 206 |
212 // This could happen if the UI triggers a stop-syncing permanently call. | 207 // This could happen if the UI triggers a stop-syncing permanently call. |
213 controller()->Reset(syncer::UserTypes()); | 208 controller()->Reset(syncer::UserTypes()); |
214 | 209 |
215 // From the UI's point of view, setup is still in progress. | 210 // From the UI's point of view, setup is still in progress. |
216 EXPECT_TRUE(controller()->IsSetupInProgress()); | 211 EXPECT_TRUE(controller()->IsSetupInProgress()); |
217 } | 212 } |
218 | 213 |
219 } // namespace browser_sync | 214 } // namespace browser_sync |
OLD | NEW |