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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 registration_ = new ServiceWorkerRegistration(kScope, kRegistrationId, | 71 registration_ = new ServiceWorkerRegistration(kScope, kRegistrationId, |
72 context()->AsWeakPtr()); | 72 context()->AsWeakPtr()); |
73 version_ = new ServiceWorkerVersion(registration_.get(), kResource1, | 73 version_ = new ServiceWorkerVersion(registration_.get(), kResource1, |
74 kVersionId, context()->AsWeakPtr()); | 74 kVersionId, context()->AsWeakPtr()); |
75 | 75 |
76 version_->set_foreign_fetch_scopes({kScope}); | 76 version_->set_foreign_fetch_scopes({kScope}); |
77 | 77 |
78 // An empty host. | 78 // An empty host. |
79 std::unique_ptr<ServiceWorkerProviderHost> host( | 79 std::unique_ptr<ServiceWorkerProviderHost> host = |
80 new ServiceWorkerProviderHost( | 80 ServiceWorkerProviderHost::CreateForTesting( |
81 helper_->mock_render_process_id(), MSG_ROUTING_NONE, | 81 helper_->mock_render_process_id(), kMockProviderId, |
82 kMockProviderId, SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 82 SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
83 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, | 83 helper_->context()->AsWeakPtr()); |
84 context()->AsWeakPtr(), nullptr)); | 84 host->set_parent_frame_secure(true); |
85 host->SetDocumentUrl(GURL("https://host/scope/")); | 85 host->SetDocumentUrl(GURL("https://host/scope/")); |
86 provider_host_ = host->AsWeakPtr(); | 86 provider_host_ = host->AsWeakPtr(); |
87 context()->AddProviderHost(std::move(host)); | 87 context()->AddProviderHost(std::move(host)); |
88 | 88 |
89 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); | 89 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); |
90 base::RunLoop().RunUntilIdle(); | 90 base::RunLoop().RunUntilIdle(); |
91 | 91 |
92 std::vector<ServiceWorkerDatabase::ResourceRecord> records; | 92 std::vector<ServiceWorkerDatabase::ResourceRecord> records; |
93 records.push_back( | 93 records.push_back( |
94 ServiceWorkerDatabase::ResourceRecord(10, version_->script_url(), 100)); | 94 ServiceWorkerDatabase::ResourceRecord(10, version_->script_url(), 100)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 SkipServiceWorker::NONE, FETCH_REQUEST_MODE_CORS, | 156 SkipServiceWorker::NONE, FETCH_REQUEST_MODE_CORS, |
157 FETCH_CREDENTIALS_MODE_OMIT, FetchRedirectMode::FOLLOW_MODE, | 157 FETCH_CREDENTIALS_MODE_OMIT, FetchRedirectMode::FOLLOW_MODE, |
158 resource_type, REQUEST_CONTEXT_TYPE_FETCH, | 158 resource_type, REQUEST_CONTEXT_TYPE_FETCH, |
159 REQUEST_CONTEXT_FRAME_TYPE_NONE, nullptr, | 159 REQUEST_CONTEXT_FRAME_TYPE_NONE, nullptr, |
160 true /* initiated_in_secure_context */); | 160 true /* initiated_in_secure_context */); |
161 | 161 |
162 return ForeignFetchRequestHandler::GetHandler(request_.get()); | 162 return ForeignFetchRequestHandler::GetHandler(request_.get()); |
163 } | 163 } |
164 | 164 |
165 void CreateServiceWorkerTypeProviderHost() { | 165 void CreateServiceWorkerTypeProviderHost() { |
166 std::unique_ptr<ServiceWorkerProviderHost> host( | 166 std::unique_ptr<ServiceWorkerProviderHost> host = |
167 new ServiceWorkerProviderHost( | 167 ServiceWorkerProviderHost::CreateForTesting( |
168 helper_->mock_render_process_id(), MSG_ROUTING_NONE, | 168 helper_->mock_render_process_id(), kMockProviderId, |
169 kMockProviderId, SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, | 169 SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, |
170 ServiceWorkerProviderHost::FrameSecurityLevel::UNINITIALIZED, | 170 helper_->context()->AsWeakPtr()); |
171 context()->AsWeakPtr(), nullptr)); | |
172 provider_host_ = host->AsWeakPtr(); | 171 provider_host_ = host->AsWeakPtr(); |
173 context()->RemoveProviderHost(host->process_id(), host->provider_id()); | 172 context()->RemoveProviderHost(host->process_id(), host->provider_id()); |
174 context()->AddProviderHost(std::move(host)); | 173 context()->AddProviderHost(std::move(host)); |
175 | 174 |
176 scoped_refptr<ServiceWorkerRegistration> registration = | 175 scoped_refptr<ServiceWorkerRegistration> registration = |
177 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, | 176 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, |
178 context()->AsWeakPtr()); | 177 context()->AsWeakPtr()); |
179 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( | 178 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( |
180 registration.get(), GURL("https://host/script.js"), 1L, | 179 registration.get(), GURL("https://host/script.js"), 1L, |
181 context()->AsWeakPtr()); | 180 context()->AsWeakPtr()); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 EXPECT_EQ(base::TimeDelta::FromSeconds(6), remaining_time); | 359 EXPECT_EQ(base::TimeDelta::FromSeconds(6), remaining_time); |
361 | 360 |
362 // Make sure new request only gets remaining timeout. | 361 // Make sure new request only gets remaining timeout. |
363 handler = InitializeHandler("https://valid.example.com/foo", | 362 handler = InitializeHandler("https://valid.example.com/foo", |
364 RESOURCE_TYPE_IMAGE, nullptr /* initiator */); | 363 RESOURCE_TYPE_IMAGE, nullptr /* initiator */); |
365 ASSERT_TRUE(handler); | 364 ASSERT_TRUE(handler); |
366 EXPECT_EQ(remaining_time, timeout_for_request(handler)); | 365 EXPECT_EQ(remaining_time, timeout_for_request(handler)); |
367 } | 366 } |
368 | 367 |
369 } // namespace content | 368 } // namespace content |
OLD | NEW |