| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/service_worker_request_handler.h" | 5 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 class ServiceWorkerRequestHandlerTest : public testing::Test { | 37 class ServiceWorkerRequestHandlerTest : public testing::Test { |
| 38 public: | 38 public: |
| 39 ServiceWorkerRequestHandlerTest() | 39 ServiceWorkerRequestHandlerTest() |
| 40 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 40 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
| 41 | 41 |
| 42 void SetUp() override { | 42 void SetUp() override { |
| 43 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); | 43 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); |
| 44 | 44 |
| 45 // An empty host. | 45 // An empty host. |
| 46 std::unique_ptr<ServiceWorkerProviderHost> host = | 46 std::unique_ptr<ServiceWorkerProviderHost> host = |
| 47 CreateProviderHostForWindow( | 47 CreateProviderHostForWindow(helper_->mock_render_process_id(), |
| 48 helper_->mock_render_process_id(), kMockProviderId, | 48 kMockProviderId, |
| 49 true /* is_parent_frame_secure */, context()->AsWeakPtr()); | 49 true /* is_parent_frame_secure */, |
| 50 context()->AsWeakPtr(), &remote_endpoint_); |
| 50 provider_host_ = host->AsWeakPtr(); | 51 provider_host_ = host->AsWeakPtr(); |
| 51 context()->AddProviderHost(std::move(host)); | 52 context()->AddProviderHost(std::move(host)); |
| 52 } | 53 } |
| 53 | 54 |
| 54 void TearDown() override { | 55 void TearDown() override { |
| 55 helper_.reset(); | 56 helper_.reset(); |
| 56 } | 57 } |
| 57 | 58 |
| 58 ServiceWorkerContextCore* context() const { return helper_->context(); } | 59 ServiceWorkerContextCore* context() const { return helper_->context(); } |
| 59 ServiceWorkerContextWrapper* context_wrapper() const { | 60 ServiceWorkerContextWrapper* context_wrapper() const { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 EXPECT_EQ(url, provider_host_->document_url().spec()); | 105 EXPECT_EQ(url, provider_host_->document_url().spec()); |
| 105 } | 106 } |
| 106 | 107 |
| 107 protected: | 108 protected: |
| 108 TestBrowserThreadBundle browser_thread_bundle_; | 109 TestBrowserThreadBundle browser_thread_bundle_; |
| 109 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 110 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
| 110 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | 111 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
| 111 net::URLRequestContext url_request_context_; | 112 net::URLRequestContext url_request_context_; |
| 112 net::TestDelegate url_request_delegate_; | 113 net::TestDelegate url_request_delegate_; |
| 113 storage::BlobStorageContext blob_storage_context_; | 114 storage::BlobStorageContext blob_storage_context_; |
| 115 ServiceWorkerRemoteProviderEndpoint remote_endpoint_; |
| 114 }; | 116 }; |
| 115 | 117 |
| 116 TEST_F(ServiceWorkerRequestHandlerTest, InitializeHandler_FTP) { | 118 TEST_F(ServiceWorkerRequestHandlerTest, InitializeHandler_FTP) { |
| 117 std::unique_ptr<net::URLRequest> request = | 119 std::unique_ptr<net::URLRequest> request = |
| 118 CreateRequest("ftp://host/scope/doc", "GET"); | 120 CreateRequest("ftp://host/scope/doc", "GET"); |
| 119 InitializeHandler(request.get(), false, RESOURCE_TYPE_MAIN_FRAME); | 121 InitializeHandler(request.get(), false, RESOURCE_TYPE_MAIN_FRAME); |
| 120 // Cannot initialize a handler for non-secure origins. | 122 // Cannot initialize a handler for non-secure origins. |
| 121 EXPECT_FALSE(GetHandler(request.get())); | 123 EXPECT_FALSE(GetHandler(request.get())); |
| 122 } | 124 } |
| 123 | 125 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 // Check provider host's URL after initializing a handler for an image. | 162 // Check provider host's URL after initializing a handler for an image. |
| 161 provider_host_->SetDocumentUrl(GURL("https://host/scope/doc")); | 163 provider_host_->SetDocumentUrl(GURL("https://host/scope/doc")); |
| 162 std::unique_ptr<net::URLRequest> request = | 164 std::unique_ptr<net::URLRequest> request = |
| 163 CreateRequest("https://host/scope/image", "GET"); | 165 CreateRequest("https://host/scope/image", "GET"); |
| 164 InitializeHandler(request.get(), true, RESOURCE_TYPE_IMAGE); | 166 InitializeHandler(request.get(), true, RESOURCE_TYPE_IMAGE); |
| 165 ASSERT_FALSE(GetHandler(request.get())); | 167 ASSERT_FALSE(GetHandler(request.get())); |
| 166 EXPECT_EQ(GURL("https://host/scope/doc"), provider_host_->document_url()); | 168 EXPECT_EQ(GURL("https://host/scope/doc"), provider_host_->document_url()); |
| 167 } | 169 } |
| 168 | 170 |
| 169 } // namespace content | 171 } // namespace content |
| OLD | NEW |