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