OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_dispatcher_host.h" | 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 179 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
180 host->SetDocumentUrl(GURL("http://127.0.0.3:81/foo")); | 180 host->SetDocumentUrl(GURL("http://127.0.0.3:81/foo")); |
181 context()->AddProviderHost(host.Pass()); | 181 context()->AddProviderHost(host.Pass()); |
182 | 182 |
183 Register(kProviderId, | 183 Register(kProviderId, |
184 GURL("http://127.0.0.3:81/bar"), | 184 GURL("http://127.0.0.3:81/bar"), |
185 GURL("http://127.0.0.3:81/baz"), | 185 GURL("http://127.0.0.3:81/baz"), |
186 ServiceWorkerMsg_ServiceWorkerRegistered::ID); | 186 ServiceWorkerMsg_ServiceWorkerRegistered::ID); |
187 } | 187 } |
188 | 188 |
| 189 TEST_F(ServiceWorkerDispatcherHostTest, |
| 190 Register_DifferentDirectoryThanScriptShouldFail) { |
| 191 const int64 kProviderId = 99; // Dummy value |
| 192 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
| 193 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
| 194 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 195 context()->AddProviderHost(host.Pass()); |
| 196 |
| 197 SendRegister(kProviderId, |
| 198 GURL("https://www.example.com/hoge/piyo"), |
| 199 GURL("https://www.example.com/bar/hoge.js")); |
| 200 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 201 } |
| 202 |
| 203 TEST_F(ServiceWorkerDispatcherHostTest, |
| 204 Register_SameDirectoryAsScriptButNoSlashShouldFail) { |
| 205 const int64 kProviderId = 99; // Dummy value |
| 206 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
| 207 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
| 208 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 209 context()->AddProviderHost(host.Pass()); |
| 210 |
| 211 SendRegister(kProviderId, |
| 212 GURL("https://www.example.com/bar"), |
| 213 GURL("https://www.example.com/bar/hoge.js")); |
| 214 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 215 } |
| 216 |
| 217 TEST_F(ServiceWorkerDispatcherHostTest, Register_InvalidScopeShouldFail) { |
| 218 const int64 kProviderId = 99; // Dummy value |
| 219 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
| 220 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
| 221 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 222 context()->AddProviderHost(host.Pass()); |
| 223 |
| 224 SendRegister( |
| 225 kProviderId, GURL(""), GURL("https://www.example.com/bar/hoge.js")); |
| 226 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 227 } |
| 228 |
| 229 TEST_F(ServiceWorkerDispatcherHostTest, Register_InvalidScriptShouldFail) { |
| 230 const int64 kProviderId = 99; // Dummy value |
| 231 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
| 232 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
| 233 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 234 context()->AddProviderHost(host.Pass()); |
| 235 |
| 236 SendRegister(kProviderId, GURL("https://www.example.com/bar/"), GURL("")); |
| 237 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 238 } |
| 239 |
189 TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureOriginShouldFail) { | 240 TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureOriginShouldFail) { |
190 const int64 kProviderId = 99; // Dummy value | 241 const int64 kProviderId = 99; // Dummy value |
191 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 242 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
192 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 243 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
193 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 244 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
194 context()->AddProviderHost(host.Pass()); | 245 context()->AddProviderHost(host.Pass()); |
195 | 246 |
196 SendRegister(kProviderId, | 247 SendRegister(kProviderId, |
197 GURL("http://www.example.com/"), | 248 GURL("http://www.example.com/"), |
198 GURL("http://www.example.com/bar")); | 249 GURL("http://www.example.com/bar")); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 const int64 kProviderId = 99; // Dummy value | 323 const int64 kProviderId = 99; // Dummy value |
273 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 324 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
274 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 325 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
275 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 326 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
276 context()->AddProviderHost(host.Pass()); | 327 context()->AddProviderHost(host.Pass()); |
277 | 328 |
278 SendUnregister(kProviderId, GURL("https://foo.example.com/")); | 329 SendUnregister(kProviderId, GURL("https://foo.example.com/")); |
279 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 330 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
280 } | 331 } |
281 | 332 |
| 333 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_InvalidScopeShouldFail) { |
| 334 const int64 kProviderId = 99; // Dummy value |
| 335 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
| 336 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
| 337 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 338 context()->AddProviderHost(host.Pass()); |
| 339 |
| 340 SendUnregister(kProviderId, GURL("")); |
| 341 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 342 } |
| 343 |
282 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_NonSecureOriginShouldFail) { | 344 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_NonSecureOriginShouldFail) { |
283 const int64 kProviderId = 99; // Dummy value | 345 const int64 kProviderId = 99; // Dummy value |
284 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 346 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
285 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 347 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
286 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 348 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
287 context()->AddProviderHost(host.Pass()); | 349 context()->AddProviderHost(host.Pass()); |
288 | 350 |
289 SendUnregister(kProviderId, GURL("http://www.example.com/")); | 351 SendUnregister(kProviderId, GURL("http://www.example.com/")); |
290 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 352 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
291 } | 353 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 412 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
351 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 413 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
352 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 414 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
353 context()->AddProviderHost(host.Pass()); | 415 context()->AddProviderHost(host.Pass()); |
354 | 416 |
355 SendGetRegistration(kProviderId, GURL("https://foo.example.com/")); | 417 SendGetRegistration(kProviderId, GURL("https://foo.example.com/")); |
356 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 418 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
357 } | 419 } |
358 | 420 |
359 TEST_F(ServiceWorkerDispatcherHostTest, | 421 TEST_F(ServiceWorkerDispatcherHostTest, |
| 422 GetRegistration_InvalidScopeShouldFail) { |
| 423 const int64 kProviderId = 99; // Dummy value |
| 424 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
| 425 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
| 426 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 427 context()->AddProviderHost(host.Pass()); |
| 428 |
| 429 SendGetRegistration(kProviderId, GURL("")); |
| 430 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 431 } |
| 432 |
| 433 TEST_F(ServiceWorkerDispatcherHostTest, |
360 GetRegistration_NotSecureOriginShouldFail) { | 434 GetRegistration_NotSecureOriginShouldFail) { |
361 const int64 kProviderId = 99; // Dummy value | 435 const int64 kProviderId = 99; // Dummy value |
362 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 436 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
363 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 437 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
364 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 438 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
365 context()->AddProviderHost(host.Pass()); | 439 context()->AddProviderHost(host.Pass()); |
366 | 440 |
367 SendGetRegistration(kProviderId, GURL("http://www.example.com/")); | 441 SendGetRegistration(kProviderId, GURL("http://www.example.com/")); |
368 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 442 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
369 } | 443 } |
370 | 444 |
371 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_EarlyContextDeletion) { | 445 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_EarlyContextDeletion) { |
372 helper_->ShutdownContext(); | 446 helper_->ShutdownContext(); |
373 | 447 |
374 // Let the shutdown reach the simulated IO thread. | 448 // Let the shutdown reach the simulated IO thread. |
375 base::RunLoop().RunUntilIdle(); | 449 base::RunLoop().RunUntilIdle(); |
376 | 450 |
377 GetRegistration(-1, | 451 GetRegistration(-1, |
378 GURL(), | 452 GURL(), |
379 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); | 453 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); |
380 } | 454 } |
381 | 455 |
382 } // namespace content | 456 } // namespace content |
OLD | NEW |