OLD | NEW |
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_manager.h" | 5 #include "content/browser/background_sync/background_sync_manager.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> |
| 11 #include <vector> |
11 | 12 |
12 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
13 #include "base/location.h" | 14 #include "base/location.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
17 #include "base/metrics/field_trial.h" | 18 #include "base/metrics/field_trial.h" |
18 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
19 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
20 #include "base/test/mock_entropy_provider.h" | 21 #include "base/test/mock_entropy_provider.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 BackgroundSyncStatus status, | 201 BackgroundSyncStatus status, |
201 std::unique_ptr<BackgroundSyncRegistration> registration) { | 202 std::unique_ptr<BackgroundSyncRegistration> registration) { |
202 *was_called = true; | 203 *was_called = true; |
203 callback_status_ = status; | 204 callback_status_ = status; |
204 callback_registration_ = std::move(registration); | 205 callback_registration_ = std::move(registration); |
205 } | 206 } |
206 | 207 |
207 void StatusAndRegistrationsCallback( | 208 void StatusAndRegistrationsCallback( |
208 bool* was_called, | 209 bool* was_called, |
209 BackgroundSyncStatus status, | 210 BackgroundSyncStatus status, |
210 std::unique_ptr<ScopedVector<BackgroundSyncRegistration>> registrations) { | 211 std::unique_ptr<std::vector<std::unique_ptr<BackgroundSyncRegistration>>> |
| 212 registrations) { |
211 *was_called = true; | 213 *was_called = true; |
212 callback_status_ = status; | 214 callback_status_ = status; |
213 callback_registrations_ = std::move(registrations); | 215 callback_registrations_ = std::move(registrations); |
214 } | 216 } |
215 | 217 |
216 void StatusCallback(bool* was_called, BackgroundSyncStatus status) { | 218 void StatusCallback(bool* was_called, BackgroundSyncStatus status) { |
217 *was_called = true; | 219 *was_called = true; |
218 callback_status_ = status; | 220 callback_status_ = status; |
219 } | 221 } |
220 | 222 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 base::Unretained(this), &was_called)); | 303 base::Unretained(this), &was_called)); |
302 base::RunLoop().RunUntilIdle(); | 304 base::RunLoop().RunUntilIdle(); |
303 EXPECT_TRUE(was_called); | 305 EXPECT_TRUE(was_called); |
304 | 306 |
305 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) { | 307 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) { |
306 for (auto iter = callback_registrations_->begin(); | 308 for (auto iter = callback_registrations_->begin(); |
307 iter < callback_registrations_->end(); ++iter) { | 309 iter < callback_registrations_->end(); ++iter) { |
308 if ((*iter)->options()->tag == registration_options.tag) { | 310 if ((*iter)->options()->tag == registration_options.tag) { |
309 // Transfer the matching registration out of the vector into | 311 // Transfer the matching registration out of the vector into |
310 // callback_registration_ for testing. | 312 // callback_registration_ for testing. |
311 callback_registration_.reset(*iter); | 313 callback_registration_ = std::move(*iter); |
312 callback_registrations_->weak_erase(iter); | 314 callback_registrations_->erase(iter); |
313 return true; | 315 return true; |
314 } | 316 } |
315 } | 317 } |
316 } | 318 } |
317 return false; | 319 return false; |
318 } | 320 } |
319 | 321 |
320 bool GetRegistrations() { | 322 bool GetRegistrations() { |
321 return GetRegistrationsWithServiceWorkerId(sw_registration_id_1_); | 323 return GetRegistrationsWithServiceWorkerId(sw_registration_id_1_); |
322 } | 324 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 int64_t sw_registration_id_2_; | 420 int64_t sw_registration_id_2_; |
419 scoped_refptr<ServiceWorkerRegistration> sw_registration_1_; | 421 scoped_refptr<ServiceWorkerRegistration> sw_registration_1_; |
420 scoped_refptr<ServiceWorkerRegistration> sw_registration_2_; | 422 scoped_refptr<ServiceWorkerRegistration> sw_registration_2_; |
421 | 423 |
422 BackgroundSyncRegistrationOptions sync_options_1_; | 424 BackgroundSyncRegistrationOptions sync_options_1_; |
423 BackgroundSyncRegistrationOptions sync_options_2_; | 425 BackgroundSyncRegistrationOptions sync_options_2_; |
424 | 426 |
425 // Callback values. | 427 // Callback values. |
426 BackgroundSyncStatus callback_status_ = BACKGROUND_SYNC_STATUS_OK; | 428 BackgroundSyncStatus callback_status_ = BACKGROUND_SYNC_STATUS_OK; |
427 std::unique_ptr<BackgroundSyncRegistration> callback_registration_; | 429 std::unique_ptr<BackgroundSyncRegistration> callback_registration_; |
428 std::unique_ptr<ScopedVector<BackgroundSyncRegistration>> | 430 std::unique_ptr<std::vector<std::unique_ptr<BackgroundSyncRegistration>>> |
429 callback_registrations_; | 431 callback_registrations_; |
430 ServiceWorkerStatusCode callback_sw_status_code_ = SERVICE_WORKER_OK; | 432 ServiceWorkerStatusCode callback_sw_status_code_ = SERVICE_WORKER_OK; |
431 int sync_events_called_ = 0; | 433 int sync_events_called_ = 0; |
432 ServiceWorkerVersion::StatusCallback sync_fired_callback_; | 434 ServiceWorkerVersion::StatusCallback sync_fired_callback_; |
433 }; | 435 }; |
434 | 436 |
435 TEST_F(BackgroundSyncManagerTest, Register) { | 437 TEST_F(BackgroundSyncManagerTest, Register) { |
436 EXPECT_TRUE(Register(sync_options_1_)); | 438 EXPECT_TRUE(Register(sync_options_1_)); |
437 } | 439 } |
438 | 440 |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 // Run it again. | 1314 // Run it again. |
1313 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); | 1315 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); |
1314 test_background_sync_manager_->delayed_task().Run(); | 1316 test_background_sync_manager_->delayed_task().Run(); |
1315 base::RunLoop().RunUntilIdle(); | 1317 base::RunLoop().RunUntilIdle(); |
1316 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1318 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
1317 EXPECT_EQ(blink::mojom::BackgroundSyncEventLastChance::IS_LAST_CHANCE, | 1319 EXPECT_EQ(blink::mojom::BackgroundSyncEventLastChance::IS_LAST_CHANCE, |
1318 test_background_sync_manager_->last_chance()); | 1320 test_background_sync_manager_->last_chance()); |
1319 } | 1321 } |
1320 | 1322 |
1321 } // namespace content | 1323 } // namespace content |
OLD | NEW |