| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/embedded_worker_test_helper.h" | 5 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 std::move(request)); | 157 std::move(request)); |
| 158 } | 158 } |
| 159 | 159 |
| 160 MockFetchEventDispatcher( | 160 MockFetchEventDispatcher( |
| 161 const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, | 161 const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, |
| 162 int thread_id) | 162 int thread_id) |
| 163 : helper_(helper), thread_id_(thread_id) {} | 163 : helper_(helper), thread_id_(thread_id) {} |
| 164 | 164 |
| 165 ~MockFetchEventDispatcher() override {} | 165 ~MockFetchEventDispatcher() override {} |
| 166 | 166 |
| 167 void DispatchFetchEvent(int response_id, | 167 void DispatchFetchEvent(int fetch_event_id, |
| 168 const ServiceWorkerFetchRequest& request, | 168 const ServiceWorkerFetchRequest& request, |
| 169 const DispatchFetchEventCallback& callback) override { | 169 const DispatchFetchEventCallback& callback) override { |
| 170 if (!helper_) | 170 if (!helper_) |
| 171 return; | 171 return; |
| 172 helper_->OnFetchEventStub(thread_id_, response_id, request, callback); | 172 helper_->OnFetchEventStub(thread_id_, fetch_event_id, request, callback); |
| 173 } | 173 } |
| 174 | 174 |
| 175 private: | 175 private: |
| 176 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; | 176 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; |
| 177 const int thread_id_; | 177 const int thread_id_; |
| 178 }; | 178 }; |
| 179 | 179 |
| 180 EmbeddedWorkerTestHelper::EmbeddedWorkerTestHelper( | 180 EmbeddedWorkerTestHelper::EmbeddedWorkerTestHelper( |
| 181 const base::FilePath& user_data_directory) | 181 const base::FilePath& user_data_directory) |
| 182 : browser_context_(new TestBrowserContext), | 182 : browser_context_(new TestBrowserContext), |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 // The installing worker may have been doomed and terminated. | 328 // The installing worker may have been doomed and terminated. |
| 329 if (!registry()->GetWorker(embedded_worker_id)) | 329 if (!registry()->GetWorker(embedded_worker_id)) |
| 330 return; | 330 return; |
| 331 SimulateSend(new ServiceWorkerHostMsg_InstallEventFinished( | 331 SimulateSend(new ServiceWorkerHostMsg_InstallEventFinished( |
| 332 embedded_worker_id, request_id, | 332 embedded_worker_id, request_id, |
| 333 blink::WebServiceWorkerEventResultCompleted, true, base::Time::Now())); | 333 blink::WebServiceWorkerEventResultCompleted, true, base::Time::Now())); |
| 334 } | 334 } |
| 335 | 335 |
| 336 void EmbeddedWorkerTestHelper::OnFetchEvent( | 336 void EmbeddedWorkerTestHelper::OnFetchEvent( |
| 337 int embedded_worker_id, | 337 int embedded_worker_id, |
| 338 int response_id, | 338 int fetch_event_id, |
| 339 const ServiceWorkerFetchRequest& request, | 339 const ServiceWorkerFetchRequest& request, |
| 340 const FetchCallback& callback) { | 340 const FetchCallback& callback) { |
| 341 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 341 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
| 342 embedded_worker_id, response_id, | 342 embedded_worker_id, fetch_event_id, |
| 343 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, | 343 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, |
| 344 ServiceWorkerResponse( | 344 ServiceWorkerResponse( |
| 345 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, | 345 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, |
| 346 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), | 346 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), |
| 347 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), | 347 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), |
| 348 false /* is_in_cache_storage */, | 348 false /* is_in_cache_storage */, |
| 349 std::string() /* cache_storage_cache_name */, | 349 std::string() /* cache_storage_cache_name */, |
| 350 ServiceWorkerHeaderList() /* cors_exposed_header_names */), | 350 ServiceWorkerHeaderList() /* cors_exposed_header_names */), |
| 351 base::Time::Now())); | 351 base::Time::Now())); |
| 352 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 352 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 | 489 |
| 490 void EmbeddedWorkerTestHelper::OnInstallEventStub(int request_id) { | 490 void EmbeddedWorkerTestHelper::OnInstallEventStub(int request_id) { |
| 491 base::ThreadTaskRunnerHandle::Get()->PostTask( | 491 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 492 FROM_HERE, | 492 FROM_HERE, |
| 493 base::Bind(&EmbeddedWorkerTestHelper::OnInstallEvent, AsWeakPtr(), | 493 base::Bind(&EmbeddedWorkerTestHelper::OnInstallEvent, AsWeakPtr(), |
| 494 current_embedded_worker_id_, request_id)); | 494 current_embedded_worker_id_, request_id)); |
| 495 } | 495 } |
| 496 | 496 |
| 497 void EmbeddedWorkerTestHelper::OnFetchEventStub( | 497 void EmbeddedWorkerTestHelper::OnFetchEventStub( |
| 498 int thread_id, | 498 int thread_id, |
| 499 int response_id, | 499 int fetch_event_id, |
| 500 const ServiceWorkerFetchRequest& request, | 500 const ServiceWorkerFetchRequest& request, |
| 501 const FetchCallback& callback) { | 501 const FetchCallback& callback) { |
| 502 base::ThreadTaskRunnerHandle::Get()->PostTask( | 502 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 503 FROM_HERE, | 503 FROM_HERE, |
| 504 base::Bind(&EmbeddedWorkerTestHelper::OnFetchEvent, AsWeakPtr(), | 504 base::Bind(&EmbeddedWorkerTestHelper::OnFetchEvent, AsWeakPtr(), |
| 505 thread_id_embedded_worker_id_map_[thread_id], response_id, | 505 thread_id_embedded_worker_id_map_[thread_id], fetch_event_id, |
| 506 request, callback)); | 506 request, callback)); |
| 507 } | 507 } |
| 508 | 508 |
| 509 void EmbeddedWorkerTestHelper::OnPushEventStub( | 509 void EmbeddedWorkerTestHelper::OnPushEventStub( |
| 510 int request_id, | 510 int request_id, |
| 511 const PushEventPayload& payload) { | 511 const PushEventPayload& payload) { |
| 512 base::ThreadTaskRunnerHandle::Get()->PostTask( | 512 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 513 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnPushEvent, AsWeakPtr(), | 513 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnPushEvent, AsWeakPtr(), |
| 514 current_embedded_worker_id_, request_id, payload)); | 514 current_embedded_worker_id_, request_id, payload)); |
| 515 } | 515 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 registry->Bind(mojo::GetProxy(&interfaces)); | 557 registry->Bind(mojo::GetProxy(&interfaces)); |
| 558 | 558 |
| 559 std::unique_ptr<shell::InterfaceProvider> remote_interfaces( | 559 std::unique_ptr<shell::InterfaceProvider> remote_interfaces( |
| 560 new shell::InterfaceProvider); | 560 new shell::InterfaceProvider); |
| 561 remote_interfaces->Bind(std::move(interfaces)); | 561 remote_interfaces->Bind(std::move(interfaces)); |
| 562 rph->SetRemoteInterfaces(std::move(remote_interfaces)); | 562 rph->SetRemoteInterfaces(std::move(remote_interfaces)); |
| 563 return registry; | 563 return registry; |
| 564 } | 564 } |
| 565 | 565 |
| 566 } // namespace content | 566 } // namespace content |
| OLD | NEW |