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

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

Issue 195873020: [Sync] Move SyncPrefs into sync_driver component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rerererebase Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/invalidation/fake_invalidation_service.h" 10 #include "chrome/browser/invalidation/fake_invalidation_service.h"
11 #include "chrome/browser/invalidation/invalidation_service_factory.h" 11 #include "chrome/browser/invalidation/invalidation_service_factory.h"
12 #include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h" 12 #include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h"
13 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 13 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
14 #include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.h" 14 #include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.h"
15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
16 #include "chrome/browser/signin/signin_manager.h" 16 #include "chrome/browser/signin/signin_manager.h"
17 #include "chrome/browser/signin/signin_manager_factory.h" 17 #include "chrome/browser/signin/signin_manager_factory.h"
18 #include "chrome/browser/sync/glue/data_type_manager_impl.h" 18 #include "chrome/browser/sync/glue/data_type_manager_impl.h"
19 #include "chrome/browser/sync/glue/sync_backend_host_mock.h" 19 #include "chrome/browser/sync/glue/sync_backend_host_mock.h"
20 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" 20 #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chrome/test/base/testing_pref_service_syncable.h" 22 #include "chrome/test/base/testing_pref_service_syncable.h"
23 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
24 #include "components/sync_driver/pref_names.h"
24 #include "content/public/test/test_browser_thread_bundle.h" 25 #include "content/public/test/test_browser_thread_bundle.h"
25 #include "google_apis/gaia/gaia_constants.h" 26 #include "google_apis/gaia/gaia_constants.h"
26 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 29
29 namespace browser_sync { 30 namespace browser_sync {
30 31
31 namespace { 32 namespace {
32 33
33 ACTION(ReturnNewDataTypeManager) { 34 ACTION(ReturnNewDataTypeManager) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 CreateService(browser_sync::AUTO_START); 186 CreateService(browser_sync::AUTO_START);
186 Initialize(); 187 Initialize();
187 const std::string& url = service()->sync_service_url().spec(); 188 const std::string& url = service()->sync_service_url().spec();
188 EXPECT_TRUE(url == ProfileSyncService::kSyncServerUrl || 189 EXPECT_TRUE(url == ProfileSyncService::kSyncServerUrl ||
189 url == ProfileSyncService::kDevServerUrl); 190 url == ProfileSyncService::kDevServerUrl);
190 } 191 }
191 192
192 // Verify a successful initialization. 193 // Verify a successful initialization.
193 TEST_F(ProfileSyncServiceTest, SuccessfulInitialization) { 194 TEST_F(ProfileSyncServiceTest, SuccessfulInitialization) {
194 profile()->GetTestingPrefService()->SetManagedPref( 195 profile()->GetTestingPrefService()->SetManagedPref(
195 prefs::kSyncManaged, 196 sync_driver::prefs::kSyncManaged, base::Value::CreateBooleanValue(false));
196 base::Value::CreateBooleanValue(false));
197 IssueTestTokens(); 197 IssueTestTokens();
198 CreateService(browser_sync::AUTO_START); 198 CreateService(browser_sync::AUTO_START);
199 ExpectDataTypeManagerCreation(); 199 ExpectDataTypeManagerCreation();
200 ExpectSyncBackendHostCreation(); 200 ExpectSyncBackendHostCreation();
201 Initialize(); 201 Initialize();
202 EXPECT_FALSE(service()->IsManaged()); 202 EXPECT_FALSE(service()->IsManaged());
203 EXPECT_TRUE(service()->sync_initialized()); 203 EXPECT_TRUE(service()->sync_initialized());
204 } 204 }
205 205
206 206
(...skipping 10 matching lines...) Expand all
217 EXPECT_TRUE(observer.first_setup_in_progress()); 217 EXPECT_TRUE(observer.first_setup_in_progress());
218 service()->SetSetupInProgress(false); 218 service()->SetSetupInProgress(false);
219 EXPECT_FALSE(observer.first_setup_in_progress()); 219 EXPECT_FALSE(observer.first_setup_in_progress());
220 220
221 service()->RemoveObserver(&observer); 221 service()->RemoveObserver(&observer);
222 } 222 }
223 223
224 // Verify that disable by enterprise policy works. 224 // Verify that disable by enterprise policy works.
225 TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) { 225 TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) {
226 profile()->GetTestingPrefService()->SetManagedPref( 226 profile()->GetTestingPrefService()->SetManagedPref(
227 prefs::kSyncManaged, 227 sync_driver::prefs::kSyncManaged, base::Value::CreateBooleanValue(true));
228 base::Value::CreateBooleanValue(true));
229 IssueTestTokens(); 228 IssueTestTokens();
230 CreateService(browser_sync::AUTO_START); 229 CreateService(browser_sync::AUTO_START);
231 Initialize(); 230 Initialize();
232 EXPECT_TRUE(service()->IsManaged()); 231 EXPECT_TRUE(service()->IsManaged());
233 EXPECT_FALSE(service()->sync_initialized()); 232 EXPECT_FALSE(service()->sync_initialized());
234 } 233 }
235 234
236 // Verify that disable by enterprise policy works even after the backend has 235 // Verify that disable by enterprise policy works even after the backend has
237 // been initialized. 236 // been initialized.
238 TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) { 237 TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) {
239 IssueTestTokens(); 238 IssueTestTokens();
240 CreateService(browser_sync::AUTO_START); 239 CreateService(browser_sync::AUTO_START);
241 ExpectDataTypeManagerCreation(); 240 ExpectDataTypeManagerCreation();
242 ExpectSyncBackendHostCreation(); 241 ExpectSyncBackendHostCreation();
243 Initialize(); 242 Initialize();
244 243
245 EXPECT_FALSE(service()->IsManaged()); 244 EXPECT_FALSE(service()->IsManaged());
246 EXPECT_TRUE(service()->sync_initialized()); 245 EXPECT_TRUE(service()->sync_initialized());
247 246
248 profile()->GetTestingPrefService()->SetManagedPref( 247 profile()->GetTestingPrefService()->SetManagedPref(
249 prefs::kSyncManaged, 248 sync_driver::prefs::kSyncManaged, base::Value::CreateBooleanValue(true));
250 base::Value::CreateBooleanValue(true));
251 249
252 EXPECT_TRUE(service()->IsManaged()); 250 EXPECT_TRUE(service()->IsManaged());
253 EXPECT_FALSE(service()->sync_initialized()); 251 EXPECT_FALSE(service()->sync_initialized());
254 } 252 }
255 253
256 // Exercies the ProfileSyncService's code paths related to getting shut down 254 // Exercies the ProfileSyncService's code paths related to getting shut down
257 // before the backend initialize call returns. 255 // before the backend initialize call returns.
258 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { 256 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) {
259 CreateService(browser_sync::AUTO_START); 257 CreateService(browser_sync::AUTO_START);
260 PrepareDelayedInitSyncBackendHost(); 258 PrepareDelayedInitSyncBackendHost();
261 259
262 IssueTestTokens(); 260 IssueTestTokens();
263 Initialize(); 261 Initialize();
264 EXPECT_FALSE(service()->sync_initialized()); 262 EXPECT_FALSE(service()->sync_initialized());
265 263
266 ShutdownAndDeleteService(); 264 ShutdownAndDeleteService();
267 } 265 }
268 266
269 // Test StopAndSuppress() before we've initialized the backend. 267 // Test StopAndSuppress() before we've initialized the backend.
270 TEST_F(ProfileSyncServiceTest, EarlyStopAndSuppress) { 268 TEST_F(ProfileSyncServiceTest, EarlyStopAndSuppress) {
271 CreateService(browser_sync::AUTO_START); 269 CreateService(browser_sync::AUTO_START);
272 IssueTestTokens(); 270 IssueTestTokens();
273 271
274 service()->StopAndSuppress(); 272 service()->StopAndSuppress();
275 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); 273 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(
274 sync_driver::prefs::kSyncSuppressStart));
276 275
277 // Because of supression, this should fail. 276 // Because of supression, this should fail.
278 Initialize(); 277 Initialize();
279 EXPECT_FALSE(service()->sync_initialized()); 278 EXPECT_FALSE(service()->sync_initialized());
280 279
281 // Remove suppression. This should be enough to allow init to happen. 280 // Remove suppression. This should be enough to allow init to happen.
282 ExpectDataTypeManagerCreation(); 281 ExpectDataTypeManagerCreation();
283 ExpectSyncBackendHostCreation(); 282 ExpectSyncBackendHostCreation();
284 service()->UnsuppressAndStart(); 283 service()->UnsuppressAndStart();
285 EXPECT_TRUE(service()->sync_initialized()); 284 EXPECT_TRUE(service()->sync_initialized());
286 EXPECT_FALSE( 285 EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(
287 profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); 286 sync_driver::prefs::kSyncSuppressStart));
288 } 287 }
289 288
290 // Test StopAndSuppress() after we've initialized the backend. 289 // Test StopAndSuppress() after we've initialized the backend.
291 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { 290 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) {
292 CreateService(browser_sync::AUTO_START); 291 CreateService(browser_sync::AUTO_START);
293 IssueTestTokens(); 292 IssueTestTokens();
294 ExpectDataTypeManagerCreation(); 293 ExpectDataTypeManagerCreation();
295 ExpectSyncBackendHostCreation(); 294 ExpectSyncBackendHostCreation();
296 Initialize(); 295 Initialize();
297 296
298 EXPECT_TRUE(service()->sync_initialized()); 297 EXPECT_TRUE(service()->sync_initialized());
299 EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); 298 EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(
299 sync_driver::prefs::kSyncSuppressStart));
300 300
301 testing::Mock::VerifyAndClearExpectations(components_factory()); 301 testing::Mock::VerifyAndClearExpectations(components_factory());
302 302
303 service()->StopAndSuppress(); 303 service()->StopAndSuppress();
304 EXPECT_FALSE(service()->sync_initialized()); 304 EXPECT_FALSE(service()->sync_initialized());
305 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); 305 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(
306 sync_driver::prefs::kSyncSuppressStart));
306 307
307 ExpectDataTypeManagerCreation(); 308 ExpectDataTypeManagerCreation();
308 ExpectSyncBackendHostCreation(); 309 ExpectSyncBackendHostCreation();
309 310
310 service()->UnsuppressAndStart(); 311 service()->UnsuppressAndStart();
311 EXPECT_TRUE(service()->sync_initialized()); 312 EXPECT_TRUE(service()->sync_initialized());
312 EXPECT_FALSE( 313 EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(
313 profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); 314 sync_driver::prefs::kSyncSuppressStart));
314 } 315 }
315 316
316 // Certain ProfileSyncService tests don't apply to Chrome OS, for example 317 // Certain ProfileSyncService tests don't apply to Chrome OS, for example
317 // things that deal with concepts like "signing out" and policy. 318 // things that deal with concepts like "signing out" and policy.
318 #if !defined (OS_CHROMEOS) 319 #if !defined (OS_CHROMEOS)
319 320
320 TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) { 321 TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) {
321 CreateService(browser_sync::AUTO_START); 322 CreateService(browser_sync::AUTO_START);
322 ExpectDataTypeManagerCreation(); 323 ExpectDataTypeManagerCreation();
323 ExpectSyncBackendHostCreation(); 324 ExpectSyncBackendHostCreation();
324 IssueTestTokens(); 325 IssueTestTokens();
325 Initialize(); 326 Initialize();
326 327
327 EXPECT_TRUE(service()->sync_initialized()); 328 EXPECT_TRUE(service()->sync_initialized());
328 EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); 329 EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(
330 sync_driver::prefs::kSyncSuppressStart));
329 331
330 SigninManagerFactory::GetForProfile(profile())->SignOut(); 332 SigninManagerFactory::GetForProfile(profile())->SignOut();
331 EXPECT_FALSE(service()->sync_initialized()); 333 EXPECT_FALSE(service()->sync_initialized());
332 } 334 }
333 335
334 #endif // !defined(OS_CHROMEOS) 336 #endif // !defined(OS_CHROMEOS)
335 337
336 TEST_F(ProfileSyncServiceTest, GetSyncTokenStatus) { 338 TEST_F(ProfileSyncServiceTest, GetSyncTokenStatus) {
337 CreateService(browser_sync::AUTO_START); 339 CreateService(browser_sync::AUTO_START);
338 IssueTestTokens(); 340 IssueTestTokens();
(...skipping 26 matching lines...) Expand all
365 EXPECT_TRUE(token_status.next_token_request_time.is_null()); 367 EXPECT_TRUE(token_status.next_token_request_time.is_null());
366 368
367 // Simulate successful connection. 369 // Simulate successful connection.
368 service()->OnConnectionStatusChange(syncer::CONNECTION_OK); 370 service()->OnConnectionStatusChange(syncer::CONNECTION_OK);
369 token_status = service()->GetSyncTokenStatus(); 371 token_status = service()->GetSyncTokenStatus();
370 EXPECT_EQ(syncer::CONNECTION_OK, token_status.connection_status); 372 EXPECT_EQ(syncer::CONNECTION_OK, token_status.connection_status);
371 } 373 }
372 374
373 } // namespace 375 } // namespace
374 } // namespace browser_sync 376 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_startup_unittest.cc ('k') | chrome/browser/sync/sessions2/sessions_sync_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698