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

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

Issue 2954433002: BackgroundSync: Convert to base::BindOnce/OnceCallback/OnceClosure (Closed)
Patch Set: rename local variable Created 3 years, 5 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 ->GetNetworkObserverForTesting(); 157 ->GetNetworkObserverForTesting();
158 network_observer->NotifyManagerIfNetworkChangedForTesting( 158 network_observer->NotifyManagerIfNetworkChangedForTesting(
159 net::NetworkChangeNotifier::CONNECTION_NONE); 159 net::NetworkChangeNotifier::CONNECTION_NONE);
160 base::RunLoop().RunUntilIdle(); 160 base::RunLoop().RunUntilIdle();
161 } 161 }
162 162
163 void CreateServiceWorkerRegistration() { 163 void CreateServiceWorkerRegistration() {
164 bool called = false; 164 bool called = false;
165 embedded_worker_helper_->context()->RegisterServiceWorker( 165 embedded_worker_helper_->context()->RegisterServiceWorker(
166 GURL(kServiceWorkerPattern), GURL(kServiceWorkerScript), NULL, 166 GURL(kServiceWorkerPattern), GURL(kServiceWorkerScript), NULL,
167 base::Bind(&RegisterServiceWorkerCallback, &called, 167 base::AdaptCallbackForRepeating(base::BindOnce(
168 &sw_registration_id_)); 168 &RegisterServiceWorkerCallback, &called, &sw_registration_id_)));
169 base::RunLoop().RunUntilIdle(); 169 base::RunLoop().RunUntilIdle();
170 EXPECT_TRUE(called); 170 EXPECT_TRUE(called);
171 171
172 embedded_worker_helper_->context_wrapper()->FindReadyRegistrationForId( 172 embedded_worker_helper_->context_wrapper()->FindReadyRegistrationForId(
173 sw_registration_id_, GURL(kServiceWorkerPattern).GetOrigin(), 173 sw_registration_id_, GURL(kServiceWorkerPattern).GetOrigin(),
174 base::Bind(FindServiceWorkerRegistrationCallback, &sw_registration_)); 174 base::AdaptCallbackForRepeating(base::BindOnce(
175 FindServiceWorkerRegistrationCallback, &sw_registration_)));
175 base::RunLoop().RunUntilIdle(); 176 base::RunLoop().RunUntilIdle();
176 EXPECT_TRUE(sw_registration_); 177 EXPECT_TRUE(sw_registration_);
177 } 178 }
178 179
179 void CreateBackgroundSyncServiceImpl() { 180 void CreateBackgroundSyncServiceImpl() {
180 // Create a dummy mojo channel so that the BackgroundSyncServiceImpl can be 181 // Create a dummy mojo channel so that the BackgroundSyncServiceImpl can be
181 // instantiated. 182 // instantiated.
182 mojo::InterfaceRequest<blink::mojom::BackgroundSyncService> 183 mojo::InterfaceRequest<blink::mojom::BackgroundSyncService>
183 service_request = mojo::MakeRequest(&service_ptr_); 184 service_request = mojo::MakeRequest(&service_ptr_);
184 // Create a new BackgroundSyncServiceImpl bound to the dummy channel. 185 // Create a new BackgroundSyncServiceImpl bound to the dummy channel.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 service_impl_; // Owned by background_sync_context_ 218 service_impl_; // Owned by background_sync_context_
218 blink::mojom::SyncRegistrationPtr default_sync_registration_; 219 blink::mojom::SyncRegistrationPtr default_sync_registration_;
219 }; 220 };
220 221
221 // Tests 222 // Tests
222 223
223 TEST_F(BackgroundSyncServiceImplTest, Register) { 224 TEST_F(BackgroundSyncServiceImplTest, Register) {
224 bool called = false; 225 bool called = false;
225 blink::mojom::BackgroundSyncError error; 226 blink::mojom::BackgroundSyncError error;
226 blink::mojom::SyncRegistrationPtr reg; 227 blink::mojom::SyncRegistrationPtr reg;
227 Register(default_sync_registration_.Clone(), 228 Register(
228 base::Bind(&ErrorAndRegistrationCallback, &called, &error, &reg)); 229 default_sync_registration_.Clone(),
230 base::BindOnce(&ErrorAndRegistrationCallback, &called, &error, &reg));
229 EXPECT_TRUE(called); 231 EXPECT_TRUE(called);
230 EXPECT_EQ(blink::mojom::BackgroundSyncError::NONE, error); 232 EXPECT_EQ(blink::mojom::BackgroundSyncError::NONE, error);
231 EXPECT_EQ("", reg->tag); 233 EXPECT_EQ("", reg->tag);
232 } 234 }
233 235
234 TEST_F(BackgroundSyncServiceImplTest, GetRegistrations) { 236 TEST_F(BackgroundSyncServiceImplTest, GetRegistrations) {
235 bool called = false; 237 bool called = false;
236 blink::mojom::BackgroundSyncError error; 238 blink::mojom::BackgroundSyncError error;
237 unsigned long array_size = 0UL; 239 unsigned long array_size = 0UL;
238 GetRegistrations(base::Bind(&ErrorAndRegistrationListCallback, &called, 240 GetRegistrations(base::BindOnce(&ErrorAndRegistrationListCallback, &called,
239 &error, &array_size)); 241 &error, &array_size));
240 EXPECT_TRUE(called); 242 EXPECT_TRUE(called);
241 EXPECT_EQ(blink::mojom::BackgroundSyncError::NONE, error); 243 EXPECT_EQ(blink::mojom::BackgroundSyncError::NONE, error);
242 EXPECT_EQ(0UL, array_size); 244 EXPECT_EQ(0UL, array_size);
243 } 245 }
244 246
245 TEST_F(BackgroundSyncServiceImplTest, GetRegistrationsWithRegisteredSync) { 247 TEST_F(BackgroundSyncServiceImplTest, GetRegistrationsWithRegisteredSync) {
246 bool register_called = false; 248 bool register_called = false;
247 bool getregistrations_called = false; 249 bool get_registrations_called = false;
248 blink::mojom::BackgroundSyncError register_error; 250 blink::mojom::BackgroundSyncError register_error;
249 blink::mojom::BackgroundSyncError getregistrations_error; 251 blink::mojom::BackgroundSyncError getregistrations_error;
250 blink::mojom::SyncRegistrationPtr register_reg; 252 blink::mojom::SyncRegistrationPtr register_reg;
251 unsigned long array_size = 0UL; 253 unsigned long array_size = 0UL;
252 Register(default_sync_registration_.Clone(), 254 Register(default_sync_registration_.Clone(),
253 base::Bind(&ErrorAndRegistrationCallback, &register_called, 255 base::BindOnce(&ErrorAndRegistrationCallback, &register_called,
254 &register_error, &register_reg)); 256 &register_error, &register_reg));
255 EXPECT_TRUE(register_called); 257 EXPECT_TRUE(register_called);
256 EXPECT_EQ(blink::mojom::BackgroundSyncError::NONE, register_error); 258 EXPECT_EQ(blink::mojom::BackgroundSyncError::NONE, register_error);
257 GetRegistrations(base::Bind(&ErrorAndRegistrationListCallback, 259 GetRegistrations(base::BindOnce(&ErrorAndRegistrationListCallback,
258 &getregistrations_called, &getregistrations_error, 260 &get_registrations_called,
259 &array_size)); 261 &getregistrations_error, &array_size));
260 EXPECT_TRUE(getregistrations_called); 262 EXPECT_TRUE(get_registrations_called);
261 EXPECT_EQ(blink::mojom::BackgroundSyncError::NONE, getregistrations_error); 263 EXPECT_EQ(blink::mojom::BackgroundSyncError::NONE, getregistrations_error);
262 EXPECT_EQ(1UL, array_size); 264 EXPECT_EQ(1UL, array_size);
263 } 265 }
264 266
265 } // namespace content 267 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698