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 <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 std::move(request)); | 151 std::move(request)); |
152 } | 152 } |
153 | 153 |
154 MockServiceWorkerEventDispatcher( | 154 MockServiceWorkerEventDispatcher( |
155 const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, | 155 const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, |
156 int thread_id) | 156 int thread_id) |
157 : helper_(helper), thread_id_(thread_id) {} | 157 : helper_(helper), thread_id_(thread_id) {} |
158 | 158 |
159 ~MockServiceWorkerEventDispatcher() override {} | 159 ~MockServiceWorkerEventDispatcher() override {} |
160 | 160 |
161 void DispatchActivateEvent( | 161 void DispatchActivateEvent(DispatchActivateEventCallback callback) override { |
162 const DispatchActivateEventCallback& callback) override { | |
163 if (!helper_) | 162 if (!helper_) |
164 return; | 163 return; |
165 helper_->OnActivateEventStub(callback); | 164 helper_->OnActivateEventStub(std::move(callback)); |
166 } | 165 } |
167 | 166 |
168 void DispatchBackgroundFetchAbortEvent( | 167 void DispatchBackgroundFetchAbortEvent( |
169 const std::string& tag, | 168 const std::string& tag, |
170 const DispatchBackgroundFetchAbortEventCallback& callback) override { | 169 DispatchBackgroundFetchAbortEventCallback callback) override { |
171 if (!helper_) | 170 if (!helper_) |
172 return; | 171 return; |
173 helper_->OnBackgroundFetchAbortEventStub(tag, callback); | 172 helper_->OnBackgroundFetchAbortEventStub(tag, std::move(callback)); |
174 } | 173 } |
175 | 174 |
176 void DispatchBackgroundFetchClickEvent( | 175 void DispatchBackgroundFetchClickEvent( |
177 const std::string& tag, | 176 const std::string& tag, |
178 mojom::BackgroundFetchState state, | 177 mojom::BackgroundFetchState state, |
179 const DispatchBackgroundFetchClickEventCallback& callback) override { | 178 DispatchBackgroundFetchClickEventCallback callback) override { |
180 if (!helper_) | 179 if (!helper_) |
181 return; | 180 return; |
182 helper_->OnBackgroundFetchClickEventStub(tag, state, callback); | 181 helper_->OnBackgroundFetchClickEventStub(tag, state, std::move(callback)); |
183 } | 182 } |
184 | 183 |
185 void DispatchBackgroundFetchFailEvent( | 184 void DispatchBackgroundFetchFailEvent( |
186 const std::string& tag, | 185 const std::string& tag, |
187 const std::vector<BackgroundFetchSettledFetch>& fetches, | 186 const std::vector<BackgroundFetchSettledFetch>& fetches, |
188 const DispatchBackgroundFetchFailEventCallback& callback) override { | 187 DispatchBackgroundFetchFailEventCallback callback) override { |
189 if (!helper_) | 188 if (!helper_) |
190 return; | 189 return; |
191 helper_->OnBackgroundFetchFailEventStub(tag, fetches, callback); | 190 helper_->OnBackgroundFetchFailEventStub(tag, fetches, std::move(callback)); |
192 } | 191 } |
193 | 192 |
194 void DispatchBackgroundFetchedEvent( | 193 void DispatchBackgroundFetchedEvent( |
195 const std::string& tag, | 194 const std::string& tag, |
196 const std::vector<BackgroundFetchSettledFetch>& fetches, | 195 const std::vector<BackgroundFetchSettledFetch>& fetches, |
197 const DispatchBackgroundFetchedEventCallback& callback) override { | 196 DispatchBackgroundFetchedEventCallback callback) override { |
198 if (!helper_) | 197 if (!helper_) |
199 return; | 198 return; |
200 helper_->OnBackgroundFetchedEventStub(tag, fetches, callback); | 199 helper_->OnBackgroundFetchedEventStub(tag, fetches, std::move(callback)); |
201 } | 200 } |
202 | 201 |
203 void DispatchFetchEvent( | 202 void DispatchFetchEvent( |
204 int fetch_event_id, | 203 int fetch_event_id, |
205 const ServiceWorkerFetchRequest& request, | 204 const ServiceWorkerFetchRequest& request, |
206 mojom::FetchEventPreloadHandlePtr preload_handle, | 205 mojom::FetchEventPreloadHandlePtr preload_handle, |
207 mojom::ServiceWorkerFetchResponseCallbackPtr response_callback, | 206 mojom::ServiceWorkerFetchResponseCallbackPtr response_callback, |
208 const DispatchFetchEventCallback& callback) override { | 207 DispatchFetchEventCallback callback) override { |
209 if (!helper_) | 208 if (!helper_) |
210 return; | 209 return; |
211 helper_->OnFetchEventStub(thread_id_, fetch_event_id, request, | 210 helper_->OnFetchEventStub( |
212 std::move(preload_handle), | 211 thread_id_, fetch_event_id, request, std::move(preload_handle), |
213 std::move(response_callback), callback); | 212 std::move(response_callback), std::move(callback)); |
214 } | 213 } |
215 | 214 |
216 void DispatchNotificationClickEvent( | 215 void DispatchNotificationClickEvent( |
217 const std::string& notification_id, | 216 const std::string& notification_id, |
218 const PlatformNotificationData& notification_data, | 217 const PlatformNotificationData& notification_data, |
219 int action_index, | 218 int action_index, |
220 const base::Optional<base::string16>& reply, | 219 const base::Optional<base::string16>& reply, |
221 const DispatchNotificationClickEventCallback& callback) override { | 220 DispatchNotificationClickEventCallback callback) override { |
222 if (!helper_) | 221 if (!helper_) |
223 return; | 222 return; |
224 helper_->OnNotificationClickEventStub(notification_id, notification_data, | 223 helper_->OnNotificationClickEventStub(notification_id, notification_data, |
225 action_index, reply, callback); | 224 action_index, reply, |
| 225 std::move(callback)); |
226 } | 226 } |
227 | 227 |
228 void DispatchNotificationCloseEvent( | 228 void DispatchNotificationCloseEvent( |
229 const std::string& notification_id, | 229 const std::string& notification_id, |
230 const PlatformNotificationData& notification_data, | 230 const PlatformNotificationData& notification_data, |
231 const DispatchNotificationCloseEventCallback& callback) override { | 231 DispatchNotificationCloseEventCallback callback) override { |
232 if (!helper_) | 232 if (!helper_) |
233 return; | 233 return; |
234 helper_->OnNotificationCloseEventStub(notification_id, notification_data, | 234 helper_->OnNotificationCloseEventStub(notification_id, notification_data, |
235 callback); | 235 std::move(callback)); |
236 } | 236 } |
237 | 237 |
238 void DispatchPushEvent(const PushEventPayload& payload, | 238 void DispatchPushEvent(const PushEventPayload& payload, |
239 const DispatchPushEventCallback& callback) override { | 239 DispatchPushEventCallback callback) override { |
240 if (!helper_) | 240 if (!helper_) |
241 return; | 241 return; |
242 helper_->OnPushEventStub(payload, callback); | 242 helper_->OnPushEventStub(payload, std::move(callback)); |
243 } | 243 } |
244 | 244 |
245 void DispatchSyncEvent( | 245 void DispatchSyncEvent( |
246 const std::string& tag, | 246 const std::string& tag, |
247 blink::mojom::BackgroundSyncEventLastChance last_chance, | 247 blink::mojom::BackgroundSyncEventLastChance last_chance, |
248 const DispatchSyncEventCallback& callback) override { | 248 DispatchSyncEventCallback callback) override { |
249 NOTIMPLEMENTED(); | 249 NOTIMPLEMENTED(); |
250 } | 250 } |
251 | 251 |
252 void DispatchPaymentRequestEvent( | 252 void DispatchPaymentRequestEvent( |
253 int payment_request_id, | 253 int payment_request_id, |
254 payments::mojom::PaymentAppRequestPtr app_request, | 254 payments::mojom::PaymentAppRequestPtr app_request, |
255 payments::mojom::PaymentAppResponseCallbackPtr response_callback, | 255 payments::mojom::PaymentAppResponseCallbackPtr response_callback, |
256 const DispatchPaymentRequestEventCallback& callback) override { | 256 DispatchPaymentRequestEventCallback callback) override { |
257 if (!helper_) | 257 if (!helper_) |
258 return; | 258 return; |
259 helper_->OnPaymentRequestEventStub(std::move(app_request), | 259 helper_->OnPaymentRequestEventStub(std::move(app_request), |
260 std::move(response_callback), callback); | 260 std::move(response_callback), |
| 261 std::move(callback)); |
261 } | 262 } |
262 | 263 |
263 void DispatchExtendableMessageEvent( | 264 void DispatchExtendableMessageEvent( |
264 mojom::ExtendableMessageEventPtr event, | 265 mojom::ExtendableMessageEventPtr event, |
265 const DispatchExtendableMessageEventCallback& callback) override { | 266 DispatchExtendableMessageEventCallback callback) override { |
266 if (!helper_) | 267 if (!helper_) |
267 return; | 268 return; |
268 helper_->OnExtendableMessageEventStub(std::move(event), callback); | 269 helper_->OnExtendableMessageEventStub(std::move(event), |
| 270 std::move(callback)); |
269 } | 271 } |
270 | 272 |
271 void Ping(const PingCallback& callback) override { callback.Run(); } | 273 void Ping(PingCallback callback) override { std::move(callback).Run(); } |
272 | 274 |
273 private: | 275 private: |
274 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; | 276 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; |
275 const int thread_id_; | 277 const int thread_id_; |
276 }; | 278 }; |
277 | 279 |
278 EmbeddedWorkerTestHelper::EmbeddedWorkerTestHelper( | 280 EmbeddedWorkerTestHelper::EmbeddedWorkerTestHelper( |
279 const base::FilePath& user_data_directory) | 281 const base::FilePath& user_data_directory) |
280 : browser_context_(new TestBrowserContext), | 282 : browser_context_(new TestBrowserContext), |
281 render_process_host_(new MockRenderProcessHost(browser_context_.get())), | 283 render_process_host_(new MockRenderProcessHost(browser_context_.get())), |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerTestHelper, message) | 424 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerTestHelper, message) |
423 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEventStub) | 425 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEventStub) |
424 IPC_MESSAGE_UNHANDLED(handled = false) | 426 IPC_MESSAGE_UNHANDLED(handled = false) |
425 IPC_END_MESSAGE_MAP() | 427 IPC_END_MESSAGE_MAP() |
426 // Record all messages directed to inner script context. | 428 // Record all messages directed to inner script context. |
427 inner_sink_.OnMessageReceived(message); | 429 inner_sink_.OnMessageReceived(message); |
428 return handled; | 430 return handled; |
429 } | 431 } |
430 | 432 |
431 void EmbeddedWorkerTestHelper::OnActivateEvent( | 433 void EmbeddedWorkerTestHelper::OnActivateEvent( |
432 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& | 434 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback |
433 callback) { | 435 callback) { |
434 dispatched_events()->push_back(Event::Activate); | 436 dispatched_events()->push_back(Event::Activate); |
435 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 437 std::move(callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
436 } | 438 } |
437 | 439 |
438 void EmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent( | 440 void EmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent( |
439 const std::string& tag, | 441 const std::string& tag, |
440 const mojom::ServiceWorkerEventDispatcher:: | 442 mojom::ServiceWorkerEventDispatcher:: |
441 DispatchBackgroundFetchAbortEventCallback& callback) { | 443 DispatchBackgroundFetchAbortEventCallback callback) { |
442 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 444 std::move(callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
443 } | 445 } |
444 | 446 |
445 void EmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent( | 447 void EmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent( |
446 const std::string& tag, | 448 const std::string& tag, |
447 mojom::BackgroundFetchState state, | 449 mojom::BackgroundFetchState state, |
448 const mojom::ServiceWorkerEventDispatcher:: | 450 mojom::ServiceWorkerEventDispatcher:: |
449 DispatchBackgroundFetchClickEventCallback& callback) { | 451 DispatchBackgroundFetchClickEventCallback callback) { |
450 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 452 std::move(callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
451 } | 453 } |
452 | 454 |
453 void EmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent( | 455 void EmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent( |
454 const std::string& tag, | 456 const std::string& tag, |
455 const std::vector<BackgroundFetchSettledFetch>& fetches, | 457 const std::vector<BackgroundFetchSettledFetch>& fetches, |
456 const mojom::ServiceWorkerEventDispatcher:: | 458 mojom::ServiceWorkerEventDispatcher:: |
457 DispatchBackgroundFetchFailEventCallback& callback) { | 459 DispatchBackgroundFetchFailEventCallback callback) { |
458 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 460 std::move(callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
459 } | 461 } |
460 | 462 |
461 void EmbeddedWorkerTestHelper::OnBackgroundFetchedEvent( | 463 void EmbeddedWorkerTestHelper::OnBackgroundFetchedEvent( |
462 const std::string& tag, | 464 const std::string& tag, |
463 const std::vector<BackgroundFetchSettledFetch>& fetches, | 465 const std::vector<BackgroundFetchSettledFetch>& fetches, |
464 const mojom::ServiceWorkerEventDispatcher:: | 466 mojom::ServiceWorkerEventDispatcher::DispatchBackgroundFetchedEventCallback |
465 DispatchBackgroundFetchedEventCallback& callback) { | 467 callback) { |
466 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 468 std::move(callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
467 } | 469 } |
468 | 470 |
469 void EmbeddedWorkerTestHelper::OnExtendableMessageEvent( | 471 void EmbeddedWorkerTestHelper::OnExtendableMessageEvent( |
470 mojom::ExtendableMessageEventPtr event, | 472 mojom::ExtendableMessageEventPtr event, |
471 const mojom::ServiceWorkerEventDispatcher:: | 473 mojom::ServiceWorkerEventDispatcher::DispatchExtendableMessageEventCallback |
472 DispatchExtendableMessageEventCallback& callback) { | 474 callback) { |
473 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 475 std::move(callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
474 } | 476 } |
475 | 477 |
476 void EmbeddedWorkerTestHelper::OnInstallEvent(int embedded_worker_id, | 478 void EmbeddedWorkerTestHelper::OnInstallEvent(int embedded_worker_id, |
477 int request_id) { | 479 int request_id) { |
478 // The installing worker may have been doomed and terminated. | 480 // The installing worker may have been doomed and terminated. |
479 if (!registry()->GetWorker(embedded_worker_id)) | 481 if (!registry()->GetWorker(embedded_worker_id)) |
480 return; | 482 return; |
481 SimulateSend(new ServiceWorkerHostMsg_InstallEventFinished( | 483 SimulateSend(new ServiceWorkerHostMsg_InstallEventFinished( |
482 embedded_worker_id, request_id, | 484 embedded_worker_id, request_id, |
483 blink::kWebServiceWorkerEventResultCompleted, true, base::Time::Now())); | 485 blink::kWebServiceWorkerEventResultCompleted, true, base::Time::Now())); |
484 } | 486 } |
485 | 487 |
486 void EmbeddedWorkerTestHelper::OnFetchEvent( | 488 void EmbeddedWorkerTestHelper::OnFetchEvent( |
487 int /* embedded_worker_id */, | 489 int /* embedded_worker_id */, |
488 int /* fetch_event_id */, | 490 int /* fetch_event_id */, |
489 const ServiceWorkerFetchRequest& /* request */, | 491 const ServiceWorkerFetchRequest& /* request */, |
490 mojom::FetchEventPreloadHandlePtr /* preload_handle */, | 492 mojom::FetchEventPreloadHandlePtr /* preload_handle */, |
491 mojom::ServiceWorkerFetchResponseCallbackPtr response_callback, | 493 mojom::ServiceWorkerFetchResponseCallbackPtr response_callback, |
492 const FetchCallback& finish_callback) { | 494 FetchCallback finish_callback) { |
493 response_callback->OnResponse( | 495 response_callback->OnResponse( |
494 ServiceWorkerResponse( | 496 ServiceWorkerResponse( |
495 base::MakeUnique<std::vector<GURL>>(), 200, "OK", | 497 base::MakeUnique<std::vector<GURL>>(), 200, "OK", |
496 blink::kWebServiceWorkerResponseTypeDefault, | 498 blink::kWebServiceWorkerResponseTypeDefault, |
497 base::MakeUnique<ServiceWorkerHeaderMap>(), std::string(), 0, | 499 base::MakeUnique<ServiceWorkerHeaderMap>(), std::string(), 0, |
498 blink::kWebServiceWorkerResponseErrorUnknown, base::Time(), | 500 blink::kWebServiceWorkerResponseErrorUnknown, base::Time(), |
499 false /* is_in_cache_storage */, | 501 false /* is_in_cache_storage */, |
500 std::string() /* cache_storage_cache_name */, | 502 std::string() /* cache_storage_cache_name */, |
501 base::MakeUnique< | 503 base::MakeUnique< |
502 ServiceWorkerHeaderList>() /* cors_exposed_header_names */), | 504 ServiceWorkerHeaderList>() /* cors_exposed_header_names */), |
503 base::Time::Now()); | 505 base::Time::Now()); |
504 finish_callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 506 std::move(finish_callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
505 } | 507 } |
506 | 508 |
507 void EmbeddedWorkerTestHelper::OnPushEvent( | 509 void EmbeddedWorkerTestHelper::OnPushEvent( |
508 const PushEventPayload& payload, | 510 const PushEventPayload& payload, |
509 const mojom::ServiceWorkerEventDispatcher::DispatchPushEventCallback& | 511 mojom::ServiceWorkerEventDispatcher::DispatchPushEventCallback callback) { |
510 callback) { | 512 std::move(callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
511 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | |
512 } | 513 } |
513 | 514 |
514 void EmbeddedWorkerTestHelper::OnNotificationClickEvent( | 515 void EmbeddedWorkerTestHelper::OnNotificationClickEvent( |
515 const std::string& notification_id, | 516 const std::string& notification_id, |
516 const PlatformNotificationData& notification_data, | 517 const PlatformNotificationData& notification_data, |
517 int action_index, | 518 int action_index, |
518 const base::Optional<base::string16>& reply, | 519 const base::Optional<base::string16>& reply, |
519 const mojom::ServiceWorkerEventDispatcher:: | 520 mojom::ServiceWorkerEventDispatcher::DispatchNotificationClickEventCallback |
520 DispatchNotificationClickEventCallback& callback) { | 521 callback) { |
521 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 522 std::move(callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
522 } | 523 } |
523 | 524 |
524 void EmbeddedWorkerTestHelper::OnNotificationCloseEvent( | 525 void EmbeddedWorkerTestHelper::OnNotificationCloseEvent( |
525 const std::string& notification_id, | 526 const std::string& notification_id, |
526 const PlatformNotificationData& notification_data, | 527 const PlatformNotificationData& notification_data, |
527 const mojom::ServiceWorkerEventDispatcher:: | 528 mojom::ServiceWorkerEventDispatcher::DispatchNotificationCloseEventCallback |
528 DispatchNotificationCloseEventCallback& callback) { | 529 callback) { |
529 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 530 std::move(callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
530 } | 531 } |
531 | 532 |
532 void EmbeddedWorkerTestHelper::OnPaymentRequestEvent( | 533 void EmbeddedWorkerTestHelper::OnPaymentRequestEvent( |
533 payments::mojom::PaymentAppRequestPtr app_request, | 534 payments::mojom::PaymentAppRequestPtr app_request, |
534 payments::mojom::PaymentAppResponseCallbackPtr response_callback, | 535 payments::mojom::PaymentAppResponseCallbackPtr response_callback, |
535 const mojom::ServiceWorkerEventDispatcher:: | 536 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback |
536 DispatchPaymentRequestEventCallback& callback) { | 537 callback) { |
537 response_callback->OnPaymentAppResponse( | 538 response_callback->OnPaymentAppResponse( |
538 payments::mojom::PaymentAppResponse::New(), base::Time::Now()); | 539 payments::mojom::PaymentAppResponse::New(), base::Time::Now()); |
539 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 540 std::move(callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
540 } | 541 } |
541 | 542 |
542 void EmbeddedWorkerTestHelper::SimulateWorkerReadyForInspection( | 543 void EmbeddedWorkerTestHelper::SimulateWorkerReadyForInspection( |
543 int embedded_worker_id) { | 544 int embedded_worker_id) { |
544 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 545 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
545 ASSERT_TRUE(worker); | 546 ASSERT_TRUE(worker); |
546 ASSERT_TRUE(embedded_worker_id_instance_host_ptr_map_[embedded_worker_id]); | 547 ASSERT_TRUE(embedded_worker_id_instance_host_ptr_map_[embedded_worker_id]); |
547 embedded_worker_id_instance_host_ptr_map_[embedded_worker_id] | 548 embedded_worker_id_instance_host_ptr_map_[embedded_worker_id] |
548 ->OnReadyForInspection(); | 549 ->OnReadyForInspection(); |
549 base::RunLoop().RunUntilIdle(); | 550 base::RunLoop().RunUntilIdle(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 ASSERT_TRUE(worker); | 671 ASSERT_TRUE(worker); |
671 EXPECT_EQ(worker->thread_id(), thread_id); | 672 EXPECT_EQ(worker->thread_id(), thread_id); |
672 base::ThreadTaskRunnerHandle::Get()->PostTask( | 673 base::ThreadTaskRunnerHandle::Get()->PostTask( |
673 FROM_HERE, | 674 FROM_HERE, |
674 base::Bind( | 675 base::Bind( |
675 base::IgnoreResult(&EmbeddedWorkerTestHelper::OnMessageToWorker), | 676 base::IgnoreResult(&EmbeddedWorkerTestHelper::OnMessageToWorker), |
676 AsWeakPtr(), thread_id, embedded_worker_id, message)); | 677 AsWeakPtr(), thread_id, embedded_worker_id, message)); |
677 } | 678 } |
678 | 679 |
679 void EmbeddedWorkerTestHelper::OnActivateEventStub( | 680 void EmbeddedWorkerTestHelper::OnActivateEventStub( |
680 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& | 681 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback |
681 callback) { | 682 callback) { |
682 base::ThreadTaskRunnerHandle::Get()->PostTask( | 683 base::ThreadTaskRunnerHandle::Get()->PostTask( |
683 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnActivateEvent, | 684 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnActivateEvent, |
684 AsWeakPtr(), callback)); | 685 AsWeakPtr(), base::Passed(&callback))); |
685 } | 686 } |
686 | 687 |
687 void EmbeddedWorkerTestHelper::OnBackgroundFetchAbortEventStub( | 688 void EmbeddedWorkerTestHelper::OnBackgroundFetchAbortEventStub( |
688 const std::string& tag, | 689 const std::string& tag, |
689 const mojom::ServiceWorkerEventDispatcher:: | 690 mojom::ServiceWorkerEventDispatcher:: |
690 DispatchBackgroundFetchAbortEventCallback& callback) { | 691 DispatchBackgroundFetchAbortEventCallback callback) { |
691 base::ThreadTaskRunnerHandle::Get()->PostTask( | 692 base::ThreadTaskRunnerHandle::Get()->PostTask( |
692 FROM_HERE, | 693 FROM_HERE, |
693 base::Bind(&EmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent, | 694 base::Bind(&EmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent, |
694 AsWeakPtr(), tag, callback)); | 695 AsWeakPtr(), tag, base::Passed(&callback))); |
695 } | 696 } |
696 | 697 |
697 void EmbeddedWorkerTestHelper::OnBackgroundFetchClickEventStub( | 698 void EmbeddedWorkerTestHelper::OnBackgroundFetchClickEventStub( |
698 const std::string& tag, | 699 const std::string& tag, |
699 mojom::BackgroundFetchState state, | 700 mojom::BackgroundFetchState state, |
700 const mojom::ServiceWorkerEventDispatcher:: | 701 mojom::ServiceWorkerEventDispatcher:: |
701 DispatchBackgroundFetchClickEventCallback& callback) { | 702 DispatchBackgroundFetchClickEventCallback callback) { |
702 base::ThreadTaskRunnerHandle::Get()->PostTask( | 703 base::ThreadTaskRunnerHandle::Get()->PostTask( |
703 FROM_HERE, | 704 FROM_HERE, |
704 base::Bind(&EmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent, | 705 base::Bind(&EmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent, |
705 AsWeakPtr(), tag, state, callback)); | 706 AsWeakPtr(), tag, state, base::Passed(&callback))); |
706 } | 707 } |
707 | 708 |
708 void EmbeddedWorkerTestHelper::OnBackgroundFetchFailEventStub( | 709 void EmbeddedWorkerTestHelper::OnBackgroundFetchFailEventStub( |
709 const std::string& tag, | 710 const std::string& tag, |
710 const std::vector<BackgroundFetchSettledFetch>& fetches, | 711 const std::vector<BackgroundFetchSettledFetch>& fetches, |
711 const mojom::ServiceWorkerEventDispatcher:: | 712 mojom::ServiceWorkerEventDispatcher:: |
712 DispatchBackgroundFetchFailEventCallback& callback) { | 713 DispatchBackgroundFetchFailEventCallback callback) { |
713 base::ThreadTaskRunnerHandle::Get()->PostTask( | 714 base::ThreadTaskRunnerHandle::Get()->PostTask( |
714 FROM_HERE, | 715 FROM_HERE, |
715 base::Bind(&EmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent, | 716 base::Bind(&EmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent, |
716 AsWeakPtr(), tag, fetches, callback)); | 717 AsWeakPtr(), tag, fetches, base::Passed(&callback))); |
717 } | 718 } |
718 | 719 |
719 void EmbeddedWorkerTestHelper::OnBackgroundFetchedEventStub( | 720 void EmbeddedWorkerTestHelper::OnBackgroundFetchedEventStub( |
720 const std::string& tag, | 721 const std::string& tag, |
721 const std::vector<BackgroundFetchSettledFetch>& fetches, | 722 const std::vector<BackgroundFetchSettledFetch>& fetches, |
722 const mojom::ServiceWorkerEventDispatcher:: | 723 mojom::ServiceWorkerEventDispatcher::DispatchBackgroundFetchedEventCallback |
723 DispatchBackgroundFetchedEventCallback& callback) { | 724 callback) { |
724 base::ThreadTaskRunnerHandle::Get()->PostTask( | 725 base::ThreadTaskRunnerHandle::Get()->PostTask( |
725 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnBackgroundFetchedEvent, | 726 FROM_HERE, |
726 AsWeakPtr(), tag, fetches, callback)); | 727 base::Bind(&EmbeddedWorkerTestHelper::OnBackgroundFetchedEvent, |
| 728 AsWeakPtr(), tag, fetches, base::Passed(&callback))); |
727 } | 729 } |
728 | 730 |
729 void EmbeddedWorkerTestHelper::OnExtendableMessageEventStub( | 731 void EmbeddedWorkerTestHelper::OnExtendableMessageEventStub( |
730 mojom::ExtendableMessageEventPtr event, | 732 mojom::ExtendableMessageEventPtr event, |
731 const mojom::ServiceWorkerEventDispatcher:: | 733 mojom::ServiceWorkerEventDispatcher::DispatchExtendableMessageEventCallback |
732 DispatchExtendableMessageEventCallback& callback) { | 734 callback) { |
733 base::ThreadTaskRunnerHandle::Get()->PostTask( | 735 base::ThreadTaskRunnerHandle::Get()->PostTask( |
734 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnExtendableMessageEvent, | 736 FROM_HERE, |
735 AsWeakPtr(), base::Passed(&event), callback)); | 737 base::Bind(&EmbeddedWorkerTestHelper::OnExtendableMessageEvent, |
| 738 AsWeakPtr(), base::Passed(&event), base::Passed(&callback))); |
736 } | 739 } |
737 | 740 |
738 void EmbeddedWorkerTestHelper::OnInstallEventStub(int request_id) { | 741 void EmbeddedWorkerTestHelper::OnInstallEventStub(int request_id) { |
739 base::ThreadTaskRunnerHandle::Get()->PostTask( | 742 base::ThreadTaskRunnerHandle::Get()->PostTask( |
740 FROM_HERE, | 743 FROM_HERE, |
741 base::Bind(&EmbeddedWorkerTestHelper::OnInstallEvent, AsWeakPtr(), | 744 base::Bind(&EmbeddedWorkerTestHelper::OnInstallEvent, AsWeakPtr(), |
742 current_embedded_worker_id_, request_id)); | 745 current_embedded_worker_id_, request_id)); |
743 } | 746 } |
744 | 747 |
745 void EmbeddedWorkerTestHelper::OnFetchEventStub( | 748 void EmbeddedWorkerTestHelper::OnFetchEventStub( |
746 int thread_id, | 749 int thread_id, |
747 int fetch_event_id, | 750 int fetch_event_id, |
748 const ServiceWorkerFetchRequest& request, | 751 const ServiceWorkerFetchRequest& request, |
749 mojom::FetchEventPreloadHandlePtr preload_handle, | 752 mojom::FetchEventPreloadHandlePtr preload_handle, |
750 mojom::ServiceWorkerFetchResponseCallbackPtr response_callback, | 753 mojom::ServiceWorkerFetchResponseCallbackPtr response_callback, |
751 const FetchCallback& finish_callback) { | 754 FetchCallback finish_callback) { |
752 base::ThreadTaskRunnerHandle::Get()->PostTask( | 755 base::ThreadTaskRunnerHandle::Get()->PostTask( |
753 FROM_HERE, | 756 FROM_HERE, |
754 base::Bind(&EmbeddedWorkerTestHelper::OnFetchEvent, AsWeakPtr(), | 757 base::Bind(&EmbeddedWorkerTestHelper::OnFetchEvent, AsWeakPtr(), |
755 thread_id_embedded_worker_id_map_[thread_id], fetch_event_id, | 758 thread_id_embedded_worker_id_map_[thread_id], fetch_event_id, |
756 request, base::Passed(&preload_handle), | 759 request, base::Passed(&preload_handle), |
757 base::Passed(&response_callback), finish_callback)); | 760 base::Passed(&response_callback), |
| 761 base::Passed(&finish_callback))); |
758 } | 762 } |
759 | 763 |
760 void EmbeddedWorkerTestHelper::OnNotificationClickEventStub( | 764 void EmbeddedWorkerTestHelper::OnNotificationClickEventStub( |
761 const std::string& notification_id, | 765 const std::string& notification_id, |
762 const PlatformNotificationData& notification_data, | 766 const PlatformNotificationData& notification_data, |
763 int action_index, | 767 int action_index, |
764 const base::Optional<base::string16>& reply, | 768 const base::Optional<base::string16>& reply, |
765 const mojom::ServiceWorkerEventDispatcher:: | 769 mojom::ServiceWorkerEventDispatcher::DispatchNotificationClickEventCallback |
766 DispatchNotificationClickEventCallback& callback) { | 770 callback) { |
767 base::ThreadTaskRunnerHandle::Get()->PostTask( | 771 base::ThreadTaskRunnerHandle::Get()->PostTask( |
768 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnNotificationClickEvent, | 772 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnNotificationClickEvent, |
769 AsWeakPtr(), notification_id, notification_data, | 773 AsWeakPtr(), notification_id, notification_data, |
770 action_index, reply, callback)); | 774 action_index, reply, base::Passed(&callback))); |
771 } | 775 } |
772 | 776 |
773 void EmbeddedWorkerTestHelper::OnNotificationCloseEventStub( | 777 void EmbeddedWorkerTestHelper::OnNotificationCloseEventStub( |
774 const std::string& notification_id, | 778 const std::string& notification_id, |
775 const PlatformNotificationData& notification_data, | 779 const PlatformNotificationData& notification_data, |
776 const mojom::ServiceWorkerEventDispatcher:: | 780 mojom::ServiceWorkerEventDispatcher::DispatchNotificationCloseEventCallback |
777 DispatchNotificationCloseEventCallback& callback) { | 781 callback) { |
778 base::ThreadTaskRunnerHandle::Get()->PostTask( | 782 base::ThreadTaskRunnerHandle::Get()->PostTask( |
779 FROM_HERE, | 783 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnNotificationCloseEvent, |
780 base::Bind(&EmbeddedWorkerTestHelper::OnNotificationCloseEvent, | 784 AsWeakPtr(), notification_id, notification_data, |
781 AsWeakPtr(), notification_id, notification_data, callback)); | 785 base::Passed(&callback))); |
782 } | 786 } |
783 | 787 |
784 void EmbeddedWorkerTestHelper::OnPushEventStub( | 788 void EmbeddedWorkerTestHelper::OnPushEventStub( |
785 const PushEventPayload& payload, | 789 const PushEventPayload& payload, |
786 const mojom::ServiceWorkerEventDispatcher::DispatchPushEventCallback& | 790 mojom::ServiceWorkerEventDispatcher::DispatchPushEventCallback callback) { |
787 callback) { | |
788 base::ThreadTaskRunnerHandle::Get()->PostTask( | 791 base::ThreadTaskRunnerHandle::Get()->PostTask( |
789 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnPushEvent, AsWeakPtr(), | 792 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnPushEvent, AsWeakPtr(), |
790 payload, callback)); | 793 payload, base::Passed(&callback))); |
791 } | 794 } |
792 | 795 |
793 void EmbeddedWorkerTestHelper::OnPaymentRequestEventStub( | 796 void EmbeddedWorkerTestHelper::OnPaymentRequestEventStub( |
794 payments::mojom::PaymentAppRequestPtr app_request, | 797 payments::mojom::PaymentAppRequestPtr app_request, |
795 payments::mojom::PaymentAppResponseCallbackPtr response_callback, | 798 payments::mojom::PaymentAppResponseCallbackPtr response_callback, |
796 const mojom::ServiceWorkerEventDispatcher:: | 799 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback |
797 DispatchPaymentRequestEventCallback& callback) { | 800 callback) { |
798 base::ThreadTaskRunnerHandle::Get()->PostTask( | 801 base::ThreadTaskRunnerHandle::Get()->PostTask( |
799 FROM_HERE, | 802 FROM_HERE, |
800 base::Bind(&EmbeddedWorkerTestHelper::OnPaymentRequestEvent, AsWeakPtr(), | 803 base::Bind(&EmbeddedWorkerTestHelper::OnPaymentRequestEvent, AsWeakPtr(), |
801 base::Passed(std::move(app_request)), | 804 base::Passed(&app_request), base::Passed(&response_callback), |
802 base::Passed(std::move(response_callback)), callback)); | 805 base::Passed(&callback))); |
803 } | 806 } |
804 | 807 |
805 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() { | 808 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() { |
806 DCHECK(context()); | 809 DCHECK(context()); |
807 return context()->embedded_worker_registry(); | 810 return context()->embedded_worker_registry(); |
808 } | 811 } |
809 | 812 |
810 } // namespace content | 813 } // namespace content |
OLD | NEW |