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

Side by Side Diff: trunk/src/chrome/browser/sync/test_profile_sync_service.h

Issue 98323003: Revert 238348 "Clean up TestProfileSyncService and related tests" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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 #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ 6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/invalidation/invalidator_storage.h"
13 #include "chrome/browser/signin/profile_oauth2_token_service.h" 14 #include "chrome/browser/signin/profile_oauth2_token_service.h"
15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
14 #include "chrome/browser/sync/glue/data_type_manager_impl.h" 16 #include "chrome/browser/sync/glue/data_type_manager_impl.h"
15 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" 17 #include "chrome/browser/sync/glue/sync_backend_host_impl.h"
18 #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
16 #include "chrome/browser/sync/profile_sync_service.h" 19 #include "chrome/browser/sync/profile_sync_service.h"
17 #include "chrome/browser/sync/sync_prefs.h" 20 #include "chrome/browser/sync/sync_prefs.h"
21 #include "chrome/test/base/profile_mock.h"
22 #include "google_apis/gaia/oauth2_token_service.h"
23 #include "sync/internal_api/public/test/test_internal_components_factory.h"
18 #include "sync/test/engine/test_id_factory.h" 24 #include "sync/test/engine/test_id_factory.h"
19 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
20 26
21 class Profile; 27 class Profile;
22 class ProfileOAuth2TokenService;
23 class ProfileSyncComponentsFactory;
24 class ProfileSyncComponentsFactoryMock;
25 28
26 ACTION(ReturnNewDataTypeManager) { 29 ACTION(ReturnNewDataTypeManager) {
27 return new browser_sync::DataTypeManagerImpl(arg0, 30 return new browser_sync::DataTypeManagerImpl(arg0,
28 arg1, 31 arg1,
29 arg2, 32 arg2,
30 arg3, 33 arg3,
31 arg4, 34 arg4,
32 arg5); 35 arg5);
33 } 36 }
34 37
35 namespace browser_sync { 38 namespace browser_sync {
36 39
37 class SyncBackendHostForProfileSyncTest : public SyncBackendHostImpl { 40 class SyncBackendHostForProfileSyncTest : public SyncBackendHostImpl {
38 public: 41 public:
42 // |synchronous_init| causes initialization to block until the syncapi has
43 // completed setting itself up and called us back.
44 // TOOD(akalin): Remove |synchronous_init| (http://crbug.com/140354).
39 SyncBackendHostForProfileSyncTest( 45 SyncBackendHostForProfileSyncTest(
40 Profile* profile, 46 Profile* profile,
41 const base::WeakPtr<SyncPrefs>& sync_prefs, 47 const base::WeakPtr<SyncPrefs>& sync_prefs,
42 base::Closure& callback); 48 base::Closure& callback,
49 bool set_initial_sync_ended_on_init,
50 bool synchronous_init,
51 bool fail_initial_download,
52 syncer::StorageOption storage_option);
43 virtual ~SyncBackendHostForProfileSyncTest(); 53 virtual ~SyncBackendHostForProfileSyncTest();
44 54
55 MOCK_METHOD1(RequestNudge, void(const tracked_objects::Location&));
56
57 virtual void UpdateCredentials(
58 const syncer::SyncCredentials& credentials) OVERRIDE;
59
45 virtual void RequestConfigureSyncer( 60 virtual void RequestConfigureSyncer(
46 syncer::ConfigureReason reason, 61 syncer::ConfigureReason reason,
47 syncer::ModelTypeSet to_download, 62 syncer::ModelTypeSet to_download,
48 syncer::ModelTypeSet to_purge, 63 syncer::ModelTypeSet to_purge,
49 syncer::ModelTypeSet to_journal, 64 syncer::ModelTypeSet to_journal,
50 syncer::ModelTypeSet to_unapply, 65 syncer::ModelTypeSet to_unapply,
51 syncer::ModelTypeSet to_ignore, 66 syncer::ModelTypeSet to_ignore,
52 const syncer::ModelSafeRoutingInfo& routing_info, 67 const syncer::ModelSafeRoutingInfo& routing_info,
53 const base::Callback<void(syncer::ModelTypeSet, 68 const base::Callback<void(syncer::ModelTypeSet,
54 syncer::ModelTypeSet)>& ready_task, 69 syncer::ModelTypeSet)>& ready_task,
55 const base::Closure& retry_callback) OVERRIDE; 70 const base::Closure& retry_callback) OVERRIDE;
56 71
72 virtual void HandleInitializationSuccessOnFrontendLoop(
73 const syncer::WeakHandle<syncer::JsBackend> js_backend,
74 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>
75 debug_info_listener) OVERRIDE;
76
57 protected: 77 protected:
58 virtual void InitCore(scoped_ptr<DoInitializeOptions> options) OVERRIDE; 78 virtual void InitCore(scoped_ptr<DoInitializeOptions> options) OVERRIDE;
59 79
60 private: 80 private:
81
82
61 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop. 83 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop.
62 // Allows extra initialization work to be performed before the backend comes 84 // Allows extra initialization work to be performed before the backend comes
63 // up. 85 // up.
64 base::Closure& callback_; 86 base::Closure& callback_;
87
88 // Saved closure in case we failed the initial download but then received
89 // new credentials. Holds the results of
90 // HandleSyncManagerInitializationOnFrontendLoop, and if
91 // |fail_initial_download_| was true, finishes the initialization process
92 // once we receive new credentials.
93 base::Closure initial_download_closure_;
94 bool fail_initial_download_;
95
96 bool set_initial_sync_ended_on_init_;
97 bool synchronous_init_;
98 syncer::StorageOption storage_option_;
99
100 base::WeakPtrFactory<SyncBackendHostForProfileSyncTest> weak_ptr_factory_;
65 }; 101 };
66 102
67 } // namespace browser_sync 103 } // namespace browser_sync
68 104
69 class TestProfileSyncService : public ProfileSyncService { 105 class TestProfileSyncService : public ProfileSyncService {
70 public: 106 public:
71 // TODO(tim): Add ability to inject TokenService alongside SigninManager. 107 // TODO(tim): Remove |synchronous_backend_initialization|, and add ability to
108 // inject TokenService alongside SigninManager.
72 // TODO(rogerta): what does above comment mean? 109 // TODO(rogerta): what does above comment mean?
73 TestProfileSyncService( 110 TestProfileSyncService(
74 ProfileSyncComponentsFactory* factory, 111 ProfileSyncComponentsFactory* factory,
75 Profile* profile, 112 Profile* profile,
76 SigninManagerBase* signin, 113 SigninManagerBase* signin,
77 ProfileOAuth2TokenService* oauth2_token_service, 114 ProfileOAuth2TokenService* oauth2_token_service,
78 ProfileSyncService::StartBehavior behavior); 115 ProfileSyncService::StartBehavior behavior,
116 bool synchronous_backend_initialization);
79 117
80 virtual ~TestProfileSyncService(); 118 virtual ~TestProfileSyncService();
81 119
120 virtual void RequestAccessToken() OVERRIDE;
121 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
122 const std::string& access_token,
123 const base::Time& expiration_time) OVERRIDE;
124 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
125 const GoogleServiceAuthError& error) OVERRIDE;
126
127 virtual void OnBackendInitialized(
128 const syncer::WeakHandle<syncer::JsBackend>& backend,
129 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
130 debug_info_listener,
131 bool success) OVERRIDE;
132
82 virtual void OnConfigureDone( 133 virtual void OnConfigureDone(
83 const browser_sync::DataTypeManager::ConfigureResult& result) OVERRIDE; 134 const browser_sync::DataTypeManager::ConfigureResult& result) OVERRIDE;
84 135
85 // We implement our own version to avoid some DCHECKs. 136 // We implement our own version to avoid some DCHECKs.
86 virtual syncer::UserShare* GetUserShare() const OVERRIDE; 137 virtual syncer::UserShare* GetUserShare() const OVERRIDE;
87 138
88 static BrowserContextKeyedService* BuildAutoStartAsyncInit( 139 static BrowserContextKeyedService* BuildAutoStartAsyncInit(
89 content::BrowserContext* profile); 140 content::BrowserContext* profile);
90 141
91 ProfileSyncComponentsFactoryMock* components_factory_mock(); 142 ProfileSyncComponentsFactoryMock* components_factory_mock();
92 143
144 // If this is called, configuring data types will require a syncer
145 // nudge.
146 void dont_set_initial_sync_ended_on_init();
147 void set_synchronous_sync_configuration();
148
149 // Fails initial download until a new auth token is provided.
150 void fail_initial_download();
151
152 void set_storage_option(syncer::StorageOption option);
153
93 // |callback| can be used to populate nodes before the OnBackendInitialized 154 // |callback| can be used to populate nodes before the OnBackendInitialized
94 // callback fires. 155 // callback fires.
95 void set_backend_init_callback(const base::Closure& callback) { 156 void set_backend_init_callback(const base::Closure& callback) {
96 callback_ = callback; 157 callback_ = callback;
97 } 158 }
98 159
99 syncer::TestIdFactory* id_factory(); 160 syncer::TestIdFactory* id_factory();
100 161
162 // Override of ProfileSyncService::GetBackendForTest() with a more
163 // specific return type (since C++ supports covariant return types)
164 // that is made public.
165 virtual browser_sync::SyncBackendHostForProfileSyncTest*
166 GetBackendForTest() OVERRIDE;
167
101 protected: 168 protected:
102 virtual void CreateBackend() OVERRIDE; 169 virtual void CreateBackend() OVERRIDE;
103 170
104 // Return NULL handle to use in backend initialization to avoid receiving 171 // Return NULL handle to use in backend initialization to avoid receiving
105 // js messages on UI loop when it's being destroyed, which are not deleted 172 // js messages on UI loop when it's being destroyed, which are not deleted
106 // and cause memory leak in test. 173 // and cause memory leak in test.
107 virtual syncer::WeakHandle<syncer::JsEventHandler> GetJsEventHandler() 174 virtual syncer::WeakHandle<syncer::JsEventHandler> GetJsEventHandler()
108 OVERRIDE; 175 OVERRIDE;
109 176
110 private: 177 private:
111 syncer::TestIdFactory id_factory_; 178 syncer::TestIdFactory id_factory_;
112 179
180 bool synchronous_backend_initialization_;
181
182 // Set to true when a mock data type manager is being used and the configure
183 // step is performed synchronously.
184 bool synchronous_sync_configuration_;
185
113 base::Closure callback_; 186 base::Closure callback_;
187 bool set_initial_sync_ended_on_init_;
188
189 bool fail_initial_download_;
190 syncer::StorageOption storage_option_;
114 }; 191 };
115 192
116 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ 193 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698