| 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/service_worker_url_request_job.h" | 5 #include "content/browser/service_worker/service_worker_url_request_job.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "base/time/time.h" |
| 20 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 21 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 21 #include "content/browser/fileapi/mock_url_request_delegate.h" | 22 #include "content/browser/fileapi/mock_url_request_delegate.h" |
| 22 #include "content/browser/resource_context_impl.h" | 23 #include "content/browser/resource_context_impl.h" |
| 23 #include "content/browser/service_worker/embedded_worker_registry.h" | 24 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 24 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 25 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 25 #include "content/browser/service_worker/service_worker_context_core.h" | 26 #include "content/browser/service_worker/service_worker_context_core.h" |
| 26 #include "content/browser/service_worker/service_worker_provider_host.h" | 27 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 27 #include "content/browser/service_worker/service_worker_registration.h" | 28 #include "content/browser/service_worker/service_worker_registration.h" |
| 28 #include "content/browser/service_worker/service_worker_response_info.h" | 29 #include "content/browser/service_worker/service_worker_response_info.h" |
| 29 #include "content/browser/service_worker/service_worker_test_utils.h" | 30 #include "content/browser/service_worker/service_worker_test_utils.h" |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 context()->RemoveProviderHost(mock_render_process_id(), kProviderID); | 369 context()->RemoveProviderHost(mock_render_process_id(), kProviderID); |
| 369 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 370 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
| 370 embedded_worker_id, response_id, | 371 embedded_worker_id, response_id, |
| 371 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, | 372 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, |
| 372 ServiceWorkerResponse( | 373 ServiceWorkerResponse( |
| 373 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, | 374 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, |
| 374 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), | 375 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), |
| 375 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), | 376 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), |
| 376 false /* response_is_in_cache_storage */, | 377 false /* response_is_in_cache_storage */, |
| 377 std::string() /* response_cache_storage_cache_name */, | 378 std::string() /* response_cache_storage_cache_name */, |
| 378 ServiceWorkerHeaderList() /* cors_exposed_header_names */))); | 379 ServiceWorkerHeaderList() /* cors_exposed_header_names */), |
| 380 base::Time::Now())); |
| 379 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( | 381 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( |
| 380 embedded_worker_id, event_finish_id, | 382 embedded_worker_id, event_finish_id, |
| 381 blink::WebServiceWorkerEventResultCompleted)); | 383 blink::WebServiceWorkerEventResultCompleted)); |
| 382 } | 384 } |
| 383 | 385 |
| 384 private: | 386 private: |
| 385 DISALLOW_COPY_AND_ASSIGN(ProviderDeleteHelper); | 387 DISALLOW_COPY_AND_ASSIGN(ProviderDeleteHelper); |
| 386 }; | 388 }; |
| 387 | 389 |
| 388 TEST_F(ServiceWorkerURLRequestJobTest, DeletedProviderHostOnFetchEvent) { | 390 TEST_F(ServiceWorkerURLRequestJobTest, DeletedProviderHostOnFetchEvent) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 const ServiceWorkerFetchRequest& request) override { | 453 const ServiceWorkerFetchRequest& request) override { |
| 452 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 454 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
| 453 embedded_worker_id, response_id, | 455 embedded_worker_id, response_id, |
| 454 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, | 456 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, |
| 455 ServiceWorkerResponse( | 457 ServiceWorkerResponse( |
| 456 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, | 458 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, |
| 457 ServiceWorkerHeaderMap(), blob_uuid_, blob_size_, GURL(), | 459 ServiceWorkerHeaderMap(), blob_uuid_, blob_size_, GURL(), |
| 458 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), | 460 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), |
| 459 false /* response_is_in_cache_storage */, | 461 false /* response_is_in_cache_storage */, |
| 460 std::string() /* response_cache_storage_cache_name */, | 462 std::string() /* response_cache_storage_cache_name */, |
| 461 ServiceWorkerHeaderList() /* cors_exposed_header_names */))); | 463 ServiceWorkerHeaderList() /* cors_exposed_header_names */), |
| 464 base::Time::Now())); |
| 462 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( | 465 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( |
| 463 embedded_worker_id, event_finish_id, | 466 embedded_worker_id, event_finish_id, |
| 464 blink::WebServiceWorkerEventResultCompleted)); | 467 blink::WebServiceWorkerEventResultCompleted)); |
| 465 } | 468 } |
| 466 | 469 |
| 467 std::string blob_uuid_; | 470 std::string blob_uuid_; |
| 468 uint64_t blob_size_; | 471 uint64_t blob_size_; |
| 469 | 472 |
| 470 private: | 473 private: |
| 471 DISALLOW_COPY_AND_ASSIGN(BlobResponder); | 474 DISALLOW_COPY_AND_ASSIGN(BlobResponder); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 const ServiceWorkerFetchRequest& request) override { | 537 const ServiceWorkerFetchRequest& request) override { |
| 535 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 538 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
| 536 embedded_worker_id, response_id, | 539 embedded_worker_id, response_id, |
| 537 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, | 540 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, |
| 538 ServiceWorkerResponse( | 541 ServiceWorkerResponse( |
| 539 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, | 542 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, |
| 540 ServiceWorkerHeaderMap(), "", 0, stream_url_, | 543 ServiceWorkerHeaderMap(), "", 0, stream_url_, |
| 541 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), | 544 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), |
| 542 false /* response_is_in_cache_storage */, | 545 false /* response_is_in_cache_storage */, |
| 543 std::string() /* response_cache_storage_cache_name */, | 546 std::string() /* response_cache_storage_cache_name */, |
| 544 ServiceWorkerHeaderList() /* cors_exposed_header_names */))); | 547 ServiceWorkerHeaderList() /* cors_exposed_header_names */), |
| 548 base::Time::Now())); |
| 545 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( | 549 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( |
| 546 embedded_worker_id, event_finish_id, | 550 embedded_worker_id, event_finish_id, |
| 547 blink::WebServiceWorkerEventResultCompleted)); | 551 blink::WebServiceWorkerEventResultCompleted)); |
| 548 } | 552 } |
| 549 | 553 |
| 550 const GURL stream_url_; | 554 const GURL stream_url_; |
| 551 | 555 |
| 552 private: | 556 private: |
| 553 DISALLOW_COPY_AND_ASSIGN(StreamResponder); | 557 DISALLOW_COPY_AND_ASSIGN(StreamResponder); |
| 554 }; | 558 }; |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 event_finish_id_ = event_finish_id; | 967 event_finish_id_ = event_finish_id; |
| 964 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 968 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
| 965 embedded_worker_id, response_id, | 969 embedded_worker_id, response_id, |
| 966 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, | 970 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, |
| 967 ServiceWorkerResponse( | 971 ServiceWorkerResponse( |
| 968 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, | 972 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, |
| 969 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), | 973 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), |
| 970 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), | 974 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), |
| 971 false /* response_is_in_cache_storage */, | 975 false /* response_is_in_cache_storage */, |
| 972 std::string() /* response_cache_storage_cache_name */, | 976 std::string() /* response_cache_storage_cache_name */, |
| 973 ServiceWorkerHeaderList() /* cors_exposed_header_names */))); | 977 ServiceWorkerHeaderList() /* cors_exposed_header_names */), |
| 978 base::Time::Now())); |
| 974 } | 979 } |
| 975 | 980 |
| 976 private: | 981 private: |
| 977 int embedded_worker_id_ = 0; | 982 int embedded_worker_id_ = 0; |
| 978 int event_finish_id_ = 0; | 983 int event_finish_id_ = 0; |
| 979 DISALLOW_COPY_AND_ASSIGN(EarlyResponseHelper); | 984 DISALLOW_COPY_AND_ASSIGN(EarlyResponseHelper); |
| 980 }; | 985 }; |
| 981 | 986 |
| 982 // This simulates the case when a response is returned and the fetch event is | 987 // This simulates the case when a response is returned and the fetch event is |
| 983 // still in flight. | 988 // still in flight. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 void Respond() { | 1021 void Respond() { |
| 1017 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 1022 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
| 1018 embedded_worker_id_, response_id_, | 1023 embedded_worker_id_, response_id_, |
| 1019 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, | 1024 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, |
| 1020 ServiceWorkerResponse( | 1025 ServiceWorkerResponse( |
| 1021 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, | 1026 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, |
| 1022 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), | 1027 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), |
| 1023 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), | 1028 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), |
| 1024 false /* response_is_in_cache_storage */, | 1029 false /* response_is_in_cache_storage */, |
| 1025 std::string() /* response_cache_storage_cache_name */, | 1030 std::string() /* response_cache_storage_cache_name */, |
| 1026 ServiceWorkerHeaderList() /* cors_exposed_header_names */))); | 1031 ServiceWorkerHeaderList() /* cors_exposed_header_names */), |
| 1032 base::Time::Now())); |
| 1027 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( | 1033 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( |
| 1028 embedded_worker_id_, event_finish_id_, | 1034 embedded_worker_id_, event_finish_id_, |
| 1029 blink::WebServiceWorkerEventResultCompleted)); | 1035 blink::WebServiceWorkerEventResultCompleted)); |
| 1030 } | 1036 } |
| 1031 | 1037 |
| 1032 protected: | 1038 protected: |
| 1033 void OnFetchEvent(int embedded_worker_id, | 1039 void OnFetchEvent(int embedded_worker_id, |
| 1034 int response_id, | 1040 int response_id, |
| 1035 int event_finish_id, | 1041 int event_finish_id, |
| 1036 const ServiceWorkerFetchRequest& request) override { | 1042 const ServiceWorkerFetchRequest& request) override { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 base::RunLoop().RunUntilIdle(); | 1077 base::RunLoop().RunUntilIdle(); |
| 1072 | 1078 |
| 1073 // The fetch event request should no longer be in-flight. | 1079 // The fetch event request should no longer be in-flight. |
| 1074 EXPECT_FALSE(version_->HasWork()); | 1080 EXPECT_FALSE(version_->HasWork()); |
| 1075 } | 1081 } |
| 1076 | 1082 |
| 1077 // TODO(kinuko): Add more tests with different response data and also for | 1083 // TODO(kinuko): Add more tests with different response data and also for |
| 1078 // FallbackToNetwork case. | 1084 // FallbackToNetwork case. |
| 1079 | 1085 |
| 1080 } // namespace content | 1086 } // namespace content |
| OLD | NEW |