| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // Test that sync doesn't when managed even if all other conditons are met. | 155 // Test that sync doesn't when managed even if all other conditons are met. |
| 156 TEST_F(StartupControllerTest, Managed) { | 156 TEST_F(StartupControllerTest, Managed) { |
| 157 sync_prefs()->SetFirstSetupComplete(); | 157 sync_prefs()->SetFirstSetupComplete(); |
| 158 sync_prefs()->SetManagedForTest(true); | 158 sync_prefs()->SetManagedForTest(true); |
| 159 signin()->set_account_id(kTestUser); | 159 signin()->set_account_id(kTestUser); |
| 160 token_service()->UpdateCredentials(kTestUser, kTestToken); | 160 token_service()->UpdateCredentials(kTestUser, kTestToken); |
| 161 controller()->TryStart(); | 161 controller()->TryStart(); |
| 162 ExpectNotStarted(); | 162 ExpectNotStarted(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 // Test that sync doesn't start until all conditions are met and a | 165 // Test that a data type triggering startup starts sync immediately. |
| 166 // data type triggers sync startup. | 166 TEST_F(StartupControllerTest, NoDeferralDataTypeTrigger) { |
| 167 TEST_F(StartupControllerTest, DataTypeTriggered) { | |
| 168 sync_prefs()->SetFirstSetupComplete(); | 167 sync_prefs()->SetFirstSetupComplete(); |
| 169 signin()->set_account_id(kTestUser); | 168 signin()->set_account_id(kTestUser); |
| 170 token_service()->UpdateCredentials(kTestUser, kTestToken); | 169 token_service()->UpdateCredentials(kTestUser, kTestToken); |
| 170 controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS); |
| 171 ExpectStarted(); |
| 172 } |
| 173 |
| 174 // Test that a data type trigger interrupts the deferral timer and starts |
| 175 // sync immediately. |
| 176 TEST_F(StartupControllerTest, DataTypeTriggerInterruptsDeferral) { |
| 177 sync_prefs()->SetFirstSetupComplete(); |
| 178 signin()->set_account_id(kTestUser); |
| 179 token_service()->UpdateCredentials(kTestUser, kTestToken); |
| 171 controller()->TryStart(); | 180 controller()->TryStart(); |
| 172 ExpectStartDeferred(); | 181 ExpectStartDeferred(); |
| 173 | 182 |
| 174 controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS); | 183 controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS); |
| 175 ExpectStarted(); | 184 ExpectStarted(); |
| 176 | 185 |
| 177 // The fallback timer shouldn't result in another invocation of the closure | 186 // The fallback timer shouldn't result in another invocation of the closure |
| 178 // we passed to the StartupController. | 187 // we passed to the StartupController. |
| 179 clear_started(); | 188 clear_started(); |
| 180 base::RunLoop().RunUntilIdle(); | 189 base::RunLoop().RunUntilIdle(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 224 |
| 216 // Sanity check that the fallback timer doesn't fire before startup | 225 // Sanity check that the fallback timer doesn't fire before startup |
| 217 // conditions are met. | 226 // conditions are met. |
| 218 TEST_F(StartupControllerTest, FallbackTimerWaits) { | 227 TEST_F(StartupControllerTest, FallbackTimerWaits) { |
| 219 controller()->TryStart(); | 228 controller()->TryStart(); |
| 220 ExpectNotStarted(); | 229 ExpectNotStarted(); |
| 221 base::RunLoop().RunUntilIdle(); | 230 base::RunLoop().RunUntilIdle(); |
| 222 ExpectNotStarted(); | 231 ExpectNotStarted(); |
| 223 } | 232 } |
| 224 | 233 |
| 225 // Test that start isn't deferred when setup is in progress. | 234 // Test that sync starts immediately when setup in progress is true. |
| 226 TEST_F(StartupControllerTest, NoDeferralWithSetupInProgress) { | 235 TEST_F(StartupControllerTest, NoDeferralSetupInProgressTrigger) { |
| 227 sync_prefs()->SetFirstSetupComplete(); | 236 sync_prefs()->SetFirstSetupComplete(); |
| 228 signin()->set_account_id(kTestUser); | 237 signin()->set_account_id(kTestUser); |
| 229 token_service()->UpdateCredentials(kTestUser, kTestToken); | 238 token_service()->UpdateCredentials(kTestUser, kTestToken); |
| 230 controller()->set_setup_in_progress(true); | 239 |
| 231 controller()->TryStart(); | 240 controller()->SetSetupInProgress(true); |
| 232 ExpectStarted(); | 241 ExpectStarted(); |
| 233 } | 242 } |
| 234 | 243 |
| 244 // Test that setup in progress being set to true interrupts the deferral timer |
| 245 // and starts sync immediately. |
| 246 TEST_F(StartupControllerTest, SetupInProgressTriggerInterruptsDeferral) { |
| 247 sync_prefs()->SetFirstSetupComplete(); |
| 248 signin()->set_account_id(kTestUser); |
| 249 token_service()->UpdateCredentials(kTestUser, kTestToken); |
| 250 controller()->TryStart(); |
| 251 ExpectStartDeferred(); |
| 252 |
| 253 controller()->SetSetupInProgress(true); |
| 254 ExpectStarted(); |
| 255 } |
| 256 |
| 235 // Test that start isn't deferred on the first start but is on restarts. | 257 // Test that start isn't deferred on the first start but is on restarts. |
| 236 TEST_F(StartupControllerTest, DeferralOnRestart) { | 258 TEST_F(StartupControllerTest, DeferralOnRestart) { |
| 237 signin()->set_account_id(kTestUser); | 259 signin()->set_account_id(kTestUser); |
| 238 token_service()->UpdateCredentials(kTestUser, kTestToken); | 260 token_service()->UpdateCredentials(kTestUser, kTestToken); |
| 239 controller()->TryStart(); | 261 controller()->TryStart(); |
| 240 ExpectStarted(); | 262 ExpectStarted(); |
| 241 | 263 |
| 242 clear_started(); | 264 clear_started(); |
| 243 controller()->Reset(syncer::UserTypes()); | 265 controller()->Reset(syncer::UserTypes()); |
| 244 ExpectNotStarted(); | 266 ExpectNotStarted(); |
| 245 controller()->TryStart(); | 267 controller()->TryStart(); |
| 246 ExpectStartDeferred(); | 268 ExpectStartDeferred(); |
| 247 } | 269 } |
| 248 | 270 |
| 249 // Test that setup-in-progress tracking is persistent across a Reset. | 271 // Test that setup-in-progress tracking is persistent across a Reset. |
| 250 TEST_F(StartupControllerTest, ResetDuringSetup) { | 272 TEST_F(StartupControllerTest, ResetDuringSetup) { |
| 251 signin()->set_account_id(kTestUser); | 273 signin()->set_account_id(kTestUser); |
| 252 token_service()->UpdateCredentials(kTestUser, kTestToken); | 274 token_service()->UpdateCredentials(kTestUser, kTestToken); |
| 253 | 275 |
| 254 // Simulate UI telling us setup is in progress. | 276 // Simulate UI telling us setup is in progress. |
| 255 controller()->set_setup_in_progress(true); | 277 controller()->SetSetupInProgress(true); |
| 256 | 278 |
| 257 // This could happen if the UI triggers a stop-syncing permanently call. | 279 // This could happen if the UI triggers a stop-syncing permanently call. |
| 258 controller()->Reset(syncer::UserTypes()); | 280 controller()->Reset(syncer::UserTypes()); |
| 259 | 281 |
| 260 // From the UI's point of view, setup is still in progress. | 282 // From the UI's point of view, setup is still in progress. |
| 261 EXPECT_TRUE(controller()->IsSetupInProgress()); | 283 EXPECT_TRUE(controller()->IsSetupInProgress()); |
| 262 } | 284 } |
| 263 | 285 |
| 264 } // namespace browser_sync | 286 } // namespace browser_sync |
| OLD | NEW |