| 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, int64 registration_id) { |
| 103 dispatcher_host_->OnMessageReceived( |
| 104 ServiceWorkerHostMsg_UnregisterServiceWorker(-1, -1, provider_id, |
| 105 registration_id)); |
| 106 base::RunLoop().RunUntilIdle(); |
| 107 } |
| 108 |
| 109 void Unregister(int64 provider_id, |
| 110 int64 registration_id, |
| 111 uint32 expected_message) { |
| 112 SendUnregister(provider_id, registration_id); |
| 113 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( |
| 114 expected_message)); |
| 115 dispatcher_host_->ipc_sink()->ClearMessages(); |
| 116 } |
| 117 |
| 102 void SendGetRegistration(int64 provider_id, GURL document_url) { | 118 void SendGetRegistration(int64 provider_id, GURL document_url) { |
| 103 dispatcher_host_->OnMessageReceived( | 119 dispatcher_host_->OnMessageReceived( |
| 104 ServiceWorkerHostMsg_GetRegistration( | 120 ServiceWorkerHostMsg_GetRegistration( |
| 105 -1, -1, provider_id, document_url)); | 121 -1, -1, provider_id, document_url)); |
| 106 base::RunLoop().RunUntilIdle(); | 122 base::RunLoop().RunUntilIdle(); |
| 107 } | 123 } |
| 108 | 124 |
| 109 void GetRegistration(int64 provider_id, | 125 void GetRegistration(int64 provider_id, |
| 110 GURL document_url, | 126 GURL document_url, |
| 111 uint32 expected_message) { | 127 uint32 expected_message) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 184 |
| 169 Register(kProviderId, | 185 Register(kProviderId, |
| 170 GURL("https://www.example.com/"), | 186 GURL("https://www.example.com/"), |
| 171 GURL("https://www.example.com/bar"), | 187 GURL("https://www.example.com/bar"), |
| 172 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); | 188 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); |
| 173 GetRegistration(kProviderId, | 189 GetRegistration(kProviderId, |
| 174 GURL("https://www.example.com/"), | 190 GURL("https://www.example.com/"), |
| 175 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); | 191 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); |
| 176 GetRegistrations(kProviderId, | 192 GetRegistrations(kProviderId, |
| 177 ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); | 193 ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); |
| 178 // TODO(nhiroki): Test Unregister() (http://crbug.com/500404). | 194 |
| 195 // Add a registration into a live registration map so that Unregister() can |
| 196 // find it. |
| 197 const int64 kRegistrationId = 999; // Dummy value |
| 198 scoped_refptr<ServiceWorkerRegistration> registration( |
| 199 new ServiceWorkerRegistration(GURL("https://www.example.com/"), |
| 200 kRegistrationId, context()->AsWeakPtr())); |
| 201 Unregister(kProviderId, kRegistrationId, |
| 202 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); |
| 179 | 203 |
| 180 SetBrowserClientForTesting(old_browser_client); | 204 SetBrowserClientForTesting(old_browser_client); |
| 181 } | 205 } |
| 182 | 206 |
| 183 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { | 207 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { |
| 184 const int64 kProviderId = 99; // Dummy value | 208 const int64 kProviderId = 99; // Dummy value |
| 185 scoped_ptr<ServiceWorkerProviderHost> host( | 209 scoped_ptr<ServiceWorkerProviderHost> host( |
| 186 CreateServiceWorkerProviderHost(kProviderId)); | 210 CreateServiceWorkerProviderHost(kProviderId)); |
| 187 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 211 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 188 context()->AddProviderHost(host.Pass()); | 212 context()->AddProviderHost(host.Pass()); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 | 555 |
| 532 // To show the new dispatcher can operate, simulate provider creation. Since | 556 // To show the new dispatcher can operate, simulate provider creation. Since |
| 533 // the old dispatcher cleaned up the old provider host, the new one won't | 557 // the old dispatcher cleaned up the old provider host, the new one won't |
| 534 // complain. | 558 // complain. |
| 535 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( | 559 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( |
| 536 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW)); | 560 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW)); |
| 537 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); | 561 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); |
| 538 } | 562 } |
| 539 | 563 |
| 540 } // namespace content | 564 } // namespace content |
| OLD | NEW |