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

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: Self review 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
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(false);
92 ExpectNotStarted(); 92 ExpectNotStarted();
93 93
94 SetCanStart(true); 94 SetCanStart(true);
95 controller()->TryStart(); 95 controller()->TryStart(false);
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(false);
104 ExpectStartDeferred(); 104 ExpectStartDeferred();
105 } 105 }
106 106
107 // Test that a data type triggering startup starts sync immediately. 107 // Test that a data type triggering startup starts sync immediately.
108 TEST_F(StartupControllerTest, NoDeferralDataTypeTrigger) { 108 TEST_F(StartupControllerTest, NoDeferralDataTypeTrigger) {
109 sync_prefs()->SetFirstSetupComplete(); 109 sync_prefs()->SetFirstSetupComplete();
110 SetCanStart(true); 110 SetCanStart(true);
111 controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS); 111 controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS);
112 ExpectStarted(); 112 ExpectStarted();
113 } 113 }
114 114
115 // Test that a data type trigger interrupts the deferral timer and starts 115 // Test that a data type trigger interrupts the deferral timer and starts
116 // sync immediately. 116 // sync immediately.
117 TEST_F(StartupControllerTest, DataTypeTriggerInterruptsDeferral) { 117 TEST_F(StartupControllerTest, DataTypeTriggerInterruptsDeferral) {
118 sync_prefs()->SetFirstSetupComplete(); 118 sync_prefs()->SetFirstSetupComplete();
119 SetCanStart(true); 119 SetCanStart(true);
120 controller()->TryStart(); 120 controller()->TryStart(false);
121 ExpectStartDeferred(); 121 ExpectStartDeferred();
122 122
123 controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS); 123 controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS);
124 ExpectStarted(); 124 ExpectStarted();
125 125
126 // The fallback timer shouldn't result in another invocation of the closure 126 // The fallback timer shouldn't result in another invocation of the closure
127 // we passed to the StartupController. 127 // we passed to the StartupController.
128 clear_started(); 128 clear_started();
129 base::RunLoop().RunUntilIdle(); 129 base::RunLoop().RunUntilIdle();
130 EXPECT_FALSE(started()); 130 EXPECT_FALSE(started());
131 } 131 }
132 132
133 // Test that the fallback timer starts sync in the event all 133 // Test that the fallback timer starts sync in the event all
134 // conditions are met and no data type requests sync. 134 // conditions are met and no data type requests sync.
135 TEST_F(StartupControllerTest, FallbackTimer) { 135 TEST_F(StartupControllerTest, FallbackTimer) {
136 sync_prefs()->SetFirstSetupComplete(); 136 sync_prefs()->SetFirstSetupComplete();
137 SetCanStart(true); 137 SetCanStart(true);
138 controller()->TryStart(); 138 controller()->TryStart(false);
139 ExpectStartDeferred(); 139 ExpectStartDeferred();
140 140
141 base::RunLoop().RunUntilIdle(); 141 base::RunLoop().RunUntilIdle();
142 ExpectStarted(); 142 ExpectStarted();
143 } 143 }
144 144
145 // Test that we start immediately if sessions is disabled. 145 // Test that we start immediately if sessions is disabled.
146 TEST_F(StartupControllerTest, NoDeferralWithoutSessionsSync) { 146 TEST_F(StartupControllerTest, NoDeferralWithoutSessionsSync) {
147 syncer::ModelTypeSet types(syncer::UserTypes()); 147 syncer::ModelTypeSet types(syncer::UserTypes());
148 // Disabling sessions means disabling 4 types due to groupings. 148 // Disabling sessions means disabling 4 types due to groupings.
149 types.Remove(syncer::SESSIONS); 149 types.Remove(syncer::SESSIONS);
150 types.Remove(syncer::PROXY_TABS); 150 types.Remove(syncer::PROXY_TABS);
151 types.Remove(syncer::TYPED_URLS); 151 types.Remove(syncer::TYPED_URLS);
152 types.Remove(syncer::SUPERVISED_USER_SETTINGS); 152 types.Remove(syncer::SUPERVISED_USER_SETTINGS);
153 sync_prefs()->SetKeepEverythingSynced(false); 153 sync_prefs()->SetKeepEverythingSynced(false);
154 sync_prefs()->SetPreferredDataTypes(syncer::UserTypes(), types); 154 sync_prefs()->SetPreferredDataTypes(syncer::UserTypes(), types);
155 controller()->Reset(syncer::UserTypes()); 155 controller()->Reset(syncer::UserTypes());
156 156
157 sync_prefs()->SetFirstSetupComplete(); 157 sync_prefs()->SetFirstSetupComplete();
158 SetCanStart(true); 158 SetCanStart(true);
159 controller()->TryStart(); 159 controller()->TryStart(false);
160 ExpectStarted(); 160 ExpectStarted();
161 } 161 }
162 162
163 // Sanity check that the fallback timer doesn't fire before startup 163 // Sanity check that the fallback timer doesn't fire before startup
164 // conditions are met. 164 // conditions are met.
165 TEST_F(StartupControllerTest, FallbackTimerWaits) { 165 TEST_F(StartupControllerTest, FallbackTimerWaits) {
166 controller()->TryStart(); 166 controller()->TryStart(false);
167 ExpectNotStarted(); 167 ExpectNotStarted();
168 base::RunLoop().RunUntilIdle(); 168 base::RunLoop().RunUntilIdle();
169 ExpectNotStarted(); 169 ExpectNotStarted();
170 } 170 }
171 171
172 // Test that sync starts immediately when setup in progress is true. 172 // Test that sync starts immediately when setup in progress is true.
173 TEST_F(StartupControllerTest, NoDeferralSetupInProgressTrigger) { 173 TEST_F(StartupControllerTest, NoDeferralSetupInProgressTrigger) {
174 sync_prefs()->SetFirstSetupComplete(); 174 sync_prefs()->SetFirstSetupComplete();
175 SetCanStart(true); 175 SetCanStart(true);
176 controller()->SetSetupInProgress(true); 176 controller()->SetSetupInProgress(true);
177 ExpectStarted(); 177 ExpectStarted();
178 } 178 }
179 179
180 // Test that setup in progress being set to true interrupts the deferral timer 180 // Test that setup in progress being set to true interrupts the deferral timer
181 // and starts sync immediately. 181 // and starts sync immediately.
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(false);
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();
194 SetCanStart(true); 195 SetCanStart(true);
195 controller()->TryStart(); 196 controller()->TryStart(true);
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
OLDNEW
« components/sync_driver/startup_controller.cc ('K') | « components/sync_driver/startup_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698