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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ 6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ 7 8 #include <string> 9 10 #include "base/callback.h" 11 #include "base/compiler_specific.h" 12 #include "base/memory/weak_ptr.h" 13 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" 14 #include "chrome/browser/sync/profile_sync_service.h" 15 #include "components/signin/core/browser/profile_oauth2_token_service.h" 16 #include "components/sync_driver/data_type_manager_impl.h" 17 #include "components/sync_driver/sync_prefs.h" 18 #include "sync/test/engine/test_id_factory.h" 19 #include "testing/gmock/include/gmock/gmock.h" 20 21 class Profile; 22 class ProfileOAuth2TokenService; 23 class ProfileSyncComponentsFactory; 24 class ProfileSyncComponentsFactoryMock; 25 26 ACTION(ReturnNewDataTypeManager) { 27 return new sync_driver::DataTypeManagerImpl(base::Closure(), 28 arg0, 29 arg1, 30 arg2, 31 arg3, 32 arg4); 33 } 34 35 namespace browser_sync { 36 37 class SyncBackendHostForProfileSyncTest : public SyncBackendHostImpl { 38 public: 39 SyncBackendHostForProfileSyncTest( 40 Profile* profile, 41 invalidation::InvalidationService* invalidator, 42 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, 43 base::Closure callback); 44 virtual ~SyncBackendHostForProfileSyncTest(); 45 46 virtual void RequestConfigureSyncer( 47 syncer::ConfigureReason reason, 48 syncer::ModelTypeSet to_download, 49 syncer::ModelTypeSet to_purge, 50 syncer::ModelTypeSet to_journal, 51 syncer::ModelTypeSet to_unapply, 52 syncer::ModelTypeSet to_ignore, 53 const syncer::ModelSafeRoutingInfo& routing_info, 54 const base::Callback<void(syncer::ModelTypeSet, 55 syncer::ModelTypeSet)>& ready_task, 56 const base::Closure& retry_callback) OVERRIDE; 57 58 protected: 59 virtual void InitCore(scoped_ptr<DoInitializeOptions> options) OVERRIDE; 60 61 private: 62 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop. 63 // Allows extra initialization work to be performed before the backend comes 64 // up. 65 base::Closure callback_; 66 }; 67 68 } // namespace browser_sync 69 70 class TestProfileSyncService : public ProfileSyncService { 71 public: 72 // TODO(tim): Add ability to inject TokenService alongside SigninManager. 73 // TODO(rogerta): what does above comment mean? 74 TestProfileSyncService( 75 scoped_ptr<ProfileSyncComponentsFactory> factory, 76 Profile* profile, 77 SigninManagerBase* signin, 78 ProfileOAuth2TokenService* oauth2_token_service, 79 browser_sync::ProfileSyncServiceStartBehavior behavior); 80 81 virtual ~TestProfileSyncService(); 82 83 virtual void OnConfigureDone( 84 const sync_driver::DataTypeManager::ConfigureResult& result) OVERRIDE; 85 86 // We implement our own version to avoid some DCHECKs. 87 virtual syncer::UserShare* GetUserShare() const OVERRIDE; 88 89 static TestProfileSyncService* BuildAutoStartAsyncInit( 90 Profile* profile, base::Closure callback); 91 92 ProfileSyncComponentsFactoryMock* components_factory_mock(); 93 94 syncer::TestIdFactory* id_factory(); 95 96 // Raise visibility to ease testing. 97 using ProfileSyncService::NotifyObservers; 98 99 protected: 100 static KeyedService* TestFactoryFunction(content::BrowserContext* profile); 101 102 // Return NULL handle to use in backend initialization to avoid receiving 103 // js messages on UI loop when it's being destroyed, which are not deleted 104 // and cause memory leak in test. 105 virtual syncer::WeakHandle<syncer::JsEventHandler> GetJsEventHandler() 106 OVERRIDE; 107 108 virtual bool NeedBackup() const OVERRIDE; 109 110 private: 111 syncer::TestIdFactory id_factory_; 112 }; 113 114 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ 115