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

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

Issue 2345843003: [Sync] Merge //components/browser_sync into one directory. (Closed)
Patch Set: Address comment + rebase. Created 4 years, 3 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/browser/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
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/feature_list.h" 14 #include "base/feature_list.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/test/scoped_feature_list.h" 20 #include "base/test/scoped_feature_list.h"
21 #include "base/test/sequenced_worker_pool_owner.h" 21 #include "base/test/sequenced_worker_pool_owner.h"
22 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/values.h" 23 #include "base/values.h"
24 #include "build/build_config.h" 24 #include "build/build_config.h"
25 #include "components/browser_sync/browser/profile_sync_test_util.h" 25 #include "components/browser_sync/browser_sync_switches.h"
26 #include "components/browser_sync/common/browser_sync_switches.h" 26 #include "components/browser_sync/profile_sync_test_util.h"
27 #include "components/invalidation/impl/profile_invalidation_provider.h" 27 #include "components/invalidation/impl/profile_invalidation_provider.h"
28 #include "components/invalidation/public/invalidation_service.h" 28 #include "components/invalidation/public/invalidation_service.h"
29 #include "components/signin/core/browser/account_tracker_service.h" 29 #include "components/signin/core/browser/account_tracker_service.h"
30 #include "components/signin/core/browser/fake_signin_manager.h" 30 #include "components/signin/core/browser/fake_signin_manager.h"
31 #include "components/strings/grit/components_strings.h" 31 #include "components/strings/grit/components_strings.h"
32 #include "components/sync/driver/data_type_manager.h" 32 #include "components/sync/driver/data_type_manager.h"
33 #include "components/sync/driver/data_type_manager_observer.h" 33 #include "components/sync/driver/data_type_manager_observer.h"
34 #include "components/sync/driver/fake_data_type_controller.h" 34 #include "components/sync/driver/fake_data_type_controller.h"
35 #include "components/sync/driver/glue/sync_backend_host_mock.h" 35 #include "components/sync/driver/glue/sync_backend_host_mock.h"
36 #include "components/sync/driver/pref_names.h" 36 #include "components/sync/driver/pref_names.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 const base::Closure& report_unrecoverable_error_function, 126 const base::Closure& report_unrecoverable_error_function,
127 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, 127 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter,
128 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> 128 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState>
129 saved_nigori_state) override {} 129 saved_nigori_state) override {}
130 }; 130 };
131 131
132 class SyncBackendHostMockCollectDeleteDirParam : public SyncBackendHostMock { 132 class SyncBackendHostMockCollectDeleteDirParam : public SyncBackendHostMock {
133 public: 133 public:
134 explicit SyncBackendHostMockCollectDeleteDirParam( 134 explicit SyncBackendHostMockCollectDeleteDirParam(
135 std::vector<bool>* delete_dir_param) 135 std::vector<bool>* delete_dir_param)
136 : delete_dir_param_(delete_dir_param) {} 136 : delete_dir_param_(delete_dir_param) {}
137 137
138 void Initialize( 138 void Initialize(
139 sync_driver::SyncFrontend* frontend, 139 sync_driver::SyncFrontend* frontend,
140 std::unique_ptr<base::Thread> sync_thread, 140 std::unique_ptr<base::Thread> sync_thread,
141 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, 141 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread,
142 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, 142 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread,
143 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 143 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
144 const GURL& service_url, 144 const GURL& service_url,
145 const std::string& sync_user_agent, 145 const std::string& sync_user_agent,
146 const syncer::SyncCredentials& credentials, 146 const syncer::SyncCredentials& credentials,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 270
271 void InitializeForNthSync() { 271 void InitializeForNthSync() {
272 // Set first sync time before initialize to simulate a complete sync setup. 272 // Set first sync time before initialize to simulate a complete sync setup.
273 sync_driver::SyncPrefs sync_prefs(prefs()); 273 sync_driver::SyncPrefs sync_prefs(prefs());
274 sync_prefs.SetFirstSyncTime(base::Time::Now()); 274 sync_prefs.SetFirstSyncTime(base::Time::Now());
275 sync_prefs.SetFirstSetupComplete(); 275 sync_prefs.SetFirstSetupComplete();
276 sync_prefs.SetKeepEverythingSynced(true); 276 sync_prefs.SetKeepEverythingSynced(true);
277 service_->Initialize(); 277 service_->Initialize();
278 } 278 }
279 279
280 void InitializeForFirstSync() { 280 void InitializeForFirstSync() { service_->Initialize(); }
281 service_->Initialize();
282 }
283 281
284 void TriggerPassphraseRequired() { 282 void TriggerPassphraseRequired() {
285 service_->OnPassphraseRequired(syncer::REASON_DECRYPTION, 283 service_->OnPassphraseRequired(syncer::REASON_DECRYPTION,
286 sync_pb::EncryptedData()); 284 sync_pb::EncryptedData());
287 } 285 }
288 286
289 void TriggerDataTypeStartRequest() { 287 void TriggerDataTypeStartRequest() {
290 service_->OnDataTypeRequestsSyncStartup(syncer::BOOKMARKS); 288 service_->OnDataTypeRequestsSyncStartup(syncer::BOOKMARKS);
291 } 289 }
292 290
(...skipping 28 matching lines...) Expand all
321 .WillRepeatedly(ReturnNewDataTypeManager(callback)); 319 .WillRepeatedly(ReturnNewDataTypeManager(callback));
322 } 320 }
323 321
324 void ExpectSyncBackendHostCreation(int times) { 322 void ExpectSyncBackendHostCreation(int times) {
325 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _)) 323 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _))
326 .Times(times) 324 .Times(times)
327 .WillRepeatedly(ReturnNewSyncBackendHostMock()); 325 .WillRepeatedly(ReturnNewSyncBackendHostMock());
328 } 326 }
329 327
330 void ExpectSyncBackendHostCreationCollectDeleteDir( 328 void ExpectSyncBackendHostCreationCollectDeleteDir(
331 int times, std::vector<bool> *delete_dir_param) { 329 int times,
330 std::vector<bool>* delete_dir_param) {
332 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _)) 331 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _))
333 .Times(times) 332 .Times(times)
334 .WillRepeatedly( 333 .WillRepeatedly(
335 ReturnNewMockHostCollectDeleteDirParam(delete_dir_param)); 334 ReturnNewMockHostCollectDeleteDirParam(delete_dir_param));
336 } 335 }
337 336
338 void ExpectSyncBackendHostCreationCaptureClearServerData( 337 void ExpectSyncBackendHostCreationCaptureClearServerData(
339 syncer::SyncManager::ClearServerDataCallback* captured_callback) { 338 syncer::SyncManager::ClearServerDataCallback* captured_callback) {
340 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _)) 339 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _))
341 .Times(1) 340 .Times(1)
(...skipping 16 matching lines...) Expand all
358 #endif 357 #endif
359 // Opening brace is outside of macro to avoid confusing lint. 358 // Opening brace is outside of macro to avoid confusing lint.
360 { 359 {
361 return profile_sync_service_bundle_.signin_manager(); 360 return profile_sync_service_bundle_.signin_manager();
362 } 361 }
363 362
364 ProfileOAuth2TokenService* auth_service() { 363 ProfileOAuth2TokenService* auth_service() {
365 return profile_sync_service_bundle_.auth_service(); 364 return profile_sync_service_bundle_.auth_service();
366 } 365 }
367 366
368 ProfileSyncService* service() { 367 ProfileSyncService* service() { return service_.get(); }
369 return service_.get();
370 }
371 368
372 syncable_prefs::TestingPrefServiceSyncable* prefs() { 369 syncable_prefs::TestingPrefServiceSyncable* prefs() {
373 return profile_sync_service_bundle_.pref_service(); 370 return profile_sync_service_bundle_.pref_service();
374 } 371 }
375 372
376 SyncApiComponentFactoryMock* component_factory() { 373 SyncApiComponentFactoryMock* component_factory() {
377 return component_factory_; 374 return component_factory_;
378 } 375 }
379 376
380 protected: 377 protected:
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 535 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
539 ExpectSyncBackendHostCreation(1); 536 ExpectSyncBackendHostCreation(1);
540 537
541 service()->RequestStart(); 538 service()->RequestStart();
542 EXPECT_TRUE(service()->IsSyncActive()); 539 EXPECT_TRUE(service()->IsSyncActive());
543 EXPECT_FALSE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart)); 540 EXPECT_FALSE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart));
544 } 541 }
545 542
546 // Certain ProfileSyncService tests don't apply to Chrome OS, for example 543 // Certain ProfileSyncService tests don't apply to Chrome OS, for example
547 // things that deal with concepts like "signing out" and policy. 544 // things that deal with concepts like "signing out" and policy.
548 #if !defined (OS_CHROMEOS) 545 #if !defined(OS_CHROMEOS)
549 TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) { 546 TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) {
550 CreateService(ProfileSyncService::AUTO_START); 547 CreateService(ProfileSyncService::AUTO_START);
551 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 548 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
552 ExpectSyncBackendHostCreation(1); 549 ExpectSyncBackendHostCreation(1);
553 IssueTestTokens(); 550 IssueTestTokens();
554 InitializeForNthSync(); 551 InitializeForNthSync();
555 552
556 EXPECT_TRUE(service()->IsSyncActive()); 553 EXPECT_TRUE(service()->IsSyncActive());
557 EXPECT_FALSE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart)); 554 EXPECT_FALSE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart));
558 555
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 // dereferenced in OnSyncCycleCompleted. The fix is to use find() to check if 963 // dereferenced in OnSyncCycleCompleted. The fix is to use find() to check if
967 // entry for sessions exists in map. 964 // entry for sessions exists in map.
968 TEST_F(ProfileSyncServiceTest, ValidPointersInDTCMap) { 965 TEST_F(ProfileSyncServiceTest, ValidPointersInDTCMap) {
969 CreateService(ProfileSyncService::AUTO_START); 966 CreateService(ProfileSyncService::AUTO_START);
970 service()->OnSessionRestoreComplete(); 967 service()->OnSessionRestoreComplete();
971 service()->OnSyncCycleCompleted(); 968 service()->OnSyncCycleCompleted();
972 } 969 }
973 970
974 } // namespace 971 } // namespace
975 } // namespace browser_sync 972 } // 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