Chromium Code Reviews| 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 #ifdef CRBUG_500404 | |
| 102 void SendUnregister(int64 provider_id, GURL pattern) { | 103 void SendUnregister(int64 provider_id, GURL pattern) { |
| 103 dispatcher_host_->OnMessageReceived( | 104 dispatcher_host_->OnMessageReceived( |
| 104 ServiceWorkerHostMsg_UnregisterServiceWorker( | 105 ServiceWorkerHostMsg_DeprecatedUnregisterServiceWorker( |
| 105 -1, -1, provider_id, pattern)); | 106 -1, -1, provider_id, pattern)); |
| 106 base::RunLoop().RunUntilIdle(); | 107 base::RunLoop().RunUntilIdle(); |
| 107 } | 108 } |
| 108 | 109 |
| 109 void Unregister(int64 provider_id, GURL pattern, uint32 expected_message) { | 110 void Unregister(int64 provider_id, GURL pattern, uint32 expected_message) { |
| 110 SendUnregister(provider_id, pattern); | 111 SendUnregister(provider_id, pattern); |
| 111 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | 112 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( |
| 112 expected_message)); | 113 expected_message)); |
| 113 dispatcher_host_->ipc_sink()->ClearMessages(); | 114 dispatcher_host_->ipc_sink()->ClearMessages(); |
| 114 } | 115 } |
| 116 #else | |
| 117 void SendUnregister(int64 provider_id, int64 registration_id) { | |
| 118 dispatcher_host_->OnMessageReceived( | |
| 119 ServiceWorkerHostMsg_UnregisterServiceWorker(-1, -1, provider_id, | |
| 120 registration_id)); | |
| 121 base::RunLoop().RunUntilIdle(); | |
| 122 } | |
| 123 | |
| 124 void Unregister(int64 provider_id, | |
| 125 int64 registration_id, | |
| 126 uint32 expected_message) { | |
| 127 SendUnregister(provider_id, registration_id); | |
| 128 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | |
| 129 expected_message)); | |
| 130 dispatcher_host_->ipc_sink()->ClearMessages(); | |
| 131 } | |
| 132 #endif // CRBUG_500404 | |
| 115 | 133 |
| 116 void SendGetRegistration(int64 provider_id, GURL document_url) { | 134 void SendGetRegistration(int64 provider_id, GURL document_url) { |
| 117 dispatcher_host_->OnMessageReceived( | 135 dispatcher_host_->OnMessageReceived( |
| 118 ServiceWorkerHostMsg_GetRegistration( | 136 ServiceWorkerHostMsg_GetRegistration( |
| 119 -1, -1, provider_id, document_url)); | 137 -1, -1, provider_id, document_url)); |
| 120 base::RunLoop().RunUntilIdle(); | 138 base::RunLoop().RunUntilIdle(); |
| 121 } | 139 } |
| 122 | 140 |
| 123 void GetRegistration(int64 provider_id, | 141 void GetRegistration(int64 provider_id, |
| 124 GURL document_url, | 142 GURL document_url, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 const int64 kProviderId = 99; // Dummy value | 195 const int64 kProviderId = 99; // Dummy value |
| 178 scoped_ptr<ServiceWorkerProviderHost> host( | 196 scoped_ptr<ServiceWorkerProviderHost> host( |
| 179 CreateServiceWorkerProviderHost(kProviderId)); | 197 CreateServiceWorkerProviderHost(kProviderId)); |
| 180 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 198 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 181 context()->AddProviderHost(host.Pass()); | 199 context()->AddProviderHost(host.Pass()); |
| 182 | 200 |
| 183 Register(kProviderId, | 201 Register(kProviderId, |
| 184 GURL("https://www.example.com/"), | 202 GURL("https://www.example.com/"), |
| 185 GURL("https://www.example.com/bar"), | 203 GURL("https://www.example.com/bar"), |
| 186 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); | 204 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); |
| 187 Unregister(kProviderId, | |
| 188 GURL("https://www.example.com/"), | |
| 189 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); | |
| 190 GetRegistration(kProviderId, | 205 GetRegistration(kProviderId, |
| 191 GURL("https://www.example.com/"), | 206 GURL("https://www.example.com/"), |
| 192 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); | 207 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); |
| 193 GetRegistrations(kProviderId, | 208 GetRegistrations(kProviderId, |
| 194 ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); | 209 ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); |
| 210 #ifdef CRBUG_500404 | |
|
kinuko
2015/06/17 17:44:56
I don't really understand why we still need these
nhiroki
2015/06/17 23:23:48
#define was already landed in the 1st patch and wi
| |
| 211 Unregister(kProviderId, GURL("https://www.example.com/"), | |
| 212 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); | |
| 213 #else | |
| 214 // Add a registration into a live registration map so that Unregister() can | |
| 215 // find it. | |
| 216 const int64 kRegistrationId = 999; // Dummy value | |
| 217 scoped_refptr<ServiceWorkerRegistration> registration( | |
| 218 new ServiceWorkerRegistration(GURL("https://www.example.com/"), | |
| 219 kRegistrationId, context()->AsWeakPtr())); | |
| 220 Unregister(kProviderId, kRegistrationId, | |
| 221 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); | |
| 222 #endif // CRBUG_500404 | |
| 195 | 223 |
| 196 SetBrowserClientForTesting(old_browser_client); | 224 SetBrowserClientForTesting(old_browser_client); |
| 197 } | 225 } |
| 198 | 226 |
| 199 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { | 227 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { |
| 200 const int64 kProviderId = 99; // Dummy value | 228 const int64 kProviderId = 99; // Dummy value |
| 201 scoped_ptr<ServiceWorkerProviderHost> host( | 229 scoped_ptr<ServiceWorkerProviderHost> host( |
| 202 CreateServiceWorkerProviderHost(kProviderId)); | 230 CreateServiceWorkerProviderHost(kProviderId)); |
| 203 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 231 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 204 context()->AddProviderHost(host.Pass()); | 232 context()->AddProviderHost(host.Pass()); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 GURL("https://www.example.com/temporary/"), | 371 GURL("https://www.example.com/temporary/"), |
| 344 GURL("filesystem:https://www.example.com/temporary/bar")); | 372 GURL("filesystem:https://www.example.com/temporary/bar")); |
| 345 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); | 373 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); |
| 346 | 374 |
| 347 SendRegister(kProviderId, | 375 SendRegister(kProviderId, |
| 348 GURL("filesystem:https://www.example.com/temporary/"), | 376 GURL("filesystem:https://www.example.com/temporary/"), |
| 349 GURL("filesystem:https://www.example.com/temporary/bar")); | 377 GURL("filesystem:https://www.example.com/temporary/bar")); |
| 350 EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); | 378 EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); |
| 351 } | 379 } |
| 352 | 380 |
| 381 // TODO(nhiroki): Remove these tests after http://crbug.com/500404 is fixed. | |
| 382 #ifdef CRBUG_500404 | |
| 353 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_HTTPS) { | 383 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_HTTPS) { |
| 354 const int64 kProviderId = 99; // Dummy value | 384 const int64 kProviderId = 99; // Dummy value |
| 355 scoped_ptr<ServiceWorkerProviderHost> host( | 385 scoped_ptr<ServiceWorkerProviderHost> host( |
| 356 CreateServiceWorkerProviderHost(kProviderId)); | 386 CreateServiceWorkerProviderHost(kProviderId)); |
| 357 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 387 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 358 context()->AddProviderHost(host.Pass()); | 388 context()->AddProviderHost(host.Pass()); |
| 359 | 389 |
| 360 Unregister(kProviderId, | 390 Unregister(kProviderId, |
| 361 GURL("https://www.example.com/"), | 391 GURL("https://www.example.com/"), |
| 362 ServiceWorkerMsg_ServiceWorkerUnregistered::ID); | 392 ServiceWorkerMsg_ServiceWorkerUnregistered::ID); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_NonSecureOriginShouldFail) { | 430 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_NonSecureOriginShouldFail) { |
| 401 const int64 kProviderId = 99; // Dummy value | 431 const int64 kProviderId = 99; // Dummy value |
| 402 scoped_ptr<ServiceWorkerProviderHost> host( | 432 scoped_ptr<ServiceWorkerProviderHost> host( |
| 403 CreateServiceWorkerProviderHost(kProviderId)); | 433 CreateServiceWorkerProviderHost(kProviderId)); |
| 404 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 434 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
| 405 context()->AddProviderHost(host.Pass()); | 435 context()->AddProviderHost(host.Pass()); |
| 406 | 436 |
| 407 SendUnregister(kProviderId, GURL("http://www.example.com/")); | 437 SendUnregister(kProviderId, GURL("http://www.example.com/")); |
| 408 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 438 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 409 } | 439 } |
| 440 #endif // CRBUG_500404 | |
| 410 | 441 |
| 411 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { | 442 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { |
| 412 helper_->ShutdownContext(); | 443 helper_->ShutdownContext(); |
| 413 | 444 |
| 414 // Let the shutdown reach the simulated IO thread. | 445 // Let the shutdown reach the simulated IO thread. |
| 415 base::RunLoop().RunUntilIdle(); | 446 base::RunLoop().RunUntilIdle(); |
| 416 | 447 |
| 417 Register(-1, | 448 Register(-1, |
| 418 GURL(), | 449 GURL(), |
| 419 GURL(), | 450 GURL(), |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 605 | 636 |
| 606 // To show the new dispatcher can operate, simulate provider creation. Since | 637 // 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 | 638 // the old dispatcher cleaned up the old provider host, the new one won't |
| 608 // complain. | 639 // complain. |
| 609 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( | 640 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( |
| 610 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW)); | 641 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW)); |
| 611 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); | 642 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); |
| 612 } | 643 } |
| 613 | 644 |
| 614 } // namespace content | 645 } // namespace content |
| OLD | NEW |