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