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

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

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

Powered by Google App Engine
This is Rietveld 408576698