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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 helper_.reset(helper.release()); | 162 helper_.reset(helper.release()); |
163 // Replace the default dispatcher host. | 163 // Replace the default dispatcher host. |
164 int process_id = helper_->mock_render_process_id(); | 164 int process_id = helper_->mock_render_process_id(); |
165 dispatcher_host_ = new TestingServiceWorkerDispatcherHost( | 165 dispatcher_host_ = new TestingServiceWorkerDispatcherHost( |
166 process_id, &resource_context_, helper_.get()); | 166 process_id, &resource_context_, helper_.get()); |
167 helper_->RegisterDispatcherHost(process_id, nullptr); | 167 helper_->RegisterDispatcherHost(process_id, nullptr); |
168 dispatcher_host_->Init(context_wrapper()); | 168 dispatcher_host_->Init(context_wrapper()); |
169 } | 169 } |
170 | 170 |
171 void SetUpRegistration(const GURL& scope, const GURL& script_url) { | 171 void SetUpRegistration(const GURL& scope, const GURL& script_url) { |
172 registration_ = new ServiceWorkerRegistration( | 172 registration_ = |
173 scope, 1L, helper_->context()->AsWeakPtr()); | 173 new ServiceWorkerRegistration(ServiceWorkerRegistrationOptions(scope), |
| 174 1L, helper_->context()->AsWeakPtr()); |
174 version_ = new ServiceWorkerVersion(registration_.get(), script_url, 1L, | 175 version_ = new ServiceWorkerVersion(registration_.get(), script_url, 1L, |
175 helper_->context()->AsWeakPtr()); | 176 helper_->context()->AsWeakPtr()); |
176 std::vector<ServiceWorkerDatabase::ResourceRecord> records; | 177 std::vector<ServiceWorkerDatabase::ResourceRecord> records; |
177 records.push_back( | 178 records.push_back( |
178 ServiceWorkerDatabase::ResourceRecord(10, version_->script_url(), 100)); | 179 ServiceWorkerDatabase::ResourceRecord(10, version_->script_url(), 100)); |
179 version_->script_cache_map()->SetResources(records); | 180 version_->script_cache_map()->SetResources(records); |
180 version_->SetMainScriptHttpResponseInfo( | 181 version_->SetMainScriptHttpResponseInfo( |
181 EmbeddedWorkerTestHelper::CreateHttpResponseInfo()); | 182 EmbeddedWorkerTestHelper::CreateHttpResponseInfo()); |
182 version_->set_fetch_handler_existence( | 183 version_->set_fetch_handler_existence( |
183 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); | 184 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); |
(...skipping 27 matching lines...) Expand all Loading... |
211 remote_endpoint_.BindWithProviderHostInfo(&info); | 212 remote_endpoint_.BindWithProviderHostInfo(&info); |
212 | 213 |
213 dispatcher_host_->OnProviderCreated(std::move(info)); | 214 dispatcher_host_->OnProviderCreated(std::move(info)); |
214 helper_->SimulateAddProcessToPattern(pattern, | 215 helper_->SimulateAddProcessToPattern(pattern, |
215 helper_->mock_render_process_id()); | 216 helper_->mock_render_process_id()); |
216 provider_host_ = context()->GetProviderHost( | 217 provider_host_ = context()->GetProviderHost( |
217 helper_->mock_render_process_id(), kProviderId); | 218 helper_->mock_render_process_id(), kProviderId); |
218 } | 219 } |
219 | 220 |
220 void SendRegister(int64_t provider_id, GURL pattern, GURL worker_url) { | 221 void SendRegister(int64_t provider_id, GURL pattern, GURL worker_url) { |
| 222 ServiceWorkerRegistrationOptions options(pattern); |
221 dispatcher_host_->OnMessageReceived( | 223 dispatcher_host_->OnMessageReceived( |
222 ServiceWorkerHostMsg_RegisterServiceWorker( | 224 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, provider_id, |
223 -1, -1, provider_id, pattern, worker_url)); | 225 worker_url, options)); |
224 base::RunLoop().RunUntilIdle(); | 226 base::RunLoop().RunUntilIdle(); |
225 } | 227 } |
226 | 228 |
227 void Register(int64_t provider_id, | 229 void Register(int64_t provider_id, |
228 GURL pattern, | 230 GURL pattern, |
229 GURL worker_url, | 231 GURL worker_url, |
230 uint32_t expected_message) { | 232 uint32_t expected_message) { |
231 SendRegister(provider_id, pattern, worker_url); | 233 SendRegister(provider_id, pattern, worker_url); |
232 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | 234 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( |
233 expected_message)); | 235 expected_message)); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 GetRegistration(kProviderId, | 341 GetRegistration(kProviderId, |
340 GURL("https://www.example.com/"), | 342 GURL("https://www.example.com/"), |
341 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); | 343 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); |
342 GetRegistrations(kProviderId, | 344 GetRegistrations(kProviderId, |
343 ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); | 345 ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); |
344 | 346 |
345 // Add a registration into a live registration map so that Unregister() can | 347 // Add a registration into a live registration map so that Unregister() can |
346 // find it. | 348 // find it. |
347 const int64_t kRegistrationId = 999; // Dummy value | 349 const int64_t kRegistrationId = 999; // Dummy value |
348 scoped_refptr<ServiceWorkerRegistration> registration( | 350 scoped_refptr<ServiceWorkerRegistration> registration( |
349 new ServiceWorkerRegistration(GURL("https://www.example.com/"), | 351 new ServiceWorkerRegistration( |
350 kRegistrationId, context()->AsWeakPtr())); | 352 ServiceWorkerRegistrationOptions(GURL("https://www.example.com/")), |
| 353 kRegistrationId, context()->AsWeakPtr())); |
351 Unregister(kProviderId, kRegistrationId, | 354 Unregister(kProviderId, kRegistrationId, |
352 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); | 355 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); |
353 | 356 |
354 SetBrowserClientForTesting(old_browser_client); | 357 SetBrowserClientForTesting(old_browser_client); |
355 } | 358 } |
356 | 359 |
357 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { | 360 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { |
358 const int64_t kProviderId = 99; // Dummy value | 361 const int64_t kProviderId = 99; // Dummy value |
359 std::unique_ptr<ServiceWorkerProviderHost> host( | 362 std::unique_ptr<ServiceWorkerProviderHost> host( |
360 CreateServiceWorkerProviderHost(kProviderId)); | 363 CreateServiceWorkerProviderHost(kProviderId)); |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 const int kFetchEventId = 91; // Dummy value | 917 const int kFetchEventId = 91; // Dummy value |
915 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse( | 918 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse( |
916 version_->embedded_worker()->embedded_worker_id(), kFetchEventId, | 919 version_->embedded_worker()->embedded_worker_id(), kFetchEventId, |
917 ServiceWorkerResponse(), base::Time::Now())); | 920 ServiceWorkerResponse(), base::Time::Now())); |
918 | 921 |
919 base::RunLoop().RunUntilIdle(); | 922 base::RunLoop().RunUntilIdle(); |
920 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); | 923 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); |
921 } | 924 } |
922 | 925 |
923 } // namespace content | 926 } // namespace content |
OLD | NEW |