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

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

Powered by Google App Engine
This is Rietveld 408576698