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

Side by Side Diff: chrome/browser/sync/startup_controller_unittest.cc

Issue 1143323005: Refactor AO2TS to make it easier to componentize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address roger's comments Created 5 years, 6 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 "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
106 // Test that sync doesn't start until all conditions are met. 106 // Test that sync doesn't start until all conditions are met.
107 TEST_F(StartupControllerTest, Basic) { 107 TEST_F(StartupControllerTest, Basic) {
108 controller()->TryStart(); 108 controller()->TryStart();
109 EXPECT_FALSE(started()); 109 EXPECT_FALSE(started());
110 sync_prefs()->SetSyncSetupCompleted(); 110 sync_prefs()->SetSyncSetupCompleted();
111 controller()->TryStart(); 111 controller()->TryStart();
112 EXPECT_FALSE(started()); 112 EXPECT_FALSE(started());
113 signin()->set_account(kTestUser); 113 signin()->set_account(kTestUser);
114 controller()->TryStart(); 114 controller()->TryStart();
115 EXPECT_FALSE(started()); 115 EXPECT_FALSE(started());
116 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); 116 token_service()->UpdateCredentials(kTestUser, kTestToken);
117 const bool deferred_start = 117 const bool deferred_start =
118 !base::CommandLine::ForCurrentProcess()->HasSwitch( 118 !base::CommandLine::ForCurrentProcess()->HasSwitch(
119 switches::kSyncDisableDeferredStartup); 119 switches::kSyncDisableDeferredStartup);
120 controller()->TryStart(); 120 controller()->TryStart();
121 EXPECT_EQ(!deferred_start, started()); 121 EXPECT_EQ(!deferred_start, started());
122 std::string state(controller()->GetBackendInitializationStateString()); 122 std::string state(controller()->GetBackendInitializationStateString());
123 EXPECT_TRUE(deferred_start ? state == kStateStringDeferred : 123 EXPECT_TRUE(deferred_start ? state == kStateStringDeferred :
124 state == kStateStringStarted); 124 state == kStateStringStarted);
125 } 125 }
126 126
127 // Test that sync doesn't when suppressed even if all other conditons are met. 127 // Test that sync doesn't when suppressed even if all other conditons are met.
128 TEST_F(StartupControllerTest, Suppressed) { 128 TEST_F(StartupControllerTest, Suppressed) {
129 sync_prefs()->SetSyncSetupCompleted(); 129 sync_prefs()->SetSyncSetupCompleted();
130 sync_prefs()->SetStartSuppressed(true); 130 sync_prefs()->SetStartSuppressed(true);
131 signin()->set_account(kTestUser); 131 signin()->set_account(kTestUser);
132 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); 132 token_service()->UpdateCredentials(kTestUser, kTestToken);
133 controller()->TryStart(); 133 controller()->TryStart();
134 EXPECT_FALSE(started()); 134 EXPECT_FALSE(started());
135 EXPECT_EQ(kStateStringNotStarted, 135 EXPECT_EQ(kStateStringNotStarted,
136 controller()->GetBackendInitializationStateString()); 136 controller()->GetBackendInitializationStateString());
137 } 137 }
138 138
139 // Test that sync doesn't when managed even if all other conditons are met. 139 // Test that sync doesn't when managed even if all other conditons are met.
140 TEST_F(StartupControllerTest, Managed) { 140 TEST_F(StartupControllerTest, Managed) {
141 sync_prefs()->SetSyncSetupCompleted(); 141 sync_prefs()->SetSyncSetupCompleted();
142 sync_prefs()->SetManagedForTest(true); 142 sync_prefs()->SetManagedForTest(true);
143 signin()->set_account(kTestUser); 143 signin()->set_account(kTestUser);
144 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); 144 token_service()->UpdateCredentials(kTestUser, kTestToken);
145 controller()->TryStart(); 145 controller()->TryStart();
146 EXPECT_FALSE(started()); 146 EXPECT_FALSE(started());
147 EXPECT_EQ(kStateStringNotStarted, 147 EXPECT_EQ(kStateStringNotStarted,
148 controller()->GetBackendInitializationStateString()); 148 controller()->GetBackendInitializationStateString());
149 } 149 }
150 150
151 // Test that sync doesn't start until all conditions are met and a 151 // Test that sync doesn't start until all conditions are met and a
152 // data type triggers sync startup. 152 // data type triggers sync startup.
153 TEST_F(StartupControllerTest, DataTypeTriggered) { 153 TEST_F(StartupControllerTest, DataTypeTriggered) {
154 sync_prefs()->SetSyncSetupCompleted(); 154 sync_prefs()->SetSyncSetupCompleted();
155 signin()->set_account(kTestUser); 155 signin()->set_account(kTestUser);
156 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); 156 token_service()->UpdateCredentials(kTestUser, kTestToken);
157 controller()->TryStart(); 157 controller()->TryStart();
158 EXPECT_FALSE(started()); 158 EXPECT_FALSE(started());
159 EXPECT_EQ(kStateStringDeferred, 159 EXPECT_EQ(kStateStringDeferred,
160 controller()->GetBackendInitializationStateString()); 160 controller()->GetBackendInitializationStateString());
161 controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS); 161 controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS);
162 EXPECT_TRUE(started()); 162 EXPECT_TRUE(started());
163 EXPECT_EQ(kStateStringStarted, 163 EXPECT_EQ(kStateStringStarted,
164 controller()->GetBackendInitializationStateString()); 164 controller()->GetBackendInitializationStateString());
165 165
166 // The fallback timer shouldn't result in another invocation of the closure 166 // The fallback timer shouldn't result in another invocation of the closure
167 // we passed to the StartupController. 167 // we passed to the StartupController.
168 clear_started(); 168 clear_started();
169 base::RunLoop().RunUntilIdle(); 169 base::RunLoop().RunUntilIdle();
170 EXPECT_FALSE(started()); 170 EXPECT_FALSE(started());
171 } 171 }
172 172
173 // Test that the fallback timer starts sync in the event all 173 // Test that the fallback timer starts sync in the event all
174 // conditions are met and no data type requests sync. 174 // conditions are met and no data type requests sync.
175 TEST_F(StartupControllerTest, FallbackTimer) { 175 TEST_F(StartupControllerTest, FallbackTimer) {
176 sync_prefs()->SetSyncSetupCompleted(); 176 sync_prefs()->SetSyncSetupCompleted();
177 signin()->set_account(kTestUser); 177 signin()->set_account(kTestUser);
178 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); 178 token_service()->UpdateCredentials(kTestUser, kTestToken);
179 controller()->TryStart(); 179 controller()->TryStart();
180 EXPECT_FALSE(started()); 180 EXPECT_FALSE(started());
181 base::RunLoop().RunUntilIdle(); 181 base::RunLoop().RunUntilIdle();
182 EXPECT_TRUE(started()); 182 EXPECT_TRUE(started());
183 } 183 }
184 184
185 // Test that we start immediately if sessions is disabled. 185 // Test that we start immediately if sessions is disabled.
186 TEST_F(StartupControllerTest, NoDeferralWithoutSessionsSync) { 186 TEST_F(StartupControllerTest, NoDeferralWithoutSessionsSync) {
187 syncer::ModelTypeSet types(syncer::UserTypes()); 187 syncer::ModelTypeSet types(syncer::UserTypes());
188 // Disabling sessions means disabling 4 types due to groupings. 188 // Disabling sessions means disabling 4 types due to groupings.
189 types.Remove(syncer::SESSIONS); 189 types.Remove(syncer::SESSIONS);
190 types.Remove(syncer::PROXY_TABS); 190 types.Remove(syncer::PROXY_TABS);
191 types.Remove(syncer::TYPED_URLS); 191 types.Remove(syncer::TYPED_URLS);
192 types.Remove(syncer::SUPERVISED_USER_SETTINGS); 192 types.Remove(syncer::SUPERVISED_USER_SETTINGS);
193 sync_prefs()->SetKeepEverythingSynced(false); 193 sync_prefs()->SetKeepEverythingSynced(false);
194 sync_prefs()->SetPreferredDataTypes(syncer::UserTypes(), types); 194 sync_prefs()->SetPreferredDataTypes(syncer::UserTypes(), types);
195 controller()->Reset(syncer::UserTypes()); 195 controller()->Reset(syncer::UserTypes());
196 sync_prefs()->SetSyncSetupCompleted(); 196 sync_prefs()->SetSyncSetupCompleted();
197 signin()->set_account(kTestUser); 197 signin()->set_account(kTestUser);
198 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); 198 token_service()->UpdateCredentials(kTestUser, kTestToken);
199 controller()->TryStart(); 199 controller()->TryStart();
200 EXPECT_TRUE(started()); 200 EXPECT_TRUE(started());
201 } 201 }
202 202
203 // Sanity check that the fallback timer doesn't fire before startup 203 // Sanity check that the fallback timer doesn't fire before startup
204 // conditions are met. 204 // conditions are met.
205 TEST_F(StartupControllerTest, FallbackTimerWaits) { 205 TEST_F(StartupControllerTest, FallbackTimerWaits) {
206 controller()->TryStart(); 206 controller()->TryStart();
207 EXPECT_FALSE(started()); 207 EXPECT_FALSE(started());
208 base::RunLoop().RunUntilIdle(); 208 base::RunLoop().RunUntilIdle();
209 EXPECT_FALSE(started()); 209 EXPECT_FALSE(started());
210 } 210 }
211 211
212 // Test that sync starts when the user first asks to setup sync (which 212 // Test that sync starts when the user first asks to setup sync (which
213 // may be implicit due to the platform). 213 // may be implicit due to the platform).
214 TEST_F(StartupControllerTest, FirstSetup) { 214 TEST_F(StartupControllerTest, FirstSetup) {
215 signin()->set_account(kTestUser); 215 signin()->set_account(kTestUser);
216 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); 216 token_service()->UpdateCredentials(kTestUser, kTestToken);
217 controller()->TryStart(); 217 controller()->TryStart();
218 218
219 if (browser_defaults::kSyncAutoStarts) { 219 if (browser_defaults::kSyncAutoStarts) {
220 EXPECT_TRUE(started()); 220 EXPECT_TRUE(started());
221 } else { 221 } else {
222 controller()->set_setup_in_progress(true); 222 controller()->set_setup_in_progress(true);
223 controller()->TryStart(); 223 controller()->TryStart();
224 EXPECT_TRUE(started()); 224 EXPECT_TRUE(started());
225 } 225 }
226 } 226 }
227 227
228 TEST_F(StartupControllerTest, Reset) { 228 TEST_F(StartupControllerTest, Reset) {
229 sync_prefs()->SetSyncSetupCompleted(); 229 sync_prefs()->SetSyncSetupCompleted();
230 signin()->set_account(kTestUser); 230 signin()->set_account(kTestUser);
231 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); 231 token_service()->UpdateCredentials(kTestUser, kTestToken);
232 controller()->TryStart(); 232 controller()->TryStart();
233 const bool deferred_start = 233 const bool deferred_start =
234 !base::CommandLine::ForCurrentProcess()->HasSwitch( 234 !base::CommandLine::ForCurrentProcess()->HasSwitch(
235 switches::kSyncDisableDeferredStartup); 235 switches::kSyncDisableDeferredStartup);
236 EXPECT_EQ(!deferred_start, started()); 236 EXPECT_EQ(!deferred_start, started());
237 controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS); 237 controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS);
238 EXPECT_TRUE(started()); 238 EXPECT_TRUE(started());
239 clear_started(); 239 clear_started();
240 controller()->Reset(syncer::UserTypes()); 240 controller()->Reset(syncer::UserTypes());
241 EXPECT_FALSE(started()); 241 EXPECT_FALSE(started());
242 controller()->TryStart(); 242 controller()->TryStart();
243 // Restart is not deferred. 243 // Restart is not deferred.
244 EXPECT_TRUE(started()); 244 EXPECT_TRUE(started());
245 } 245 }
246 246
247 // Test that setup-in-progress tracking is persistent across a Reset. 247 // Test that setup-in-progress tracking is persistent across a Reset.
248 TEST_F(StartupControllerTest, ResetDuringSetup) { 248 TEST_F(StartupControllerTest, ResetDuringSetup) {
249 signin()->set_account(kTestUser); 249 signin()->set_account(kTestUser);
250 token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken); 250 token_service()->UpdateCredentials(kTestUser, kTestToken);
251 251
252 // Simulate UI telling us setup is in progress. 252 // Simulate UI telling us setup is in progress.
253 controller()->set_setup_in_progress(true); 253 controller()->set_setup_in_progress(true);
254 254
255 // This could happen if the UI triggers a stop-syncing permanently call. 255 // This could happen if the UI triggers a stop-syncing permanently call.
256 controller()->Reset(syncer::UserTypes()); 256 controller()->Reset(syncer::UserTypes());
257 257
258 // From the UI's point of view, setup is still in progress. 258 // From the UI's point of view, setup is still in progress.
259 EXPECT_TRUE(controller()->setup_in_progress()); 259 EXPECT_TRUE(controller()->setup_in_progress());
260 } 260 }
261 261
262 } // namespace browser_sync 262 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698