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

Side by Side Diff: components/browser_sync/profile_sync_service_unittest.cc

Issue 2388163002: [Sync] Move //components/sync to the syncer namespace, take 2. (Closed)
Patch Set: Rebase. Created 4 years, 2 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 (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 "components/browser_sync/profile_sync_service.h" 5 #include "components/browser_sync/profile_sync_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 29 matching lines...) Expand all
40 #include "components/sync/driver/sync_service_observer.h" 40 #include "components/sync/driver/sync_service_observer.h"
41 #include "components/sync/driver/sync_util.h" 41 #include "components/sync/driver/sync_util.h"
42 #include "components/syncable_prefs/testing_pref_service_syncable.h" 42 #include "components/syncable_prefs/testing_pref_service_syncable.h"
43 #include "components/version_info/version_info.h" 43 #include "components/version_info/version_info.h"
44 #include "components/version_info/version_info_values.h" 44 #include "components/version_info/version_info_values.h"
45 #include "google_apis/gaia/gaia_constants.h" 45 #include "google_apis/gaia/gaia_constants.h"
46 #include "testing/gmock/include/gmock/gmock.h" 46 #include "testing/gmock/include/gmock/gmock.h"
47 #include "testing/gtest/include/gtest/gtest.h" 47 #include "testing/gtest/include/gtest/gtest.h"
48 #include "ui/base/l10n/l10n_util.h" 48 #include "ui/base/l10n/l10n_util.h"
49 49
50 using syncer::SyncBackendHostMock;
50 using testing::Return; 51 using testing::Return;
51 52
52 namespace browser_sync { 53 namespace browser_sync {
53 54
54 namespace { 55 namespace {
55 56
56 const char kGaiaId[] = "12345"; 57 const char kGaiaId[] = "12345";
57 const char kEmail[] = "test_user@gmail.com"; 58 const char kEmail[] = "test_user@gmail.com";
58 59
59 class FakeDataTypeManager : public sync_driver::DataTypeManager { 60 class FakeDataTypeManager : public syncer::DataTypeManager {
60 public: 61 public:
61 typedef base::Callback<void(syncer::ConfigureReason)> ConfigureCalled; 62 typedef base::Callback<void(syncer::ConfigureReason)> ConfigureCalled;
62 63
63 explicit FakeDataTypeManager(const ConfigureCalled& configure_called) 64 explicit FakeDataTypeManager(const ConfigureCalled& configure_called)
64 : configure_called_(configure_called) {} 65 : configure_called_(configure_called) {}
65 66
66 ~FakeDataTypeManager() override{}; 67 ~FakeDataTypeManager() override{};
67 68
68 void Configure(syncer::ModelTypeSet desired_types, 69 void Configure(syncer::ModelTypeSet desired_types,
69 syncer::ConfigureReason reason) override { 70 syncer::ConfigureReason reason) override {
70 DCHECK(!configure_called_.is_null()); 71 DCHECK(!configure_called_.is_null());
71 configure_called_.Run(reason); 72 configure_called_.Run(reason);
72 } 73 }
73 74
74 void ReenableType(syncer::ModelType type) override {} 75 void ReenableType(syncer::ModelType type) override {}
75 void ResetDataTypeErrors() override {} 76 void ResetDataTypeErrors() override {}
76 void PurgeForMigration(syncer::ModelTypeSet undesired_types, 77 void PurgeForMigration(syncer::ModelTypeSet undesired_types,
77 syncer::ConfigureReason reason) override {} 78 syncer::ConfigureReason reason) override {}
78 void Stop() override{}; 79 void Stop() override{};
79 State state() const override { 80 State state() const override { return syncer::DataTypeManager::CONFIGURED; };
80 return sync_driver::DataTypeManager::CONFIGURED;
81 };
82 81
83 private: 82 private:
84 ConfigureCalled configure_called_; 83 ConfigureCalled configure_called_;
85 }; 84 };
86 85
87 ACTION_P(ReturnNewDataTypeManager, configure_called) { 86 ACTION_P(ReturnNewDataTypeManager, configure_called) {
88 return new FakeDataTypeManager(configure_called); 87 return new FakeDataTypeManager(configure_called);
89 } 88 }
90 89
91 using testing::Return; 90 using testing::Return;
92 using testing::StrictMock; 91 using testing::StrictMock;
93 using testing::_; 92 using testing::_;
94 93
95 class TestSyncServiceObserver : public sync_driver::SyncServiceObserver { 94 class TestSyncServiceObserver : public syncer::SyncServiceObserver {
96 public: 95 public:
97 explicit TestSyncServiceObserver(ProfileSyncService* service) 96 explicit TestSyncServiceObserver(ProfileSyncService* service)
98 : service_(service), setup_in_progress_(false) {} 97 : service_(service), setup_in_progress_(false) {}
99 void OnStateChanged() override { 98 void OnStateChanged() override {
100 setup_in_progress_ = service_->IsSetupInProgress(); 99 setup_in_progress_ = service_->IsSetupInProgress();
101 } 100 }
102 bool setup_in_progress() const { return setup_in_progress_; } 101 bool setup_in_progress() const { return setup_in_progress_; }
103 102
104 private: 103 private:
105 ProfileSyncService* service_; 104 ProfileSyncService* service_;
106 bool setup_in_progress_; 105 bool setup_in_progress_;
107 }; 106 };
108 107
109 // A variant of the SyncBackendHostMock that won't automatically 108 // A variant of the SyncBackendHostMock that won't automatically
110 // call back when asked to initialized. Allows us to test things 109 // call back when asked to initialized. Allows us to test things
111 // that could happen while backend init is in progress. 110 // that could happen while backend init is in progress.
112 class SyncBackendHostNoReturn : public SyncBackendHostMock { 111 class SyncBackendHostNoReturn : public SyncBackendHostMock {
113 void Initialize( 112 void Initialize(
114 sync_driver::SyncFrontend* frontend, 113 syncer::SyncFrontend* frontend,
115 std::unique_ptr<base::Thread> sync_thread, 114 std::unique_ptr<base::Thread> sync_thread,
116 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, 115 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread,
117 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, 116 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread,
118 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 117 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
119 const GURL& service_url, 118 const GURL& service_url,
120 const std::string& sync_user_agent, 119 const std::string& sync_user_agent,
121 const syncer::SyncCredentials& credentials, 120 const syncer::SyncCredentials& credentials,
122 bool delete_sync_data_folder, 121 bool delete_sync_data_folder,
123 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory, 122 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory,
124 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>& 123 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>&
125 unrecoverable_error_handler, 124 unrecoverable_error_handler,
126 const base::Closure& report_unrecoverable_error_function, 125 const base::Closure& report_unrecoverable_error_function,
127 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, 126 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter,
128 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> 127 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState>
129 saved_nigori_state) override {} 128 saved_nigori_state) override {}
130 }; 129 };
131 130
132 class SyncBackendHostMockCollectDeleteDirParam : public SyncBackendHostMock { 131 class SyncBackendHostMockCollectDeleteDirParam : public SyncBackendHostMock {
133 public: 132 public:
134 explicit SyncBackendHostMockCollectDeleteDirParam( 133 explicit SyncBackendHostMockCollectDeleteDirParam(
135 std::vector<bool>* delete_dir_param) 134 std::vector<bool>* delete_dir_param)
136 : delete_dir_param_(delete_dir_param) {} 135 : delete_dir_param_(delete_dir_param) {}
137 136
138 void Initialize( 137 void Initialize(
139 sync_driver::SyncFrontend* frontend, 138 syncer::SyncFrontend* frontend,
140 std::unique_ptr<base::Thread> sync_thread, 139 std::unique_ptr<base::Thread> sync_thread,
141 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, 140 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread,
142 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, 141 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread,
143 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 142 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
144 const GURL& service_url, 143 const GURL& service_url,
145 const std::string& sync_user_agent, 144 const std::string& sync_user_agent,
146 const syncer::SyncCredentials& credentials, 145 const syncer::SyncCredentials& credentials,
147 bool delete_sync_data_folder, 146 bool delete_sync_data_folder,
148 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory, 147 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory,
149 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>& 148 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>&
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 signin_manager()->SetAuthenticatedAccountInfo(kGaiaId, kEmail); 240 signin_manager()->SetAuthenticatedAccountInfo(kGaiaId, kEmail);
242 component_factory_ = profile_sync_service_bundle_.component_factory(); 241 component_factory_ = profile_sync_service_bundle_.component_factory();
243 ProfileSyncServiceBundle::SyncClientBuilder builder( 242 ProfileSyncServiceBundle::SyncClientBuilder builder(
244 &profile_sync_service_bundle_); 243 &profile_sync_service_bundle_);
245 ProfileSyncService::InitParams init_params = 244 ProfileSyncService::InitParams init_params =
246 profile_sync_service_bundle_.CreateBasicInitParams(behavior, 245 profile_sync_service_bundle_.CreateBasicInitParams(behavior,
247 builder.Build()); 246 builder.Build());
248 247
249 service_.reset(new ProfileSyncService(std::move(init_params))); 248 service_.reset(new ProfileSyncService(std::move(init_params)));
250 service_->RegisterDataTypeController( 249 service_->RegisterDataTypeController(
251 base::MakeUnique<sync_driver::FakeDataTypeController>( 250 base::MakeUnique<syncer::FakeDataTypeController>(syncer::BOOKMARKS));
252 syncer::BOOKMARKS));
253 } 251 }
254 252
255 #if defined(OS_WIN) || defined(OS_MACOSX) || \ 253 #if defined(OS_WIN) || defined(OS_MACOSX) || \
256 (defined(OS_LINUX) && !defined(OS_CHROMEOS)) 254 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
257 void CreateServiceWithoutSignIn() { 255 void CreateServiceWithoutSignIn() {
258 CreateService(ProfileSyncService::AUTO_START); 256 CreateService(ProfileSyncService::AUTO_START);
259 signin_manager()->SignOut(signin_metrics::SIGNOUT_TEST, 257 signin_manager()->SignOut(signin_metrics::SIGNOUT_TEST,
260 signin_metrics::SignoutDelete::IGNORE_METRIC); 258 signin_metrics::SignoutDelete::IGNORE_METRIC);
261 } 259 }
262 #endif 260 #endif
263 261
264 void ShutdownAndDeleteService() { 262 void ShutdownAndDeleteService() {
265 if (service_) 263 if (service_)
266 service_->Shutdown(); 264 service_->Shutdown();
267 service_.reset(); 265 service_.reset();
268 } 266 }
269 267
270 void InitializeForNthSync() { 268 void InitializeForNthSync() {
271 // Set first sync time before initialize to simulate a complete sync setup. 269 // Set first sync time before initialize to simulate a complete sync setup.
272 sync_driver::SyncPrefs sync_prefs(prefs()); 270 syncer::SyncPrefs sync_prefs(prefs());
273 sync_prefs.SetFirstSyncTime(base::Time::Now()); 271 sync_prefs.SetFirstSyncTime(base::Time::Now());
274 sync_prefs.SetFirstSetupComplete(); 272 sync_prefs.SetFirstSetupComplete();
275 sync_prefs.SetKeepEverythingSynced(true); 273 sync_prefs.SetKeepEverythingSynced(true);
276 service_->Initialize(); 274 service_->Initialize();
277 } 275 }
278 276
279 void InitializeForFirstSync() { service_->Initialize(); } 277 void InitializeForFirstSync() { service_->Initialize(); }
280 278
281 void TriggerPassphraseRequired() { 279 void TriggerPassphraseRequired() {
282 service_->OnPassphraseRequired(syncer::REASON_DECRYPTION, 280 service_->OnPassphraseRequired(syncer::REASON_DECRYPTION,
283 sync_pb::EncryptedData()); 281 sync_pb::EncryptedData());
284 } 282 }
285 283
286 void TriggerDataTypeStartRequest() { 284 void TriggerDataTypeStartRequest() {
287 service_->OnDataTypeRequestsSyncStartup(syncer::BOOKMARKS); 285 service_->OnDataTypeRequestsSyncStartup(syncer::BOOKMARKS);
288 } 286 }
289 287
290 void OnConfigureCalled(syncer::ConfigureReason configure_reason) { 288 void OnConfigureCalled(syncer::ConfigureReason configure_reason) {
291 sync_driver::DataTypeManager::ConfigureResult result; 289 syncer::DataTypeManager::ConfigureResult result;
292 result.status = sync_driver::DataTypeManager::OK; 290 result.status = syncer::DataTypeManager::OK;
293 service()->OnConfigureDone(result); 291 service()->OnConfigureDone(result);
294 } 292 }
295 293
296 FakeDataTypeManager::ConfigureCalled GetDefaultConfigureCalledCallback() { 294 FakeDataTypeManager::ConfigureCalled GetDefaultConfigureCalledCallback() {
297 return base::Bind(&ProfileSyncServiceTest::OnConfigureCalled, 295 return base::Bind(&ProfileSyncServiceTest::OnConfigureCalled,
298 base::Unretained(this)); 296 base::Unretained(this));
299 } 297 }
300 298
301 void OnConfigureCalledRecordReason(syncer::ConfigureReason* reason_dest, 299 void OnConfigureCalledRecordReason(syncer::ConfigureReason* reason_dest,
302 syncer::ConfigureReason reason) { 300 syncer::ConfigureReason reason) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 ProfileOAuth2TokenService* auth_service() { 360 ProfileOAuth2TokenService* auth_service() {
363 return profile_sync_service_bundle_.auth_service(); 361 return profile_sync_service_bundle_.auth_service();
364 } 362 }
365 363
366 ProfileSyncService* service() { return service_.get(); } 364 ProfileSyncService* service() { return service_.get(); }
367 365
368 syncable_prefs::TestingPrefServiceSyncable* prefs() { 366 syncable_prefs::TestingPrefServiceSyncable* prefs() {
369 return profile_sync_service_bundle_.pref_service(); 367 return profile_sync_service_bundle_.pref_service();
370 } 368 }
371 369
372 SyncApiComponentFactoryMock* component_factory() { 370 syncer::SyncApiComponentFactoryMock* component_factory() {
373 return component_factory_; 371 return component_factory_;
374 } 372 }
375 373
376 protected: 374 protected:
377 void PumpLoop() { 375 void PumpLoop() {
378 base::RunLoop run_loop; 376 base::RunLoop run_loop;
379 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 377 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
380 run_loop.QuitClosure()); 378 run_loop.QuitClosure());
381 run_loop.Run(); 379 run_loop.Run();
382 } 380 }
383 381
384 private: 382 private:
385 base::MessageLoop message_loop_; 383 base::MessageLoop message_loop_;
386 ProfileSyncServiceBundle profile_sync_service_bundle_; 384 ProfileSyncServiceBundle profile_sync_service_bundle_;
387 std::unique_ptr<ProfileSyncService> service_; 385 std::unique_ptr<ProfileSyncService> service_;
388 386
389 // The current component factory used by sync. May be null if the server 387 // The current component factory used by sync. May be null if the server
390 // hasn't been created yet. 388 // hasn't been created yet.
391 SyncApiComponentFactoryMock* component_factory_; 389 syncer::SyncApiComponentFactoryMock* component_factory_;
392 }; 390 };
393 391
394 // Verify that the server URLs are sane. 392 // Verify that the server URLs are sane.
395 TEST_F(ProfileSyncServiceTest, InitialState) { 393 TEST_F(ProfileSyncServiceTest, InitialState) {
396 CreateService(ProfileSyncService::AUTO_START); 394 CreateService(ProfileSyncService::AUTO_START);
397 InitializeForNthSync(); 395 InitializeForNthSync();
398 const std::string& url = service()->sync_service_url().spec(); 396 const std::string& url = service()->sync_service_url().spec();
399 EXPECT_TRUE(url == internal::kSyncServerUrl || 397 EXPECT_TRUE(url == syncer::internal::kSyncServerUrl ||
400 url == internal::kSyncDevServerUrl); 398 url == syncer::internal::kSyncDevServerUrl);
401 } 399 }
402 400
403 // Verify a successful initialization. 401 // Verify a successful initialization.
404 TEST_F(ProfileSyncServiceTest, SuccessfulInitialization) { 402 TEST_F(ProfileSyncServiceTest, SuccessfulInitialization) {
405 prefs()->SetManagedPref(sync_driver::prefs::kSyncManaged, 403 prefs()->SetManagedPref(syncer::prefs::kSyncManaged,
406 new base::FundamentalValue(false)); 404 new base::FundamentalValue(false));
407 IssueTestTokens(); 405 IssueTestTokens();
408 CreateService(ProfileSyncService::AUTO_START); 406 CreateService(ProfileSyncService::AUTO_START);
409 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 407 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
410 ExpectSyncBackendHostCreation(1); 408 ExpectSyncBackendHostCreation(1);
411 InitializeForNthSync(); 409 InitializeForNthSync();
412 EXPECT_FALSE(service()->IsManaged()); 410 EXPECT_FALSE(service()->IsManaged());
413 EXPECT_TRUE(service()->IsSyncActive()); 411 EXPECT_TRUE(service()->IsSyncActive());
414 } 412 }
415 413
416 // Verify that an initialization where first setup is not complete does not 414 // Verify that an initialization where first setup is not complete does not
417 // start up the backend. 415 // start up the backend.
418 TEST_F(ProfileSyncServiceTest, NeedsConfirmation) { 416 TEST_F(ProfileSyncServiceTest, NeedsConfirmation) {
419 prefs()->SetManagedPref(sync_driver::prefs::kSyncManaged, 417 prefs()->SetManagedPref(syncer::prefs::kSyncManaged,
420 new base::FundamentalValue(false)); 418 new base::FundamentalValue(false));
421 IssueTestTokens(); 419 IssueTestTokens();
422 CreateService(ProfileSyncService::MANUAL_START); 420 CreateService(ProfileSyncService::MANUAL_START);
423 sync_driver::SyncPrefs sync_prefs(prefs()); 421 syncer::SyncPrefs sync_prefs(prefs());
424 base::Time now = base::Time::Now(); 422 base::Time now = base::Time::Now();
425 sync_prefs.SetLastSyncedTime(now); 423 sync_prefs.SetLastSyncedTime(now);
426 sync_prefs.SetKeepEverythingSynced(true); 424 sync_prefs.SetKeepEverythingSynced(true);
427 service()->Initialize(); 425 service()->Initialize();
428 EXPECT_FALSE(service()->IsSyncActive()); 426 EXPECT_FALSE(service()->IsSyncActive());
429 427
430 // The last sync time shouldn't be cleared. 428 // The last sync time shouldn't be cleared.
431 // TODO(zea): figure out a way to check that the directory itself wasn't 429 // TODO(zea): figure out a way to check that the directory itself wasn't
432 // cleared. 430 // cleared.
433 EXPECT_EQ(now, sync_prefs.GetLastSyncedTime()); 431 EXPECT_EQ(now, sync_prefs.GetLastSyncedTime());
(...skipping 11 matching lines...) Expand all
445 auto sync_blocker = service()->GetSetupInProgressHandle(); 443 auto sync_blocker = service()->GetSetupInProgressHandle();
446 EXPECT_TRUE(observer.setup_in_progress()); 444 EXPECT_TRUE(observer.setup_in_progress());
447 sync_blocker.reset(); 445 sync_blocker.reset();
448 EXPECT_FALSE(observer.setup_in_progress()); 446 EXPECT_FALSE(observer.setup_in_progress());
449 447
450 service()->RemoveObserver(&observer); 448 service()->RemoveObserver(&observer);
451 } 449 }
452 450
453 // Verify that disable by enterprise policy works. 451 // Verify that disable by enterprise policy works.
454 TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) { 452 TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) {
455 prefs()->SetManagedPref(sync_driver::prefs::kSyncManaged, 453 prefs()->SetManagedPref(syncer::prefs::kSyncManaged,
456 new base::FundamentalValue(true)); 454 new base::FundamentalValue(true));
457 IssueTestTokens(); 455 IssueTestTokens();
458 CreateService(ProfileSyncService::AUTO_START); 456 CreateService(ProfileSyncService::AUTO_START);
459 InitializeForNthSync(); 457 InitializeForNthSync();
460 EXPECT_TRUE(service()->IsManaged()); 458 EXPECT_TRUE(service()->IsManaged());
461 EXPECT_FALSE(service()->IsSyncActive()); 459 EXPECT_FALSE(service()->IsSyncActive());
462 } 460 }
463 461
464 // Verify that disable by enterprise policy works even after the backend has 462 // Verify that disable by enterprise policy works even after the backend has
465 // been initialized. 463 // been initialized.
466 TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) { 464 TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) {
467 IssueTestTokens(); 465 IssueTestTokens();
468 CreateService(ProfileSyncService::AUTO_START); 466 CreateService(ProfileSyncService::AUTO_START);
469 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 467 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
470 ExpectSyncBackendHostCreation(1); 468 ExpectSyncBackendHostCreation(1);
471 InitializeForNthSync(); 469 InitializeForNthSync();
472 470
473 EXPECT_FALSE(service()->IsManaged()); 471 EXPECT_FALSE(service()->IsManaged());
474 EXPECT_TRUE(service()->IsSyncActive()); 472 EXPECT_TRUE(service()->IsSyncActive());
475 473
476 prefs()->SetManagedPref(sync_driver::prefs::kSyncManaged, 474 prefs()->SetManagedPref(syncer::prefs::kSyncManaged,
477 new base::FundamentalValue(true)); 475 new base::FundamentalValue(true));
478 476
479 EXPECT_TRUE(service()->IsManaged()); 477 EXPECT_TRUE(service()->IsManaged());
480 EXPECT_FALSE(service()->IsSyncActive()); 478 EXPECT_FALSE(service()->IsSyncActive());
481 } 479 }
482 480
483 // Exercies the ProfileSyncService's code paths related to getting shut down 481 // Exercies the ProfileSyncService's code paths related to getting shut down
484 // before the backend initialize call returns. 482 // before the backend initialize call returns.
485 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { 483 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) {
486 CreateService(ProfileSyncService::AUTO_START); 484 CreateService(ProfileSyncService::AUTO_START);
(...skipping 29 matching lines...) Expand all
516 514
517 // Test RequestStop() after we've initialized the backend. 515 // Test RequestStop() after we've initialized the backend.
518 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { 516 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) {
519 CreateService(ProfileSyncService::AUTO_START); 517 CreateService(ProfileSyncService::AUTO_START);
520 IssueTestTokens(); 518 IssueTestTokens();
521 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 519 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
522 ExpectSyncBackendHostCreation(1); 520 ExpectSyncBackendHostCreation(1);
523 InitializeForNthSync(); 521 InitializeForNthSync();
524 522
525 EXPECT_TRUE(service()->IsSyncActive()); 523 EXPECT_TRUE(service()->IsSyncActive());
526 EXPECT_FALSE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart)); 524 EXPECT_FALSE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart));
527 525
528 testing::Mock::VerifyAndClearExpectations(component_factory()); 526 testing::Mock::VerifyAndClearExpectations(component_factory());
529 527
530 service()->RequestStop(ProfileSyncService::KEEP_DATA); 528 service()->RequestStop(ProfileSyncService::KEEP_DATA);
531 EXPECT_FALSE(service()->IsSyncActive()); 529 EXPECT_FALSE(service()->IsSyncActive());
532 EXPECT_TRUE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart)); 530 EXPECT_TRUE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart));
533 531
534 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 532 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
535 ExpectSyncBackendHostCreation(1); 533 ExpectSyncBackendHostCreation(1);
536 534
537 service()->RequestStart(); 535 service()->RequestStart();
538 EXPECT_TRUE(service()->IsSyncActive()); 536 EXPECT_TRUE(service()->IsSyncActive());
539 EXPECT_FALSE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart)); 537 EXPECT_FALSE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart));
540 } 538 }
541 539
542 // Certain ProfileSyncService tests don't apply to Chrome OS, for example 540 // Certain ProfileSyncService tests don't apply to Chrome OS, for example
543 // things that deal with concepts like "signing out" and policy. 541 // things that deal with concepts like "signing out" and policy.
544 #if !defined(OS_CHROMEOS) 542 #if !defined(OS_CHROMEOS)
545 TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) { 543 TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) {
546 CreateService(ProfileSyncService::AUTO_START); 544 CreateService(ProfileSyncService::AUTO_START);
547 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 545 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
548 ExpectSyncBackendHostCreation(1); 546 ExpectSyncBackendHostCreation(1);
549 IssueTestTokens(); 547 IssueTestTokens();
550 InitializeForNthSync(); 548 InitializeForNthSync();
551 549
552 EXPECT_TRUE(service()->IsSyncActive()); 550 EXPECT_TRUE(service()->IsSyncActive());
553 EXPECT_FALSE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart)); 551 EXPECT_FALSE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart));
554 552
555 signin_manager()->SignOut(signin_metrics::SIGNOUT_TEST, 553 signin_manager()->SignOut(signin_metrics::SIGNOUT_TEST,
556 signin_metrics::SignoutDelete::IGNORE_METRIC); 554 signin_metrics::SignoutDelete::IGNORE_METRIC);
557 EXPECT_FALSE(service()->IsSyncActive()); 555 EXPECT_FALSE(service()->IsSyncActive());
558 } 556 }
559 #endif // !defined(OS_CHROMEOS) 557 #endif // !defined(OS_CHROMEOS)
560 558
561 TEST_F(ProfileSyncServiceTest, GetSyncTokenStatus) { 559 TEST_F(ProfileSyncServiceTest, GetSyncTokenStatus) {
562 CreateService(ProfileSyncService::AUTO_START); 560 CreateService(ProfileSyncService::AUTO_START);
563 IssueTestTokens(); 561 IssueTestTokens();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 676
679 // Test Sync will stop after receive memory pressure 677 // Test Sync will stop after receive memory pressure
680 TEST_F(ProfileSyncServiceTest, MemoryPressureRecording) { 678 TEST_F(ProfileSyncServiceTest, MemoryPressureRecording) {
681 CreateService(ProfileSyncService::AUTO_START); 679 CreateService(ProfileSyncService::AUTO_START);
682 IssueTestTokens(); 680 IssueTestTokens();
683 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 681 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
684 ExpectSyncBackendHostCreation(1); 682 ExpectSyncBackendHostCreation(1);
685 InitializeForNthSync(); 683 InitializeForNthSync();
686 684
687 EXPECT_TRUE(service()->IsSyncActive()); 685 EXPECT_TRUE(service()->IsSyncActive());
688 EXPECT_FALSE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart)); 686 EXPECT_FALSE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart));
689 687
690 testing::Mock::VerifyAndClearExpectations(component_factory()); 688 testing::Mock::VerifyAndClearExpectations(component_factory());
691 689
692 sync_driver::SyncPrefs sync_prefs( 690 syncer::SyncPrefs sync_prefs(service()->GetSyncClient()->GetPrefService());
693 service()->GetSyncClient()->GetPrefService());
694 691
695 EXPECT_EQ( 692 EXPECT_EQ(prefs()->GetInteger(syncer::prefs::kSyncMemoryPressureWarningCount),
696 prefs()->GetInteger(sync_driver::prefs::kSyncMemoryPressureWarningCount), 693 0);
697 0);
698 EXPECT_FALSE(sync_prefs.DidSyncShutdownCleanly()); 694 EXPECT_FALSE(sync_prefs.DidSyncShutdownCleanly());
699 695
700 // Simulate memory pressure notification. 696 // Simulate memory pressure notification.
701 base::MemoryPressureListener::NotifyMemoryPressure( 697 base::MemoryPressureListener::NotifyMemoryPressure(
702 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); 698 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
703 base::RunLoop().RunUntilIdle(); 699 base::RunLoop().RunUntilIdle();
704 700
705 // Verify memory pressure recorded. 701 // Verify memory pressure recorded.
706 EXPECT_EQ( 702 EXPECT_EQ(prefs()->GetInteger(syncer::prefs::kSyncMemoryPressureWarningCount),
707 prefs()->GetInteger(sync_driver::prefs::kSyncMemoryPressureWarningCount), 703 1);
708 1);
709 EXPECT_FALSE(sync_prefs.DidSyncShutdownCleanly()); 704 EXPECT_FALSE(sync_prefs.DidSyncShutdownCleanly());
710 705
711 // Simulate memory pressure notification. 706 // Simulate memory pressure notification.
712 base::MemoryPressureListener::NotifyMemoryPressure( 707 base::MemoryPressureListener::NotifyMemoryPressure(
713 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); 708 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
714 base::RunLoop().RunUntilIdle(); 709 base::RunLoop().RunUntilIdle();
715 ShutdownAndDeleteService(); 710 ShutdownAndDeleteService();
716 711
717 // Verify memory pressure and shutdown recorded. 712 // Verify memory pressure and shutdown recorded.
718 EXPECT_EQ( 713 EXPECT_EQ(prefs()->GetInteger(syncer::prefs::kSyncMemoryPressureWarningCount),
719 prefs()->GetInteger(sync_driver::prefs::kSyncMemoryPressureWarningCount), 714 2);
720 2);
721 EXPECT_TRUE(sync_prefs.DidSyncShutdownCleanly()); 715 EXPECT_TRUE(sync_prefs.DidSyncShutdownCleanly());
722 } 716 }
723 717
724 // Verify that OnLocalSetPassphraseEncryption triggers catch up configure sync 718 // Verify that OnLocalSetPassphraseEncryption triggers catch up configure sync
725 // cycle, calls ClearServerData, shuts down and restarts sync. 719 // cycle, calls ClearServerData, shuts down and restarts sync.
726 TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) { 720 TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) {
727 base::test::ScopedFeatureList scoped_feature_list; 721 base::test::ScopedFeatureList scoped_feature_list;
728 scoped_feature_list.InitAndEnableFeature( 722 scoped_feature_list.InitAndEnableFeature(
729 switches::kSyncClearDataOnPassphraseEncryption); 723 switches::kSyncClearDataOnPassphraseEncryption);
730 IssueTestTokens(); 724 IssueTestTokens();
731 CreateService(ProfileSyncService::AUTO_START); 725 CreateService(ProfileSyncService::AUTO_START);
732 726
733 syncer::SyncManager::ClearServerDataCallback captured_callback; 727 syncer::SyncManager::ClearServerDataCallback captured_callback;
734 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; 728 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN;
735 729
736 // Initialize sync, ensure that both DataTypeManager and SyncBackendHost are 730 // Initialize sync, ensure that both DataTypeManager and SyncBackendHost are
737 // initialized and DTM::Configure is called with 731 // initialized and DTM::Configure is called with
738 // CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE. 732 // CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE.
739 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback); 733 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback);
740 ExpectDataTypeManagerCreation( 734 ExpectDataTypeManagerCreation(
741 1, GetRecordingConfigureCalledCallback(&configure_reason)); 735 1, GetRecordingConfigureCalledCallback(&configure_reason));
742 InitializeForNthSync(); 736 InitializeForNthSync();
743 EXPECT_TRUE(service()->IsSyncActive()); 737 EXPECT_TRUE(service()->IsSyncActive());
744 testing::Mock::VerifyAndClearExpectations(component_factory()); 738 testing::Mock::VerifyAndClearExpectations(component_factory());
745 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 739 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
746 sync_driver::DataTypeManager::ConfigureResult result; 740 syncer::DataTypeManager::ConfigureResult result;
747 result.status = sync_driver::DataTypeManager::OK; 741 result.status = syncer::DataTypeManager::OK;
748 service()->OnConfigureDone(result); 742 service()->OnConfigureDone(result);
749 743
750 // Simulate user entering encryption passphrase. Ensure that catch up 744 // Simulate user entering encryption passphrase. Ensure that catch up
751 // configure cycle is started (DTM::Configure is called with 745 // configure cycle is started (DTM::Configure is called with
752 // CONFIGURE_REASON_CATCH_UP). 746 // CONFIGURE_REASON_CATCH_UP).
753 const syncer::SyncEncryptionHandler::NigoriState nigori_state; 747 const syncer::SyncEncryptionHandler::NigoriState nigori_state;
754 service()->OnLocalSetPassphraseEncryption(nigori_state); 748 service()->OnLocalSetPassphraseEncryption(nigori_state);
755 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); 749 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason);
756 EXPECT_TRUE(captured_callback.is_null()); 750 EXPECT_TRUE(captured_callback.is_null());
757 751
(...skipping 22 matching lines...) Expand all
780 scoped_feature_list.InitAndEnableFeature( 774 scoped_feature_list.InitAndEnableFeature(
781 switches::kSyncClearDataOnPassphraseEncryption); 775 switches::kSyncClearDataOnPassphraseEncryption);
782 IssueTestTokens(); 776 IssueTestTokens();
783 CreateService(ProfileSyncService::AUTO_START); 777 CreateService(ProfileSyncService::AUTO_START);
784 ExpectSyncBackendHostCreation(1); 778 ExpectSyncBackendHostCreation(1);
785 ExpectDataTypeManagerCreation( 779 ExpectDataTypeManagerCreation(
786 1, GetRecordingConfigureCalledCallback(&configure_reason)); 780 1, GetRecordingConfigureCalledCallback(&configure_reason));
787 InitializeForNthSync(); 781 InitializeForNthSync();
788 testing::Mock::VerifyAndClearExpectations(component_factory()); 782 testing::Mock::VerifyAndClearExpectations(component_factory());
789 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 783 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
790 sync_driver::DataTypeManager::ConfigureResult result; 784 syncer::DataTypeManager::ConfigureResult result;
791 result.status = sync_driver::DataTypeManager::OK; 785 result.status = syncer::DataTypeManager::OK;
792 service()->OnConfigureDone(result); 786 service()->OnConfigureDone(result);
793 787
794 // Simulate user entering encryption passphrase. Ensure Configure was called 788 // Simulate user entering encryption passphrase. Ensure Configure was called
795 // but don't let it continue. 789 // but don't let it continue.
796 const syncer::SyncEncryptionHandler::NigoriState nigori_state; 790 const syncer::SyncEncryptionHandler::NigoriState nigori_state;
797 service()->OnLocalSetPassphraseEncryption(nigori_state); 791 service()->OnLocalSetPassphraseEncryption(nigori_state);
798 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); 792 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason);
799 793
800 // Simulate browser restart. First configuration is a regular one. 794 // Simulate browser restart. First configuration is a regular one.
801 service()->Shutdown(); 795 service()->Shutdown();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 service()->Shutdown(); 846 service()->Shutdown();
853 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback); 847 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback);
854 ExpectDataTypeManagerCreation( 848 ExpectDataTypeManagerCreation(
855 1, GetRecordingConfigureCalledCallback(&configure_reason)); 849 1, GetRecordingConfigureCalledCallback(&configure_reason));
856 service()->RequestStart(); 850 service()->RequestStart();
857 testing::Mock::VerifyAndClearExpectations(component_factory()); 851 testing::Mock::VerifyAndClearExpectations(component_factory());
858 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 852 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
859 EXPECT_TRUE(captured_callback.is_null()); 853 EXPECT_TRUE(captured_callback.is_null());
860 854
861 // Simulate configure successful. This time it should be catch up. 855 // Simulate configure successful. This time it should be catch up.
862 sync_driver::DataTypeManager::ConfigureResult result; 856 syncer::DataTypeManager::ConfigureResult result;
863 result.status = sync_driver::DataTypeManager::OK; 857 result.status = syncer::DataTypeManager::OK;
864 service()->OnConfigureDone(result); 858 service()->OnConfigureDone(result);
865 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); 859 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason);
866 EXPECT_TRUE(captured_callback.is_null()); 860 EXPECT_TRUE(captured_callback.is_null());
867 861
868 // Simulate catch up configure successful. Ensure that SBH::ClearServerData is 862 // Simulate catch up configure successful. Ensure that SBH::ClearServerData is
869 // called. 863 // called.
870 service()->OnConfigureDone(result); 864 service()->OnConfigureDone(result);
871 EXPECT_FALSE(captured_callback.is_null()); 865 EXPECT_FALSE(captured_callback.is_null());
872 866
873 ExpectSyncBackendHostCreation(1); 867 ExpectSyncBackendHostCreation(1);
874 ExpectDataTypeManagerCreation( 868 ExpectDataTypeManagerCreation(
875 1, GetRecordingConfigureCalledCallback(&configure_reason)); 869 1, GetRecordingConfigureCalledCallback(&configure_reason));
876 captured_callback.Run(); 870 captured_callback.Run();
877 testing::Mock::VerifyAndClearExpectations(component_factory()); 871 testing::Mock::VerifyAndClearExpectations(component_factory());
878 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 872 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
879 } 873 }
880 874
881 // Test that the passphrase prompt due to version change logic gets triggered 875 // Test that the passphrase prompt due to version change logic gets triggered
882 // on a datatype type requesting startup, but only happens once. 876 // on a datatype type requesting startup, but only happens once.
883 TEST_F(ProfileSyncServiceTest, PassphrasePromptDueToVersion) { 877 TEST_F(ProfileSyncServiceTest, PassphrasePromptDueToVersion) {
884 IssueTestTokens(); 878 IssueTestTokens();
885 CreateService(ProfileSyncService::AUTO_START); 879 CreateService(ProfileSyncService::AUTO_START);
886 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 880 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
887 ExpectSyncBackendHostCreation(1); 881 ExpectSyncBackendHostCreation(1);
888 InitializeForNthSync(); 882 InitializeForNthSync();
889 883
890 sync_driver::SyncPrefs sync_prefs( 884 syncer::SyncPrefs sync_prefs(service()->GetSyncClient()->GetPrefService());
891 service()->GetSyncClient()->GetPrefService());
892 EXPECT_EQ(PRODUCT_VERSION, sync_prefs.GetLastRunVersion()); 885 EXPECT_EQ(PRODUCT_VERSION, sync_prefs.GetLastRunVersion());
893 886
894 sync_prefs.SetPassphrasePrompted(true); 887 sync_prefs.SetPassphrasePrompted(true);
895 888
896 // Until a datatype requests startup while a passphrase is required the 889 // Until a datatype requests startup while a passphrase is required the
897 // passphrase prompt bit should remain set. 890 // passphrase prompt bit should remain set.
898 EXPECT_TRUE(sync_prefs.IsPassphrasePrompted()); 891 EXPECT_TRUE(sync_prefs.IsPassphrasePrompted());
899 TriggerPassphraseRequired(); 892 TriggerPassphraseRequired();
900 EXPECT_TRUE(sync_prefs.IsPassphrasePrompted()); 893 EXPECT_TRUE(sync_prefs.IsPassphrasePrompted());
901 894
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 // dereferenced in OnSyncCycleCompleted. The fix is to use find() to check if 955 // dereferenced in OnSyncCycleCompleted. The fix is to use find() to check if
963 // entry for sessions exists in map. 956 // entry for sessions exists in map.
964 TEST_F(ProfileSyncServiceTest, ValidPointersInDTCMap) { 957 TEST_F(ProfileSyncServiceTest, ValidPointersInDTCMap) {
965 CreateService(ProfileSyncService::AUTO_START); 958 CreateService(ProfileSyncService::AUTO_START);
966 service()->OnSessionRestoreComplete(); 959 service()->OnSessionRestoreComplete();
967 service()->OnSyncCycleCompleted(); 960 service()->OnSyncCycleCompleted();
968 } 961 }
969 962
970 } // namespace 963 } // namespace
971 } // namespace browser_sync 964 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/browser_sync/profile_sync_service_typed_url_unittest.cc ('k') | components/browser_sync/profile_sync_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698