Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1168)

Side by Side Diff: components/sync_driver/startup_controller_unittest.cc

Issue 2159453002: [Sync] Don't start up sync when FirstSetupCompleted is false and no setup in progress (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Android fix attempt Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/sync_driver/startup_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 SetCanStart(true); 194 SetCanStart(true);
195 controller()->TryStart(); 195 controller()->TryStartImmediately();
196 ExpectStarted(); 196 ExpectStarted();
197
198 clear_started();
199 controller()->Reset(syncer::UserTypes());
200 ExpectNotStarted();
201 controller()->TryStart();
202 ExpectStartDeferred();
203 } 197 }
204 198
205 // Test that setup-in-progress tracking is persistent across a Reset. 199 // Test that setup-in-progress tracking is persistent across a Reset.
206 TEST_F(StartupControllerTest, ResetDuringSetup) { 200 TEST_F(StartupControllerTest, ResetDuringSetup) {
207 SetCanStart(true); 201 SetCanStart(true);
208 202
209 // Simulate UI telling us setup is in progress. 203 // Simulate UI telling us setup is in progress.
210 controller()->SetSetupInProgress(true); 204 controller()->SetSetupInProgress(true);
211 205
212 // 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.
213 controller()->Reset(syncer::UserTypes()); 207 controller()->Reset(syncer::UserTypes());
214 208
215 // 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.
216 EXPECT_TRUE(controller()->IsSetupInProgress()); 210 EXPECT_TRUE(controller()->IsSetupInProgress());
217 } 211 }
218 212
219 } // namespace browser_sync 213 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync_driver/startup_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698