| 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> |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 359 |
| 360 class ProviderDeleteHelper : public EmbeddedWorkerTestHelper { | 360 class ProviderDeleteHelper : public EmbeddedWorkerTestHelper { |
| 361 public: | 361 public: |
| 362 ProviderDeleteHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} | 362 ProviderDeleteHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} |
| 363 ~ProviderDeleteHelper() override {} | 363 ~ProviderDeleteHelper() override {} |
| 364 | 364 |
| 365 protected: | 365 protected: |
| 366 void OnFetchEvent(int embedded_worker_id, | 366 void OnFetchEvent(int embedded_worker_id, |
| 367 int fetch_event_id, | 367 int fetch_event_id, |
| 368 const ServiceWorkerFetchRequest& request, | 368 const ServiceWorkerFetchRequest& request, |
| 369 mojom::FetchEventPreloadHandlePtr preload_handle, |
| 369 const FetchCallback& callback) override { | 370 const FetchCallback& callback) override { |
| 370 context()->RemoveProviderHost(mock_render_process_id(), kProviderID); | 371 context()->RemoveProviderHost(mock_render_process_id(), kProviderID); |
| 371 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 372 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
| 372 embedded_worker_id, fetch_event_id, | 373 embedded_worker_id, fetch_event_id, |
| 373 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, | 374 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, |
| 374 ServiceWorkerResponse( | 375 ServiceWorkerResponse( |
| 375 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, | 376 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, |
| 376 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), | 377 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), |
| 377 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), | 378 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), |
| 378 false /* response_is_in_cache_storage */, | 379 false /* response_is_in_cache_storage */, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 BlobResponder(const std::string& blob_uuid, uint64_t blob_size) | 443 BlobResponder(const std::string& blob_uuid, uint64_t blob_size) |
| 443 : EmbeddedWorkerTestHelper(base::FilePath()), | 444 : EmbeddedWorkerTestHelper(base::FilePath()), |
| 444 blob_uuid_(blob_uuid), | 445 blob_uuid_(blob_uuid), |
| 445 blob_size_(blob_size) {} | 446 blob_size_(blob_size) {} |
| 446 ~BlobResponder() override {} | 447 ~BlobResponder() override {} |
| 447 | 448 |
| 448 protected: | 449 protected: |
| 449 void OnFetchEvent(int embedded_worker_id, | 450 void OnFetchEvent(int embedded_worker_id, |
| 450 int fetch_event_id, | 451 int fetch_event_id, |
| 451 const ServiceWorkerFetchRequest& request, | 452 const ServiceWorkerFetchRequest& request, |
| 453 mojom::FetchEventPreloadHandlePtr preload_handle, |
| 452 const FetchCallback& callback) override { | 454 const FetchCallback& callback) override { |
| 453 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 455 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
| 454 embedded_worker_id, fetch_event_id, | 456 embedded_worker_id, fetch_event_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 */, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 class StreamResponder : public EmbeddedWorkerTestHelper { | 526 class StreamResponder : public EmbeddedWorkerTestHelper { |
| 525 public: | 527 public: |
| 526 explicit StreamResponder(const GURL& stream_url) | 528 explicit StreamResponder(const GURL& stream_url) |
| 527 : EmbeddedWorkerTestHelper(base::FilePath()), stream_url_(stream_url) {} | 529 : EmbeddedWorkerTestHelper(base::FilePath()), stream_url_(stream_url) {} |
| 528 ~StreamResponder() override {} | 530 ~StreamResponder() override {} |
| 529 | 531 |
| 530 protected: | 532 protected: |
| 531 void OnFetchEvent(int embedded_worker_id, | 533 void OnFetchEvent(int embedded_worker_id, |
| 532 int fetch_event_id, | 534 int fetch_event_id, |
| 533 const ServiceWorkerFetchRequest& request, | 535 const ServiceWorkerFetchRequest& request, |
| 536 mojom::FetchEventPreloadHandlePtr preload_handle, |
| 534 const FetchCallback& callback) override { | 537 const FetchCallback& callback) override { |
| 535 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 538 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
| 536 embedded_worker_id, fetch_event_id, | 539 embedded_worker_id, fetch_event_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 */, |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 // Helper to simulate failing to dispatch a fetch event to a worker. | 840 // Helper to simulate failing to dispatch a fetch event to a worker. |
| 838 class FailFetchHelper : public EmbeddedWorkerTestHelper { | 841 class FailFetchHelper : public EmbeddedWorkerTestHelper { |
| 839 public: | 842 public: |
| 840 FailFetchHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} | 843 FailFetchHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} |
| 841 ~FailFetchHelper() override {} | 844 ~FailFetchHelper() override {} |
| 842 | 845 |
| 843 protected: | 846 protected: |
| 844 void OnFetchEvent(int embedded_worker_id, | 847 void OnFetchEvent(int embedded_worker_id, |
| 845 int fetch_event_id, | 848 int fetch_event_id, |
| 846 const ServiceWorkerFetchRequest& request, | 849 const ServiceWorkerFetchRequest& request, |
| 850 mojom::FetchEventPreloadHandlePtr preload_handle, |
| 847 const FetchCallback& callback) override { | 851 const FetchCallback& callback) override { |
| 848 SimulateWorkerStopped(embedded_worker_id); | 852 SimulateWorkerStopped(embedded_worker_id); |
| 849 callback.Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now()); | 853 callback.Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now()); |
| 850 } | 854 } |
| 851 | 855 |
| 852 private: | 856 private: |
| 853 DISALLOW_COPY_AND_ASSIGN(FailFetchHelper); | 857 DISALLOW_COPY_AND_ASSIGN(FailFetchHelper); |
| 854 }; | 858 }; |
| 855 | 859 |
| 856 TEST_F(ServiceWorkerURLRequestJobTest, FailFetchDispatch) { | 860 TEST_F(ServiceWorkerURLRequestJobTest, FailFetchDispatch) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 ~EarlyResponseHelper() override {} | 953 ~EarlyResponseHelper() override {} |
| 950 | 954 |
| 951 void FinishWaitUntil() { | 955 void FinishWaitUntil() { |
| 952 callback_.Run(SERVICE_WORKER_OK, base::Time::Now()); | 956 callback_.Run(SERVICE_WORKER_OK, base::Time::Now()); |
| 953 } | 957 } |
| 954 | 958 |
| 955 protected: | 959 protected: |
| 956 void OnFetchEvent(int embedded_worker_id, | 960 void OnFetchEvent(int embedded_worker_id, |
| 957 int fetch_event_id, | 961 int fetch_event_id, |
| 958 const ServiceWorkerFetchRequest& request, | 962 const ServiceWorkerFetchRequest& request, |
| 963 mojom::FetchEventPreloadHandlePtr preload_handle, |
| 959 const FetchCallback& callback) override { | 964 const FetchCallback& callback) override { |
| 960 callback_ = callback; | 965 callback_ = callback; |
| 961 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( | 966 SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse( |
| 962 embedded_worker_id, fetch_event_id, | 967 embedded_worker_id, fetch_event_id, |
| 963 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, | 968 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, |
| 964 ServiceWorkerResponse( | 969 ServiceWorkerResponse( |
| 965 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, | 970 GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault, |
| 966 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), | 971 ServiceWorkerHeaderMap(), std::string(), 0, GURL(), |
| 967 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), | 972 blink::WebServiceWorkerResponseErrorUnknown, base::Time(), |
| 968 false /* response_is_in_cache_storage */, | 973 false /* response_is_in_cache_storage */, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 std::string() /* response_cache_storage_cache_name */, | 1028 std::string() /* response_cache_storage_cache_name */, |
| 1024 ServiceWorkerHeaderList() /* cors_exposed_header_names */), | 1029 ServiceWorkerHeaderList() /* cors_exposed_header_names */), |
| 1025 base::Time::Now())); | 1030 base::Time::Now())); |
| 1026 callback_.Run(SERVICE_WORKER_OK, base::Time::Now()); | 1031 callback_.Run(SERVICE_WORKER_OK, base::Time::Now()); |
| 1027 } | 1032 } |
| 1028 | 1033 |
| 1029 protected: | 1034 protected: |
| 1030 void OnFetchEvent(int embedded_worker_id, | 1035 void OnFetchEvent(int embedded_worker_id, |
| 1031 int fetch_event_id, | 1036 int fetch_event_id, |
| 1032 const ServiceWorkerFetchRequest& request, | 1037 const ServiceWorkerFetchRequest& request, |
| 1038 mojom::FetchEventPreloadHandlePtr preload_handle, |
| 1033 const FetchCallback& callback) override { | 1039 const FetchCallback& callback) override { |
| 1034 embedded_worker_id_ = embedded_worker_id; | 1040 embedded_worker_id_ = embedded_worker_id; |
| 1035 fetch_event_id_ = fetch_event_id; | 1041 fetch_event_id_ = fetch_event_id; |
| 1036 callback_ = callback; | 1042 callback_ = callback; |
| 1037 } | 1043 } |
| 1038 | 1044 |
| 1039 private: | 1045 private: |
| 1040 int embedded_worker_id_ = 0; | 1046 int embedded_worker_id_ = 0; |
| 1041 int fetch_event_id_ = 0; | 1047 int fetch_event_id_ = 0; |
| 1042 FetchCallback callback_; | 1048 FetchCallback callback_; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1068 base::RunLoop().RunUntilIdle(); | 1074 base::RunLoop().RunUntilIdle(); |
| 1069 | 1075 |
| 1070 // The fetch event request should no longer be in-flight. | 1076 // The fetch event request should no longer be in-flight. |
| 1071 EXPECT_FALSE(version_->HasWork()); | 1077 EXPECT_FALSE(version_->HasWork()); |
| 1072 } | 1078 } |
| 1073 | 1079 |
| 1074 // TODO(kinuko): Add more tests with different response data and also for | 1080 // TODO(kinuko): Add more tests with different response data and also for |
| 1075 // FallbackToNetwork case. | 1081 // FallbackToNetwork case. |
| 1076 | 1082 |
| 1077 } // namespace content | 1083 } // namespace content |
| OLD | NEW |