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/loader/resource_request_info_impl.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 LinkHeaderServiceWorkerTest() | 58 LinkHeaderServiceWorkerTest() |
59 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 59 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
60 resource_context_(&request_context_) { | 60 resource_context_(&request_context_) { |
61 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 61 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
62 switches::kEnableExperimentalWebPlatformFeatures); | 62 switches::kEnableExperimentalWebPlatformFeatures); |
63 } | 63 } |
64 ~LinkHeaderServiceWorkerTest() override {} | 64 ~LinkHeaderServiceWorkerTest() override {} |
65 | 65 |
66 void SetUp() override { | 66 void SetUp() override { |
67 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); | 67 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); |
68 | |
69 // An empty host. | |
70 std::unique_ptr<ServiceWorkerProviderHost> host( | |
71 new ServiceWorkerProviderHost( | |
72 render_process_id(), MSG_ROUTING_NONE, kMockProviderId, | |
73 SERVICE_WORKER_PROVIDER_FOR_WINDOW, | |
74 ServiceWorkerProviderHost::FrameSecurityLevel::UNINITIALIZED, | |
75 context()->AsWeakPtr(), nullptr)); | |
76 provider_host_ = host->AsWeakPtr(); | |
77 context()->AddProviderHost(std::move(host)); | |
78 } | 68 } |
79 | 69 |
80 void TearDown() override { helper_.reset(); } | 70 void TearDown() override { helper_.reset(); } |
81 | 71 |
82 ServiceWorkerContextCore* context() { return helper_->context(); } | 72 ServiceWorkerContextCore* context() { return helper_->context(); } |
83 ServiceWorkerContextWrapper* context_wrapper() { | 73 ServiceWorkerContextWrapper* context_wrapper() { |
84 return helper_->context_wrapper(); | 74 return helper_->context_wrapper(); |
85 } | 75 } |
86 ServiceWorkerProviderHost* provider_host() { return provider_host_.get(); } | 76 ServiceWorkerProviderHost* provider_host() { return provider_host_.get(); } |
87 int render_process_id() const { return helper_->mock_render_process_id(); } | 77 int render_process_id() const { return helper_->mock_render_process_id(); } |
88 | 78 |
| 79 void CreateDocumentProviderHost() { |
| 80 // An empty host. |
| 81 std::unique_ptr<ServiceWorkerProviderHost> host = |
| 82 CreateProviderHostForWindow(render_process_id(), kMockProviderId, |
| 83 true /* is_parent_frame_secure */, |
| 84 context()->AsWeakPtr()); |
| 85 provider_host_ = host->AsWeakPtr(); |
| 86 EXPECT_FALSE( |
| 87 context()->GetProviderHost(host->process_id(), host->provider_id())); |
| 88 context()->AddProviderHost(std::move(host)); |
| 89 } |
| 90 |
| 91 void CreateInsecureDocumentProviderHost() { |
| 92 // An empty host. |
| 93 std::unique_ptr<ServiceWorkerProviderHost> host = |
| 94 CreateProviderHostForWindow(render_process_id(), kMockProviderId, |
| 95 false /* is_parent_frame_secure */, |
| 96 context()->AsWeakPtr()); |
| 97 provider_host_ = host->AsWeakPtr(); |
| 98 EXPECT_FALSE( |
| 99 context()->GetProviderHost(host->process_id(), host->provider_id())); |
| 100 context()->AddProviderHost(std::move(host)); |
| 101 } |
| 102 |
89 void CreateServiceWorkerProviderHost() { | 103 void CreateServiceWorkerProviderHost() { |
90 std::unique_ptr<ServiceWorkerProviderHost> host( | 104 std::unique_ptr<ServiceWorkerProviderHost> host = |
91 new ServiceWorkerProviderHost( | 105 CreateProviderHostForServiceWorkerContext( |
92 render_process_id(), MSG_ROUTING_NONE, kMockProviderId, | 106 render_process_id(), kMockProviderId, |
93 SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, | 107 true /* is_parent_frame_secure */, context()->AsWeakPtr()); |
94 ServiceWorkerProviderHost::FrameSecurityLevel::UNINITIALIZED, | |
95 context()->AsWeakPtr(), nullptr)); | |
96 provider_host_ = host->AsWeakPtr(); | 108 provider_host_ = host->AsWeakPtr(); |
97 context()->RemoveProviderHost(host->process_id(), host->provider_id()); | 109 EXPECT_FALSE( |
| 110 context()->GetProviderHost(host->process_id(), host->provider_id())); |
98 context()->AddProviderHost(std::move(host)); | 111 context()->AddProviderHost(std::move(host)); |
99 | 112 |
100 scoped_refptr<ServiceWorkerRegistration> registration = | 113 scoped_refptr<ServiceWorkerRegistration> registration = |
101 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, | 114 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, |
102 context()->AsWeakPtr()); | 115 context()->AsWeakPtr()); |
103 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( | 116 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( |
104 registration.get(), GURL("https://host/script.js"), 1L, | 117 registration.get(), GURL("https://host/script.js"), 1L, |
105 context()->AsWeakPtr()); | 118 context()->AsWeakPtr()); |
106 | 119 |
107 provider_host_->running_hosted_version_ = version; | 120 provider_host_->running_hosted_version_ = version; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 TestBrowserThreadBundle thread_bundle_; | 163 TestBrowserThreadBundle thread_bundle_; |
151 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 164 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
152 net::TestURLRequestContext request_context_; | 165 net::TestURLRequestContext request_context_; |
153 net::TestDelegate request_delegate_; | 166 net::TestDelegate request_delegate_; |
154 MockResourceContext resource_context_; | 167 MockResourceContext resource_context_; |
155 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | 168 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
156 storage::BlobStorageContext blob_storage_context_; | 169 storage::BlobStorageContext blob_storage_context_; |
157 }; | 170 }; |
158 | 171 |
159 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_Basic) { | 172 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_Basic) { |
| 173 CreateDocumentProviderHost(); |
160 ProcessLinkHeaderForRequest( | 174 ProcessLinkHeaderForRequest( |
161 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), | 175 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), |
162 "<../foo.js>; rel=serviceworker", context_wrapper()); | 176 "<../foo.js>; rel=serviceworker", context_wrapper()); |
163 base::RunLoop().RunUntilIdle(); | 177 base::RunLoop().RunUntilIdle(); |
164 | 178 |
165 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 179 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
166 ASSERT_EQ(1u, registrations.size()); | 180 ASSERT_EQ(1u, registrations.size()); |
167 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); | 181 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); |
168 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), | 182 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), |
169 registrations[0].active_version.script_url); | 183 registrations[0].active_version.script_url); |
170 } | 184 } |
171 | 185 |
172 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeWithFragment) { | 186 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeWithFragment) { |
| 187 CreateDocumentProviderHost(); |
173 ProcessLinkHeaderForRequest( | 188 ProcessLinkHeaderForRequest( |
174 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), | 189 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), |
175 "<../bar.js>; rel=serviceworker; scope=\"scope#ref\"", context_wrapper()); | 190 "<../bar.js>; rel=serviceworker; scope=\"scope#ref\"", context_wrapper()); |
176 base::RunLoop().RunUntilIdle(); | 191 base::RunLoop().RunUntilIdle(); |
177 | 192 |
178 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 193 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
179 ASSERT_EQ(1u, registrations.size()); | 194 ASSERT_EQ(1u, registrations.size()); |
180 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), | 195 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), |
181 registrations[0].pattern); | 196 registrations[0].pattern); |
182 EXPECT_EQ(GURL("https://example.com/foo/bar.js"), | 197 EXPECT_EQ(GURL("https://example.com/foo/bar.js"), |
183 registrations[0].active_version.script_url); | 198 registrations[0].active_version.script_url); |
184 } | 199 } |
185 | 200 |
186 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeAbsoluteUrl) { | 201 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeAbsoluteUrl) { |
| 202 CreateDocumentProviderHost(); |
187 ProcessLinkHeaderForRequest( | 203 ProcessLinkHeaderForRequest( |
188 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), | 204 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), |
189 "<bar.js>; rel=serviceworker; " | 205 "<bar.js>; rel=serviceworker; " |
190 "scope=\"https://example.com:443/foo/bar/scope\"", | 206 "scope=\"https://example.com:443/foo/bar/scope\"", |
191 context_wrapper()); | 207 context_wrapper()); |
192 base::RunLoop().RunUntilIdle(); | 208 base::RunLoop().RunUntilIdle(); |
193 | 209 |
194 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 210 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
195 ASSERT_EQ(1u, registrations.size()); | 211 ASSERT_EQ(1u, registrations.size()); |
196 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), | 212 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), |
197 registrations[0].pattern); | 213 registrations[0].pattern); |
198 EXPECT_EQ(GURL("https://example.com/foo/bar/bar.js"), | 214 EXPECT_EQ(GURL("https://example.com/foo/bar/bar.js"), |
199 registrations[0].active_version.script_url); | 215 registrations[0].active_version.script_url); |
200 } | 216 } |
201 | 217 |
202 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeDifferentOrigin) { | 218 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeDifferentOrigin) { |
| 219 CreateDocumentProviderHost(); |
203 ProcessLinkHeaderForRequest( | 220 ProcessLinkHeaderForRequest( |
204 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), | 221 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
205 "<bar.js>; rel=serviceworker; scope=\"https://google.com/scope\"", | 222 "<bar.js>; rel=serviceworker; scope=\"https://google.com/scope\"", |
206 context_wrapper()); | 223 context_wrapper()); |
207 base::RunLoop().RunUntilIdle(); | 224 base::RunLoop().RunUntilIdle(); |
208 | 225 |
209 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 226 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
210 ASSERT_EQ(0u, registrations.size()); | 227 ASSERT_EQ(0u, registrations.size()); |
211 } | 228 } |
212 | 229 |
213 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeUrlEncodedSlash) { | 230 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeUrlEncodedSlash) { |
| 231 CreateDocumentProviderHost(); |
214 ProcessLinkHeaderForRequest( | 232 ProcessLinkHeaderForRequest( |
215 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), | 233 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
216 "<bar.js>; rel=serviceworker; scope=\"./foo%2Fbar\"", context_wrapper()); | 234 "<bar.js>; rel=serviceworker; scope=\"./foo%2Fbar\"", context_wrapper()); |
217 base::RunLoop().RunUntilIdle(); | 235 base::RunLoop().RunUntilIdle(); |
218 | 236 |
219 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 237 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
220 ASSERT_EQ(0u, registrations.size()); | 238 ASSERT_EQ(0u, registrations.size()); |
221 } | 239 } |
222 | 240 |
223 TEST_F(LinkHeaderServiceWorkerTest, | 241 TEST_F(LinkHeaderServiceWorkerTest, |
224 InstallServiceWorker_ScriptUrlEncodedSlash) { | 242 InstallServiceWorker_ScriptUrlEncodedSlash) { |
| 243 CreateDocumentProviderHost(); |
225 ProcessLinkHeaderForRequest( | 244 ProcessLinkHeaderForRequest( |
226 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), | 245 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
227 "<foo%2Fbar.js>; rel=serviceworker", context_wrapper()); | 246 "<foo%2Fbar.js>; rel=serviceworker", context_wrapper()); |
228 base::RunLoop().RunUntilIdle(); | 247 base::RunLoop().RunUntilIdle(); |
229 | 248 |
230 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 249 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
231 ASSERT_EQ(0u, registrations.size()); | 250 ASSERT_EQ(0u, registrations.size()); |
232 } | 251 } |
233 | 252 |
234 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScriptAbsoluteUrl) { | 253 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScriptAbsoluteUrl) { |
| 254 CreateDocumentProviderHost(); |
235 ProcessLinkHeaderForRequest( | 255 ProcessLinkHeaderForRequest( |
236 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), | 256 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
237 "<https://example.com/bar.js>; rel=serviceworker; scope=foo", | 257 "<https://example.com/bar.js>; rel=serviceworker; scope=foo", |
238 context_wrapper()); | 258 context_wrapper()); |
239 base::RunLoop().RunUntilIdle(); | 259 base::RunLoop().RunUntilIdle(); |
240 | 260 |
241 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 261 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
242 ASSERT_EQ(1u, registrations.size()); | 262 ASSERT_EQ(1u, registrations.size()); |
243 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); | 263 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); |
244 EXPECT_EQ(GURL("https://example.com/bar.js"), | 264 EXPECT_EQ(GURL("https://example.com/bar.js"), |
245 registrations[0].active_version.script_url); | 265 registrations[0].active_version.script_url); |
246 } | 266 } |
247 | 267 |
248 TEST_F(LinkHeaderServiceWorkerTest, | 268 TEST_F(LinkHeaderServiceWorkerTest, |
249 InstallServiceWorker_ScriptDifferentOrigin) { | 269 InstallServiceWorker_ScriptDifferentOrigin) { |
| 270 CreateDocumentProviderHost(); |
250 ProcessLinkHeaderForRequest( | 271 ProcessLinkHeaderForRequest( |
251 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), | 272 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
252 "<https://google.com/bar.js>; rel=serviceworker; scope=foo", | 273 "<https://google.com/bar.js>; rel=serviceworker; scope=foo", |
253 context_wrapper()); | 274 context_wrapper()); |
254 base::RunLoop().RunUntilIdle(); | 275 base::RunLoop().RunUntilIdle(); |
255 | 276 |
256 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 277 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
257 ASSERT_EQ(0u, registrations.size()); | 278 ASSERT_EQ(0u, registrations.size()); |
258 } | 279 } |
259 | 280 |
260 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_MultipleWorkers) { | 281 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_MultipleWorkers) { |
| 282 CreateDocumentProviderHost(); |
261 ProcessLinkHeaderForRequest( | 283 ProcessLinkHeaderForRequest( |
262 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), | 284 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
263 "<bar.js>; rel=serviceworker; scope=foo, <baz.js>; " | 285 "<bar.js>; rel=serviceworker; scope=foo, <baz.js>; " |
264 "rel=serviceworker; scope=scope", | 286 "rel=serviceworker; scope=scope", |
265 context_wrapper()); | 287 context_wrapper()); |
266 base::RunLoop().RunUntilIdle(); | 288 base::RunLoop().RunUntilIdle(); |
267 | 289 |
268 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 290 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
269 ASSERT_EQ(2u, registrations.size()); | 291 ASSERT_EQ(2u, registrations.size()); |
270 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); | 292 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); |
271 EXPECT_EQ(GURL("https://example.com/foobar/bar.js"), | 293 EXPECT_EQ(GURL("https://example.com/foobar/bar.js"), |
272 registrations[0].active_version.script_url); | 294 registrations[0].active_version.script_url); |
273 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[1].pattern); | 295 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[1].pattern); |
274 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), | 296 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), |
275 registrations[1].active_version.script_url); | 297 registrations[1].active_version.script_url); |
276 } | 298 } |
277 | 299 |
278 TEST_F(LinkHeaderServiceWorkerTest, | 300 TEST_F(LinkHeaderServiceWorkerTest, |
279 InstallServiceWorker_ValidAndInvalidValues) { | 301 InstallServiceWorker_ValidAndInvalidValues) { |
| 302 CreateDocumentProviderHost(); |
280 ProcessLinkHeaderForRequest( | 303 ProcessLinkHeaderForRequest( |
281 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), | 304 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
282 "<https://google.com/bar.js>; rel=serviceworker; scope=foo, <baz.js>; " | 305 "<https://google.com/bar.js>; rel=serviceworker; scope=foo, <baz.js>; " |
283 "rel=serviceworker; scope=scope", | 306 "rel=serviceworker; scope=scope", |
284 context_wrapper()); | 307 context_wrapper()); |
285 base::RunLoop().RunUntilIdle(); | 308 base::RunLoop().RunUntilIdle(); |
286 | 309 |
287 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 310 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
288 ASSERT_EQ(1u, registrations.size()); | 311 ASSERT_EQ(1u, registrations.size()); |
289 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[0].pattern); | 312 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[0].pattern); |
290 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), | 313 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), |
291 registrations[0].active_version.script_url); | 314 registrations[0].active_version.script_url); |
292 } | 315 } |
293 | 316 |
294 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_InsecureContext) { | 317 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_InsecureContext) { |
| 318 CreateDocumentProviderHost(); |
295 std::unique_ptr<net::URLRequest> request = | 319 std::unique_ptr<net::URLRequest> request = |
296 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")); | 320 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")); |
297 ResourceRequestInfoImpl::ForRequest(request.get()) | 321 ResourceRequestInfoImpl::ForRequest(request.get()) |
298 ->set_initiated_in_secure_context_for_testing(false); | 322 ->set_initiated_in_secure_context_for_testing(false); |
299 ProcessLinkHeaderForRequest(request.get(), "<../foo.js>; rel=serviceworker", | 323 ProcessLinkHeaderForRequest(request.get(), "<../foo.js>; rel=serviceworker", |
300 context_wrapper()); | 324 context_wrapper()); |
301 base::RunLoop().RunUntilIdle(); | 325 base::RunLoop().RunUntilIdle(); |
302 | 326 |
303 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 327 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
304 ASSERT_EQ(0u, registrations.size()); | 328 ASSERT_EQ(0u, registrations.size()); |
305 } | 329 } |
306 | 330 |
307 TEST_F(LinkHeaderServiceWorkerTest, | 331 TEST_F(LinkHeaderServiceWorkerTest, |
308 InstallServiceWorker_NavigationFromInsecureContextToSecureContext) { | 332 InstallServiceWorker_NavigationFromInsecureContextToSecureContext) { |
| 333 CreateDocumentProviderHost(); |
309 std::unique_ptr<net::URLRequest> request = CreateRequest( | 334 std::unique_ptr<net::URLRequest> request = CreateRequest( |
310 GURL("https://example.com/foo/bar/"), RESOURCE_TYPE_MAIN_FRAME); | 335 GURL("https://example.com/foo/bar/"), RESOURCE_TYPE_MAIN_FRAME); |
311 ResourceRequestInfoImpl::ForRequest(request.get()) | 336 ResourceRequestInfoImpl::ForRequest(request.get()) |
312 ->set_initiated_in_secure_context_for_testing(false); | 337 ->set_initiated_in_secure_context_for_testing(false); |
313 | 338 |
314 provider_host()->SetDocumentUrl(GURL("https://example.com/foo/bar/")); | 339 provider_host()->SetDocumentUrl(GURL("https://example.com/foo/bar/")); |
315 provider_host()->set_parent_frame_secure(true); | |
316 | 340 |
317 ProcessLinkHeaderForRequest(request.get(), "<../foo.js>; rel=serviceworker", | 341 ProcessLinkHeaderForRequest(request.get(), "<../foo.js>; rel=serviceworker", |
318 context_wrapper()); | 342 context_wrapper()); |
319 base::RunLoop().RunUntilIdle(); | 343 base::RunLoop().RunUntilIdle(); |
320 | 344 |
321 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 345 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
322 ASSERT_EQ(1u, registrations.size()); | 346 ASSERT_EQ(1u, registrations.size()); |
323 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); | 347 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); |
324 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), | 348 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), |
325 registrations[0].active_version.script_url); | 349 registrations[0].active_version.script_url); |
326 } | 350 } |
327 | 351 |
328 TEST_F(LinkHeaderServiceWorkerTest, | 352 TEST_F(LinkHeaderServiceWorkerTest, |
329 InstallServiceWorker_NavigationToInsecureContext) { | 353 InstallServiceWorker_NavigationToInsecureContext) { |
| 354 CreateDocumentProviderHost(); |
330 provider_host()->SetDocumentUrl(GURL("http://example.com/foo/bar/")); | 355 provider_host()->SetDocumentUrl(GURL("http://example.com/foo/bar/")); |
331 provider_host()->set_parent_frame_secure(true); | |
332 ProcessLinkHeaderForRequest(CreateRequest(GURL("http://example.com/foo/bar/"), | 356 ProcessLinkHeaderForRequest(CreateRequest(GURL("http://example.com/foo/bar/"), |
333 RESOURCE_TYPE_MAIN_FRAME) | 357 RESOURCE_TYPE_MAIN_FRAME) |
334 .get(), | 358 .get(), |
335 "<../foo.js>; rel=serviceworker", | 359 "<../foo.js>; rel=serviceworker", |
336 context_wrapper()); | 360 context_wrapper()); |
337 base::RunLoop().RunUntilIdle(); | 361 base::RunLoop().RunUntilIdle(); |
338 | 362 |
339 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 363 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
340 ASSERT_EQ(0u, registrations.size()); | 364 ASSERT_EQ(0u, registrations.size()); |
341 } | 365 } |
342 | 366 |
343 TEST_F(LinkHeaderServiceWorkerTest, | 367 TEST_F(LinkHeaderServiceWorkerTest, |
344 InstallServiceWorker_NavigationToInsecureHttpsContext) { | 368 InstallServiceWorker_NavigationToInsecureHttpsContext) { |
| 369 CreateInsecureDocumentProviderHost(); |
345 provider_host()->SetDocumentUrl(GURL("https://example.com/foo/bar/")); | 370 provider_host()->SetDocumentUrl(GURL("https://example.com/foo/bar/")); |
346 provider_host()->set_parent_frame_secure(false); | |
347 ProcessLinkHeaderForRequest( | 371 ProcessLinkHeaderForRequest( |
348 CreateRequest(GURL("https://example.com/foo/bar/"), | 372 CreateRequest(GURL("https://example.com/foo/bar/"), |
349 RESOURCE_TYPE_MAIN_FRAME) | 373 RESOURCE_TYPE_MAIN_FRAME) |
350 .get(), | 374 .get(), |
351 "<../foo.js>; rel=serviceworker", context_wrapper()); | 375 "<../foo.js>; rel=serviceworker", context_wrapper()); |
352 base::RunLoop().RunUntilIdle(); | 376 base::RunLoop().RunUntilIdle(); |
353 | 377 |
354 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 378 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
355 ASSERT_EQ(0u, registrations.size()); | 379 ASSERT_EQ(0u, registrations.size()); |
356 } | 380 } |
357 | 381 |
358 TEST_F(LinkHeaderServiceWorkerTest, | 382 TEST_F(LinkHeaderServiceWorkerTest, |
359 InstallServiceWorker_FromWorkerWithoutControllees) { | 383 InstallServiceWorker_FromWorkerWithoutControllees) { |
360 CreateServiceWorkerProviderHost(); | 384 CreateServiceWorkerProviderHost(); |
361 ProcessLinkHeaderForRequest( | 385 ProcessLinkHeaderForRequest( |
362 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), | 386 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), |
363 "<../foo.js>; rel=serviceworker", context_wrapper()); | 387 "<../foo.js>; rel=serviceworker", context_wrapper()); |
364 base::RunLoop().RunUntilIdle(); | 388 base::RunLoop().RunUntilIdle(); |
365 | 389 |
366 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 390 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
367 ASSERT_EQ(0u, registrations.size()); | 391 ASSERT_EQ(0u, registrations.size()); |
368 } | 392 } |
369 | 393 |
370 TEST_F(LinkHeaderServiceWorkerTest, | 394 TEST_F(LinkHeaderServiceWorkerTest, |
371 InstallServiceWorker_FromWorkerWithControllees) { | 395 InstallServiceWorker_FromWorkerWithControllees) { |
372 CreateServiceWorkerProviderHost(); | 396 CreateServiceWorkerProviderHost(); |
373 | 397 |
374 std::unique_ptr<ServiceWorkerProviderHost> controllee( | 398 std::unique_ptr<ServiceWorkerProviderHost> controllee = |
375 new ServiceWorkerProviderHost( | 399 CreateProviderHostForWindow(render_process_id(), kMockProviderId, |
376 render_process_id(), MSG_ROUTING_NONE, kMockProviderId, | 400 true /* is_parent_frame_secure */, |
377 SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 401 context()->AsWeakPtr()); |
378 ServiceWorkerProviderHost::FrameSecurityLevel::UNINITIALIZED, | |
379 context()->AsWeakPtr(), nullptr)); | |
380 provider_host()->running_hosted_version()->AddControllee(controllee.get()); | 402 provider_host()->running_hosted_version()->AddControllee(controllee.get()); |
381 | 403 |
382 ProcessLinkHeaderForRequest( | 404 ProcessLinkHeaderForRequest( |
383 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), | 405 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), |
384 "<../foo.js>; rel=serviceworker", context_wrapper()); | 406 "<../foo.js>; rel=serviceworker", context_wrapper()); |
385 base::RunLoop().RunUntilIdle(); | 407 base::RunLoop().RunUntilIdle(); |
386 | 408 |
387 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 409 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
388 ASSERT_EQ(1u, registrations.size()); | 410 ASSERT_EQ(1u, registrations.size()); |
389 } | 411 } |
390 | 412 |
391 } // namespace content | 413 } // namespace content |
OLD | NEW |