| Index: content/browser/service_worker/service_worker_url_request_job_unittest.cc
|
| diff --git a/content/browser/service_worker/service_worker_url_request_job_unittest.cc b/content/browser/service_worker/service_worker_url_request_job_unittest.cc
|
| index 08d8888d9ec37e82049972366cade3a1eed7f643..ee7bf47e65f923b80f6a19bd07e6a41f27da99a2 100644
|
| --- a/content/browser/service_worker/service_worker_url_request_job_unittest.cc
|
| +++ b/content/browser/service_worker/service_worker_url_request_job_unittest.cc
|
| @@ -104,6 +104,7 @@ class MockHttpProtocolHandler
|
| job_->ForwardToServiceWorker();
|
| return job_;
|
| }
|
| + ServiceWorkerURLRequestJob* job() { return job_; }
|
|
|
| private:
|
| base::WeakPtr<ServiceWorkerProviderHost> provider_host_;
|
| @@ -1006,6 +1007,73 @@ TEST_F(ServiceWorkerURLRequestJobTest, EarlyResponse) {
|
| EXPECT_FALSE(version_->HasInflightRequests());
|
| }
|
|
|
| +// Helper for controlling when to respond to a fetch event.
|
| +class DelayedResponseHelper : public EmbeddedWorkerTestHelper {
|
| + public:
|
| + DelayedResponseHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {}
|
| + ~DelayedResponseHelper() override {}
|
| +
|
| + void Respond() {
|
| + SimulateSend(new ServiceWorkerHostMsg_FetchEventResponse(
|
| + embedded_worker_id_, response_id_,
|
| + SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE,
|
| + ServiceWorkerResponse(
|
| + GURL(), 200, "OK", blink::WebServiceWorkerResponseTypeDefault,
|
| + ServiceWorkerHeaderMap(), std::string(), 0, GURL(),
|
| + blink::WebServiceWorkerResponseErrorUnknown, base::Time(),
|
| + false /* response_is_in_cache_storage */,
|
| + std::string() /* response_cache_storage_cache_name */,
|
| + ServiceWorkerHeaderList() /* cors_exposed_header_names */)));
|
| + SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished(
|
| + embedded_worker_id_, event_finish_id_,
|
| + blink::WebServiceWorkerEventResultCompleted));
|
| + }
|
| +
|
| + protected:
|
| + void OnFetchEvent(int embedded_worker_id,
|
| + int response_id,
|
| + int event_finish_id,
|
| + const ServiceWorkerFetchRequest& request) override {
|
| + embedded_worker_id_ = embedded_worker_id;
|
| + response_id_ = response_id;
|
| + event_finish_id_ = event_finish_id;
|
| + }
|
| +
|
| + private:
|
| + int embedded_worker_id_ = 0;
|
| + int response_id_ = 0;
|
| + int event_finish_id_ = 0;
|
| + DISALLOW_COPY_AND_ASSIGN(DelayedResponseHelper);
|
| +};
|
| +
|
| +// Test cancelling the URLRequest while the fetch event is in flight.
|
| +TEST_F(ServiceWorkerURLRequestJobTest, CancelRequest) {
|
| + DelayedResponseHelper* helper = new DelayedResponseHelper;
|
| + SetUpWithHelper(helper);
|
| +
|
| + // Start the URL request. The job will be waiting for the
|
| + // worker to respond to the fetch event.
|
| + version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
|
| + request_ = url_request_context_.CreateRequest(
|
| + GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
|
| + &url_request_delegate_);
|
| + request_->set_method("GET");
|
| + request_->Start();
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + // Cancel the URL request.
|
| + request_->Cancel();
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + // Respond to the fetch event.
|
| + EXPECT_TRUE(version_->HasInflightRequests());
|
| + helper->Respond();
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + // The fetch event request should no longer be in-flight.
|
| + EXPECT_FALSE(version_->HasInflightRequests());
|
| +}
|
| +
|
| // TODO(kinuko): Add more tests with different response data and also for
|
| // FallbackToNetwork case.
|
|
|
|
|