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 #include <vector> |
12 | 12 |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "base/metrics/field_trial.h" | 18 #include "base/metrics/field_trial.h" |
19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
21 #include "base/test/mock_entropy_provider.h" | 21 #include "base/test/mock_entropy_provider.h" |
22 #include "base/test/simple_test_clock.h" | 22 #include "base/test/simple_test_clock.h" |
23 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
24 #include "content/browser/background_sync/background_sync_network_observer.h" | 24 #include "content/browser/background_sync/background_sync_network_observer.h" |
25 #include "content/browser/background_sync/background_sync_status.h" | 25 #include "content/browser/background_sync/background_sync_status.h" |
26 #include "content/browser/browser_thread_impl.h" | 26 #include "content/browser/browser_thread_impl.h" |
27 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 27 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
28 #include "content/browser/service_worker/service_worker_context_core.h" | 28 #include "content/browser/service_worker/service_worker_context_core.h" |
29 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 29 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
30 #include "content/browser/service_worker/service_worker_dispatcher_host.h" | |
31 #include "content/browser/service_worker/service_worker_registration_handle.h" | |
32 #include "content/browser/service_worker/service_worker_storage.h" | 30 #include "content/browser/service_worker/service_worker_storage.h" |
33 #include "content/browser/storage_partition_impl.h" | 31 #include "content/browser/storage_partition_impl.h" |
34 #include "content/public/browser/background_sync_parameters.h" | 32 #include "content/public/browser/background_sync_parameters.h" |
35 #include "content/public/browser/permission_type.h" | 33 #include "content/public/browser/permission_type.h" |
36 #include "content/public/test/background_sync_test_util.h" | 34 #include "content/public/test/background_sync_test_util.h" |
37 #include "content/public/test/test_browser_context.h" | 35 #include "content/public/test/test_browser_context.h" |
38 #include "content/public/test/test_browser_thread_bundle.h" | 36 #include "content/public/test/test_browser_thread_bundle.h" |
39 #include "content/test/mock_background_sync_controller.h" | 37 #include "content/test/mock_background_sync_controller.h" |
40 #include "content/test/mock_permission_manager.h" | 38 #include "content/test/mock_permission_manager.h" |
41 #include "content/test/test_background_sync_manager.h" | 39 #include "content/test/test_background_sync_manager.h" |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 } | 438 } |
441 | 439 |
442 TEST_F(BackgroundSyncManagerTest, RegistrationIntact) { | 440 TEST_F(BackgroundSyncManagerTest, RegistrationIntact) { |
443 EXPECT_TRUE(Register(sync_options_1_)); | 441 EXPECT_TRUE(Register(sync_options_1_)); |
444 EXPECT_STREQ(sync_options_1_.tag.c_str(), | 442 EXPECT_STREQ(sync_options_1_.tag.c_str(), |
445 callback_registration_->options()->tag.c_str()); | 443 callback_registration_->options()->tag.c_str()); |
446 EXPECT_TRUE(callback_registration_->IsValid()); | 444 EXPECT_TRUE(callback_registration_->IsValid()); |
447 } | 445 } |
448 | 446 |
449 TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) { | 447 TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) { |
450 // Get a provider host which is used to install the service worker. | |
451 ASSERT_TRUE(sw_registration_1_->active_version()); | |
452 ASSERT_FALSE(sw_registration_1_->waiting_version()); | |
453 ASSERT_FALSE(sw_registration_1_->installing_version()); | |
454 ServiceWorkerProviderHost* provider_host = | |
455 sw_registration_1_->active_version()->provider_host(); | |
456 ASSERT_TRUE(provider_host); | |
457 int process_id = provider_host->process_id(); | |
458 int provider_id = provider_host->provider_id(); | |
459 | |
460 // Remove the registration handle registered on the dispatcher host. | |
461 ServiceWorkerDispatcherHost* dispatcher_host = | |
462 helper_->context()->GetDispatcherHost(process_id); | |
463 ServiceWorkerRegistrationHandle* handle = | |
464 dispatcher_host->FindRegistrationHandle(provider_id, | |
465 sw_registration_1_->id()); | |
466 dispatcher_host->OnDecrementRegistrationRefCount(handle->handle_id()); | |
467 | |
468 // Ensure |sw_registration_1_| is the last reference to the registration. | |
469 ASSERT_TRUE(sw_registration_1_->HasOneRef()); | |
470 sw_registration_1_ = nullptr; | 448 sw_registration_1_ = nullptr; |
471 | |
472 EXPECT_FALSE(Register(sync_options_1_)); | 449 EXPECT_FALSE(Register(sync_options_1_)); |
473 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); | 450 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); |
474 } | 451 } |
475 | 452 |
476 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) { | 453 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) { |
477 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version()); | 454 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version()); |
478 EXPECT_FALSE(Register(sync_options_1_)); | 455 EXPECT_FALSE(Register(sync_options_1_)); |
479 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); | 456 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); |
480 } | 457 } |
481 | 458 |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 // Run it again. | 1313 // Run it again. |
1337 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); | 1314 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); |
1338 test_background_sync_manager_->delayed_task().Run(); | 1315 test_background_sync_manager_->delayed_task().Run(); |
1339 base::RunLoop().RunUntilIdle(); | 1316 base::RunLoop().RunUntilIdle(); |
1340 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1317 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
1341 EXPECT_EQ(blink::mojom::BackgroundSyncEventLastChance::IS_LAST_CHANCE, | 1318 EXPECT_EQ(blink::mojom::BackgroundSyncEventLastChance::IS_LAST_CHANCE, |
1342 test_background_sync_manager_->last_chance()); | 1319 test_background_sync_manager_->last_chance()); |
1343 } | 1320 } |
1344 | 1321 |
1345 } // namespace content | 1322 } // namespace content |
OLD | NEW |