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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 void Register(int64 provider_id, | 92 void Register(int64 provider_id, |
93 GURL pattern, | 93 GURL pattern, |
94 GURL worker_url, | 94 GURL worker_url, |
95 uint32 expected_message) { | 95 uint32 expected_message) { |
96 SendRegister(provider_id, pattern, worker_url); | 96 SendRegister(provider_id, pattern, worker_url); |
97 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | 97 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( |
98 expected_message)); | 98 expected_message)); |
99 dispatcher_host_->ipc_sink()->ClearMessages(); | 99 dispatcher_host_->ipc_sink()->ClearMessages(); |
100 } | 100 } |
101 | 101 |
102 void SendUnregister(int64 provider_id, GURL pattern) { | |
103 dispatcher_host_->OnMessageReceived( | |
104 ServiceWorkerHostMsg_UnregisterServiceWorker( | |
105 -1, -1, provider_id, pattern)); | |
106 base::RunLoop().RunUntilIdle(); | |
107 } | |
108 | |
109 void Unregister(int64 provider_id, GURL pattern, uint32 expected_message) { | |
110 SendUnregister(provider_id, pattern); | |
111 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | |
112 expected_message)); | |
113 dispatcher_host_->ipc_sink()->ClearMessages(); | |
114 } | |
115 | |
116 void SendGetRegistration(int64 provider_id, GURL document_url) { | 102 void SendGetRegistration(int64 provider_id, GURL document_url) { |
117 dispatcher_host_->OnMessageReceived( | 103 dispatcher_host_->OnMessageReceived( |
118 ServiceWorkerHostMsg_GetRegistration( | 104 ServiceWorkerHostMsg_GetRegistration( |
119 -1, -1, provider_id, document_url)); | 105 -1, -1, provider_id, document_url)); |
120 base::RunLoop().RunUntilIdle(); | 106 base::RunLoop().RunUntilIdle(); |
121 } | 107 } |
122 | 108 |
123 void GetRegistration(int64 provider_id, | 109 void GetRegistration(int64 provider_id, |
124 GURL document_url, | 110 GURL document_url, |
125 uint32 expected_message) { | 111 uint32 expected_message) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 const int64 kProviderId = 99; // Dummy value | 163 const int64 kProviderId = 99; // Dummy value |
178 scoped_ptr<ServiceWorkerProviderHost> host( | 164 scoped_ptr<ServiceWorkerProviderHost> host( |
179 CreateServiceWorkerProviderHost(kProviderId)); | 165 CreateServiceWorkerProviderHost(kProviderId)); |
180 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 166 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
181 context()->AddProviderHost(host.Pass()); | 167 context()->AddProviderHost(host.Pass()); |
182 | 168 |
183 Register(kProviderId, | 169 Register(kProviderId, |
184 GURL("https://www.example.com/"), | 170 GURL("https://www.example.com/"), |
185 GURL("https://www.example.com/bar"), | 171 GURL("https://www.example.com/bar"), |
186 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); | 172 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); |
187 Unregister(kProviderId, | |
188 GURL("https://www.example.com/"), | |
189 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); | |
190 GetRegistration(kProviderId, | 173 GetRegistration(kProviderId, |
191 GURL("https://www.example.com/"), | 174 GURL("https://www.example.com/"), |
192 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); | 175 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); |
193 GetRegistrations(kProviderId, | 176 GetRegistrations(kProviderId, |
194 ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); | 177 ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); |
| 178 // TODO(nhiroki): Test Unregister() (http://crbug.com/500404). |
195 | 179 |
196 SetBrowserClientForTesting(old_browser_client); | 180 SetBrowserClientForTesting(old_browser_client); |
197 } | 181 } |
198 | 182 |
199 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { | 183 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { |
200 const int64 kProviderId = 99; // Dummy value | 184 const int64 kProviderId = 99; // Dummy value |
201 scoped_ptr<ServiceWorkerProviderHost> host( | 185 scoped_ptr<ServiceWorkerProviderHost> host( |
202 CreateServiceWorkerProviderHost(kProviderId)); | 186 CreateServiceWorkerProviderHost(kProviderId)); |
203 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 187 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
204 context()->AddProviderHost(host.Pass()); | 188 context()->AddProviderHost(host.Pass()); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 GURL("https://www.example.com/temporary/"), | 327 GURL("https://www.example.com/temporary/"), |
344 GURL("filesystem:https://www.example.com/temporary/bar")); | 328 GURL("filesystem:https://www.example.com/temporary/bar")); |
345 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); | 329 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); |
346 | 330 |
347 SendRegister(kProviderId, | 331 SendRegister(kProviderId, |
348 GURL("filesystem:https://www.example.com/temporary/"), | 332 GURL("filesystem:https://www.example.com/temporary/"), |
349 GURL("filesystem:https://www.example.com/temporary/bar")); | 333 GURL("filesystem:https://www.example.com/temporary/bar")); |
350 EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); | 334 EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); |
351 } | 335 } |
352 | 336 |
353 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_HTTPS) { | |
354 const int64 kProviderId = 99; // Dummy value | |
355 scoped_ptr<ServiceWorkerProviderHost> host( | |
356 CreateServiceWorkerProviderHost(kProviderId)); | |
357 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | |
358 context()->AddProviderHost(host.Pass()); | |
359 | |
360 Unregister(kProviderId, | |
361 GURL("https://www.example.com/"), | |
362 ServiceWorkerMsg_ServiceWorkerUnregistered::ID); | |
363 } | |
364 | |
365 TEST_F(ServiceWorkerDispatcherHostTest, | |
366 Unregister_NotSecureTransportLocalhost) { | |
367 const int64 kProviderId = 99; // Dummy value | |
368 scoped_ptr<ServiceWorkerProviderHost> host( | |
369 CreateServiceWorkerProviderHost(kProviderId)); | |
370 host->SetDocumentUrl(GURL("http://localhost/foo")); | |
371 context()->AddProviderHost(host.Pass()); | |
372 | |
373 Unregister(kProviderId, | |
374 GURL("http://localhost/"), | |
375 ServiceWorkerMsg_ServiceWorkerUnregistered::ID); | |
376 } | |
377 | |
378 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_CrossOriginShouldFail) { | |
379 const int64 kProviderId = 99; // Dummy value | |
380 scoped_ptr<ServiceWorkerProviderHost> host( | |
381 CreateServiceWorkerProviderHost(kProviderId)); | |
382 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | |
383 context()->AddProviderHost(host.Pass()); | |
384 | |
385 SendUnregister(kProviderId, GURL("https://foo.example.com/")); | |
386 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | |
387 } | |
388 | |
389 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_InvalidScopeShouldFail) { | |
390 const int64 kProviderId = 99; // Dummy value | |
391 scoped_ptr<ServiceWorkerProviderHost> host( | |
392 CreateServiceWorkerProviderHost(kProviderId)); | |
393 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | |
394 context()->AddProviderHost(host.Pass()); | |
395 | |
396 SendUnregister(kProviderId, GURL("")); | |
397 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | |
398 } | |
399 | |
400 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_NonSecureOriginShouldFail) { | |
401 const int64 kProviderId = 99; // Dummy value | |
402 scoped_ptr<ServiceWorkerProviderHost> host( | |
403 CreateServiceWorkerProviderHost(kProviderId)); | |
404 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | |
405 context()->AddProviderHost(host.Pass()); | |
406 | |
407 SendUnregister(kProviderId, GURL("http://www.example.com/")); | |
408 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | |
409 } | |
410 | |
411 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { | 337 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { |
412 helper_->ShutdownContext(); | 338 helper_->ShutdownContext(); |
413 | 339 |
414 // Let the shutdown reach the simulated IO thread. | 340 // Let the shutdown reach the simulated IO thread. |
415 base::RunLoop().RunUntilIdle(); | 341 base::RunLoop().RunUntilIdle(); |
416 | 342 |
417 Register(-1, | 343 Register(-1, |
418 GURL(), | 344 GURL(), |
419 GURL(), | 345 GURL(), |
420 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); | 346 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 | 531 |
606 // To show the new dispatcher can operate, simulate provider creation. Since | 532 // To show the new dispatcher can operate, simulate provider creation. Since |
607 // the old dispatcher cleaned up the old provider host, the new one won't | 533 // the old dispatcher cleaned up the old provider host, the new one won't |
608 // complain. | 534 // complain. |
609 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( | 535 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( |
610 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW)); | 536 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW)); |
611 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); | 537 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); |
612 } | 538 } |
613 | 539 |
614 } // namespace content | 540 } // namespace content |
OLD | NEW |