OLD | NEW |
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/invalidation/invalidator_storage.h" |
| 14 #include "chrome/browser/signin/oauth2_token_service.h" |
| 15 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
14 #include "chrome/browser/sync/glue/data_type_manager_impl.h" | 17 #include "chrome/browser/sync/glue/data_type_manager_impl.h" |
15 #include "chrome/browser/sync/profile_sync_components_factory_mock.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" |
18 #include "chrome/test/base/profile_mock.h" | 21 #include "chrome/test/base/profile_mock.h" |
19 #include "sync/internal_api/public/test/test_internal_components_factory.h" | 22 #include "sync/internal_api/public/test/test_internal_components_factory.h" |
20 #include "sync/test/engine/test_id_factory.h" | 23 #include "sync/test/engine/test_id_factory.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
22 | 25 |
23 class Profile; | 26 class Profile; |
24 class Task; | 27 class Task; |
25 class TestProfileSyncService; | 28 class TestProfileSyncService; |
26 | 29 |
27 ACTION(ReturnNewDataTypeManager) { | 30 ACTION(ReturnNewDataTypeManager) { |
28 return new browser_sync::DataTypeManagerImpl(arg0, arg1, arg2, arg3, arg4); | 31 return new browser_sync::DataTypeManagerImpl(arg0, arg1, arg2, arg3, arg4); |
29 } | 32 } |
30 | 33 |
31 namespace browser_sync { | 34 namespace browser_sync { |
32 | 35 |
| 36 // MessageLoopRunner::Run() may be called multiple times recursively. Only first |
| 37 // call will execute MessageLoop::current()->Run(). |
| 38 class MessageLoopRunner { |
| 39 public: |
| 40 MessageLoopRunner(); |
| 41 ~MessageLoopRunner(); |
| 42 |
| 43 void Run(); |
| 44 void Quit(); |
| 45 |
| 46 private: |
| 47 bool running_; |
| 48 }; |
| 49 |
33 class SyncBackendHostForProfileSyncTest : public SyncBackendHost { | 50 class SyncBackendHostForProfileSyncTest : public SyncBackendHost { |
34 public: | 51 public: |
35 // |synchronous_init| causes initialization to block until the syncapi has | 52 // |synchronous_init| causes initialization to block until the syncapi has |
36 // completed setting itself up and called us back. | 53 // completed setting itself up and called us back. |
37 // TOOD(akalin): Remove |synchronous_init| (http://crbug.com/140354). | 54 // TOOD(akalin): Remove |synchronous_init| (http://crbug.com/140354). |
38 SyncBackendHostForProfileSyncTest( | 55 SyncBackendHostForProfileSyncTest( |
39 Profile* profile, | 56 Profile* profile, |
40 const base::WeakPtr<SyncPrefs>& sync_prefs, | 57 const base::WeakPtr<SyncPrefs>& sync_prefs, |
41 const base::WeakPtr<invalidation::InvalidatorStorage>& | 58 const base::WeakPtr<invalidation::InvalidatorStorage>& |
42 invalidator_storage, | 59 invalidator_storage, |
43 syncer::TestIdFactory& id_factory, | 60 syncer::TestIdFactory& id_factory, |
44 base::Closure& callback, | 61 base::Closure& callback, |
45 bool set_initial_sync_ended_on_init, | 62 bool set_initial_sync_ended_on_init, |
46 bool synchronous_init, | 63 bool synchronous_init, |
47 bool fail_initial_download, | 64 bool fail_initial_download, |
48 syncer::StorageOption storage_option); | 65 syncer::StorageOption storage_option, |
| 66 MessageLoopRunner* message_loop_runner); |
49 virtual ~SyncBackendHostForProfileSyncTest(); | 67 virtual ~SyncBackendHostForProfileSyncTest(); |
50 | 68 |
51 MOCK_METHOD1(RequestNudge, void(const tracked_objects::Location&)); | 69 MOCK_METHOD1(RequestNudge, void(const tracked_objects::Location&)); |
52 | 70 |
53 virtual void UpdateCredentials( | 71 virtual void UpdateCredentials( |
54 const syncer::SyncCredentials& credentials) OVERRIDE; | 72 const syncer::SyncCredentials& credentials) OVERRIDE; |
55 | 73 |
56 virtual void RequestConfigureSyncer( | 74 virtual void RequestConfigureSyncer( |
57 syncer::ConfigureReason reason, | 75 syncer::ConfigureReason reason, |
58 syncer::ModelTypeSet types_to_config, | 76 syncer::ModelTypeSet types_to_config, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // new credentials. Holds the results of | 115 // new credentials. Holds the results of |
98 // HandleSyncManagerInitializationOnFrontendLoop, and if | 116 // HandleSyncManagerInitializationOnFrontendLoop, and if |
99 // |fail_initial_download_| was true, finishes the initialization process | 117 // |fail_initial_download_| was true, finishes the initialization process |
100 // once we receive new credentials. | 118 // once we receive new credentials. |
101 base::Closure initial_download_closure_; | 119 base::Closure initial_download_closure_; |
102 bool fail_initial_download_; | 120 bool fail_initial_download_; |
103 | 121 |
104 bool set_initial_sync_ended_on_init_; | 122 bool set_initial_sync_ended_on_init_; |
105 bool synchronous_init_; | 123 bool synchronous_init_; |
106 syncer::StorageOption storage_option_; | 124 syncer::StorageOption storage_option_; |
| 125 MessageLoopRunner* message_loop_runner_; |
107 }; | 126 }; |
108 | 127 |
109 } // namespace browser_sync | 128 } // namespace browser_sync |
110 | 129 |
111 class TestProfileSyncService : public ProfileSyncService { | 130 class TestProfileSyncService : public ProfileSyncService { |
112 public: | 131 public: |
113 // TODO(tim): Remove |synchronous_backend_initialization|, and add ability to | 132 // TODO(tim): Remove |synchronous_backend_initialization|, and add ability to |
114 // inject TokenService alongside SigninManager. | 133 // inject TokenService alongside SigninManager. |
115 TestProfileSyncService( | 134 TestProfileSyncService( |
116 ProfileSyncComponentsFactory* factory, | 135 ProfileSyncComponentsFactory* factory, |
117 Profile* profile, | 136 Profile* profile, |
118 SigninManagerBase* signin, | 137 SigninManagerBase* signin, |
119 ProfileSyncService::StartBehavior behavior, | 138 ProfileSyncService::StartBehavior behavior, |
120 bool synchronous_backend_initialization); | 139 bool synchronous_backend_initialization); |
121 | 140 |
122 virtual ~TestProfileSyncService(); | 141 virtual ~TestProfileSyncService(); |
123 | 142 |
| 143 virtual void RequestAccessToken( |
| 144 bool invalidate_previous_token, |
| 145 bool invoke_callback) OVERRIDE; |
| 146 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 147 const GoogleServiceAuthError& error) OVERRIDE; |
| 148 |
124 virtual void OnBackendInitialized( | 149 virtual void OnBackendInitialized( |
125 const syncer::WeakHandle<syncer::JsBackend>& backend, | 150 const syncer::WeakHandle<syncer::JsBackend>& backend, |
126 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 151 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
127 debug_info_listener, | 152 debug_info_listener, |
128 bool success) OVERRIDE; | 153 bool success) OVERRIDE; |
129 | 154 |
130 virtual void OnConfigureDone( | 155 virtual void OnConfigureDone( |
131 const browser_sync::DataTypeManager::ConfigureResult& result) OVERRIDE; | 156 const browser_sync::DataTypeManager::ConfigureResult& result) OVERRIDE; |
132 | 157 |
133 // We implement our own version to avoid some DCHECKs. | 158 // We implement our own version to avoid some DCHECKs. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 197 |
173 // Set to true when a mock data type manager is being used and the configure | 198 // Set to true when a mock data type manager is being used and the configure |
174 // step is performed synchronously. | 199 // step is performed synchronously. |
175 bool synchronous_sync_configuration_; | 200 bool synchronous_sync_configuration_; |
176 | 201 |
177 base::Closure callback_; | 202 base::Closure callback_; |
178 bool set_initial_sync_ended_on_init_; | 203 bool set_initial_sync_ended_on_init_; |
179 | 204 |
180 bool fail_initial_download_; | 205 bool fail_initial_download_; |
181 syncer::StorageOption storage_option_; | 206 syncer::StorageOption storage_option_; |
| 207 browser_sync::MessageLoopRunner message_loop_runner_; |
| 208 }; |
| 209 |
| 210 |
| 211 class FakeOAuth2TokenService : public ProfileOAuth2TokenService { |
| 212 public: |
| 213 explicit FakeOAuth2TokenService(net::URLRequestContextGetter* getter) |
| 214 : ProfileOAuth2TokenService(getter) {} |
| 215 |
| 216 virtual scoped_ptr<OAuth2TokenService::Request> StartRequest( |
| 217 const OAuth2TokenService::ScopeSet& scopes, |
| 218 OAuth2TokenService::Consumer* consumer); |
| 219 |
| 220 static BrowserContextKeyedService* BuildTokenService( |
| 221 content::BrowserContext* context); |
182 }; | 222 }; |
183 | 223 |
184 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ | 224 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |
OLD | NEW |