OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" | 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 void GetRegistration(int64 provider_id, | 123 void GetRegistration(int64 provider_id, |
124 GURL document_url, | 124 GURL document_url, |
125 uint32 expected_message) { | 125 uint32 expected_message) { |
126 SendGetRegistration(provider_id, document_url); | 126 SendGetRegistration(provider_id, document_url); |
127 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | 127 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( |
128 expected_message)); | 128 expected_message)); |
129 dispatcher_host_->ipc_sink()->ClearMessages(); | 129 dispatcher_host_->ipc_sink()->ClearMessages(); |
130 } | 130 } |
131 | 131 |
| 132 void SendGetRegistrations(int64 provider_id) { |
| 133 dispatcher_host_->OnMessageReceived( |
| 134 ServiceWorkerHostMsg_GetRegistrations(-1, -1, provider_id)); |
| 135 base::RunLoop().RunUntilIdle(); |
| 136 } |
| 137 |
| 138 void GetRegistrations(int64 provider_id, uint32 expected_message) { |
| 139 SendGetRegistrations(provider_id); |
| 140 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( |
| 141 expected_message)); |
| 142 dispatcher_host_->ipc_sink()->ClearMessages(); |
| 143 } |
| 144 |
132 ServiceWorkerProviderHost* CreateServiceWorkerProviderHost(int provider_id) { | 145 ServiceWorkerProviderHost* CreateServiceWorkerProviderHost(int provider_id) { |
133 return new ServiceWorkerProviderHost( | 146 return new ServiceWorkerProviderHost( |
134 kRenderProcessId, kRenderFrameId, provider_id, | 147 kRenderProcessId, kRenderFrameId, provider_id, |
135 SERVICE_WORKER_PROVIDER_FOR_WINDOW, context()->AsWeakPtr(), | 148 SERVICE_WORKER_PROVIDER_FOR_WINDOW, context()->AsWeakPtr(), |
136 dispatcher_host_.get()); | 149 dispatcher_host_.get()); |
137 } | 150 } |
138 | 151 |
139 | 152 |
140 TestBrowserThreadBundle browser_thread_bundle_; | 153 TestBrowserThreadBundle browser_thread_bundle_; |
141 content::MockResourceContext resource_context_; | 154 content::MockResourceContext resource_context_; |
(...skipping 28 matching lines...) Expand all Loading... |
170 Register(kProviderId, | 183 Register(kProviderId, |
171 GURL("https://www.example.com/"), | 184 GURL("https://www.example.com/"), |
172 GURL("https://www.example.com/bar"), | 185 GURL("https://www.example.com/bar"), |
173 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); | 186 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); |
174 Unregister(kProviderId, | 187 Unregister(kProviderId, |
175 GURL("https://www.example.com/"), | 188 GURL("https://www.example.com/"), |
176 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); | 189 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); |
177 GetRegistration(kProviderId, | 190 GetRegistration(kProviderId, |
178 GURL("https://www.example.com/"), | 191 GURL("https://www.example.com/"), |
179 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); | 192 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); |
| 193 GetRegistrations(kProviderId, |
| 194 ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); |
180 | 195 |
181 SetBrowserClientForTesting(old_browser_client); | 196 SetBrowserClientForTesting(old_browser_client); |
182 } | 197 } |
183 | 198 |
184 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { | 199 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { |
185 const int64 kProviderId = 99; // Dummy value | 200 const int64 kProviderId = 99; // Dummy value |
186 scoped_ptr<ServiceWorkerProviderHost> host( | 201 scoped_ptr<ServiceWorkerProviderHost> host( |
187 CreateServiceWorkerProviderHost(kProviderId)); | 202 CreateServiceWorkerProviderHost(kProviderId)); |
188 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 203 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
189 context()->AddProviderHost(host.Pass()); | 204 context()->AddProviderHost(host.Pass()); |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 helper_->ShutdownContext(); | 502 helper_->ShutdownContext(); |
488 | 503 |
489 // Let the shutdown reach the simulated IO thread. | 504 // Let the shutdown reach the simulated IO thread. |
490 base::RunLoop().RunUntilIdle(); | 505 base::RunLoop().RunUntilIdle(); |
491 | 506 |
492 GetRegistration(-1, | 507 GetRegistration(-1, |
493 GURL(), | 508 GURL(), |
494 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); | 509 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); |
495 } | 510 } |
496 | 511 |
| 512 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistrations_SecureOrigin) { |
| 513 const int64 kProviderId = 99; // Dummy value |
| 514 scoped_ptr<ServiceWorkerProviderHost> host( |
| 515 CreateServiceWorkerProviderHost(kProviderId)); |
| 516 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 517 context()->AddProviderHost(host.Pass()); |
| 518 |
| 519 GetRegistrations(kProviderId, ServiceWorkerMsg_DidGetRegistrations::ID); |
| 520 } |
| 521 |
| 522 TEST_F(ServiceWorkerDispatcherHostTest, |
| 523 GetRegistrations_NonSecureOriginShouldFail) { |
| 524 const int64 kProviderId = 99; // Dummy value |
| 525 scoped_ptr<ServiceWorkerProviderHost> host( |
| 526 CreateServiceWorkerProviderHost(kProviderId)); |
| 527 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
| 528 context()->AddProviderHost(host.Pass()); |
| 529 |
| 530 SendGetRegistrations(kProviderId); |
| 531 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 532 } |
| 533 |
| 534 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistrations_EarlyContextDeletion) { |
| 535 helper_->ShutdownContext(); |
| 536 |
| 537 // Let the shutdown reach the simulated IO thread. |
| 538 base::RunLoop().RunUntilIdle(); |
| 539 |
| 540 GetRegistrations(-1, ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); |
| 541 } |
| 542 |
497 TEST_F(ServiceWorkerDispatcherHostTest, CleanupOnRendererCrash) { | 543 TEST_F(ServiceWorkerDispatcherHostTest, CleanupOnRendererCrash) { |
498 // Add a provider and worker. | 544 // Add a provider and worker. |
499 const int64 kProviderId = 99; // Dummy value | 545 const int64 kProviderId = 99; // Dummy value |
500 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( | 546 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( |
501 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW)); | 547 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW)); |
502 | 548 |
503 GURL pattern = GURL("http://www.example.com/"); | 549 GURL pattern = GURL("http://www.example.com/"); |
504 scoped_refptr<ServiceWorkerRegistration> registration( | 550 scoped_refptr<ServiceWorkerRegistration> registration( |
505 new ServiceWorkerRegistration(pattern, | 551 new ServiceWorkerRegistration(pattern, |
506 1L, | 552 1L, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 | 605 |
560 // To show the new dispatcher can operate, simulate provider creation. Since | 606 // To show the new dispatcher can operate, simulate provider creation. Since |
561 // the old dispatcher cleaned up the old provider host, the new one won't | 607 // the old dispatcher cleaned up the old provider host, the new one won't |
562 // complain. | 608 // complain. |
563 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( | 609 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( |
564 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW)); | 610 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW)); |
565 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); | 611 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); |
566 } | 612 } |
567 | 613 |
568 } // namespace content | 614 } // namespace content |
OLD | NEW |