Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: content/browser/service_worker/service_worker_url_request_job_unittest.cc

Issue 2071433003: Reland: service worker: Don't control a subframe of an insecure context (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revised Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 browser_context_.reset(new TestBrowserContext); 136 browser_context_.reset(new TestBrowserContext);
137 InitializeResourceContext(browser_context_.get()); 137 InitializeResourceContext(browser_context_.get());
138 SetUpWithHelper(new EmbeddedWorkerTestHelper(base::FilePath())); 138 SetUpWithHelper(new EmbeddedWorkerTestHelper(base::FilePath()));
139 } 139 }
140 140
141 void SetUpWithHelper(EmbeddedWorkerTestHelper* helper, 141 void SetUpWithHelper(EmbeddedWorkerTestHelper* helper,
142 bool set_main_script_http_response_info = true) { 142 bool set_main_script_http_response_info = true) {
143 helper_.reset(helper); 143 helper_.reset(helper);
144 144
145 registration_ = new ServiceWorkerRegistration( 145 registration_ = new ServiceWorkerRegistration(
146 GURL("http://example.com/"), 146 GURL("https://example.com/"), 1L, helper_->context()->AsWeakPtr());
147 1L,
148 helper_->context()->AsWeakPtr());
149 version_ = new ServiceWorkerVersion( 147 version_ = new ServiceWorkerVersion(
150 registration_.get(), 148 registration_.get(), GURL("https://example.com/service_worker.js"), 1L,
151 GURL("http://example.com/service_worker.js"),
152 1L,
153 helper_->context()->AsWeakPtr()); 149 helper_->context()->AsWeakPtr());
154 std::vector<ServiceWorkerDatabase::ResourceRecord> records; 150 std::vector<ServiceWorkerDatabase::ResourceRecord> records;
155 records.push_back( 151 records.push_back(
156 ServiceWorkerDatabase::ResourceRecord(10, version_->script_url(), 100)); 152 ServiceWorkerDatabase::ResourceRecord(10, version_->script_url(), 100));
157 version_->script_cache_map()->SetResources(records); 153 version_->script_cache_map()->SetResources(records);
158 154
159 // Make the registration findable via storage functions. 155 // Make the registration findable via storage functions.
160 helper_->context()->storage()->LazyInitialize(base::Bind(&base::DoNothing)); 156 helper_->context()->storage()->LazyInitialize(base::Bind(&base::DoNothing));
161 base::RunLoop().RunUntilIdle(); 157 base::RunLoop().RunUntilIdle();
162 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 158 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
(...skipping 11 matching lines...) Expand all
174 EXPECT_TRUE(http_info.ssl_info.is_valid()); 170 EXPECT_TRUE(http_info.ssl_info.is_valid());
175 http_info.ssl_info.security_bits = 0x100; 171 http_info.ssl_info.security_bits = 0x100;
176 // SSL3 TLS_DHE_RSA_WITH_AES_256_CBC_SHA 172 // SSL3 TLS_DHE_RSA_WITH_AES_256_CBC_SHA
177 http_info.ssl_info.connection_status = 0x300039; 173 http_info.ssl_info.connection_status = 0x300039;
178 version_->SetMainScriptHttpResponseInfo(http_info); 174 version_->SetMainScriptHttpResponseInfo(http_info);
179 } 175 }
180 176
181 std::unique_ptr<ServiceWorkerProviderHost> provider_host( 177 std::unique_ptr<ServiceWorkerProviderHost> provider_host(
182 new ServiceWorkerProviderHost( 178 new ServiceWorkerProviderHost(
183 helper_->mock_render_process_id(), MSG_ROUTING_NONE, kProviderID, 179 helper_->mock_render_process_id(), MSG_ROUTING_NONE, kProviderID,
184 SERVICE_WORKER_PROVIDER_FOR_WINDOW, helper_->context()->AsWeakPtr(), 180 SERVICE_WORKER_PROVIDER_FOR_WINDOW,
185 nullptr)); 181 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE,
182 helper_->context()->AsWeakPtr(), nullptr));
186 provider_host_ = provider_host->AsWeakPtr(); 183 provider_host_ = provider_host->AsWeakPtr();
187 provider_host->SetDocumentUrl(GURL("http://example.com/")); 184 provider_host->SetDocumentUrl(GURL("https://example.com/"));
188 registration_->SetActiveVersion(version_); 185 registration_->SetActiveVersion(version_);
189 provider_host->AssociateRegistration(registration_.get(), 186 provider_host->AssociateRegistration(registration_.get(),
190 false /* notify_controllerchange */); 187 false /* notify_controllerchange */);
191 188
192 ChromeBlobStorageContext* chrome_blob_storage_context = 189 ChromeBlobStorageContext* chrome_blob_storage_context =
193 ChromeBlobStorageContext::GetFor(browser_context_.get()); 190 ChromeBlobStorageContext::GetFor(browser_context_.get());
194 // Wait for chrome_blob_storage_context to finish initializing. 191 // Wait for chrome_blob_storage_context to finish initializing.
195 base::RunLoop().RunUntilIdle(); 192 base::RunLoop().RunUntilIdle();
196 storage::BlobStorageContext* blob_storage_context = 193 storage::BlobStorageContext* blob_storage_context =
197 chrome_blob_storage_context->context(); 194 chrome_blob_storage_context->context();
198 195
199 url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl); 196 url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl);
200 url_request_job_factory_->SetProtocolHandler( 197 url_request_job_factory_->SetProtocolHandler(
201 "http", 198 "https",
202 base::WrapUnique(new MockHttpProtocolHandler( 199 base::WrapUnique(new MockHttpProtocolHandler(
203 provider_host->AsWeakPtr(), browser_context_->GetResourceContext(), 200 provider_host->AsWeakPtr(), browser_context_->GetResourceContext(),
204 blob_storage_context->AsWeakPtr(), this))); 201 blob_storage_context->AsWeakPtr(), this)));
205 url_request_job_factory_->SetProtocolHandler( 202 url_request_job_factory_->SetProtocolHandler(
206 "blob", CreateMockBlobProtocolHandler(blob_storage_context)); 203 "blob", CreateMockBlobProtocolHandler(blob_storage_context));
207 url_request_context_.set_job_factory(url_request_job_factory_.get()); 204 url_request_context_.set_job_factory(url_request_job_factory_.get());
208 205
209 helper_->context()->AddProviderHost(std::move(provider_host)); 206 helper_->context()->AddProviderHost(std::move(provider_host));
210 } 207 }
211 208
(...skipping 21 matching lines...) Expand all
233 } else { 230 } else {
234 EXPECT_FALSE(ssl_info.is_valid()); 231 EXPECT_FALSE(ssl_info.is_valid());
235 } 232 }
236 } 233 }
237 234
238 void TestRequest(int expected_status_code, 235 void TestRequest(int expected_status_code,
239 const std::string& expected_status_text, 236 const std::string& expected_status_text,
240 const std::string& expected_response, 237 const std::string& expected_response,
241 bool expect_valid_ssl) { 238 bool expect_valid_ssl) {
242 request_ = url_request_context_.CreateRequest( 239 request_ = url_request_context_.CreateRequest(
243 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 240 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
244 &url_request_delegate_); 241 &url_request_delegate_);
245 242
246 request_->set_method("GET"); 243 request_->set_method("GET");
247 request_->Start(); 244 request_->Start();
248 base::RunLoop().RunUntilIdle(); 245 base::RunLoop().RunUntilIdle();
249 TestRequestResult(expected_status_code, expected_status_text, 246 TestRequestResult(expected_status_code, expected_status_text,
250 expected_response, expect_valid_ssl); 247 expected_response, expect_valid_ssl);
251 } 248 }
252 249
253 bool HasInflightRequests() { 250 bool HasInflightRequests() {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 EXPECT_EQ(GURL(), info->original_url_via_service_worker()); 367 EXPECT_EQ(GURL(), info->original_url_via_service_worker());
371 EXPECT_EQ(blink::WebServiceWorkerResponseTypeDefault, 368 EXPECT_EQ(blink::WebServiceWorkerResponseTypeDefault,
372 info->response_type_via_service_worker()); 369 info->response_type_via_service_worker());
373 EXPECT_FALSE(info->service_worker_start_time().is_null()); 370 EXPECT_FALSE(info->service_worker_start_time().is_null());
374 EXPECT_FALSE(info->service_worker_ready_time().is_null()); 371 EXPECT_FALSE(info->service_worker_ready_time().is_null());
375 } 372 }
376 373
377 TEST_F(ServiceWorkerURLRequestJobTest, DeletedProviderHostBeforeFetchEvent) { 374 TEST_F(ServiceWorkerURLRequestJobTest, DeletedProviderHostBeforeFetchEvent) {
378 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 375 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
379 request_ = url_request_context_.CreateRequest( 376 request_ = url_request_context_.CreateRequest(
380 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 377 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
381 &url_request_delegate_); 378 &url_request_delegate_);
382 379
383 request_->set_method("GET"); 380 request_->set_method("GET");
384 request_->Start(); 381 request_->Start();
385 helper_->context()->RemoveProviderHost(helper_->mock_render_process_id(), 382 helper_->context()->RemoveProviderHost(helper_->mock_render_process_id(),
386 kProviderID); 383 kProviderID);
387 base::RunLoop().RunUntilIdle(); 384 base::RunLoop().RunUntilIdle();
388 TestRequestResult(500, "Service Worker Response Error", std::string(), 385 TestRequestResult(500, "Service Worker Response Error", std::string(),
389 false /* expect_valid_ssl */); 386 false /* expect_valid_ssl */);
390 387
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 TEST_F(ServiceWorkerURLRequestJobTest, StreamResponse) { 511 TEST_F(ServiceWorkerURLRequestJobTest, StreamResponse) {
515 const GURL stream_url("blob://stream"); 512 const GURL stream_url("blob://stream");
516 StreamContext* stream_context = 513 StreamContext* stream_context =
517 GetStreamContextForResourceContext( 514 GetStreamContextForResourceContext(
518 browser_context_->GetResourceContext()); 515 browser_context_->GetResourceContext());
519 scoped_refptr<Stream> stream = 516 scoped_refptr<Stream> stream =
520 new Stream(stream_context->registry(), nullptr, stream_url); 517 new Stream(stream_context->registry(), nullptr, stream_url);
521 SetUpWithHelper(new StreamResponder(stream_url)); 518 SetUpWithHelper(new StreamResponder(stream_url));
522 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 519 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
523 request_ = url_request_context_.CreateRequest( 520 request_ = url_request_context_.CreateRequest(
524 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 521 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
525 &url_request_delegate_); 522 &url_request_delegate_);
526 request_->set_method("GET"); 523 request_->set_method("GET");
527 request_->Start(); 524 request_->Start();
528 525
529 std::string expected_response; 526 std::string expected_response;
530 expected_response.reserve((sizeof(kTestData) - 1) * 1024); 527 expected_response.reserve((sizeof(kTestData) - 1) * 1024);
531 for (int i = 0; i < 1024; ++i) { 528 for (int i = 0; i < 1024; ++i) {
532 expected_response += kTestData; 529 expected_response += kTestData;
533 stream->AddData(kTestData, sizeof(kTestData) - 1); 530 stream->AddData(kTestData, sizeof(kTestData) - 1);
534 } 531 }
(...skipping 27 matching lines...) Expand all
562 559
563 TEST_F(ServiceWorkerURLRequestJobTest, StreamResponse_DelayedRegistration) { 560 TEST_F(ServiceWorkerURLRequestJobTest, StreamResponse_DelayedRegistration) {
564 const GURL stream_url("blob://stream"); 561 const GURL stream_url("blob://stream");
565 StreamContext* stream_context = 562 StreamContext* stream_context =
566 GetStreamContextForResourceContext( 563 GetStreamContextForResourceContext(
567 browser_context_->GetResourceContext()); 564 browser_context_->GetResourceContext());
568 SetUpWithHelper(new StreamResponder(stream_url)); 565 SetUpWithHelper(new StreamResponder(stream_url));
569 566
570 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 567 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
571 request_ = url_request_context_.CreateRequest( 568 request_ = url_request_context_.CreateRequest(
572 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 569 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
573 &url_request_delegate_); 570 &url_request_delegate_);
574 request_->set_method("GET"); 571 request_->set_method("GET");
575 request_->Start(); 572 request_->Start();
576 573
577 scoped_refptr<Stream> stream = 574 scoped_refptr<Stream> stream =
578 new Stream(stream_context->registry(), nullptr, stream_url); 575 new Stream(stream_context->registry(), nullptr, stream_url);
579 std::string expected_response; 576 std::string expected_response;
580 expected_response.reserve((sizeof(kTestData) - 1) * 1024); 577 expected_response.reserve((sizeof(kTestData) - 1) * 1024);
581 for (int i = 0; i < 1024; ++i) { 578 for (int i = 0; i < 1024; ++i) {
582 expected_response += kTestData; 579 expected_response += kTestData;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 expected_response.reserve((sizeof(kTestData) - 1) * 1024); 619 expected_response.reserve((sizeof(kTestData) - 1) * 1024);
623 for (int i = 0; i < 1024; ++i) { 620 for (int i = 0; i < 1024; ++i) {
624 expected_response += kTestData; 621 expected_response += kTestData;
625 stream->AddData(kTestData, sizeof(kTestData) - 1); 622 stream->AddData(kTestData, sizeof(kTestData) - 1);
626 } 623 }
627 stream->Finalize(); 624 stream->Finalize();
628 SetUpWithHelper(new StreamResponder(stream_url)); 625 SetUpWithHelper(new StreamResponder(stream_url));
629 626
630 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 627 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
631 request_ = url_request_context_.CreateRequest( 628 request_ = url_request_context_.CreateRequest(
632 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 629 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
633 &url_request_delegate_); 630 &url_request_delegate_);
634 request_->set_method("GET"); 631 request_->set_method("GET");
635 request_->Start(); 632 request_->Start();
636 EXPECT_FALSE(HasInflightRequests()); 633 EXPECT_FALSE(HasInflightRequests());
637 base::RunLoop().RunUntilIdle(); 634 base::RunLoop().RunUntilIdle();
638 EXPECT_TRUE(HasInflightRequests()); 635 EXPECT_TRUE(HasInflightRequests());
639 EXPECT_TRUE(request_->status().is_success()); 636 EXPECT_TRUE(request_->status().is_success());
640 EXPECT_EQ(200, 637 EXPECT_EQ(200,
641 request_->response_headers()->response_code()); 638 request_->response_headers()->response_code());
642 EXPECT_EQ("OK", 639 EXPECT_EQ("OK",
(...skipping 21 matching lines...) Expand all
664 const GURL stream_url("blob://stream"); 661 const GURL stream_url("blob://stream");
665 StreamContext* stream_context = 662 StreamContext* stream_context =
666 GetStreamContextForResourceContext( 663 GetStreamContextForResourceContext(
667 browser_context_->GetResourceContext()); 664 browser_context_->GetResourceContext());
668 scoped_refptr<Stream> stream = 665 scoped_refptr<Stream> stream =
669 new Stream(stream_context->registry(), nullptr, stream_url); 666 new Stream(stream_context->registry(), nullptr, stream_url);
670 SetUpWithHelper(new StreamResponder(stream_url)); 667 SetUpWithHelper(new StreamResponder(stream_url));
671 668
672 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 669 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
673 request_ = url_request_context_.CreateRequest( 670 request_ = url_request_context_.CreateRequest(
674 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 671 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
675 &url_request_delegate_); 672 &url_request_delegate_);
676 request_->set_method("GET"); 673 request_->set_method("GET");
677 request_->Start(); 674 request_->Start();
678 std::string expected_response; 675 std::string expected_response;
679 expected_response.reserve((sizeof(kTestData) - 1) * 1024); 676 expected_response.reserve((sizeof(kTestData) - 1) * 1024);
680 for (int i = 0; i < 1024; ++i) { 677 for (int i = 0; i < 1024; ++i) {
681 expected_response += kTestData; 678 expected_response += kTestData;
682 stream->AddData(kTestData, sizeof(kTestData) - 1); 679 stream->AddData(kTestData, sizeof(kTestData) - 1);
683 stream->Flush(); 680 stream->Flush();
684 base::RunLoop().RunUntilIdle(); 681 base::RunLoop().RunUntilIdle();
(...skipping 27 matching lines...) Expand all
712 GetStreamContextForResourceContext( 709 GetStreamContextForResourceContext(
713 browser_context_->GetResourceContext()); 710 browser_context_->GetResourceContext());
714 scoped_refptr<Stream> stream = 711 scoped_refptr<Stream> stream =
715 new Stream(stream_context->registry(), nullptr, stream_url); 712 new Stream(stream_context->registry(), nullptr, stream_url);
716 ASSERT_EQ(stream.get(), 713 ASSERT_EQ(stream.get(),
717 stream_context->registry()->GetStream(stream_url).get()); 714 stream_context->registry()->GetStream(stream_url).get());
718 SetUpWithHelper(new StreamResponder(stream_url)); 715 SetUpWithHelper(new StreamResponder(stream_url));
719 716
720 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 717 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
721 request_ = url_request_context_.CreateRequest( 718 request_ = url_request_context_.CreateRequest(
722 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 719 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
723 &url_request_delegate_); 720 &url_request_delegate_);
724 request_->set_method("GET"); 721 request_->set_method("GET");
725 request_->Start(); 722 request_->Start();
726 EXPECT_FALSE(HasInflightRequests()); 723 EXPECT_FALSE(HasInflightRequests());
727 base::RunLoop().RunUntilIdle(); 724 base::RunLoop().RunUntilIdle();
728 EXPECT_TRUE(HasInflightRequests()); 725 EXPECT_TRUE(HasInflightRequests());
729 726
730 std::string expected_response; 727 std::string expected_response;
731 expected_response.reserve((sizeof(kTestData) - 1) * 1024); 728 expected_response.reserve((sizeof(kTestData) - 1) * 1024);
732 for (int i = 0; i < 512; ++i) { 729 for (int i = 0; i < 512; ++i) {
(...skipping 29 matching lines...) Expand all
762 TEST_F(ServiceWorkerURLRequestJobTest, 759 TEST_F(ServiceWorkerURLRequestJobTest,
763 StreamResponse_DelayedRegistrationAndCancel) { 760 StreamResponse_DelayedRegistrationAndCancel) {
764 const GURL stream_url("blob://stream"); 761 const GURL stream_url("blob://stream");
765 StreamContext* stream_context = 762 StreamContext* stream_context =
766 GetStreamContextForResourceContext( 763 GetStreamContextForResourceContext(
767 browser_context_->GetResourceContext()); 764 browser_context_->GetResourceContext());
768 SetUpWithHelper(new StreamResponder(stream_url)); 765 SetUpWithHelper(new StreamResponder(stream_url));
769 766
770 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 767 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
771 request_ = url_request_context_.CreateRequest( 768 request_ = url_request_context_.CreateRequest(
772 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 769 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
773 &url_request_delegate_); 770 &url_request_delegate_);
774 request_->set_method("GET"); 771 request_->set_method("GET");
775 request_->Start(); 772 request_->Start();
776 EXPECT_FALSE(HasInflightRequests()); 773 EXPECT_FALSE(HasInflightRequests());
777 base::RunLoop().RunUntilIdle(); 774 base::RunLoop().RunUntilIdle();
778 EXPECT_TRUE(HasInflightRequests()); 775 EXPECT_TRUE(HasInflightRequests());
779 request_->Cancel(); 776 request_->Cancel();
780 EXPECT_FALSE(HasInflightRequests()); 777 EXPECT_FALSE(HasInflightRequests());
781 778
782 scoped_refptr<Stream> stream = 779 scoped_refptr<Stream> stream =
(...skipping 26 matching lines...) Expand all
809 806
810 private: 807 private:
811 DISALLOW_COPY_AND_ASSIGN(FailFetchHelper); 808 DISALLOW_COPY_AND_ASSIGN(FailFetchHelper);
812 }; 809 };
813 810
814 TEST_F(ServiceWorkerURLRequestJobTest, FailFetchDispatch) { 811 TEST_F(ServiceWorkerURLRequestJobTest, FailFetchDispatch) {
815 SetUpWithHelper(new FailFetchHelper); 812 SetUpWithHelper(new FailFetchHelper);
816 813
817 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 814 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
818 request_ = url_request_context_.CreateRequest( 815 request_ = url_request_context_.CreateRequest(
819 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 816 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
820 &url_request_delegate_); 817 &url_request_delegate_);
821 request_->set_method("GET"); 818 request_->set_method("GET");
822 request_->Start(); 819 request_->Start();
823 820
824 base::RunLoop().RunUntilIdle(); 821 base::RunLoop().RunUntilIdle();
825 EXPECT_TRUE(request_->status().is_success()); 822 EXPECT_TRUE(request_->status().is_success());
826 // We should have fallen back to network. 823 // We should have fallen back to network.
827 EXPECT_EQ(200, request_->GetResponseCode()); 824 EXPECT_EQ(200, request_->GetResponseCode());
828 EXPECT_EQ("PASS", url_request_delegate_.response_data()); 825 EXPECT_EQ("PASS", url_request_delegate_.response_data());
829 EXPECT_FALSE(HasInflightRequests()); 826 EXPECT_FALSE(HasInflightRequests());
830 ServiceWorkerProviderHost* host = helper_->context()->GetProviderHost( 827 ServiceWorkerProviderHost* host = helper_->context()->GetProviderHost(
831 helper_->mock_render_process_id(), kProviderID); 828 helper_->mock_render_process_id(), kProviderID);
832 ASSERT_TRUE(host); 829 ASSERT_TRUE(host);
833 EXPECT_EQ(host->controlling_version(), nullptr); 830 EXPECT_EQ(host->controlling_version(), nullptr);
834 831
835 EXPECT_EQ(1, times_prepare_to_restart_invoked_); 832 EXPECT_EQ(1, times_prepare_to_restart_invoked_);
836 ServiceWorkerResponseInfo* info = 833 ServiceWorkerResponseInfo* info =
837 ServiceWorkerResponseInfo::ForRequest(request_.get()); 834 ServiceWorkerResponseInfo::ForRequest(request_.get());
838 ASSERT_TRUE(info); 835 ASSERT_TRUE(info);
839 EXPECT_FALSE(info->service_worker_start_time().is_null()); 836 EXPECT_FALSE(info->service_worker_start_time().is_null());
840 EXPECT_FALSE(info->service_worker_ready_time().is_null()); 837 EXPECT_FALSE(info->service_worker_ready_time().is_null());
841 } 838 }
842 839
843 // TODO(horo): Remove this test when crbug.com/485900 is fixed. 840 // TODO(horo): Remove this test when crbug.com/485900 is fixed.
844 TEST_F(ServiceWorkerURLRequestJobTest, MainScriptHTTPResponseInfoNotSet) { 841 TEST_F(ServiceWorkerURLRequestJobTest, MainScriptHTTPResponseInfoNotSet) {
845 // Shouldn't crash if MainScriptHttpResponseInfo is not set. 842 // Shouldn't crash if MainScriptHttpResponseInfo is not set.
846 SetUpWithHelper(new EmbeddedWorkerTestHelper(base::FilePath()), false); 843 SetUpWithHelper(new EmbeddedWorkerTestHelper(base::FilePath()), false);
847 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 844 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
848 request_ = url_request_context_.CreateRequest( 845 request_ = url_request_context_.CreateRequest(
849 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 846 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
850 &url_request_delegate_); 847 &url_request_delegate_);
851 request_->set_method("GET"); 848 request_->set_method("GET");
852 request_->Start(); 849 request_->Start();
853 base::RunLoop().RunUntilIdle(); 850 base::RunLoop().RunUntilIdle();
854 EXPECT_TRUE(request_->status().is_success()); 851 EXPECT_TRUE(request_->status().is_success());
855 EXPECT_EQ(200, request_->GetResponseCode()); 852 EXPECT_EQ(200, request_->GetResponseCode());
856 EXPECT_EQ("", url_request_delegate_.response_data()); 853 EXPECT_EQ("", url_request_delegate_.response_data());
857 854
858 EXPECT_EQ(0, times_prepare_to_restart_invoked_); 855 EXPECT_EQ(0, times_prepare_to_restart_invoked_);
859 ServiceWorkerResponseInfo* info = 856 ServiceWorkerResponseInfo* info =
860 ServiceWorkerResponseInfo::ForRequest(request_.get()); 857 ServiceWorkerResponseInfo::ForRequest(request_.get());
861 ASSERT_TRUE(info); 858 ASSERT_TRUE(info);
862 EXPECT_TRUE(info->was_fetched_via_service_worker()); 859 EXPECT_TRUE(info->was_fetched_via_service_worker());
863 EXPECT_FALSE(info->was_fallback_required()); 860 EXPECT_FALSE(info->was_fallback_required());
864 EXPECT_EQ(GURL(), info->original_url_via_service_worker()); 861 EXPECT_EQ(GURL(), info->original_url_via_service_worker());
865 EXPECT_EQ(blink::WebServiceWorkerResponseTypeDefault, 862 EXPECT_EQ(blink::WebServiceWorkerResponseTypeDefault,
866 info->response_type_via_service_worker()); 863 info->response_type_via_service_worker());
867 EXPECT_FALSE(info->service_worker_start_time().is_null()); 864 EXPECT_FALSE(info->service_worker_start_time().is_null());
868 EXPECT_FALSE(info->service_worker_ready_time().is_null()); 865 EXPECT_FALSE(info->service_worker_ready_time().is_null());
869 } 866 }
870 867
871 // TODO(kinuko): Add more tests with different response data and also for 868 // TODO(kinuko): Add more tests with different response data and also for
872 // FallbackToNetwork case. 869 // FallbackToNetwork case.
873 870
874 } // namespace content 871 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698