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 "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "content/browser/fileapi/mock_url_request_delegate.h" | 8 #include "content/browser/fileapi/mock_url_request_delegate.h" |
9 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 9 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
10 #include "content/browser/service_worker/service_worker_context_core.h" | 10 #include "content/browser/service_worker/service_worker_context_core.h" |
11 #include "content/browser/service_worker/service_worker_provider_host.h" | 11 #include "content/browser/service_worker/service_worker_provider_host.h" |
12 #include "content/browser/service_worker/service_worker_registration.h" | 12 #include "content/browser/service_worker/service_worker_registration.h" |
13 #include "content/browser/service_worker/service_worker_utils.h" | 13 #include "content/browser/service_worker/service_worker_utils.h" |
14 #include "content/common/resource_request_body.h" | 14 #include "content/common/resource_request_body.h" |
| 15 #include "content/public/common/request_context_frame_type.h" |
| 16 #include "content/public/common/request_context_type.h" |
| 17 #include "content/public/common/resource_type.h" |
15 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
16 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
17 #include "storage/browser/blob/blob_storage_context.h" | 20 #include "storage/browser/blob/blob_storage_context.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
19 | 22 |
20 namespace content { | 23 namespace content { |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 int kMockRenderProcessId = 1224; | 27 int kMockRenderProcessId = 1224; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 79 } |
77 | 80 |
78 bool InitializeHandlerCheck(const std::string& url, | 81 bool InitializeHandlerCheck(const std::string& url, |
79 const std::string& method, | 82 const std::string& method, |
80 bool skip_service_worker, | 83 bool skip_service_worker, |
81 ResourceType resource_type) { | 84 ResourceType resource_type) { |
82 const GURL kDocUrl(url); | 85 const GURL kDocUrl(url); |
83 scoped_ptr<net::URLRequest> request = url_request_context_.CreateRequest( | 86 scoped_ptr<net::URLRequest> request = url_request_context_.CreateRequest( |
84 kDocUrl, net::DEFAULT_PRIORITY, &url_request_delegate_, NULL); | 87 kDocUrl, net::DEFAULT_PRIORITY, &url_request_delegate_, NULL); |
85 request->set_method(method); | 88 request->set_method(method); |
86 ServiceWorkerRequestHandler::InitializeHandler(request.get(), | 89 ServiceWorkerRequestHandler::InitializeHandler( |
87 context_wrapper(), | 90 request.get(), |
88 &blob_storage_context_, | 91 context_wrapper(), |
89 kMockRenderProcessId, | 92 &blob_storage_context_, |
90 kMockProviderId, | 93 kMockRenderProcessId, |
91 skip_service_worker, | 94 kMockProviderId, |
92 FETCH_REQUEST_MODE_NO_CORS, | 95 skip_service_worker, |
93 FETCH_CREDENTIALS_MODE_OMIT, | 96 FETCH_REQUEST_MODE_NO_CORS, |
94 resource_type, | 97 FETCH_CREDENTIALS_MODE_OMIT, |
95 NULL); | 98 resource_type, |
| 99 REQUEST_CONTEXT_TYPE_HYPERLINK, |
| 100 REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL, |
| 101 NULL); |
96 return ServiceWorkerRequestHandler::GetHandler(request.get()) != NULL; | 102 return ServiceWorkerRequestHandler::GetHandler(request.get()) != NULL; |
97 } | 103 } |
98 | 104 |
99 protected: | 105 protected: |
100 TestBrowserThreadBundle browser_thread_bundle_; | 106 TestBrowserThreadBundle browser_thread_bundle_; |
101 scoped_ptr<EmbeddedWorkerTestHelper> helper_; | 107 scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
102 scoped_refptr<ServiceWorkerRegistration> registration_; | 108 scoped_refptr<ServiceWorkerRegistration> registration_; |
103 scoped_refptr<ServiceWorkerVersion> version_; | 109 scoped_refptr<ServiceWorkerVersion> version_; |
104 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | 110 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
105 net::URLRequestContext url_request_context_; | 111 net::URLRequestContext url_request_context_; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 provider_host_->SetDocumentUrl(GURL("")); | 149 provider_host_->SetDocumentUrl(GURL("")); |
144 EXPECT_FALSE(InitializeHandlerCheck( | 150 EXPECT_FALSE(InitializeHandlerCheck( |
145 "http://host/scope/doc", "GET", true, RESOURCE_TYPE_IMAGE)); | 151 "http://host/scope/doc", "GET", true, RESOURCE_TYPE_IMAGE)); |
146 EXPECT_STREQ("", provider_host_->document_url().spec().c_str()); | 152 EXPECT_STREQ("", provider_host_->document_url().spec().c_str()); |
147 EXPECT_FALSE(InitializeHandlerCheck( | 153 EXPECT_FALSE(InitializeHandlerCheck( |
148 "https://host/scope/doc", "GET", true, RESOURCE_TYPE_IMAGE)); | 154 "https://host/scope/doc", "GET", true, RESOURCE_TYPE_IMAGE)); |
149 EXPECT_STREQ("", provider_host_->document_url().spec().c_str()); | 155 EXPECT_STREQ("", provider_host_->document_url().spec().c_str()); |
150 } | 156 } |
151 | 157 |
152 } // namespace content | 158 } // namespace content |
OLD | NEW |