| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/service_worker/foreign_fetch_request_handler.h" | 5 #include "content/browser/service_worker/foreign_fetch_request_handler.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/test/simple_test_tick_clock.h" | 9 #include "base/test/simple_test_tick_clock.h" |
| 10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 void SetUp() override { | 66 void SetUp() override { |
| 67 const GURL kScope("https://valid.example.com/scope/"); | 67 const GURL kScope("https://valid.example.com/scope/"); |
| 68 const GURL kResource1("https://valid.example.com/scope/sw.js"); | 68 const GURL kResource1("https://valid.example.com/scope/sw.js"); |
| 69 const int64_t kRegistrationId = 0; | 69 const int64_t kRegistrationId = 0; |
| 70 const int64_t kVersionId = 0; | 70 const int64_t kVersionId = 0; |
| 71 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); | 71 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); |
| 72 | 72 |
| 73 // Create a registration for the worker which has foreign fetch event | 73 // Create a registration for the worker which has foreign fetch event |
| 74 // handler. | 74 // handler. |
| 75 registration_ = new ServiceWorkerRegistration(kScope, kRegistrationId, | 75 registration_ = |
| 76 context()->AsWeakPtr()); | 76 new ServiceWorkerRegistration(ServiceWorkerRegistrationOptions(kScope), |
| 77 kRegistrationId, context()->AsWeakPtr()); |
| 77 version_ = new ServiceWorkerVersion(registration_.get(), kResource1, | 78 version_ = new ServiceWorkerVersion(registration_.get(), kResource1, |
| 78 kVersionId, context()->AsWeakPtr()); | 79 kVersionId, context()->AsWeakPtr()); |
| 79 version_->set_foreign_fetch_scopes({kScope}); | 80 version_->set_foreign_fetch_scopes({kScope}); |
| 80 | 81 |
| 81 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); | 82 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); |
| 82 base::RunLoop().RunUntilIdle(); | 83 base::RunLoop().RunUntilIdle(); |
| 83 | 84 |
| 84 // Persist the registration data. | 85 // Persist the registration data. |
| 85 std::vector<ServiceWorkerDatabase::ResourceRecord> records; | 86 std::vector<ServiceWorkerDatabase::ResourceRecord> records; |
| 86 records.push_back( | 87 records.push_back( |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 true /* is_parent_frame_secure */, helper_->context()->AsWeakPtr(), | 179 true /* is_parent_frame_secure */, helper_->context()->AsWeakPtr(), |
| 179 &remote_endpoints_.back()); | 180 &remote_endpoints_.back()); |
| 180 EXPECT_FALSE( | 181 EXPECT_FALSE( |
| 181 context()->GetProviderHost(host->process_id(), host->provider_id())); | 182 context()->GetProviderHost(host->process_id(), host->provider_id())); |
| 182 provider_host_ = host->AsWeakPtr(); | 183 provider_host_ = host->AsWeakPtr(); |
| 183 context()->AddProviderHost(std::move(host)); | 184 context()->AddProviderHost(std::move(host)); |
| 184 | 185 |
| 185 // Create another worker whose requests will be intercepted by the foreign | 186 // Create another worker whose requests will be intercepted by the foreign |
| 186 // fetch event handler. | 187 // fetch event handler. |
| 187 scoped_refptr<ServiceWorkerRegistration> registration = | 188 scoped_refptr<ServiceWorkerRegistration> registration = |
| 188 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, | 189 new ServiceWorkerRegistration( |
| 189 context()->AsWeakPtr()); | 190 ServiceWorkerRegistrationOptions(GURL("https://host/scope")), 1L, |
| 191 context()->AsWeakPtr()); |
| 190 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( | 192 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( |
| 191 registration.get(), GURL("https://host/script.js"), 1L, | 193 registration.get(), GURL("https://host/script.js"), 1L, |
| 192 context()->AsWeakPtr()); | 194 context()->AsWeakPtr()); |
| 193 | 195 |
| 194 std::vector<ServiceWorkerDatabase::ResourceRecord> records; | 196 std::vector<ServiceWorkerDatabase::ResourceRecord> records; |
| 195 records.push_back( | 197 records.push_back( |
| 196 ServiceWorkerDatabase::ResourceRecord(10, version->script_url(), 100)); | 198 ServiceWorkerDatabase::ResourceRecord(10, version->script_url(), 100)); |
| 197 version->script_cache_map()->SetResources(records); | 199 version->script_cache_map()->SetResources(records); |
| 198 version->set_fetch_handler_existence( | 200 version->set_fetch_handler_existence( |
| 199 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); | 201 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 // Make sure new request only gets remaining timeout. | 386 // Make sure new request only gets remaining timeout. |
| 385 ForeignFetchRequestHandler* handler = | 387 ForeignFetchRequestHandler* handler = |
| 386 InitializeHandler("https://valid.example.com/foo", RESOURCE_TYPE_IMAGE, | 388 InitializeHandler("https://valid.example.com/foo", RESOURCE_TYPE_IMAGE, |
| 387 nullptr /* initiator */); | 389 nullptr /* initiator */); |
| 388 ASSERT_TRUE(handler); | 390 ASSERT_TRUE(handler); |
| 389 ASSERT_TRUE(timeout_for_request(handler).has_value()); | 391 ASSERT_TRUE(timeout_for_request(handler).has_value()); |
| 390 EXPECT_EQ(remaining_time, timeout_for_request(handler).value()); | 392 EXPECT_EQ(remaining_time, timeout_for_request(handler).value()); |
| 391 } | 393 } |
| 392 | 394 |
| 393 } // namespace content | 395 } // namespace content |
| OLD | NEW |