| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 helper_.reset(helper.release()); | 120 helper_.reset(helper.release()); |
| 121 // Replace the default dispatcher host. | 121 // Replace the default dispatcher host. |
| 122 int process_id = helper_->mock_render_process_id(); | 122 int process_id = helper_->mock_render_process_id(); |
| 123 context()->RemoveDispatcherHost(process_id); | 123 context()->RemoveDispatcherHost(process_id); |
| 124 dispatcher_host_ = new TestingServiceWorkerDispatcherHost( | 124 dispatcher_host_ = new TestingServiceWorkerDispatcherHost( |
| 125 process_id, context_wrapper(), &resource_context_, helper_.get()); | 125 process_id, context_wrapper(), &resource_context_, helper_.get()); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void SetUpRegistration(const GURL& scope, const GURL& script_url) { | 128 void SetUpRegistration(const GURL& scope, const GURL& script_url) { |
| 129 registration_ = new ServiceWorkerRegistration( | 129 registration_ = new ServiceWorkerRegistration( |
| 130 scope, 1L, helper_->context()->AsWeakPtr()); | 130 scope, false /* use_cache */, 1L, helper_->context()->AsWeakPtr()); |
| 131 version_ = new ServiceWorkerVersion(registration_.get(), script_url, 1L, | 131 version_ = new ServiceWorkerVersion(registration_.get(), script_url, 1L, |
| 132 helper_->context()->AsWeakPtr()); | 132 helper_->context()->AsWeakPtr()); |
| 133 std::vector<ServiceWorkerDatabase::ResourceRecord> records; | 133 std::vector<ServiceWorkerDatabase::ResourceRecord> records; |
| 134 records.push_back( | 134 records.push_back( |
| 135 ServiceWorkerDatabase::ResourceRecord(10, version_->script_url(), 100)); | 135 ServiceWorkerDatabase::ResourceRecord(10, version_->script_url(), 100)); |
| 136 version_->script_cache_map()->SetResources(records); | 136 version_->script_cache_map()->SetResources(records); |
| 137 version_->SetMainScriptHttpResponseInfo( | 137 version_->SetMainScriptHttpResponseInfo( |
| 138 EmbeddedWorkerTestHelper::CreateHttpResponseInfo()); | 138 EmbeddedWorkerTestHelper::CreateHttpResponseInfo()); |
| 139 version_->set_fetch_handler_existence( | 139 version_->set_fetch_handler_existence( |
| 140 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); | 140 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 166 ServiceWorkerProviderHostInfo info(kProviderId, MSG_ROUTING_NONE, type, | 166 ServiceWorkerProviderHostInfo info(kProviderId, MSG_ROUTING_NONE, type, |
| 167 true /* is_parent_frame_secure */); | 167 true /* is_parent_frame_secure */); |
| 168 dispatcher_host_->OnProviderCreated(std::move(info)); | 168 dispatcher_host_->OnProviderCreated(std::move(info)); |
| 169 helper_->SimulateAddProcessToPattern(pattern, | 169 helper_->SimulateAddProcessToPattern(pattern, |
| 170 helper_->mock_render_process_id()); | 170 helper_->mock_render_process_id()); |
| 171 provider_host_ = context()->GetProviderHost( | 171 provider_host_ = context()->GetProviderHost( |
| 172 helper_->mock_render_process_id(), kProviderId); | 172 helper_->mock_render_process_id(), kProviderId); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void SendRegister(int64_t provider_id, GURL pattern, GURL worker_url) { | 175 void SendRegister(int64_t provider_id, GURL pattern, GURL worker_url) { |
| 176 ServiceWorkerRegistrationOptions options(pattern); |
| 176 dispatcher_host_->OnMessageReceived( | 177 dispatcher_host_->OnMessageReceived( |
| 177 ServiceWorkerHostMsg_RegisterServiceWorker( | 178 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, provider_id, |
| 178 -1, -1, provider_id, pattern, worker_url)); | 179 worker_url, options)); |
| 179 base::RunLoop().RunUntilIdle(); | 180 base::RunLoop().RunUntilIdle(); |
| 180 } | 181 } |
| 181 | 182 |
| 182 void Register(int64_t provider_id, | 183 void Register(int64_t provider_id, |
| 183 GURL pattern, | 184 GURL pattern, |
| 184 GURL worker_url, | 185 GURL worker_url, |
| 185 uint32_t expected_message) { | 186 uint32_t expected_message) { |
| 186 SendRegister(provider_id, pattern, worker_url); | 187 SendRegister(provider_id, pattern, worker_url); |
| 187 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | 188 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( |
| 188 expected_message)); | 189 expected_message)); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 GURL("https://www.example.com/"), | 295 GURL("https://www.example.com/"), |
| 295 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); | 296 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); |
| 296 GetRegistrations(kProviderId, | 297 GetRegistrations(kProviderId, |
| 297 ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); | 298 ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); |
| 298 | 299 |
| 299 // Add a registration into a live registration map so that Unregister() can | 300 // Add a registration into a live registration map so that Unregister() can |
| 300 // find it. | 301 // find it. |
| 301 const int64_t kRegistrationId = 999; // Dummy value | 302 const int64_t kRegistrationId = 999; // Dummy value |
| 302 scoped_refptr<ServiceWorkerRegistration> registration( | 303 scoped_refptr<ServiceWorkerRegistration> registration( |
| 303 new ServiceWorkerRegistration(GURL("https://www.example.com/"), | 304 new ServiceWorkerRegistration(GURL("https://www.example.com/"), |
| 304 kRegistrationId, context()->AsWeakPtr())); | 305 false /* use_cache */, kRegistrationId, |
| 306 context()->AsWeakPtr())); |
| 305 Unregister(kProviderId, kRegistrationId, | 307 Unregister(kProviderId, kRegistrationId, |
| 306 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); | 308 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); |
| 307 | 309 |
| 308 SetBrowserClientForTesting(old_browser_client); | 310 SetBrowserClientForTesting(old_browser_client); |
| 309 } | 311 } |
| 310 | 312 |
| 311 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { | 313 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { |
| 312 const int64_t kProviderId = 99; // Dummy value | 314 const int64_t kProviderId = 99; // Dummy value |
| 313 std::unique_ptr<ServiceWorkerProviderHost> host( | 315 std::unique_ptr<ServiceWorkerProviderHost> host( |
| 314 CreateServiceWorkerProviderHost(kProviderId)); | 316 CreateServiceWorkerProviderHost(kProviderId)); |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse( | 833 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse( |
| 832 version_->embedded_worker()->embedded_worker_id(), kFetchEventId, | 834 version_->embedded_worker()->embedded_worker_id(), kFetchEventId, |
| 833 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse(), | 835 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse(), |
| 834 base::Time::Now())); | 836 base::Time::Now())); |
| 835 | 837 |
| 836 base::RunLoop().RunUntilIdle(); | 838 base::RunLoop().RunUntilIdle(); |
| 837 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); | 839 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); |
| 838 } | 840 } |
| 839 | 841 |
| 840 } // namespace content | 842 } // namespace content |
| OLD | NEW |