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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 context()->RemoveProviderHost(mock_render_process_id(), kProviderID); | 370 context()->RemoveProviderHost(mock_render_process_id(), kProviderID); |
370 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 371 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
371 embedded_worker_id, response_id, | 372 embedded_worker_id, response_id, |
372 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, | 373 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, |
373 ServiceWorkerResponse( | 374 ServiceWorkerResponse( |
374 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, | 375 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, |
375 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), | 376 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), |
376 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), | 377 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), |
377 false /* response_is_in_cache_storage */, | 378 false /* response_is_in_cache_storage */, |
378 std::string() /* response_cache_storage_cache_name */, | 379 std::string() /* response_cache_storage_cache_name */, |
379 ServiceWorkerHeaderList() /* cors_exposed_header_names */))); | 380 ServiceWorkerHeaderList() /* cors_exposed_header_names */), |
| 381 base::Time::Now())); |
380 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( | 382 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( |
381 embedded_worker_id, event_finish_id, | 383 embedded_worker_id, event_finish_id, |
382 blink::WebServiceWorkerEventResultCompleted)); | 384 blink::WebServiceWorkerEventResultCompleted, base::Time::Now())); |
383 } | 385 } |
384 | 386 |
385 private: | 387 private: |
386 DISALLOW_COPY_AND_ASSIGN(ProviderDeleteHelper); | 388 DISALLOW_COPY_AND_ASSIGN(ProviderDeleteHelper); |
387 }; | 389 }; |
388 | 390 |
389 TEST_F(ServiceWorkerURLRequestJobTest, DeletedProviderHostOnFetchEvent) { | 391 TEST_F(ServiceWorkerURLRequestJobTest, DeletedProviderHostOnFetchEvent) { |
390 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 392 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
391 // Shouldn't crash if the ProviderHost is deleted prior to completion of | 393 // Shouldn't crash if the ProviderHost is deleted prior to completion of |
392 // the fetch event. | 394 // the fetch event. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 const ServiceWorkerFetchRequest& request) override { | 454 const ServiceWorkerFetchRequest& request) override { |
453 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 455 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
454 embedded_worker_id, response_id, | 456 embedded_worker_id, response_id, |
455 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, | 457 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, |
456 ServiceWorkerResponse( | 458 ServiceWorkerResponse( |
457 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, | 459 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, |
458 ServiceWorkerHeaderMap(), blob_uuid_, blob_size_, GURL(), | 460 ServiceWorkerHeaderMap(), blob_uuid_, blob_size_, GURL(), |
459 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), | 461 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), |
460 false /* response_is_in_cache_storage */, | 462 false /* response_is_in_cache_storage */, |
461 std::string() /* response_cache_storage_cache_name */, | 463 std::string() /* response_cache_storage_cache_name */, |
462 ServiceWorkerHeaderList() /* cors_exposed_header_names */))); | 464 ServiceWorkerHeaderList() /* cors_exposed_header_names */), |
| 465 base::Time::Now())); |
463 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( | 466 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( |
464 embedded_worker_id, event_finish_id, | 467 embedded_worker_id, event_finish_id, |
465 blink::WebServiceWorkerEventResultCompleted)); | 468 blink::WebServiceWorkerEventResultCompleted, base::Time::Now())); |
466 } | 469 } |
467 | 470 |
468 std::string blob_uuid_; | 471 std::string blob_uuid_; |
469 uint64_t blob_size_; | 472 uint64_t blob_size_; |
470 | 473 |
471 private: | 474 private: |
472 DISALLOW_COPY_AND_ASSIGN(BlobResponder); | 475 DISALLOW_COPY_AND_ASSIGN(BlobResponder); |
473 }; | 476 }; |
474 | 477 |
475 TEST_F(ServiceWorkerURLRequestJobTest, BlobResponse) { | 478 TEST_F(ServiceWorkerURLRequestJobTest, BlobResponse) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 const ServiceWorkerFetchRequest& request) override { | 538 const ServiceWorkerFetchRequest& request) override { |
536 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 539 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
537 embedded_worker_id, response_id, | 540 embedded_worker_id, response_id, |
538 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, | 541 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, |
539 ServiceWorkerResponse( | 542 ServiceWorkerResponse( |
540 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, | 543 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, |
541 ServiceWorkerHeaderMap(), "", 0, stream_url_, | 544 ServiceWorkerHeaderMap(), "", 0, stream_url_, |
542 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), | 545 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), |
543 false /* response_is_in_cache_storage */, | 546 false /* response_is_in_cache_storage */, |
544 std::string() /* response_cache_storage_cache_name */, | 547 std::string() /* response_cache_storage_cache_name */, |
545 ServiceWorkerHeaderList() /* cors_exposed_header_names */))); | 548 ServiceWorkerHeaderList() /* cors_exposed_header_names */), |
| 549 base::Time::Now())); |
546 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( | 550 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( |
547 embedded_worker_id, event_finish_id, | 551 embedded_worker_id, event_finish_id, |
548 blink::WebServiceWorkerEventResultCompleted)); | 552 blink::WebServiceWorkerEventResultCompleted, base::Time::Now())); |
549 } | 553 } |
550 | 554 |
551 const GURL stream_url_; | 555 const GURL stream_url_; |
552 | 556 |
553 private: | 557 private: |
554 DISALLOW_COPY_AND_ASSIGN(StreamResponder); | 558 DISALLOW_COPY_AND_ASSIGN(StreamResponder); |
555 }; | 559 }; |
556 | 560 |
557 TEST_F(ServiceWorkerURLRequestJobTest, StreamResponse) { | 561 TEST_F(ServiceWorkerURLRequestJobTest, StreamResponse) { |
558 const GURL stream_url("blob://stream"); | 562 const GURL stream_url("blob://stream"); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 } | 949 } |
946 | 950 |
947 class EarlyResponseHelper : public EmbeddedWorkerTestHelper { | 951 class EarlyResponseHelper : public EmbeddedWorkerTestHelper { |
948 public: | 952 public: |
949 EarlyResponseHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} | 953 EarlyResponseHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} |
950 ~EarlyResponseHelper() override {} | 954 ~EarlyResponseHelper() override {} |
951 | 955 |
952 void FinishWaitUntil() { | 956 void FinishWaitUntil() { |
953 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( | 957 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( |
954 embedded_worker_id_, event_finish_id_, | 958 embedded_worker_id_, event_finish_id_, |
955 blink::WebServiceWorkerEventResultCompleted)); | 959 blink::WebServiceWorkerEventResultCompleted, base::Time::Now())); |
956 } | 960 } |
957 | 961 |
958 protected: | 962 protected: |
959 void OnFetchEvent(int embedded_worker_id, | 963 void OnFetchEvent(int embedded_worker_id, |
960 int response_id, | 964 int response_id, |
961 int event_finish_id, | 965 int event_finish_id, |
962 const ServiceWorkerFetchRequest& request) override { | 966 const ServiceWorkerFetchRequest& request) override { |
963 embedded_worker_id_ = embedded_worker_id; | 967 embedded_worker_id_ = embedded_worker_id; |
964 event_finish_id_ = event_finish_id; | 968 event_finish_id_ = event_finish_id; |
965 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 969 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
966 embedded_worker_id, response_id, | 970 embedded_worker_id, response_id, |
967 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, | 971 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, |
968 ServiceWorkerResponse( | 972 ServiceWorkerResponse( |
969 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, | 973 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, |
970 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), | 974 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), |
971 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), | 975 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), |
972 false /* response_is_in_cache_storage */, | 976 false /* response_is_in_cache_storage */, |
973 std::string() /* response_cache_storage_cache_name */, | 977 std::string() /* response_cache_storage_cache_name */, |
974 ServiceWorkerHeaderList() /* cors_exposed_header_names */))); | 978 ServiceWorkerHeaderList() /* cors_exposed_header_names */), |
| 979 base::Time::Now())); |
975 } | 980 } |
976 | 981 |
977 private: | 982 private: |
978 int embedded_worker_id_ = 0; | 983 int embedded_worker_id_ = 0; |
979 int event_finish_id_ = 0; | 984 int event_finish_id_ = 0; |
980 DISALLOW_COPY_AND_ASSIGN(EarlyResponseHelper); | 985 DISALLOW_COPY_AND_ASSIGN(EarlyResponseHelper); |
981 }; | 986 }; |
982 | 987 |
983 // This simulates the case when a response is returned and the fetch event is | 988 // This simulates the case when a response is returned and the fetch event is |
984 // still in flight. | 989 // still in flight. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 void Respond() { | 1022 void Respond() { |
1018 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 1023 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
1019 embedded_worker_id_, response_id_, | 1024 embedded_worker_id_, response_id_, |
1020 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, | 1025 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, |
1021 ServiceWorkerResponse( | 1026 ServiceWorkerResponse( |
1022 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, | 1027 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, |
1023 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), | 1028 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), |
1024 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), | 1029 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), |
1025 false /* response_is_in_cache_storage */, | 1030 false /* response_is_in_cache_storage */, |
1026 std::string() /* response_cache_storage_cache_name */, | 1031 std::string() /* response_cache_storage_cache_name */, |
1027 ServiceWorkerHeaderList() /* cors_exposed_header_names */))); | 1032 ServiceWorkerHeaderList() /* cors_exposed_header_names */), |
| 1033 base::Time::Now())); |
1028 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( | 1034 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( |
1029 embedded_worker_id_, event_finish_id_, | 1035 embedded_worker_id_, event_finish_id_, |
1030 blink::WebServiceWorkerEventResultCompleted)); | 1036 blink::WebServiceWorkerEventResultCompleted, base::Time::Now())); |
1031 } | 1037 } |
1032 | 1038 |
1033 protected: | 1039 protected: |
1034 void OnFetchEvent(int embedded_worker_id, | 1040 void OnFetchEvent(int embedded_worker_id, |
1035 int response_id, | 1041 int response_id, |
1036 int event_finish_id, | 1042 int event_finish_id, |
1037 const ServiceWorkerFetchRequest& request) override { | 1043 const ServiceWorkerFetchRequest& request) override { |
1038 embedded_worker_id_ = embedded_worker_id; | 1044 embedded_worker_id_ = embedded_worker_id; |
1039 response_id_ = response_id; | 1045 response_id_ = response_id; |
1040 event_finish_id_ = event_finish_id; | 1046 event_finish_id_ = event_finish_id; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 base::RunLoop().RunUntilIdle(); | 1078 base::RunLoop().RunUntilIdle(); |
1073 | 1079 |
1074 // The fetch event request should no longer be in-flight. | 1080 // The fetch event request should no longer be in-flight. |
1075 EXPECT_FALSE(version_->HasWork()); | 1081 EXPECT_FALSE(version_->HasWork()); |
1076 } | 1082 } |
1077 | 1083 |
1078 // TODO(kinuko): Add more tests with different response data and also for | 1084 // TODO(kinuko): Add more tests with different response data and also for |
1079 // FallbackToNetwork case. | 1085 // FallbackToNetwork case. |
1080 | 1086 |
1081 } // namespace content | 1087 } // namespace content |
OLD | NEW |