| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "content/browser/browser_thread_impl.h" | 16 #include "content/browser/browser_thread_impl.h" |
| 17 #include "content/browser/message_port_service.h" | 17 #include "content/browser/message_port_service.h" |
| 18 #include "content/browser/service_worker/embedded_worker_instance.h" | 18 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 19 #include "content/browser/service_worker/embedded_worker_registry.h" | 19 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 20 #include "content/browser/service_worker/embedded_worker_status.h" | 20 #include "content/browser/service_worker/embedded_worker_status.h" |
| 21 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 21 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 22 #include "content/browser/service_worker/service_worker_context_core.h" | 22 #include "content/browser/service_worker/service_worker_context_core.h" |
| 23 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 23 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 24 #include "content/browser/service_worker/service_worker_handle.h" | 24 #include "content/browser/service_worker/service_worker_handle.h" |
| 25 #include "content/browser/service_worker/service_worker_test_utils.h" |
| 25 #include "content/common/service_worker/embedded_worker_messages.h" | 26 #include "content/common/service_worker/embedded_worker_messages.h" |
| 26 #include "content/common/service_worker/service_worker_messages.h" | 27 #include "content/common/service_worker/service_worker_messages.h" |
| 27 #include "content/common/service_worker/service_worker_types.h" | 28 #include "content/common/service_worker/service_worker_types.h" |
| 28 #include "content/common/service_worker/service_worker_utils.h" | 29 #include "content/common/service_worker/service_worker_utils.h" |
| 29 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
| 30 #include "content/public/test/mock_resource_context.h" | 31 #include "content/public/test/mock_resource_context.h" |
| 31 #include "content/public/test/test_browser_thread_bundle.h" | 32 #include "content/public/test/test_browser_thread_bundle.h" |
| 32 #include "content/test/test_content_browser_client.h" | 33 #include "content/test/test_content_browser_client.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 34 | 35 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 254 |
| 254 TestBrowserThreadBundle browser_thread_bundle_; | 255 TestBrowserThreadBundle browser_thread_bundle_; |
| 255 content::MockResourceContext resource_context_; | 256 content::MockResourceContext resource_context_; |
| 256 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 257 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
| 257 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; | 258 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; |
| 258 scoped_refptr<ServiceWorkerRegistration> registration_; | 259 scoped_refptr<ServiceWorkerRegistration> registration_; |
| 259 scoped_refptr<ServiceWorkerVersion> version_; | 260 scoped_refptr<ServiceWorkerVersion> version_; |
| 260 ServiceWorkerProviderHost* provider_host_; | 261 ServiceWorkerProviderHost* provider_host_; |
| 261 }; | 262 }; |
| 262 | 263 |
| 264 class ServiceWorkerDispatcherHostTestP |
| 265 : public MojoServiceWorkerTestP<ServiceWorkerDispatcherHostTest> {}; |
| 266 |
| 263 class ServiceWorkerTestContentBrowserClient : public TestContentBrowserClient { | 267 class ServiceWorkerTestContentBrowserClient : public TestContentBrowserClient { |
| 264 public: | 268 public: |
| 265 ServiceWorkerTestContentBrowserClient() {} | 269 ServiceWorkerTestContentBrowserClient() {} |
| 266 bool AllowServiceWorker(const GURL& scope, | 270 bool AllowServiceWorker(const GURL& scope, |
| 267 const GURL& first_party, | 271 const GURL& first_party, |
| 268 content::ResourceContext* context, | 272 content::ResourceContext* context, |
| 269 int render_process_id, | 273 int render_process_id, |
| 270 int render_frame_id) override { | 274 int render_frame_id) override { |
| 271 return false; | 275 return false; |
| 272 } | 276 } |
| 273 }; | 277 }; |
| 274 | 278 |
| 275 TEST_F(ServiceWorkerDispatcherHostTest, | 279 TEST_P(ServiceWorkerDispatcherHostTestP, |
| 276 Register_ContentSettingsDisallowsServiceWorker) { | 280 Register_ContentSettingsDisallowsServiceWorker) { |
| 277 ServiceWorkerTestContentBrowserClient test_browser_client; | 281 ServiceWorkerTestContentBrowserClient test_browser_client; |
| 278 ContentBrowserClient* old_browser_client = | 282 ContentBrowserClient* old_browser_client = |
| 279 SetBrowserClientForTesting(&test_browser_client); | 283 SetBrowserClientForTesting(&test_browser_client); |
| 280 | 284 |
| 281 const int64_t kProviderId = 99; // Dummy value | 285 const int64_t kProviderId = 99; // Dummy value |
| 282 std::unique_ptr<ServiceWorkerProviderHost> host( | 286 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 283 CreateServiceWorkerProviderHost(kProviderId)); | 287 CreateServiceWorkerProviderHost(kProviderId)); |
| 284 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 288 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 285 context()->AddProviderHost(std::move(host)); | 289 context()->AddProviderHost(std::move(host)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 299 const int64_t kRegistrationId = 999; // Dummy value | 303 const int64_t kRegistrationId = 999; // Dummy value |
| 300 scoped_refptr<ServiceWorkerRegistration> registration( | 304 scoped_refptr<ServiceWorkerRegistration> registration( |
| 301 new ServiceWorkerRegistration(GURL("https://www.example.com/"), | 305 new ServiceWorkerRegistration(GURL("https://www.example.com/"), |
| 302 kRegistrationId, context()->AsWeakPtr())); | 306 kRegistrationId, context()->AsWeakPtr())); |
| 303 Unregister(kProviderId, kRegistrationId, | 307 Unregister(kProviderId, kRegistrationId, |
| 304 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); | 308 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); |
| 305 | 309 |
| 306 SetBrowserClientForTesting(old_browser_client); | 310 SetBrowserClientForTesting(old_browser_client); |
| 307 } | 311 } |
| 308 | 312 |
| 309 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { | 313 TEST_P(ServiceWorkerDispatcherHostTestP, Register_HTTPS) { |
| 310 const int64_t kProviderId = 99; // Dummy value | 314 const int64_t kProviderId = 99; // Dummy value |
| 311 std::unique_ptr<ServiceWorkerProviderHost> host( | 315 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 312 CreateServiceWorkerProviderHost(kProviderId)); | 316 CreateServiceWorkerProviderHost(kProviderId)); |
| 313 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 317 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 314 context()->AddProviderHost(std::move(host)); | 318 context()->AddProviderHost(std::move(host)); |
| 315 | 319 |
| 316 Register(kProviderId, | 320 Register(kProviderId, |
| 317 GURL("https://www.example.com/"), | 321 GURL("https://www.example.com/"), |
| 318 GURL("https://www.example.com/bar"), | 322 GURL("https://www.example.com/bar"), |
| 319 ServiceWorkerMsg_ServiceWorkerRegistered::ID); | 323 ServiceWorkerMsg_ServiceWorkerRegistered::ID); |
| 320 } | 324 } |
| 321 | 325 |
| 322 TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureTransportLocalhost) { | 326 TEST_P(ServiceWorkerDispatcherHostTestP, Register_NonSecureTransportLocalhost) { |
| 323 const int64_t kProviderId = 99; // Dummy value | 327 const int64_t kProviderId = 99; // Dummy value |
| 324 std::unique_ptr<ServiceWorkerProviderHost> host( | 328 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 325 CreateServiceWorkerProviderHost(kProviderId)); | 329 CreateServiceWorkerProviderHost(kProviderId)); |
| 326 host->SetDocumentUrl(GURL("http://127.0.0.3:81/foo")); | 330 host->SetDocumentUrl(GURL("http://127.0.0.3:81/foo")); |
| 327 context()->AddProviderHost(std::move(host)); | 331 context()->AddProviderHost(std::move(host)); |
| 328 | 332 |
| 329 Register(kProviderId, | 333 Register(kProviderId, |
| 330 GURL("http://127.0.0.3:81/bar"), | 334 GURL("http://127.0.0.3:81/bar"), |
| 331 GURL("http://127.0.0.3:81/baz"), | 335 GURL("http://127.0.0.3:81/baz"), |
| 332 ServiceWorkerMsg_ServiceWorkerRegistered::ID); | 336 ServiceWorkerMsg_ServiceWorkerRegistered::ID); |
| 333 } | 337 } |
| 334 | 338 |
| 335 TEST_F(ServiceWorkerDispatcherHostTest, Register_InvalidScopeShouldFail) { | 339 TEST_P(ServiceWorkerDispatcherHostTestP, Register_InvalidScopeShouldFail) { |
| 336 const int64_t kProviderId = 99; // Dummy value | 340 const int64_t kProviderId = 99; // Dummy value |
| 337 std::unique_ptr<ServiceWorkerProviderHost> host( | 341 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 338 CreateServiceWorkerProviderHost(kProviderId)); | 342 CreateServiceWorkerProviderHost(kProviderId)); |
| 339 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 343 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 340 context()->AddProviderHost(std::move(host)); | 344 context()->AddProviderHost(std::move(host)); |
| 341 | 345 |
| 342 SendRegister(kProviderId, GURL(""), | 346 SendRegister(kProviderId, GURL(""), |
| 343 GURL("https://www.example.com/bar/hoge.js")); | 347 GURL("https://www.example.com/bar/hoge.js")); |
| 344 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 348 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 345 } | 349 } |
| 346 | 350 |
| 347 TEST_F(ServiceWorkerDispatcherHostTest, Register_InvalidScriptShouldFail) { | 351 TEST_P(ServiceWorkerDispatcherHostTestP, Register_InvalidScriptShouldFail) { |
| 348 const int64_t kProviderId = 99; // Dummy value | 352 const int64_t kProviderId = 99; // Dummy value |
| 349 std::unique_ptr<ServiceWorkerProviderHost> host( | 353 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 350 CreateServiceWorkerProviderHost(kProviderId)); | 354 CreateServiceWorkerProviderHost(kProviderId)); |
| 351 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 355 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 352 context()->AddProviderHost(std::move(host)); | 356 context()->AddProviderHost(std::move(host)); |
| 353 | 357 |
| 354 SendRegister(kProviderId, GURL("https://www.example.com/bar/"), GURL("")); | 358 SendRegister(kProviderId, GURL("https://www.example.com/bar/"), GURL("")); |
| 355 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 359 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 356 } | 360 } |
| 357 | 361 |
| 358 TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureOriginShouldFail) { | 362 TEST_P(ServiceWorkerDispatcherHostTestP, Register_NonSecureOriginShouldFail) { |
| 359 const int64_t kProviderId = 99; // Dummy value | 363 const int64_t kProviderId = 99; // Dummy value |
| 360 std::unique_ptr<ServiceWorkerProviderHost> host( | 364 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 361 CreateServiceWorkerProviderHost(kProviderId)); | 365 CreateServiceWorkerProviderHost(kProviderId)); |
| 362 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 366 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
| 363 context()->AddProviderHost(std::move(host)); | 367 context()->AddProviderHost(std::move(host)); |
| 364 | 368 |
| 365 SendRegister(kProviderId, | 369 SendRegister(kProviderId, |
| 366 GURL("http://www.example.com/"), | 370 GURL("http://www.example.com/"), |
| 367 GURL("http://www.example.com/bar")); | 371 GURL("http://www.example.com/bar")); |
| 368 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 372 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 369 } | 373 } |
| 370 | 374 |
| 371 TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOriginShouldFail) { | 375 TEST_P(ServiceWorkerDispatcherHostTestP, Register_CrossOriginShouldFail) { |
| 372 const int64_t kProviderId = 99; // Dummy value | 376 const int64_t kProviderId = 99; // Dummy value |
| 373 std::unique_ptr<ServiceWorkerProviderHost> host( | 377 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 374 CreateServiceWorkerProviderHost(kProviderId)); | 378 CreateServiceWorkerProviderHost(kProviderId)); |
| 375 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 379 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 376 context()->AddProviderHost(std::move(host)); | 380 context()->AddProviderHost(std::move(host)); |
| 377 | 381 |
| 378 // Script has a different host | 382 // Script has a different host |
| 379 SendRegister(kProviderId, | 383 SendRegister(kProviderId, |
| 380 GURL("https://www.example.com/"), | 384 GURL("https://www.example.com/"), |
| 381 GURL("https://foo.example.com/bar")); | 385 GURL("https://foo.example.com/bar")); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 405 GURL("https://foo.example.com/bar")); | 409 GURL("https://foo.example.com/bar")); |
| 406 EXPECT_EQ(5, dispatcher_host_->bad_messages_received_count_); | 410 EXPECT_EQ(5, dispatcher_host_->bad_messages_received_count_); |
| 407 | 411 |
| 408 // Script and scope URLs are invalid | 412 // Script and scope URLs are invalid |
| 409 SendRegister(kProviderId, | 413 SendRegister(kProviderId, |
| 410 GURL(), | 414 GURL(), |
| 411 GURL("h@ttps://@")); | 415 GURL("h@ttps://@")); |
| 412 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); | 416 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); |
| 413 } | 417 } |
| 414 | 418 |
| 415 TEST_F(ServiceWorkerDispatcherHostTest, Register_BadCharactersShouldFail) { | 419 TEST_P(ServiceWorkerDispatcherHostTestP, Register_BadCharactersShouldFail) { |
| 416 const int64_t kProviderId = 99; // Dummy value | 420 const int64_t kProviderId = 99; // Dummy value |
| 417 std::unique_ptr<ServiceWorkerProviderHost> host( | 421 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 418 CreateServiceWorkerProviderHost(kProviderId)); | 422 CreateServiceWorkerProviderHost(kProviderId)); |
| 419 host->SetDocumentUrl(GURL("https://www.example.com/")); | 423 host->SetDocumentUrl(GURL("https://www.example.com/")); |
| 420 context()->AddProviderHost(std::move(host)); | 424 context()->AddProviderHost(std::move(host)); |
| 421 | 425 |
| 422 SendRegister(kProviderId, GURL("https://www.example.com/%2f"), | 426 SendRegister(kProviderId, GURL("https://www.example.com/%2f"), |
| 423 GURL("https://www.example.com/")); | 427 GURL("https://www.example.com/")); |
| 424 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 428 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 425 | 429 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 437 | 441 |
| 438 SendRegister(kProviderId, GURL("https://www.example.com/"), | 442 SendRegister(kProviderId, GURL("https://www.example.com/"), |
| 439 GURL("https://www.example.com/%5c")); | 443 GURL("https://www.example.com/%5c")); |
| 440 EXPECT_EQ(5, dispatcher_host_->bad_messages_received_count_); | 444 EXPECT_EQ(5, dispatcher_host_->bad_messages_received_count_); |
| 441 | 445 |
| 442 SendRegister(kProviderId, GURL("https://www.example.com/"), | 446 SendRegister(kProviderId, GURL("https://www.example.com/"), |
| 443 GURL("https://www.example.com/%5C")); | 447 GURL("https://www.example.com/%5C")); |
| 444 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); | 448 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); |
| 445 } | 449 } |
| 446 | 450 |
| 447 TEST_F(ServiceWorkerDispatcherHostTest, | 451 TEST_P(ServiceWorkerDispatcherHostTestP, |
| 448 Register_FileSystemDocumentShouldFail) { | 452 Register_FileSystemDocumentShouldFail) { |
| 449 const int64_t kProviderId = 99; // Dummy value | 453 const int64_t kProviderId = 99; // Dummy value |
| 450 std::unique_ptr<ServiceWorkerProviderHost> host( | 454 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 451 CreateServiceWorkerProviderHost(kProviderId)); | 455 CreateServiceWorkerProviderHost(kProviderId)); |
| 452 host->SetDocumentUrl(GURL("filesystem:https://www.example.com/temporary/a")); | 456 host->SetDocumentUrl(GURL("filesystem:https://www.example.com/temporary/a")); |
| 453 context()->AddProviderHost(std::move(host)); | 457 context()->AddProviderHost(std::move(host)); |
| 454 | 458 |
| 455 SendRegister(kProviderId, | 459 SendRegister(kProviderId, |
| 456 GURL("filesystem:https://www.example.com/temporary/"), | 460 GURL("filesystem:https://www.example.com/temporary/"), |
| 457 GURL("https://www.example.com/temporary/bar")); | 461 GURL("https://www.example.com/temporary/bar")); |
| 458 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 462 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 459 | 463 |
| 460 SendRegister(kProviderId, | 464 SendRegister(kProviderId, |
| 461 GURL("https://www.example.com/temporary/"), | 465 GURL("https://www.example.com/temporary/"), |
| 462 GURL("filesystem:https://www.example.com/temporary/bar")); | 466 GURL("filesystem:https://www.example.com/temporary/bar")); |
| 463 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); | 467 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); |
| 464 | 468 |
| 465 SendRegister(kProviderId, | 469 SendRegister(kProviderId, |
| 466 GURL("filesystem:https://www.example.com/temporary/"), | 470 GURL("filesystem:https://www.example.com/temporary/"), |
| 467 GURL("filesystem:https://www.example.com/temporary/bar")); | 471 GURL("filesystem:https://www.example.com/temporary/bar")); |
| 468 EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); | 472 EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); |
| 469 } | 473 } |
| 470 | 474 |
| 471 TEST_F(ServiceWorkerDispatcherHostTest, | 475 TEST_P(ServiceWorkerDispatcherHostTestP, |
| 472 Register_FileSystemScriptOrScopeShouldFail) { | 476 Register_FileSystemScriptOrScopeShouldFail) { |
| 473 const int64_t kProviderId = 99; // Dummy value | 477 const int64_t kProviderId = 99; // Dummy value |
| 474 std::unique_ptr<ServiceWorkerProviderHost> host( | 478 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 475 CreateServiceWorkerProviderHost(kProviderId)); | 479 CreateServiceWorkerProviderHost(kProviderId)); |
| 476 host->SetDocumentUrl(GURL("https://www.example.com/temporary/")); | 480 host->SetDocumentUrl(GURL("https://www.example.com/temporary/")); |
| 477 context()->AddProviderHost(std::move(host)); | 481 context()->AddProviderHost(std::move(host)); |
| 478 | 482 |
| 479 SendRegister(kProviderId, | 483 SendRegister(kProviderId, |
| 480 GURL("filesystem:https://www.example.com/temporary/"), | 484 GURL("filesystem:https://www.example.com/temporary/"), |
| 481 GURL("https://www.example.com/temporary/bar")); | 485 GURL("https://www.example.com/temporary/bar")); |
| 482 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 486 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 483 | 487 |
| 484 SendRegister(kProviderId, | 488 SendRegister(kProviderId, |
| 485 GURL("https://www.example.com/temporary/"), | 489 GURL("https://www.example.com/temporary/"), |
| 486 GURL("filesystem:https://www.example.com/temporary/bar")); | 490 GURL("filesystem:https://www.example.com/temporary/bar")); |
| 487 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); | 491 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); |
| 488 | 492 |
| 489 SendRegister(kProviderId, | 493 SendRegister(kProviderId, |
| 490 GURL("filesystem:https://www.example.com/temporary/"), | 494 GURL("filesystem:https://www.example.com/temporary/"), |
| 491 GURL("filesystem:https://www.example.com/temporary/bar")); | 495 GURL("filesystem:https://www.example.com/temporary/bar")); |
| 492 EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); | 496 EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); |
| 493 } | 497 } |
| 494 | 498 |
| 495 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { | 499 TEST_P(ServiceWorkerDispatcherHostTestP, EarlyContextDeletion) { |
| 496 helper_->ShutdownContext(); | 500 helper_->ShutdownContext(); |
| 497 | 501 |
| 498 // Let the shutdown reach the simulated IO thread. | 502 // Let the shutdown reach the simulated IO thread. |
| 499 base::RunLoop().RunUntilIdle(); | 503 base::RunLoop().RunUntilIdle(); |
| 500 | 504 |
| 501 Register(-1, | 505 Register(-1, |
| 502 GURL(), | 506 GURL(), |
| 503 GURL(), | 507 GURL(), |
| 504 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); | 508 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); |
| 505 } | 509 } |
| 506 | 510 |
| 507 TEST_F(ServiceWorkerDispatcherHostTest, ProviderCreatedAndDestroyed) { | 511 TEST_P(ServiceWorkerDispatcherHostTestP, ProviderCreatedAndDestroyed) { |
| 508 const int kProviderId = 1001; | 512 const int kProviderId = 1001; |
| 509 int process_id = helper_->mock_render_process_id(); | 513 int process_id = helper_->mock_render_process_id(); |
| 510 | 514 |
| 511 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( | 515 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( |
| 512 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 516 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| 513 true /* is_parent_frame_secure */)); | 517 true /* is_parent_frame_secure */)); |
| 514 EXPECT_TRUE(context()->GetProviderHost(process_id, kProviderId)); | 518 EXPECT_TRUE(context()->GetProviderHost(process_id, kProviderId)); |
| 515 | 519 |
| 516 // Two with the same ID should be seen as a bad message. | 520 // Two with the same ID should be seen as a bad message. |
| 517 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( | 521 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 532 // process to get deleted as well. | 536 // process to get deleted as well. |
| 533 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( | 537 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( |
| 534 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 538 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| 535 true /* is_parent_frame_secure */)); | 539 true /* is_parent_frame_secure */)); |
| 536 EXPECT_TRUE(context()->GetProviderHost(process_id, kProviderId)); | 540 EXPECT_TRUE(context()->GetProviderHost(process_id, kProviderId)); |
| 537 EXPECT_TRUE(dispatcher_host_->HasOneRef()); | 541 EXPECT_TRUE(dispatcher_host_->HasOneRef()); |
| 538 dispatcher_host_ = NULL; | 542 dispatcher_host_ = NULL; |
| 539 EXPECT_FALSE(context()->GetProviderHost(process_id, kProviderId)); | 543 EXPECT_FALSE(context()->GetProviderHost(process_id, kProviderId)); |
| 540 } | 544 } |
| 541 | 545 |
| 542 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_SameOrigin) { | 546 TEST_P(ServiceWorkerDispatcherHostTestP, GetRegistration_SameOrigin) { |
| 543 const int64_t kProviderId = 99; // Dummy value | 547 const int64_t kProviderId = 99; // Dummy value |
| 544 std::unique_ptr<ServiceWorkerProviderHost> host( | 548 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 545 CreateServiceWorkerProviderHost(kProviderId)); | 549 CreateServiceWorkerProviderHost(kProviderId)); |
| 546 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 550 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 547 context()->AddProviderHost(std::move(host)); | 551 context()->AddProviderHost(std::move(host)); |
| 548 | 552 |
| 549 GetRegistration(kProviderId, | 553 GetRegistration(kProviderId, |
| 550 GURL("https://www.example.com/"), | 554 GURL("https://www.example.com/"), |
| 551 ServiceWorkerMsg_DidGetRegistration::ID); | 555 ServiceWorkerMsg_DidGetRegistration::ID); |
| 552 } | 556 } |
| 553 | 557 |
| 554 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_CrossOriginShouldFail) { | 558 TEST_P(ServiceWorkerDispatcherHostTestP, |
| 559 GetRegistration_CrossOriginShouldFail) { |
| 555 const int64_t kProviderId = 99; // Dummy value | 560 const int64_t kProviderId = 99; // Dummy value |
| 556 std::unique_ptr<ServiceWorkerProviderHost> host( | 561 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 557 CreateServiceWorkerProviderHost(kProviderId)); | 562 CreateServiceWorkerProviderHost(kProviderId)); |
| 558 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 563 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 559 context()->AddProviderHost(std::move(host)); | 564 context()->AddProviderHost(std::move(host)); |
| 560 | 565 |
| 561 SendGetRegistration(kProviderId, GURL("https://foo.example.com/")); | 566 SendGetRegistration(kProviderId, GURL("https://foo.example.com/")); |
| 562 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 567 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 563 } | 568 } |
| 564 | 569 |
| 565 TEST_F(ServiceWorkerDispatcherHostTest, | 570 TEST_P(ServiceWorkerDispatcherHostTestP, |
| 566 GetRegistration_InvalidScopeShouldFail) { | 571 GetRegistration_InvalidScopeShouldFail) { |
| 567 const int64_t kProviderId = 99; // Dummy value | 572 const int64_t kProviderId = 99; // Dummy value |
| 568 std::unique_ptr<ServiceWorkerProviderHost> host( | 573 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 569 CreateServiceWorkerProviderHost(kProviderId)); | 574 CreateServiceWorkerProviderHost(kProviderId)); |
| 570 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 575 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 571 context()->AddProviderHost(std::move(host)); | 576 context()->AddProviderHost(std::move(host)); |
| 572 | 577 |
| 573 SendGetRegistration(kProviderId, GURL("")); | 578 SendGetRegistration(kProviderId, GURL("")); |
| 574 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 579 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 575 } | 580 } |
| 576 | 581 |
| 577 TEST_F(ServiceWorkerDispatcherHostTest, | 582 TEST_P(ServiceWorkerDispatcherHostTestP, |
| 578 GetRegistration_NonSecureOriginShouldFail) { | 583 GetRegistration_NonSecureOriginShouldFail) { |
| 579 const int64_t kProviderId = 99; // Dummy value | 584 const int64_t kProviderId = 99; // Dummy value |
| 580 std::unique_ptr<ServiceWorkerProviderHost> host( | 585 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 581 CreateServiceWorkerProviderHost(kProviderId)); | 586 CreateServiceWorkerProviderHost(kProviderId)); |
| 582 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 587 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
| 583 context()->AddProviderHost(std::move(host)); | 588 context()->AddProviderHost(std::move(host)); |
| 584 | 589 |
| 585 SendGetRegistration(kProviderId, GURL("http://www.example.com/")); | 590 SendGetRegistration(kProviderId, GURL("http://www.example.com/")); |
| 586 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 591 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 587 } | 592 } |
| 588 | 593 |
| 589 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_EarlyContextDeletion) { | 594 TEST_P(ServiceWorkerDispatcherHostTestP, GetRegistration_EarlyContextDeletion) { |
| 590 helper_->ShutdownContext(); | 595 helper_->ShutdownContext(); |
| 591 | 596 |
| 592 // Let the shutdown reach the simulated IO thread. | 597 // Let the shutdown reach the simulated IO thread. |
| 593 base::RunLoop().RunUntilIdle(); | 598 base::RunLoop().RunUntilIdle(); |
| 594 | 599 |
| 595 GetRegistration(-1, | 600 GetRegistration(-1, |
| 596 GURL(), | 601 GURL(), |
| 597 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); | 602 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); |
| 598 } | 603 } |
| 599 | 604 |
| 600 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistrations_SecureOrigin) { | 605 TEST_P(ServiceWorkerDispatcherHostTestP, GetRegistrations_SecureOrigin) { |
| 601 const int64_t kProviderId = 99; // Dummy value | 606 const int64_t kProviderId = 99; // Dummy value |
| 602 std::unique_ptr<ServiceWorkerProviderHost> host( | 607 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 603 CreateServiceWorkerProviderHost(kProviderId)); | 608 CreateServiceWorkerProviderHost(kProviderId)); |
| 604 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 609 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 605 context()->AddProviderHost(std::move(host)); | 610 context()->AddProviderHost(std::move(host)); |
| 606 | 611 |
| 607 GetRegistrations(kProviderId, ServiceWorkerMsg_DidGetRegistrations::ID); | 612 GetRegistrations(kProviderId, ServiceWorkerMsg_DidGetRegistrations::ID); |
| 608 } | 613 } |
| 609 | 614 |
| 610 TEST_F(ServiceWorkerDispatcherHostTest, | 615 TEST_P(ServiceWorkerDispatcherHostTestP, |
| 611 GetRegistrations_NonSecureOriginShouldFail) { | 616 GetRegistrations_NonSecureOriginShouldFail) { |
| 612 const int64_t kProviderId = 99; // Dummy value | 617 const int64_t kProviderId = 99; // Dummy value |
| 613 std::unique_ptr<ServiceWorkerProviderHost> host( | 618 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 614 CreateServiceWorkerProviderHost(kProviderId)); | 619 CreateServiceWorkerProviderHost(kProviderId)); |
| 615 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 620 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
| 616 context()->AddProviderHost(std::move(host)); | 621 context()->AddProviderHost(std::move(host)); |
| 617 | 622 |
| 618 SendGetRegistrations(kProviderId); | 623 SendGetRegistrations(kProviderId); |
| 619 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 624 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 620 } | 625 } |
| 621 | 626 |
| 622 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistrations_EarlyContextDeletion) { | 627 TEST_P(ServiceWorkerDispatcherHostTestP, |
| 628 GetRegistrations_EarlyContextDeletion) { |
| 623 helper_->ShutdownContext(); | 629 helper_->ShutdownContext(); |
| 624 | 630 |
| 625 // Let the shutdown reach the simulated IO thread. | 631 // Let the shutdown reach the simulated IO thread. |
| 626 base::RunLoop().RunUntilIdle(); | 632 base::RunLoop().RunUntilIdle(); |
| 627 | 633 |
| 628 GetRegistrations(-1, ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); | 634 GetRegistrations(-1, ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); |
| 629 } | 635 } |
| 630 | 636 |
| 631 TEST_F(ServiceWorkerDispatcherHostTest, CleanupOnRendererCrash) { | 637 TEST_P(ServiceWorkerDispatcherHostTestP, CleanupOnRendererCrash) { |
| 632 GURL pattern = GURL("http://www.example.com/"); | 638 GURL pattern = GURL("http://www.example.com/"); |
| 633 GURL script_url = GURL("http://www.example.com/service_worker.js"); | 639 GURL script_url = GURL("http://www.example.com/service_worker.js"); |
| 634 int process_id = helper_->mock_render_process_id(); | 640 int process_id = helper_->mock_render_process_id(); |
| 635 | 641 |
| 636 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_WINDOW, pattern); | 642 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_WINDOW, pattern); |
| 637 SetUpRegistration(pattern, script_url); | 643 SetUpRegistration(pattern, script_url); |
| 638 int64_t provider_id = provider_host_->provider_id(); | 644 int64_t provider_id = provider_host_->provider_id(); |
| 639 | 645 |
| 640 // Start up the worker. | 646 // Start up the worker. |
| 641 bool called = false; | 647 bool called = false; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 666 | 672 |
| 667 // To show the new dispatcher can operate, simulate provider creation. Since | 673 // To show the new dispatcher can operate, simulate provider creation. Since |
| 668 // the old dispatcher cleaned up the old provider host, the new one won't | 674 // the old dispatcher cleaned up the old provider host, the new one won't |
| 669 // complain. | 675 // complain. |
| 670 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( | 676 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( |
| 671 provider_id, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 677 provider_id, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| 672 true /* is_parent_frame_secure */)); | 678 true /* is_parent_frame_secure */)); |
| 673 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); | 679 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); |
| 674 } | 680 } |
| 675 | 681 |
| 676 TEST_F(ServiceWorkerDispatcherHostTest, DispatchExtendableMessageEvent) { | 682 TEST_P(ServiceWorkerDispatcherHostTestP, DispatchExtendableMessageEvent) { |
| 677 GURL pattern = GURL("http://www.example.com/"); | 683 GURL pattern = GURL("http://www.example.com/"); |
| 678 GURL script_url = GURL("http://www.example.com/service_worker.js"); | 684 GURL script_url = GURL("http://www.example.com/service_worker.js"); |
| 679 | 685 |
| 680 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, pattern); | 686 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, pattern); |
| 681 SetUpRegistration(pattern, script_url); | 687 SetUpRegistration(pattern, script_url); |
| 682 | 688 |
| 683 // Set the running hosted version so that we can retrieve a valid service | 689 // Set the running hosted version so that we can retrieve a valid service |
| 684 // worker object information for the source attribute of the message event. | 690 // worker object information for the source attribute of the message event. |
| 685 provider_host_->running_hosted_version_ = version_; | 691 provider_host_->running_hosted_version_ = version_; |
| 686 | 692 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 706 EXPECT_TRUE(called); | 712 EXPECT_TRUE(called); |
| 707 EXPECT_EQ(SERVICE_WORKER_OK, status); | 713 EXPECT_EQ(SERVICE_WORKER_OK, status); |
| 708 | 714 |
| 709 // Messages should be held until ports are created at the destination. | 715 // Messages should be held until ports are created at the destination. |
| 710 for (int port : ports) | 716 for (int port : ports) |
| 711 EXPECT_TRUE(MessagePortService::GetInstance()->AreMessagesHeld(port)); | 717 EXPECT_TRUE(MessagePortService::GetInstance()->AreMessagesHeld(port)); |
| 712 | 718 |
| 713 EXPECT_EQ(ref_count + 1, sender_worker_handle->ref_count()); | 719 EXPECT_EQ(ref_count + 1, sender_worker_handle->ref_count()); |
| 714 } | 720 } |
| 715 | 721 |
| 716 TEST_F(ServiceWorkerDispatcherHostTest, DispatchExtendableMessageEvent_Fail) { | 722 TEST_P(ServiceWorkerDispatcherHostTestP, DispatchExtendableMessageEvent_Fail) { |
| 717 GURL pattern = GURL("http://www.example.com/"); | 723 GURL pattern = GURL("http://www.example.com/"); |
| 718 GURL script_url = GURL("http://www.example.com/service_worker.js"); | 724 GURL script_url = GURL("http://www.example.com/service_worker.js"); |
| 719 | 725 |
| 720 Initialize(base::WrapUnique(new FailToStartWorkerTestHelper)); | 726 Initialize(base::WrapUnique(new FailToStartWorkerTestHelper)); |
| 721 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, pattern); | 727 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, pattern); |
| 722 SetUpRegistration(pattern, script_url); | 728 SetUpRegistration(pattern, script_url); |
| 723 | 729 |
| 724 // Set the running hosted version so that we can retrieve a valid service | 730 // Set the running hosted version so that we can retrieve a valid service |
| 725 // worker object information for the source attribute of the message event. | 731 // worker object information for the source attribute of the message event. |
| 726 provider_host_->running_hosted_version_ = version_; | 732 provider_host_->running_hosted_version_ = version_; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 747 base::RunLoop().RunUntilIdle(); | 753 base::RunLoop().RunUntilIdle(); |
| 748 EXPECT_TRUE(called); | 754 EXPECT_TRUE(called); |
| 749 EXPECT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status); | 755 EXPECT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status); |
| 750 | 756 |
| 751 // The error callback should clean up the ports and handle. | 757 // The error callback should clean up the ports and handle. |
| 752 for (int port : ports) | 758 for (int port : ports) |
| 753 EXPECT_FALSE(MessagePortService::GetInstance()->AreMessagesHeld(port)); | 759 EXPECT_FALSE(MessagePortService::GetInstance()->AreMessagesHeld(port)); |
| 754 EXPECT_EQ(ref_count, sender_worker_handle->ref_count()); | 760 EXPECT_EQ(ref_count, sender_worker_handle->ref_count()); |
| 755 } | 761 } |
| 756 | 762 |
| 757 TEST_F(ServiceWorkerDispatcherHostTest, OnSetHostedVersionId) { | 763 TEST_P(ServiceWorkerDispatcherHostTestP, OnSetHostedVersionId) { |
| 758 GURL pattern = GURL("http://www.example.com/"); | 764 GURL pattern = GURL("http://www.example.com/"); |
| 759 GURL script_url = GURL("http://www.example.com/service_worker.js"); | 765 GURL script_url = GURL("http://www.example.com/service_worker.js"); |
| 760 | 766 |
| 761 Initialize(base::WrapUnique(new FailToStartWorkerTestHelper)); | 767 Initialize(base::WrapUnique(new FailToStartWorkerTestHelper)); |
| 762 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, pattern); | 768 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, pattern); |
| 763 SetUpRegistration(pattern, script_url); | 769 SetUpRegistration(pattern, script_url); |
| 764 | 770 |
| 765 const int64_t kProviderId = 99; // Dummy value | 771 const int64_t kProviderId = 99; // Dummy value |
| 766 bool called; | 772 bool called; |
| 767 ServiceWorkerStatusCode status; | 773 ServiceWorkerStatusCode status; |
| 768 // StartWorker puts the worker in STARTING state but it will have no | 774 // StartWorker puts the worker in STARTING state but it will have no |
| 769 // process id yet. | 775 // process id yet. |
| 770 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, | 776 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, |
| 771 base::Bind(&SaveStatusCallback, &called, &status)); | 777 base::Bind(&SaveStatusCallback, &called, &status)); |
| 772 EXPECT_NE(version_->embedded_worker()->process_id(), | 778 EXPECT_NE(version_->embedded_worker()->process_id(), |
| 773 provider_host_->process_id()); | 779 provider_host_->process_id()); |
| 774 // SendSetHostedVersionId should reject because the provider host process id | 780 // SendSetHostedVersionId should reject because the provider host process id |
| 775 // is different. It should call BadMessageReceived because it's not an | 781 // is different. It should call BadMessageReceived because it's not an |
| 776 // expected error state. | 782 // expected error state. |
| 777 SendSetHostedVersionId(kProviderId, version_->version_id(), | 783 SendSetHostedVersionId(kProviderId, version_->version_id(), |
| 778 version_->embedded_worker()->embedded_worker_id()); | 784 version_->embedded_worker()->embedded_worker_id()); |
| 779 base::RunLoop().RunUntilIdle(); | 785 base::RunLoop().RunUntilIdle(); |
| 780 EXPECT_FALSE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | 786 EXPECT_FALSE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( |
| 781 ServiceWorkerMsg_AssociateRegistration::ID)); | 787 ServiceWorkerMsg_AssociateRegistration::ID)); |
| 782 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 788 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 783 } | 789 } |
| 784 | 790 |
| 785 TEST_F(ServiceWorkerDispatcherHostTest, OnSetHostedVersionId_DetachedWorker) { | 791 TEST_P(ServiceWorkerDispatcherHostTestP, OnSetHostedVersionId_DetachedWorker) { |
| 786 GURL pattern = GURL("http://www.example.com/"); | 792 GURL pattern = GURL("http://www.example.com/"); |
| 787 GURL script_url = GURL("http://www.example.com/service_worker.js"); | 793 GURL script_url = GURL("http://www.example.com/service_worker.js"); |
| 788 | 794 |
| 789 Initialize(base::WrapUnique(new FailToStartWorkerTestHelper)); | 795 Initialize(base::WrapUnique(new FailToStartWorkerTestHelper)); |
| 790 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, pattern); | 796 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, pattern); |
| 791 SetUpRegistration(pattern, script_url); | 797 SetUpRegistration(pattern, script_url); |
| 792 | 798 |
| 793 const int64_t kProviderId = 99; // Dummy value | 799 const int64_t kProviderId = 99; // Dummy value |
| 794 bool called; | 800 bool called; |
| 795 ServiceWorkerStatusCode status; | 801 ServiceWorkerStatusCode status; |
| 796 // StartWorker puts the worker in STARTING state. | 802 // StartWorker puts the worker in STARTING state. |
| 797 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, | 803 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, |
| 798 base::Bind(&SaveStatusCallback, &called, &status)); | 804 base::Bind(&SaveStatusCallback, &called, &status)); |
| 799 | 805 |
| 800 // SendSetHostedVersionId should bail because the embedded worker is | 806 // SendSetHostedVersionId should bail because the embedded worker is |
| 801 // different. It shouldn't call BadMessageReceived because receiving a message | 807 // different. It shouldn't call BadMessageReceived because receiving a message |
| 802 // for a detached worker is a legitimite possibility. | 808 // for a detached worker is a legitimite possibility. |
| 803 int bad_embedded_worker_id = | 809 int bad_embedded_worker_id = |
| 804 version_->embedded_worker()->embedded_worker_id() + 1; | 810 version_->embedded_worker()->embedded_worker_id() + 1; |
| 805 SendSetHostedVersionId(kProviderId, version_->version_id(), | 811 SendSetHostedVersionId(kProviderId, version_->version_id(), |
| 806 bad_embedded_worker_id); | 812 bad_embedded_worker_id); |
| 807 base::RunLoop().RunUntilIdle(); | 813 base::RunLoop().RunUntilIdle(); |
| 808 EXPECT_FALSE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | 814 EXPECT_FALSE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( |
| 809 ServiceWorkerMsg_AssociateRegistration::ID)); | 815 ServiceWorkerMsg_AssociateRegistration::ID)); |
| 810 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); | 816 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); |
| 811 } | 817 } |
| 812 | 818 |
| 813 TEST_F(ServiceWorkerDispatcherHostTest, ReceivedTimedOutRequestResponse) { | 819 TEST_P(ServiceWorkerDispatcherHostTestP, ReceivedTimedOutRequestResponse) { |
| 814 GURL pattern = GURL("https://www.example.com/"); | 820 GURL pattern = GURL("https://www.example.com/"); |
| 815 GURL script_url = GURL("https://www.example.com/service_worker.js"); | 821 GURL script_url = GURL("https://www.example.com/service_worker.js"); |
| 816 | 822 |
| 817 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_WINDOW, pattern); | 823 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_WINDOW, pattern); |
| 818 SetUpRegistration(pattern, script_url); | 824 SetUpRegistration(pattern, script_url); |
| 819 | 825 |
| 820 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, | 826 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, |
| 821 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 827 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 822 base::RunLoop().RunUntilIdle(); | 828 base::RunLoop().RunUntilIdle(); |
| 823 | 829 |
| 824 // Set the worker status to STOPPING. | 830 // Set the worker status to STOPPING. |
| 825 version_->embedded_worker()->Stop(); | 831 version_->embedded_worker()->Stop(); |
| 826 EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, version_->running_status()); | 832 EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, version_->running_status()); |
| 827 | 833 |
| 828 // Receive a response for a timed out request. The bad message count should | 834 // Receive a response for a timed out request. The bad message count should |
| 829 // not increase. | 835 // not increase. |
| 830 const int kFetchEventId = 91; // Dummy value | 836 const int kFetchEventId = 91; // Dummy value |
| 831 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse( | 837 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse( |
| 832 version_->embedded_worker()->embedded_worker_id(), kFetchEventId, | 838 version_->embedded_worker()->embedded_worker_id(), kFetchEventId, |
| 833 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse(), | 839 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse(), |
| 834 base::Time::Now())); | 840 base::Time::Now())); |
| 835 | 841 |
| 836 base::RunLoop().RunUntilIdle(); | 842 base::RunLoop().RunUntilIdle(); |
| 837 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); | 843 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); |
| 838 } | 844 } |
| 839 | 845 |
| 846 INSTANTIATE_TEST_CASE_P(ServiceWorkerDispatcherHostTest, |
| 847 ServiceWorkerDispatcherHostTestP, |
| 848 testing::Bool()); |
| 849 |
| 840 } // namespace content | 850 } // namespace content |
| OLD | NEW |