| 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" |
| 11 #include "content/browser/fileapi/mock_url_request_delegate.h" | |
| 12 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 11 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 13 #include "content/browser/service_worker/service_worker_context_core.h" | 12 #include "content/browser/service_worker/service_worker_context_core.h" |
| 14 #include "content/browser/service_worker/service_worker_registration.h" | 13 #include "content/browser/service_worker/service_worker_registration.h" |
| 15 #include "content/browser/service_worker/service_worker_test_utils.h" | 14 #include "content/browser/service_worker/service_worker_test_utils.h" |
| 16 #include "content/browser/service_worker/service_worker_version.h" | 15 #include "content/browser/service_worker/service_worker_version.h" |
| 17 #include "content/common/service_worker/service_worker_utils.h" | 16 #include "content/common/service_worker/service_worker_utils.h" |
| 18 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
| 19 #include "content/public/common/origin_trial_policy.h" | 18 #include "content/public/common/origin_trial_policy.h" |
| 20 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
| 21 #include "content/test/test_content_browser_client.h" | 20 #include "content/test/test_content_browser_client.h" |
| 22 #include "net/http/http_response_info.h" | 21 #include "net/http/http_response_info.h" |
| 23 #include "net/test/cert_test_util.h" | 22 #include "net/test/cert_test_util.h" |
| 24 #include "net/test/test_data_directory.h" | 23 #include "net/test/test_data_directory.h" |
| 25 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
| 25 #include "net/url_request/url_request_test_util.h" |
| 26 #include "storage/browser/blob/blob_storage_context.h" | 26 #include "storage/browser/blob/blob_storage_context.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // This is a sample public key for testing the API. The corresponding private | 33 // This is a sample public key for testing the API. The corresponding private |
| 34 // key (use this to generate new samples for this test file) is: | 34 // key (use this to generate new samples for this test file) is: |
| 35 // | 35 // |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 }; | 222 }; |
| 223 | 223 |
| 224 scoped_refptr<ServiceWorkerRegistration> registration_; | 224 scoped_refptr<ServiceWorkerRegistration> registration_; |
| 225 scoped_refptr<ServiceWorkerVersion> version_; | 225 scoped_refptr<ServiceWorkerVersion> version_; |
| 226 TestContentClient test_content_client_; | 226 TestContentClient test_content_client_; |
| 227 TestContentBrowserClient test_content_browser_client_; | 227 TestContentBrowserClient test_content_browser_client_; |
| 228 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 228 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
| 229 TestBrowserThreadBundle browser_thread_bundle_; | 229 TestBrowserThreadBundle browser_thread_bundle_; |
| 230 | 230 |
| 231 net::URLRequestContext url_request_context_; | 231 net::URLRequestContext url_request_context_; |
| 232 MockURLRequestDelegate url_request_delegate_; | 232 net::TestDelegate url_request_delegate_; |
| 233 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | 233 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
| 234 storage::BlobStorageContext blob_storage_context_; | 234 storage::BlobStorageContext blob_storage_context_; |
| 235 std::unique_ptr<net::URLRequest> request_; | 235 std::unique_ptr<net::URLRequest> request_; |
| 236 | 236 |
| 237 DISALLOW_COPY_AND_ASSIGN(ForeignFetchRequestHandlerTest); | 237 DISALLOW_COPY_AND_ASSIGN(ForeignFetchRequestHandlerTest); |
| 238 }; | 238 }; |
| 239 | 239 |
| 240 TEST_F(ForeignFetchRequestHandlerTest, CheckOriginTrialToken_NoToken) { | 240 TEST_F(ForeignFetchRequestHandlerTest, CheckOriginTrialToken_NoToken) { |
| 241 CreateWindowTypeProviderHost(); | 241 CreateWindowTypeProviderHost(); |
| 242 EXPECT_TRUE(CheckOriginTrialToken(version())); | 242 EXPECT_TRUE(CheckOriginTrialToken(version())); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 // Make sure new request only gets remaining timeout. | 377 // Make sure new request only gets remaining timeout. |
| 378 ForeignFetchRequestHandler* handler = | 378 ForeignFetchRequestHandler* handler = |
| 379 InitializeHandler("https://valid.example.com/foo", RESOURCE_TYPE_IMAGE, | 379 InitializeHandler("https://valid.example.com/foo", RESOURCE_TYPE_IMAGE, |
| 380 nullptr /* initiator */); | 380 nullptr /* initiator */); |
| 381 ASSERT_TRUE(handler); | 381 ASSERT_TRUE(handler); |
| 382 ASSERT_TRUE(timeout_for_request(handler).has_value()); | 382 ASSERT_TRUE(timeout_for_request(handler).has_value()); |
| 383 EXPECT_EQ(remaining_time, timeout_for_request(handler).value()); | 383 EXPECT_EQ(remaining_time, timeout_for_request(handler).value()); |
| 384 } | 384 } |
| 385 | 385 |
| 386 } // namespace content | 386 } // namespace content |
| OLD | NEW |