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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 *called = true; | 43 *called = true; |
44 *out = status; | 44 *out = status; |
45 } | 45 } |
46 | 46 |
47 void SetUpDummyMessagePort(std::vector<MessagePort>* ports) { | 47 void SetUpDummyMessagePort(std::vector<MessagePort>* ports) { |
48 // Let the other end of the pipe close. | 48 // Let the other end of the pipe close. |
49 mojo::MessagePipe pipe; | 49 mojo::MessagePipe pipe; |
50 ports->push_back(MessagePort(std::move(pipe.handle0))); | 50 ports->push_back(MessagePort(std::move(pipe.handle0))); |
51 } | 51 } |
52 | 52 |
| 53 struct RemoteProviderInfo { |
| 54 mojom::ServiceWorkerProviderHostAssociatedPtr host_ptr; |
| 55 mojom::ServiceWorkerProviderAssociatedRequest client_request; |
| 56 }; |
| 57 |
| 58 RemoteProviderInfo SetupProviderHostInfoPtrs( |
| 59 ServiceWorkerProviderHostInfo* host_info) { |
| 60 RemoteProviderInfo remote_info; |
| 61 mojom::ServiceWorkerProviderAssociatedPtr browser_side_client_ptr; |
| 62 remote_info.client_request = |
| 63 mojo::MakeIsolatedRequest(&browser_side_client_ptr); |
| 64 host_info->host_request = mojo::MakeIsolatedRequest(&remote_info.host_ptr); |
| 65 host_info->client_ptr_info = browser_side_client_ptr.PassInterface(); |
| 66 EXPECT_TRUE(host_info->host_request.is_pending()); |
| 67 EXPECT_TRUE(host_info->client_ptr_info.is_valid()); |
| 68 EXPECT_TRUE(remote_info.host_ptr.is_bound()); |
| 69 EXPECT_TRUE(remote_info.client_request.is_pending()); |
| 70 return remote_info; |
| 71 } |
| 72 |
53 } // namespace | 73 } // namespace |
54 | 74 |
55 static const int kRenderFrameId = 1; | 75 static const int kRenderFrameId = 1; |
56 | 76 |
57 class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost { | 77 class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost { |
58 public: | 78 public: |
59 TestingServiceWorkerDispatcherHost( | 79 TestingServiceWorkerDispatcherHost( |
60 int process_id, | 80 int process_id, |
61 ServiceWorkerContextWrapper* context_wrapper, | 81 ServiceWorkerContextWrapper* context_wrapper, |
62 ResourceContext* resource_context, | 82 ResourceContext* resource_context, |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 Register(-1, | 522 Register(-1, |
503 GURL(), | 523 GURL(), |
504 GURL(), | 524 GURL(), |
505 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); | 525 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); |
506 } | 526 } |
507 | 527 |
508 TEST_F(ServiceWorkerDispatcherHostTest, ProviderCreatedAndDestroyed) { | 528 TEST_F(ServiceWorkerDispatcherHostTest, ProviderCreatedAndDestroyed) { |
509 const int kProviderId = 1001; | 529 const int kProviderId = 1001; |
510 int process_id = helper_->mock_render_process_id(); | 530 int process_id = helper_->mock_render_process_id(); |
511 | 531 |
512 dispatcher_host_->OnProviderCreated(ServiceWorkerProviderHostInfo( | 532 // Setup ServiceWorkerProviderHostInfo |
513 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 533 ServiceWorkerProviderHostInfo host_info_1(kProviderId, MSG_ROUTING_NONE, |
514 true /* is_parent_frame_secure */)); | 534 SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| 535 true /* is_parent_frame_secure */); |
| 536 ServiceWorkerProviderHostInfo host_info_2(kProviderId, MSG_ROUTING_NONE, |
| 537 SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| 538 true /* is_parent_frame_secure */); |
| 539 ServiceWorkerProviderHostInfo host_info_3(kProviderId, MSG_ROUTING_NONE, |
| 540 SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| 541 true /* is_parent_frame_secure */); |
| 542 RemoteProviderInfo remote_info_1 = SetupProviderHostInfoPtrs(&host_info_1); |
| 543 RemoteProviderInfo remote_info_2 = SetupProviderHostInfoPtrs(&host_info_2); |
| 544 RemoteProviderInfo remote_info_3 = SetupProviderHostInfoPtrs(&host_info_3); |
| 545 |
| 546 dispatcher_host_->OnProviderCreated(std::move(host_info_1)); |
515 EXPECT_TRUE(context()->GetProviderHost(process_id, kProviderId)); | 547 EXPECT_TRUE(context()->GetProviderHost(process_id, kProviderId)); |
516 | 548 |
517 // Two with the same ID should be seen as a bad message. | 549 // Two with the same ID should be seen as a bad message. |
518 dispatcher_host_->OnProviderCreated(ServiceWorkerProviderHostInfo( | 550 dispatcher_host_->OnProviderCreated(std::move(host_info_2)); |
519 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW, | |
520 true /* is_parent_frame_secure */)); | |
521 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 551 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
522 | 552 |
523 dispatcher_host_->OnProviderDestroyed(kProviderId); | 553 // Releasing the interface pointer destroys the counterpart. |
| 554 remote_info_1.host_ptr.reset(); |
| 555 base::RunLoop().RunUntilIdle(); |
524 EXPECT_FALSE(context()->GetProviderHost(process_id, kProviderId)); | 556 EXPECT_FALSE(context()->GetProviderHost(process_id, kProviderId)); |
525 | 557 |
526 // Destroying an ID that does not exist warrants a bad message. | |
527 dispatcher_host_->OnProviderDestroyed(kProviderId); | |
528 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); | |
529 | |
530 // Deletion of the dispatcher_host should cause providers for that | 558 // Deletion of the dispatcher_host should cause providers for that |
531 // process to get deleted as well. | 559 // process to get deleted as well. |
532 dispatcher_host_->OnProviderCreated(ServiceWorkerProviderHostInfo( | 560 dispatcher_host_->OnProviderCreated(std::move(host_info_3)); |
533 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW, | |
534 true /* is_parent_frame_secure */)); | |
535 EXPECT_TRUE(context()->GetProviderHost(process_id, kProviderId)); | 561 EXPECT_TRUE(context()->GetProviderHost(process_id, kProviderId)); |
536 EXPECT_TRUE(dispatcher_host_->HasOneRef()); | 562 EXPECT_TRUE(dispatcher_host_->HasOneRef()); |
537 dispatcher_host_ = nullptr; | 563 dispatcher_host_ = nullptr; |
538 EXPECT_FALSE(context()->GetProviderHost(process_id, kProviderId)); | 564 EXPECT_FALSE(context()->GetProviderHost(process_id, kProviderId)); |
539 } | 565 } |
540 | 566 |
541 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_SameOrigin) { | 567 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_SameOrigin) { |
542 const int64_t kProviderId = 99; // Dummy value | 568 const int64_t kProviderId = 99; // Dummy value |
543 std::unique_ptr<ServiceWorkerProviderHost> host( | 569 std::unique_ptr<ServiceWorkerProviderHost> host( |
544 CreateServiceWorkerProviderHost(kProviderId)); | 570 CreateServiceWorkerProviderHost(kProviderId)); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse( | 857 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse( |
832 version_->embedded_worker()->embedded_worker_id(), kFetchEventId, | 858 version_->embedded_worker()->embedded_worker_id(), kFetchEventId, |
833 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse(), | 859 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse(), |
834 base::Time::Now())); | 860 base::Time::Now())); |
835 | 861 |
836 base::RunLoop().RunUntilIdle(); | 862 base::RunLoop().RunUntilIdle(); |
837 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); | 863 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); |
838 } | 864 } |
839 | 865 |
840 } // namespace content | 866 } // namespace content |
OLD | NEW |