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

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

Issue 2936623002: Implement dumb URLLoader{Factory} for ServiceWorker script loading (for try)
Patch Set: . Created 3 years, 6 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
« no previous file with comments | « no previous file | content/browser/payments/payment_app_content_unittest_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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"
30 #include "content/browser/service_worker/service_worker_storage.h" 32 #include "content/browser/service_worker/service_worker_storage.h"
31 #include "content/browser/storage_partition_impl.h" 33 #include "content/browser/storage_partition_impl.h"
32 #include "content/public/browser/background_sync_parameters.h" 34 #include "content/public/browser/background_sync_parameters.h"
33 #include "content/public/browser/permission_type.h" 35 #include "content/public/browser/permission_type.h"
34 #include "content/public/test/background_sync_test_util.h" 36 #include "content/public/test/background_sync_test_util.h"
35 #include "content/public/test/test_browser_context.h" 37 #include "content/public/test/test_browser_context.h"
36 #include "content/public/test/test_browser_thread_bundle.h" 38 #include "content/public/test/test_browser_thread_bundle.h"
37 #include "content/test/mock_background_sync_controller.h" 39 #include "content/test/mock_background_sync_controller.h"
38 #include "content/test/mock_permission_manager.h" 40 #include "content/test/mock_permission_manager.h"
39 #include "content/test/test_background_sync_manager.h" 41 #include "content/test/test_background_sync_manager.h"
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 } 440 }
439 441
440 TEST_F(BackgroundSyncManagerTest, RegistrationIntact) { 442 TEST_F(BackgroundSyncManagerTest, RegistrationIntact) {
441 EXPECT_TRUE(Register(sync_options_1_)); 443 EXPECT_TRUE(Register(sync_options_1_));
442 EXPECT_STREQ(sync_options_1_.tag.c_str(), 444 EXPECT_STREQ(sync_options_1_.tag.c_str(),
443 callback_registration_->options()->tag.c_str()); 445 callback_registration_->options()->tag.c_str());
444 EXPECT_TRUE(callback_registration_->IsValid()); 446 EXPECT_TRUE(callback_registration_->IsValid());
445 } 447 }
446 448
447 TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) { 449 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());
448 sw_registration_1_ = nullptr; 470 sw_registration_1_ = nullptr;
471
449 EXPECT_FALSE(Register(sync_options_1_)); 472 EXPECT_FALSE(Register(sync_options_1_));
450 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); 473 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_);
451 } 474 }
452 475
453 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) { 476 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) {
454 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version()); 477 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version());
455 EXPECT_FALSE(Register(sync_options_1_)); 478 EXPECT_FALSE(Register(sync_options_1_));
456 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); 479 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_);
457 } 480 }
458 481
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 // Run it again. 1336 // Run it again.
1314 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); 1337 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta());
1315 test_background_sync_manager_->delayed_task().Run(); 1338 test_background_sync_manager_->delayed_task().Run();
1316 base::RunLoop().RunUntilIdle(); 1339 base::RunLoop().RunUntilIdle();
1317 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1340 EXPECT_FALSE(GetRegistration(sync_options_1_));
1318 EXPECT_EQ(blink::mojom::BackgroundSyncEventLastChance::IS_LAST_CHANCE, 1341 EXPECT_EQ(blink::mojom::BackgroundSyncEventLastChance::IS_LAST_CHANCE,
1319 test_background_sync_manager_->last_chance()); 1342 test_background_sync_manager_->last_chance());
1320 } 1343 }
1321 1344
1322 } // namespace content 1345 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/payments/payment_app_content_unittest_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698