| 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 "chrome/browser/sync/startup_controller.h" | 5 #include "chrome/browser/sync/startup_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 TEST_F(StartupControllerTest, Basic) { | 106 TEST_F(StartupControllerTest, Basic) { |
| 107 controller()->TryStart(); | 107 controller()->TryStart(); |
| 108 EXPECT_FALSE(started()); | 108 EXPECT_FALSE(started()); |
| 109 sync_prefs()->SetSyncSetupCompleted(); | 109 sync_prefs()->SetSyncSetupCompleted(); |
| 110 controller()->TryStart(); | 110 controller()->TryStart(); |
| 111 EXPECT_FALSE(started()); | 111 EXPECT_FALSE(started()); |
| 112 signin()->set_account(kTestUser); | 112 signin()->set_account(kTestUser); |
| 113 controller()->TryStart(); | 113 controller()->TryStart(); |
| 114 EXPECT_FALSE(started()); | 114 EXPECT_FALSE(started()); |
| 115 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); | 115 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); |
| 116 const bool deferred_start = !CommandLine::ForCurrentProcess()-> | 116 const bool deferred_start = |
| 117 HasSwitch(switches::kSyncDisableDeferredStartup); | 117 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 118 switches::kSyncDisableDeferredStartup); |
| 118 controller()->TryStart(); | 119 controller()->TryStart(); |
| 119 EXPECT_EQ(!deferred_start, started()); | 120 EXPECT_EQ(!deferred_start, started()); |
| 120 std::string state(controller()->GetBackendInitializationStateString()); | 121 std::string state(controller()->GetBackendInitializationStateString()); |
| 121 EXPECT_TRUE(deferred_start ? state == kStateStringDeferred : | 122 EXPECT_TRUE(deferred_start ? state == kStateStringDeferred : |
| 122 state == kStateStringStarted); | 123 state == kStateStringStarted); |
| 123 } | 124 } |
| 124 | 125 |
| 125 // Test that sync doesn't when suppressed even if all other conditons are met. | 126 // Test that sync doesn't when suppressed even if all other conditons are met. |
| 126 TEST_F(StartupControllerTest, Suppressed) { | 127 TEST_F(StartupControllerTest, Suppressed) { |
| 127 sync_prefs()->SetSyncSetupCompleted(); | 128 sync_prefs()->SetSyncSetupCompleted(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 controller()->TryStart(); | 222 controller()->TryStart(); |
| 222 EXPECT_TRUE(started()); | 223 EXPECT_TRUE(started()); |
| 223 } | 224 } |
| 224 } | 225 } |
| 225 | 226 |
| 226 TEST_F(StartupControllerTest, Reset) { | 227 TEST_F(StartupControllerTest, Reset) { |
| 227 sync_prefs()->SetSyncSetupCompleted(); | 228 sync_prefs()->SetSyncSetupCompleted(); |
| 228 signin()->set_account(kTestUser); | 229 signin()->set_account(kTestUser); |
| 229 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); | 230 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); |
| 230 controller()->TryStart(); | 231 controller()->TryStart(); |
| 231 const bool deferred_start = !CommandLine::ForCurrentProcess()-> | 232 const bool deferred_start = |
| 232 HasSwitch(switches::kSyncDisableDeferredStartup); | 233 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 234 switches::kSyncDisableDeferredStartup); |
| 233 EXPECT_EQ(!deferred_start, started()); | 235 EXPECT_EQ(!deferred_start, started()); |
| 234 controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS); | 236 controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS); |
| 235 EXPECT_TRUE(started()); | 237 EXPECT_TRUE(started()); |
| 236 clear_started(); | 238 clear_started(); |
| 237 controller()->Reset(syncer::UserTypes()); | 239 controller()->Reset(syncer::UserTypes()); |
| 238 EXPECT_FALSE(started()); | 240 EXPECT_FALSE(started()); |
| 239 controller()->TryStart(); | 241 controller()->TryStart(); |
| 240 // Restart is not deferred. | 242 // Restart is not deferred. |
| 241 EXPECT_TRUE(started()); | 243 EXPECT_TRUE(started()); |
| 242 } | 244 } |
| 243 | 245 |
| 244 // Test that setup-in-progress tracking is persistent across a Reset. | 246 // Test that setup-in-progress tracking is persistent across a Reset. |
| 245 TEST_F(StartupControllerTest, ResetDuringSetup) { | 247 TEST_F(StartupControllerTest, ResetDuringSetup) { |
| 246 signin()->set_account(kTestUser); | 248 signin()->set_account(kTestUser); |
| 247 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); | 249 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); |
| 248 | 250 |
| 249 // Simulate UI telling us setup is in progress. | 251 // Simulate UI telling us setup is in progress. |
| 250 controller()->set_setup_in_progress(true); | 252 controller()->set_setup_in_progress(true); |
| 251 | 253 |
| 252 // This could happen if the UI triggers a stop-syncing permanently call. | 254 // This could happen if the UI triggers a stop-syncing permanently call. |
| 253 controller()->Reset(syncer::UserTypes()); | 255 controller()->Reset(syncer::UserTypes()); |
| 254 | 256 |
| 255 // From the UI's point of view, setup is still in progress. | 257 // From the UI's point of view, setup is still in progress. |
| 256 EXPECT_TRUE(controller()->setup_in_progress()); | 258 EXPECT_TRUE(controller()->setup_in_progress()); |
| 257 } | 259 } |
| 258 | 260 |
| 259 } // namespace browser_sync | 261 } // namespace browser_sync |
| OLD | NEW |