| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 void SetUp() override { | 65 void SetUp() override { |
| 66 const GURL kScope("https://valid.example.com/scope/"); | 66 const GURL kScope("https://valid.example.com/scope/"); |
| 67 const GURL kResource1("https://valid.example.com/scope/sw.js"); | 67 const GURL kResource1("https://valid.example.com/scope/sw.js"); |
| 68 const int64_t kRegistrationId = 0; | 68 const int64_t kRegistrationId = 0; |
| 69 const int64_t kVersionId = 0; | 69 const int64_t kVersionId = 0; |
| 70 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); | 70 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); |
| 71 | 71 |
| 72 // Create a registration for the worker which has foreign fetch event | 72 // Create a registration for the worker which has foreign fetch event |
| 73 // handler. | 73 // handler. |
| 74 registration_ = new ServiceWorkerRegistration(kScope, kRegistrationId, | 74 registration_ = new ServiceWorkerRegistration( |
| 75 context()->AsWeakPtr()); | 75 kScope, false /* use_cache */, kRegistrationId, context()->AsWeakPtr()); |
| 76 version_ = new ServiceWorkerVersion(registration_.get(), kResource1, | 76 version_ = new ServiceWorkerVersion(registration_.get(), kResource1, |
| 77 kVersionId, context()->AsWeakPtr()); | 77 kVersionId, context()->AsWeakPtr()); |
| 78 version_->set_foreign_fetch_scopes({kScope}); | 78 version_->set_foreign_fetch_scopes({kScope}); |
| 79 | 79 |
| 80 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); | 80 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); |
| 81 base::RunLoop().RunUntilIdle(); | 81 base::RunLoop().RunUntilIdle(); |
| 82 | 82 |
| 83 // Persist the registration data. | 83 // Persist the registration data. |
| 84 std::vector<ServiceWorkerDatabase::ResourceRecord> records; | 84 std::vector<ServiceWorkerDatabase::ResourceRecord> records; |
| 85 records.push_back( | 85 records.push_back( |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 helper_->mock_render_process_id(), kMockProviderId, | 172 helper_->mock_render_process_id(), kMockProviderId, |
| 173 true /* is_parent_frame_secure */, helper_->context()->AsWeakPtr()); | 173 true /* is_parent_frame_secure */, helper_->context()->AsWeakPtr()); |
| 174 EXPECT_FALSE( | 174 EXPECT_FALSE( |
| 175 context()->GetProviderHost(host->process_id(), host->provider_id())); | 175 context()->GetProviderHost(host->process_id(), host->provider_id())); |
| 176 provider_host_ = host->AsWeakPtr(); | 176 provider_host_ = host->AsWeakPtr(); |
| 177 context()->AddProviderHost(std::move(host)); | 177 context()->AddProviderHost(std::move(host)); |
| 178 | 178 |
| 179 // Create another worker whose requests will be intercepted by the foreign | 179 // Create another worker whose requests will be intercepted by the foreign |
| 180 // fetch event handler. | 180 // fetch event handler. |
| 181 scoped_refptr<ServiceWorkerRegistration> registration = | 181 scoped_refptr<ServiceWorkerRegistration> registration = |
| 182 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, | 182 new ServiceWorkerRegistration(GURL("https://host/scope"), |
| 183 false /* use_cache */, 1L, |
| 183 context()->AsWeakPtr()); | 184 context()->AsWeakPtr()); |
| 184 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( | 185 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( |
| 185 registration.get(), GURL("https://host/script.js"), 1L, | 186 registration.get(), GURL("https://host/script.js"), 1L, |
| 186 context()->AsWeakPtr()); | 187 context()->AsWeakPtr()); |
| 187 | 188 |
| 188 std::vector<ServiceWorkerDatabase::ResourceRecord> records; | 189 std::vector<ServiceWorkerDatabase::ResourceRecord> records; |
| 189 records.push_back( | 190 records.push_back( |
| 190 ServiceWorkerDatabase::ResourceRecord(10, version->script_url(), 100)); | 191 ServiceWorkerDatabase::ResourceRecord(10, version->script_url(), 100)); |
| 191 version->script_cache_map()->SetResources(records); | 192 version->script_cache_map()->SetResources(records); |
| 192 version->set_fetch_handler_existence( | 193 version->set_fetch_handler_existence( |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 // Make sure new request only gets remaining timeout. | 378 // Make sure new request only gets remaining timeout. |
| 378 ForeignFetchRequestHandler* handler = | 379 ForeignFetchRequestHandler* handler = |
| 379 InitializeHandler("https://valid.example.com/foo", RESOURCE_TYPE_IMAGE, | 380 InitializeHandler("https://valid.example.com/foo", RESOURCE_TYPE_IMAGE, |
| 380 nullptr /* initiator */); | 381 nullptr /* initiator */); |
| 381 ASSERT_TRUE(handler); | 382 ASSERT_TRUE(handler); |
| 382 ASSERT_TRUE(timeout_for_request(handler).has_value()); | 383 ASSERT_TRUE(timeout_for_request(handler).has_value()); |
| 383 EXPECT_EQ(remaining_time, timeout_for_request(handler).value()); | 384 EXPECT_EQ(remaining_time, timeout_for_request(handler).value()); |
| 384 } | 385 } |
| 385 | 386 |
| 386 } // namespace content | 387 } // namespace content |
| OLD | NEW |