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/link_header_support.h" | 5 #include "content/browser/service_worker/link_header_support.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "content/browser/loader/resource_request_info_impl.h" |
10 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 11 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
11 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
12 #include "content/browser/service_worker/service_worker_registration.h" | 13 #include "content/browser/service_worker/service_worker_registration.h" |
13 #include "content/public/browser/resource_request_info.h" | 14 #include "content/browser/service_worker/service_worker_request_handler.h" |
14 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
15 #include "content/public/test/mock_resource_context.h" | 16 #include "content/public/test/mock_resource_context.h" |
16 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
18 #include "net/url_request/url_request_test_job.h" | 19 #include "net/url_request/url_request_test_job.h" |
19 #include "net/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
| 21 #include "storage/browser/blob/blob_storage_context.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
21 | 23 |
22 namespace content { | 24 namespace content { |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
| 28 const int kMockProviderId = 1; |
| 29 |
26 void SaveFoundRegistrationsCallback( | 30 void SaveFoundRegistrationsCallback( |
27 ServiceWorkerStatusCode expected_status, | 31 ServiceWorkerStatusCode expected_status, |
28 bool* called, | 32 bool* called, |
29 std::vector<ServiceWorkerRegistrationInfo>* registrations, | 33 std::vector<ServiceWorkerRegistrationInfo>* registrations, |
30 ServiceWorkerStatusCode status, | 34 ServiceWorkerStatusCode status, |
31 const std::vector<ServiceWorkerRegistrationInfo>& result) { | 35 const std::vector<ServiceWorkerRegistrationInfo>& result) { |
32 EXPECT_EQ(expected_status, status); | 36 EXPECT_EQ(expected_status, status); |
33 *called = true; | 37 *called = true; |
34 *registrations = result; | 38 *registrations = result; |
35 } | 39 } |
(...skipping 13 matching lines...) Expand all Loading... |
49 LinkHeaderServiceWorkerTest() | 53 LinkHeaderServiceWorkerTest() |
50 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 54 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
51 resource_context_(&request_context_) { | 55 resource_context_(&request_context_) { |
52 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 56 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
53 switches::kEnableExperimentalWebPlatformFeatures); | 57 switches::kEnableExperimentalWebPlatformFeatures); |
54 } | 58 } |
55 ~LinkHeaderServiceWorkerTest() override {} | 59 ~LinkHeaderServiceWorkerTest() override {} |
56 | 60 |
57 void SetUp() override { | 61 void SetUp() override { |
58 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); | 62 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); |
| 63 |
| 64 // An empty host. |
| 65 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 66 new ServiceWorkerProviderHost( |
| 67 helper_->mock_render_process_id(), MSG_ROUTING_NONE, |
| 68 kMockProviderId, SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| 69 ServiceWorkerProviderHost::FrameSecurityLevel::UNINITIALIZED, |
| 70 context()->AsWeakPtr(), nullptr)); |
| 71 provider_host_ = host->AsWeakPtr(); |
| 72 context()->AddProviderHost(std::move(host)); |
59 } | 73 } |
60 | 74 |
61 void TearDown() override { helper_.reset(); } | 75 void TearDown() override { helper_.reset(); } |
62 | 76 |
| 77 ServiceWorkerContextCore* context() { return helper_->context(); } |
63 ServiceWorkerContextWrapper* context_wrapper() { | 78 ServiceWorkerContextWrapper* context_wrapper() { |
64 return helper_->context_wrapper(); | 79 return helper_->context_wrapper(); |
65 } | 80 } |
| 81 ServiceWorkerProviderHost* provider_host() { return provider_host_.get(); } |
66 | 82 |
67 void ProcessLinkHeader(const GURL& request_url, | 83 std::unique_ptr<net::URLRequest> CreateRequest(const GURL& request_url, |
68 const std::string& link_header) { | 84 ResourceType resource_type) { |
69 std::unique_ptr<net::URLRequest> request = request_context_.CreateRequest( | 85 std::unique_ptr<net::URLRequest> request = request_context_.CreateRequest( |
70 request_url, net::DEFAULT_PRIORITY, &request_delegate_); | 86 request_url, net::DEFAULT_PRIORITY, &request_delegate_); |
71 ResourceRequestInfo::AllocateForTesting( | 87 ResourceRequestInfo::AllocateForTesting( |
72 request.get(), RESOURCE_TYPE_SCRIPT, &resource_context_, | 88 request.get(), resource_type, &resource_context_, |
73 -1 /* render_process_id */, -1 /* render_view_id */, | 89 -1 /* render_process_id */, -1 /* render_view_id */, |
74 -1 /* render_frame_id */, false /* is_main_frame */, | 90 -1 /* render_frame_id */, resource_type == RESOURCE_TYPE_MAIN_FRAME, |
75 false /* parent_is_main_frame */, true /* allow_download */, | 91 false /* parent_is_main_frame */, true /* allow_download */, |
76 true /* is_async */, false /* is_using_lofi */); | 92 true /* is_async */, false /* is_using_lofi */); |
| 93 ResourceRequestInfoImpl::ForRequest(request.get()) |
| 94 ->set_initiated_in_secure_context_for_testing(true); |
77 | 95 |
78 ProcessLinkHeaderForRequest(request.get(), link_header, context_wrapper()); | 96 ServiceWorkerRequestHandler::InitializeHandler( |
79 base::RunLoop().RunUntilIdle(); | 97 request.get(), context_wrapper(), &blob_storage_context_, |
| 98 helper_->mock_render_process_id(), kMockProviderId, |
| 99 false /* skip_service_worker */, FETCH_REQUEST_MODE_NO_CORS, |
| 100 FETCH_CREDENTIALS_MODE_OMIT, FetchRedirectMode::FOLLOW_MODE, |
| 101 resource_type, REQUEST_CONTEXT_TYPE_HYPERLINK, |
| 102 REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL, nullptr); |
| 103 |
| 104 return request; |
| 105 } |
| 106 |
| 107 std::unique_ptr<net::URLRequest> CreateSubresourceRequest( |
| 108 const GURL& request_url) { |
| 109 return CreateRequest(request_url, RESOURCE_TYPE_SCRIPT); |
80 } | 110 } |
81 | 111 |
82 std::vector<ServiceWorkerRegistrationInfo> GetRegistrations() { | 112 std::vector<ServiceWorkerRegistrationInfo> GetRegistrations() { |
83 bool called; | 113 bool called; |
84 std::vector<ServiceWorkerRegistrationInfo> registrations; | 114 std::vector<ServiceWorkerRegistrationInfo> registrations; |
85 context_wrapper()->GetAllRegistrations( | 115 context_wrapper()->GetAllRegistrations( |
86 SaveFoundRegistrations(SERVICE_WORKER_OK, &called, ®istrations)); | 116 SaveFoundRegistrations(SERVICE_WORKER_OK, &called, ®istrations)); |
87 base::RunLoop().RunUntilIdle(); | 117 base::RunLoop().RunUntilIdle(); |
88 EXPECT_TRUE(called); | 118 EXPECT_TRUE(called); |
89 return registrations; | 119 return registrations; |
90 } | 120 } |
91 | 121 |
92 private: | 122 private: |
93 TestBrowserThreadBundle thread_bundle_; | 123 TestBrowserThreadBundle thread_bundle_; |
94 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 124 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
95 net::TestURLRequestContext request_context_; | 125 net::TestURLRequestContext request_context_; |
96 net::TestDelegate request_delegate_; | 126 net::TestDelegate request_delegate_; |
97 MockResourceContext resource_context_; | 127 MockResourceContext resource_context_; |
| 128 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
| 129 storage::BlobStorageContext blob_storage_context_; |
98 }; | 130 }; |
99 | 131 |
100 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_Basic) { | 132 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_Basic) { |
101 ProcessLinkHeader(GURL("https://example.com/foo/bar/"), | 133 ProcessLinkHeaderForRequest( |
102 "<../foo.js>; rel=serviceworker"); | 134 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), |
| 135 "<../foo.js>; rel=serviceworker", context_wrapper()); |
| 136 base::RunLoop().RunUntilIdle(); |
103 | 137 |
104 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 138 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
105 ASSERT_EQ(1u, registrations.size()); | 139 ASSERT_EQ(1u, registrations.size()); |
106 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); | 140 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); |
107 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), | 141 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), |
108 registrations[0].active_version.script_url); | 142 registrations[0].active_version.script_url); |
109 } | 143 } |
110 | 144 |
111 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeWithFragment) { | 145 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeWithFragment) { |
112 ProcessLinkHeader(GURL("https://example.com/foo/bar/"), | 146 ProcessLinkHeaderForRequest( |
113 "<../bar.js>; rel=serviceworker; scope=\"scope#ref\""); | 147 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), |
| 148 "<../bar.js>; rel=serviceworker; scope=\"scope#ref\"", context_wrapper()); |
| 149 base::RunLoop().RunUntilIdle(); |
114 | 150 |
115 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 151 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
116 ASSERT_EQ(1u, registrations.size()); | 152 ASSERT_EQ(1u, registrations.size()); |
117 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), | 153 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), |
118 registrations[0].pattern); | 154 registrations[0].pattern); |
119 EXPECT_EQ(GURL("https://example.com/foo/bar.js"), | 155 EXPECT_EQ(GURL("https://example.com/foo/bar.js"), |
120 registrations[0].active_version.script_url); | 156 registrations[0].active_version.script_url); |
121 } | 157 } |
122 | 158 |
123 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeAbsoluteUrl) { | 159 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeAbsoluteUrl) { |
124 ProcessLinkHeader(GURL("https://example.com/foo/bar/"), | 160 ProcessLinkHeaderForRequest( |
125 "<bar.js>; rel=serviceworker; " | 161 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), |
126 "scope=\"https://example.com:443/foo/bar/scope\""); | 162 "<bar.js>; rel=serviceworker; " |
| 163 "scope=\"https://example.com:443/foo/bar/scope\"", |
| 164 context_wrapper()); |
| 165 base::RunLoop().RunUntilIdle(); |
127 | 166 |
128 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 167 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
129 ASSERT_EQ(1u, registrations.size()); | 168 ASSERT_EQ(1u, registrations.size()); |
130 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), | 169 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), |
131 registrations[0].pattern); | 170 registrations[0].pattern); |
132 EXPECT_EQ(GURL("https://example.com/foo/bar/bar.js"), | 171 EXPECT_EQ(GURL("https://example.com/foo/bar/bar.js"), |
133 registrations[0].active_version.script_url); | 172 registrations[0].active_version.script_url); |
134 } | 173 } |
135 | 174 |
136 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeDifferentOrigin) { | 175 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeDifferentOrigin) { |
137 ProcessLinkHeader( | 176 ProcessLinkHeaderForRequest( |
138 GURL("https://example.com/foobar/"), | 177 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
139 "<bar.js>; rel=serviceworker; scope=\"https://google.com/scope\""); | 178 "<bar.js>; rel=serviceworker; scope=\"https://google.com/scope\"", |
| 179 context_wrapper()); |
| 180 base::RunLoop().RunUntilIdle(); |
140 | 181 |
141 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 182 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
142 ASSERT_EQ(0u, registrations.size()); | 183 ASSERT_EQ(0u, registrations.size()); |
143 } | 184 } |
144 | 185 |
145 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeUrlEncodedSlash) { | 186 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeUrlEncodedSlash) { |
146 ProcessLinkHeader(GURL("https://example.com/foobar/"), | 187 ProcessLinkHeaderForRequest( |
147 "<bar.js>; rel=serviceworker; scope=\"./foo%2Fbar\""); | 188 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
| 189 "<bar.js>; rel=serviceworker; scope=\"./foo%2Fbar\"", context_wrapper()); |
| 190 base::RunLoop().RunUntilIdle(); |
148 | 191 |
149 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 192 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
150 ASSERT_EQ(0u, registrations.size()); | 193 ASSERT_EQ(0u, registrations.size()); |
151 } | 194 } |
152 | 195 |
153 TEST_F(LinkHeaderServiceWorkerTest, | 196 TEST_F(LinkHeaderServiceWorkerTest, |
154 InstallServiceWorker_ScriptUrlEncodedSlash) { | 197 InstallServiceWorker_ScriptUrlEncodedSlash) { |
155 ProcessLinkHeader(GURL("https://example.com/foobar/"), | 198 ProcessLinkHeaderForRequest( |
156 "<foo%2Fbar.js>; rel=serviceworker"); | 199 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
| 200 "<foo%2Fbar.js>; rel=serviceworker", context_wrapper()); |
| 201 base::RunLoop().RunUntilIdle(); |
157 | 202 |
158 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 203 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
159 ASSERT_EQ(0u, registrations.size()); | 204 ASSERT_EQ(0u, registrations.size()); |
160 } | 205 } |
161 | 206 |
162 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScriptAbsoluteUrl) { | 207 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScriptAbsoluteUrl) { |
163 ProcessLinkHeader( | 208 ProcessLinkHeaderForRequest( |
164 GURL("https://example.com/foobar/"), | 209 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
165 "<https://example.com/bar.js>; rel=serviceworker; scope=foo"); | 210 "<https://example.com/bar.js>; rel=serviceworker; scope=foo", |
| 211 context_wrapper()); |
| 212 base::RunLoop().RunUntilIdle(); |
166 | 213 |
167 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 214 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
168 ASSERT_EQ(1u, registrations.size()); | 215 ASSERT_EQ(1u, registrations.size()); |
169 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); | 216 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); |
170 EXPECT_EQ(GURL("https://example.com/bar.js"), | 217 EXPECT_EQ(GURL("https://example.com/bar.js"), |
171 registrations[0].active_version.script_url); | 218 registrations[0].active_version.script_url); |
172 } | 219 } |
173 | 220 |
174 TEST_F(LinkHeaderServiceWorkerTest, | 221 TEST_F(LinkHeaderServiceWorkerTest, |
175 InstallServiceWorker_ScriptDifferentOrigin) { | 222 InstallServiceWorker_ScriptDifferentOrigin) { |
176 ProcessLinkHeader( | 223 ProcessLinkHeaderForRequest( |
177 GURL("https://example.com/foobar/"), | 224 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
178 "<https://google.com/bar.js>; rel=serviceworker; scope=foo"); | 225 "<https://google.com/bar.js>; rel=serviceworker; scope=foo", |
| 226 context_wrapper()); |
| 227 base::RunLoop().RunUntilIdle(); |
179 | 228 |
180 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 229 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
181 ASSERT_EQ(0u, registrations.size()); | 230 ASSERT_EQ(0u, registrations.size()); |
182 } | 231 } |
183 | 232 |
184 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_MultipleWorkers) { | 233 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_MultipleWorkers) { |
185 ProcessLinkHeader(GURL("https://example.com/foobar/"), | 234 ProcessLinkHeaderForRequest( |
186 "<bar.js>; rel=serviceworker; scope=foo, <baz.js>; " | 235 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
187 "rel=serviceworker; scope=scope"); | 236 "<bar.js>; rel=serviceworker; scope=foo, <baz.js>; " |
| 237 "rel=serviceworker; scope=scope", |
| 238 context_wrapper()); |
| 239 base::RunLoop().RunUntilIdle(); |
188 | 240 |
189 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 241 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
190 ASSERT_EQ(2u, registrations.size()); | 242 ASSERT_EQ(2u, registrations.size()); |
191 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); | 243 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); |
192 EXPECT_EQ(GURL("https://example.com/foobar/bar.js"), | 244 EXPECT_EQ(GURL("https://example.com/foobar/bar.js"), |
193 registrations[0].active_version.script_url); | 245 registrations[0].active_version.script_url); |
194 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[1].pattern); | 246 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[1].pattern); |
195 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), | 247 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), |
196 registrations[1].active_version.script_url); | 248 registrations[1].active_version.script_url); |
197 } | 249 } |
198 | 250 |
199 TEST_F(LinkHeaderServiceWorkerTest, | 251 TEST_F(LinkHeaderServiceWorkerTest, |
200 InstallServiceWorker_ValidAndInvalidValues) { | 252 InstallServiceWorker_ValidAndInvalidValues) { |
201 ProcessLinkHeader( | 253 ProcessLinkHeaderForRequest( |
202 GURL("https://example.com/foobar/"), | 254 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
203 "<https://google.com/bar.js>; rel=serviceworker; scope=foo, <baz.js>; " | 255 "<https://google.com/bar.js>; rel=serviceworker; scope=foo, <baz.js>; " |
204 "rel=serviceworker; scope=scope"); | 256 "rel=serviceworker; scope=scope", |
| 257 context_wrapper()); |
| 258 base::RunLoop().RunUntilIdle(); |
205 | 259 |
206 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 260 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
207 ASSERT_EQ(1u, registrations.size()); | 261 ASSERT_EQ(1u, registrations.size()); |
208 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[0].pattern); | 262 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[0].pattern); |
209 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), | 263 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), |
210 registrations[0].active_version.script_url); | 264 registrations[0].active_version.script_url); |
211 } | 265 } |
212 | 266 |
| 267 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_InsecureContext) { |
| 268 std::unique_ptr<net::URLRequest> request = |
| 269 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")); |
| 270 ResourceRequestInfoImpl::ForRequest(request.get()) |
| 271 ->set_initiated_in_secure_context_for_testing(false); |
| 272 ProcessLinkHeaderForRequest(request.get(), "<../foo.js>; rel=serviceworker", |
| 273 context_wrapper()); |
| 274 base::RunLoop().RunUntilIdle(); |
| 275 |
| 276 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 277 ASSERT_EQ(0u, registrations.size()); |
| 278 } |
| 279 |
| 280 TEST_F(LinkHeaderServiceWorkerTest, |
| 281 InstallServiceWorker_NavigationFromInsecureContextToSecureContext) { |
| 282 std::unique_ptr<net::URLRequest> request = CreateRequest( |
| 283 GURL("https://example.com/foo/bar/"), RESOURCE_TYPE_MAIN_FRAME); |
| 284 ResourceRequestInfoImpl::ForRequest(request.get()) |
| 285 ->set_initiated_in_secure_context_for_testing(false); |
| 286 |
| 287 provider_host()->SetDocumentUrl(GURL("https://example.com/foo/bar/")); |
| 288 provider_host()->set_parent_frame_secure(true); |
| 289 |
| 290 ProcessLinkHeaderForRequest(request.get(), "<../foo.js>; rel=serviceworker", |
| 291 context_wrapper()); |
| 292 base::RunLoop().RunUntilIdle(); |
| 293 |
| 294 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 295 ASSERT_EQ(1u, registrations.size()); |
| 296 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); |
| 297 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), |
| 298 registrations[0].active_version.script_url); |
| 299 } |
| 300 |
| 301 TEST_F(LinkHeaderServiceWorkerTest, |
| 302 InstallServiceWorker_NavigationToInsecureContext) { |
| 303 provider_host()->SetDocumentUrl(GURL("http://example.com/foo/bar/")); |
| 304 provider_host()->set_parent_frame_secure(true); |
| 305 ProcessLinkHeaderForRequest(CreateRequest(GURL("http://example.com/foo/bar/"), |
| 306 RESOURCE_TYPE_MAIN_FRAME) |
| 307 .get(), |
| 308 "<../foo.js>; rel=serviceworker", |
| 309 context_wrapper()); |
| 310 base::RunLoop().RunUntilIdle(); |
| 311 |
| 312 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 313 ASSERT_EQ(0u, registrations.size()); |
| 314 } |
| 315 |
| 316 TEST_F(LinkHeaderServiceWorkerTest, |
| 317 InstallServiceWorker_NavigationToInsecureHttpsContext) { |
| 318 provider_host()->SetDocumentUrl(GURL("https://example.com/foo/bar/")); |
| 319 provider_host()->set_parent_frame_secure(false); |
| 320 ProcessLinkHeaderForRequest( |
| 321 CreateRequest(GURL("https://example.com/foo/bar/"), |
| 322 RESOURCE_TYPE_MAIN_FRAME) |
| 323 .get(), |
| 324 "<../foo.js>; rel=serviceworker", context_wrapper()); |
| 325 base::RunLoop().RunUntilIdle(); |
| 326 |
| 327 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 328 ASSERT_EQ(0u, registrations.size()); |
| 329 } |
| 330 |
213 } // namespace | 331 } // namespace |
214 | 332 |
215 } // namespace content | 333 } // namespace content |
OLD | NEW |