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

Side by Side Diff: content/browser/background_sync/background_sync_service_impl_unittest.cc

Issue 1282013004: BackgroundSyncManager tracks client registrations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed test Created 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/background_sync/background_sync_service_impl.h" 5 #include "content/browser/background_sync/background_sync_service_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/power_monitor/power_monitor.h" 10 #include "base/power_monitor/power_monitor.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 void RemoveWindowClient() { 164 void RemoveWindowClient() {
165 sw_registration_->active_version()->RemoveControllee(provider_host_.get()); 165 sw_registration_->active_version()->RemoveControllee(provider_host_.get());
166 } 166 }
167 167
168 void CreateBackgroundSyncServiceImpl() { 168 void CreateBackgroundSyncServiceImpl() {
169 // Create a dummy mojo channel so that the BackgroundSyncServiceImpl can be 169 // Create a dummy mojo channel so that the BackgroundSyncServiceImpl can be
170 // instantiated 170 // instantiated
171 mojo::InterfaceRequest<BackgroundSyncService> service_request = 171 mojo::InterfaceRequest<BackgroundSyncService> service_request =
172 mojo::GetProxy(&service_ptr_); 172 mojo::GetProxy(&service_ptr_);
173 // Create a new BackgroundSyncServiceImpl bound to the dummy channel 173 // Create a new BackgroundSyncServiceImpl bound to the dummy channel
174 service_impl_.reset(new BackgroundSyncServiceImpl( 174 background_sync_context_->CreateService(service_request.Pass());
175 background_sync_context_.get(), service_request.Pass()));
176 base::RunLoop().RunUntilIdle(); 175 base::RunLoop().RunUntilIdle();
176
177 service_impl_ = *background_sync_context_->services_.begin();
178 ASSERT_TRUE(service_impl_);
177 } 179 }
178 180
179 // Helpers for testing BackgroundSyncServiceImpl methods 181 // Helpers for testing BackgroundSyncServiceImpl methods
180 void RegisterOneShot( 182 void RegisterOneShot(
181 SyncRegistrationPtr sync, 183 SyncRegistrationPtr sync,
182 const BackgroundSyncService::RegisterCallback& callback) { 184 const BackgroundSyncService::RegisterCallback& callback) {
183 service_impl_->Register(sync.Pass(), sw_registration_id_, 185 service_impl_->Register(sync.Pass(), sw_registration_id_,
184 true /* requested_from_service_worker */, callback); 186 true /* requested_from_service_worker */, callback);
185 base::RunLoop().RunUntilIdle(); 187 base::RunLoop().RunUntilIdle();
186 } 188 }
187 189
188 void RegisterOneShotFromDocument( 190 void RegisterOneShotFromDocument(
189 SyncRegistrationPtr sync, 191 SyncRegistrationPtr sync,
190 const BackgroundSyncService::RegisterCallback& callback) { 192 const BackgroundSyncService::RegisterCallback& callback) {
191 service_impl_->Register(sync.Pass(), sw_registration_id_, 193 service_impl_->Register(sync.Pass(), sw_registration_id_,
192 false /* requested_from_service_worker */, 194 false /* requested_from_service_worker */,
193 callback); 195 callback);
194 base::RunLoop().RunUntilIdle(); 196 base::RunLoop().RunUntilIdle();
195 } 197 }
196 198
197 void UnregisterOneShot( 199 void UnregisterOneShot(
198 SyncRegistrationPtr sync, 200 SyncRegistrationPtr sync,
199 const BackgroundSyncService::UnregisterCallback& callback) { 201 const BackgroundSyncService::UnregisterCallback& callback) {
200 service_impl_->Unregister( 202 service_impl_->Unregister(
201 BackgroundSyncPeriodicity::BACKGROUND_SYNC_PERIODICITY_ONE_SHOT, 203 BackgroundSyncPeriodicity::BACKGROUND_SYNC_PERIODICITY_ONE_SHOT,
202 sync->id, sync->tag, sw_registration_id_, callback); 204 sync->handle_id, sw_registration_id_, callback);
203 base::RunLoop().RunUntilIdle(); 205 base::RunLoop().RunUntilIdle();
204 } 206 }
205 207
206 void GetRegistrationOneShot( 208 void GetRegistrationOneShot(
207 const mojo::String& tag, 209 const mojo::String& tag,
208 const BackgroundSyncService::RegisterCallback& callback) { 210 const BackgroundSyncService::RegisterCallback& callback) {
209 service_impl_->GetRegistration( 211 service_impl_->GetRegistration(
210 BackgroundSyncPeriodicity::BACKGROUND_SYNC_PERIODICITY_ONE_SHOT, tag, 212 BackgroundSyncPeriodicity::BACKGROUND_SYNC_PERIODICITY_ONE_SHOT, tag,
211 sw_registration_id_, callback); 213 sw_registration_id_, callback);
212 base::RunLoop().RunUntilIdle(); 214 base::RunLoop().RunUntilIdle();
213 } 215 }
214 216
215 void GetRegistrationsOneShot( 217 void GetRegistrationsOneShot(
216 const BackgroundSyncService::GetRegistrationsCallback& callback) { 218 const BackgroundSyncService::GetRegistrationsCallback& callback) {
217 service_impl_->GetRegistrations( 219 service_impl_->GetRegistrations(
218 BackgroundSyncPeriodicity::BACKGROUND_SYNC_PERIODICITY_ONE_SHOT, 220 BackgroundSyncPeriodicity::BACKGROUND_SYNC_PERIODICITY_ONE_SHOT,
219 sw_registration_id_, callback); 221 sw_registration_id_, callback);
220 base::RunLoop().RunUntilIdle(); 222 base::RunLoop().RunUntilIdle();
221 } 223 }
222 224
223 scoped_ptr<TestBrowserThreadBundle> thread_bundle_; 225 scoped_ptr<TestBrowserThreadBundle> thread_bundle_;
224 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 226 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
225 scoped_ptr<EmbeddedWorkerTestHelper> embedded_worker_helper_; 227 scoped_ptr<EmbeddedWorkerTestHelper> embedded_worker_helper_;
226 scoped_ptr<base::PowerMonitor> power_monitor_; 228 scoped_ptr<base::PowerMonitor> power_monitor_;
227 scoped_refptr<BackgroundSyncContextImpl> background_sync_context_; 229 scoped_refptr<BackgroundSyncContextImpl> background_sync_context_;
228 scoped_ptr<ServiceWorkerProviderHost> provider_host_; 230 scoped_ptr<ServiceWorkerProviderHost> provider_host_;
229 int64 sw_registration_id_; 231 int64 sw_registration_id_;
230 scoped_refptr<ServiceWorkerRegistration> sw_registration_; 232 scoped_refptr<ServiceWorkerRegistration> sw_registration_;
231 BackgroundSyncServicePtr service_ptr_; 233 BackgroundSyncServicePtr service_ptr_;
232 scoped_ptr<BackgroundSyncServiceImpl> service_impl_; 234 BackgroundSyncServiceImpl*
235 service_impl_; // Owned by background_sync_context_
233 SyncRegistrationPtr default_sync_registration_; 236 SyncRegistrationPtr default_sync_registration_;
234 }; 237 };
235 238
236 // Tests 239 // Tests
237 240
238 TEST_F(BackgroundSyncServiceImplTest, Register) { 241 TEST_F(BackgroundSyncServiceImplTest, Register) {
239 bool called = false; 242 bool called = false;
240 BackgroundSyncError error; 243 BackgroundSyncError error;
241 SyncRegistrationPtr reg; 244 SyncRegistrationPtr reg;
242 RegisterOneShot( 245 RegisterOneShot(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 288 }
286 289
287 TEST_F(BackgroundSyncServiceImplTest, Unregister) { 290 TEST_F(BackgroundSyncServiceImplTest, Unregister) {
288 bool unregister_called = false; 291 bool unregister_called = false;
289 BackgroundSyncError unregister_error; 292 BackgroundSyncError unregister_error;
290 SyncRegistrationPtr reg; 293 SyncRegistrationPtr reg;
291 UnregisterOneShot( 294 UnregisterOneShot(
292 default_sync_registration_.Clone(), 295 default_sync_registration_.Clone(),
293 base::Bind(&ErrorCallback, &unregister_called, &unregister_error)); 296 base::Bind(&ErrorCallback, &unregister_called, &unregister_error));
294 EXPECT_TRUE(unregister_called); 297 EXPECT_TRUE(unregister_called);
295 EXPECT_EQ(BackgroundSyncError::BACKGROUND_SYNC_ERROR_NOT_FOUND, 298 EXPECT_EQ(BackgroundSyncError::BACKGROUND_SYNC_ERROR_NOT_ALLOWED,
296 unregister_error); 299 unregister_error);
297 } 300 }
298 301
299 TEST_F(BackgroundSyncServiceImplTest, UnregisterWithRegisteredSync) { 302 TEST_F(BackgroundSyncServiceImplTest, UnregisterWithRegisteredSync) {
300 bool register_called = false; 303 bool register_called = false;
301 bool unregister_called = false; 304 bool unregister_called = false;
302 BackgroundSyncError register_error; 305 BackgroundSyncError register_error;
303 BackgroundSyncError unregister_error; 306 BackgroundSyncError unregister_error;
304 SyncRegistrationPtr reg; 307 SyncRegistrationPtr reg;
305 RegisterOneShot(default_sync_registration_.Clone(), 308 RegisterOneShot(default_sync_registration_.Clone(),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 GetRegistrationsOneShot(base::Bind(&ErrorAndRegistrationListCallback, 373 GetRegistrationsOneShot(base::Bind(&ErrorAndRegistrationListCallback,
371 &getregistrations_called, 374 &getregistrations_called,
372 &getregistrations_error, &array_size)); 375 &getregistrations_error, &array_size));
373 EXPECT_TRUE(getregistrations_called); 376 EXPECT_TRUE(getregistrations_called);
374 EXPECT_EQ(BackgroundSyncError::BACKGROUND_SYNC_ERROR_NONE, 377 EXPECT_EQ(BackgroundSyncError::BACKGROUND_SYNC_ERROR_NONE,
375 getregistrations_error); 378 getregistrations_error);
376 EXPECT_EQ(1UL, array_size); 379 EXPECT_EQ(1UL, array_size);
377 } 380 }
378 381
379 } // namespace content 382 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698