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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 ServiceWorkerMode::ALL, FETCH_REQUEST_MODE_CORS, | 150 ServiceWorkerMode::ALL, FETCH_REQUEST_MODE_CORS, |
151 FETCH_CREDENTIALS_MODE_OMIT, FetchRedirectMode::FOLLOW_MODE, | 151 FETCH_CREDENTIALS_MODE_OMIT, FetchRedirectMode::FOLLOW_MODE, |
152 resource_type, REQUEST_CONTEXT_TYPE_FETCH, | 152 resource_type, REQUEST_CONTEXT_TYPE_FETCH, |
153 REQUEST_CONTEXT_FRAME_TYPE_NONE, nullptr, | 153 REQUEST_CONTEXT_FRAME_TYPE_NONE, nullptr, |
154 true /* initiated_in_secure_context */); | 154 true /* initiated_in_secure_context */); |
155 | 155 |
156 return ForeignFetchRequestHandler::GetHandler(request_.get()); | 156 return ForeignFetchRequestHandler::GetHandler(request_.get()); |
157 } | 157 } |
158 | 158 |
159 void CreateWindowTypeProviderHost() { | 159 void CreateWindowTypeProviderHost() { |
| 160 remote_endpoints_.emplace_back(); |
160 std::unique_ptr<ServiceWorkerProviderHost> host = | 161 std::unique_ptr<ServiceWorkerProviderHost> host = |
161 CreateProviderHostForWindow( | 162 CreateProviderHostForWindow( |
162 helper_->mock_render_process_id(), kMockProviderId, | 163 helper_->mock_render_process_id(), kMockProviderId, |
163 true /* is_parent_frame_secure */, helper_->context()->AsWeakPtr()); | 164 true /* is_parent_frame_secure */, helper_->context()->AsWeakPtr(), |
| 165 &remote_endpoints_.back()); |
164 EXPECT_FALSE( | 166 EXPECT_FALSE( |
165 context()->GetProviderHost(host->process_id(), host->provider_id())); | 167 context()->GetProviderHost(host->process_id(), host->provider_id())); |
166 host->SetDocumentUrl(GURL("https://host/scope/")); | 168 host->SetDocumentUrl(GURL("https://host/scope/")); |
167 provider_host_ = host->AsWeakPtr(); | 169 provider_host_ = host->AsWeakPtr(); |
168 context()->AddProviderHost(std::move(host)); | 170 context()->AddProviderHost(std::move(host)); |
169 } | 171 } |
170 | 172 |
171 void CreateServiceWorkerTypeProviderHost() { | 173 void CreateServiceWorkerTypeProviderHost() { |
| 174 remote_endpoints_.emplace_back(); |
172 std::unique_ptr<ServiceWorkerProviderHost> host = | 175 std::unique_ptr<ServiceWorkerProviderHost> host = |
173 CreateProviderHostForServiceWorkerContext( | 176 CreateProviderHostForServiceWorkerContext( |
174 helper_->mock_render_process_id(), kMockProviderId, | 177 helper_->mock_render_process_id(), kMockProviderId, |
175 true /* is_parent_frame_secure */, helper_->context()->AsWeakPtr()); | 178 true /* is_parent_frame_secure */, helper_->context()->AsWeakPtr(), |
| 179 &remote_endpoints_.back()); |
176 EXPECT_FALSE( | 180 EXPECT_FALSE( |
177 context()->GetProviderHost(host->process_id(), host->provider_id())); | 181 context()->GetProviderHost(host->process_id(), host->provider_id())); |
178 provider_host_ = host->AsWeakPtr(); | 182 provider_host_ = host->AsWeakPtr(); |
179 context()->AddProviderHost(std::move(host)); | 183 context()->AddProviderHost(std::move(host)); |
180 | 184 |
181 // Create another worker whose requests will be intercepted by the foreign | 185 // Create another worker whose requests will be intercepted by the foreign |
182 // fetch event handler. | 186 // fetch event handler. |
183 scoped_refptr<ServiceWorkerRegistration> registration = | 187 scoped_refptr<ServiceWorkerRegistration> registration = |
184 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, | 188 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, |
185 context()->AsWeakPtr()); | 189 context()->AsWeakPtr()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 TestContentClient test_content_client_; | 232 TestContentClient test_content_client_; |
229 TestContentBrowserClient test_content_browser_client_; | 233 TestContentBrowserClient test_content_browser_client_; |
230 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 234 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
231 TestBrowserThreadBundle browser_thread_bundle_; | 235 TestBrowserThreadBundle browser_thread_bundle_; |
232 | 236 |
233 net::URLRequestContext url_request_context_; | 237 net::URLRequestContext url_request_context_; |
234 net::TestDelegate url_request_delegate_; | 238 net::TestDelegate url_request_delegate_; |
235 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | 239 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
236 storage::BlobStorageContext blob_storage_context_; | 240 storage::BlobStorageContext blob_storage_context_; |
237 std::unique_ptr<net::URLRequest> request_; | 241 std::unique_ptr<net::URLRequest> request_; |
| 242 std::vector<ServiceWorkerRemoteProviderEndpoint> remote_endpoints_; |
238 | 243 |
239 DISALLOW_COPY_AND_ASSIGN(ForeignFetchRequestHandlerTest); | 244 DISALLOW_COPY_AND_ASSIGN(ForeignFetchRequestHandlerTest); |
240 }; | 245 }; |
241 | 246 |
242 TEST_F(ForeignFetchRequestHandlerTest, CheckOriginTrialToken_NoToken) { | 247 TEST_F(ForeignFetchRequestHandlerTest, CheckOriginTrialToken_NoToken) { |
243 CreateWindowTypeProviderHost(); | 248 CreateWindowTypeProviderHost(); |
244 EXPECT_TRUE(CheckOriginTrialToken(version())); | 249 EXPECT_TRUE(CheckOriginTrialToken(version())); |
245 std::unique_ptr<net::HttpResponseInfo> http_info( | 250 std::unique_ptr<net::HttpResponseInfo> http_info( |
246 CreateTestHttpResponseInfo()); | 251 CreateTestHttpResponseInfo()); |
247 version()->SetMainScriptHttpResponseInfo(*http_info); | 252 version()->SetMainScriptHttpResponseInfo(*http_info); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 // Make sure new request only gets remaining timeout. | 384 // Make sure new request only gets remaining timeout. |
380 ForeignFetchRequestHandler* handler = | 385 ForeignFetchRequestHandler* handler = |
381 InitializeHandler("https://valid.example.com/foo", RESOURCE_TYPE_IMAGE, | 386 InitializeHandler("https://valid.example.com/foo", RESOURCE_TYPE_IMAGE, |
382 nullptr /* initiator */); | 387 nullptr /* initiator */); |
383 ASSERT_TRUE(handler); | 388 ASSERT_TRUE(handler); |
384 ASSERT_TRUE(timeout_for_request(handler).has_value()); | 389 ASSERT_TRUE(timeout_for_request(handler).has_value()); |
385 EXPECT_EQ(remaining_time, timeout_for_request(handler).value()); | 390 EXPECT_EQ(remaining_time, timeout_for_request(handler).value()); |
386 } | 391 } |
387 | 392 |
388 } // namespace content | 393 } // namespace content |
OLD | NEW |