summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTsuyoshi Horo <horo@chromium.org>2015-06-03 11:12:20 +0900
committerTsuyoshi Horo <horo@chromium.org>2015-06-03 02:13:33 +0000
commit7900258543d920405ea9a6f6488fbee5d5e196b3 (patch)
tree1ba3690cd814600f32dfa0a5c15f80ca4ef1a85a
parent83c6571b44023a6aacd18cc35c8731c9fa4aa1f9 (diff)
downloadchromium_src-7900258543d920405ea9a6f6488fbee5d5e196b3.zip
chromium_src-7900258543d920405ea9a6f6488fbee5d5e196b3.tar.gz
chromium_src-7900258543d920405ea9a6f6488fbee5d5e196b3.tar.bz2
Check the existence of provider_host and active_version in ServiceWorkerURLRequestJob::StartRequest()
They could be null when ServiceWorkerURLRequestJob::StartRequest() is called. BUG=491768 Review URL: https://codereview.chromium.org/1153033002 Cr-Commit-Position: refs/heads/master@{#331500} (cherry picked from commit 9b46187de99621f3da730b0a97c9837c0af5d447) R=nhiroki@chromium.org Review URL: https://codereview.chromium.org/1159793008 Cr-Commit-Position: refs/branch-heads/2357@{#458} Cr-Branched-From: 59d4494849b405682265ed5d3f5164573b9a939b-refs/heads/master@{#323860}
-rw-r--r--content/browser/service_worker/service_worker_url_request_job.cc5
-rw-r--r--content/browser/service_worker/service_worker_url_request_job_unittest.cc19
2 files changed, 22 insertions, 2 deletions
diff --git a/content/browser/service_worker/service_worker_url_request_job.cc b/content/browser/service_worker/service_worker_url_request_job.cc
index a487b7f..2463edb 100644
--- a/content/browser/service_worker/service_worker_url_request_job.cc
+++ b/content/browser/service_worker/service_worker_url_request_job.cc
@@ -359,7 +359,10 @@ void ServiceWorkerURLRequestJob::StartRequest() {
return;
case FORWARD_TO_SERVICE_WORKER:
- DCHECK(provider_host_ && provider_host_->active_version());
+ if (!provider_host_ || !provider_host_->active_version()) {
+ DeliverErrorResponse();
+ return;
+ }
DCHECK(!fetch_dispatcher_);
// Send a fetch event to the ServiceWorker associated to the
// provider_host.
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 e70391e..cdd545f 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
@@ -260,7 +260,7 @@ class ProviderDeleteHelper : public EmbeddedWorkerTestHelper {
DISALLOW_COPY_AND_ASSIGN(ProviderDeleteHelper);
};
-TEST_F(ServiceWorkerURLRequestJobTest, DeletedProviderHost) {
+TEST_F(ServiceWorkerURLRequestJobTest, DeletedProviderHostOnFetchEvent) {
version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
// Shouldn't crash if the ProviderHost is deleted prior to completion of
// the fetch event.
@@ -270,6 +270,23 @@ TEST_F(ServiceWorkerURLRequestJobTest, DeletedProviderHost) {
TestRequest(200, "OK", std::string());
}
+TEST_F(ServiceWorkerURLRequestJobTest, DeletedProviderHostBeforeFetchEvent) {
+ version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
+ request_ = url_request_context_.CreateRequest(
+ GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY,
+ &url_request_delegate_);
+
+ request_->set_method("GET");
+ request_->Start();
+ helper_->context()->RemoveProviderHost(kProcessID, kProviderID);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(request_->status().is_success());
+ EXPECT_EQ(500, request_->response_headers()->response_code());
+ EXPECT_EQ("Service Worker Response Error",
+ request_->response_headers()->GetStatusText());
+ EXPECT_EQ(std::string(), url_request_delegate_.response_data());
+}
+
// Responds to fetch events with a blob.
class BlobResponder : public EmbeddedWorkerTestHelper {
public: