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

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

Issue 2142523004: M52: Merge "Reland: service worker: Don't control a subframe of an insecure context" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: fix compile errors Created 4 years, 5 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 EXPECT_EQ(GURL(), info->original_url_via_service_worker()); 366 EXPECT_EQ(GURL(), info->original_url_via_service_worker());
370 EXPECT_EQ(blink::WebServiceWorkerResponseTypeDefault, 367 EXPECT_EQ(blink::WebServiceWorkerResponseTypeDefault,
371 info->response_type_via_service_worker()); 368 info->response_type_via_service_worker());
372 EXPECT_FALSE(info->service_worker_start_time().is_null()); 369 EXPECT_FALSE(info->service_worker_start_time().is_null());
373 EXPECT_FALSE(info->service_worker_ready_time().is_null()); 370 EXPECT_FALSE(info->service_worker_ready_time().is_null());
374 } 371 }
375 372
376 TEST_F(ServiceWorkerURLRequestJobTest, DeletedProviderHostBeforeFetchEvent) { 373 TEST_F(ServiceWorkerURLRequestJobTest, DeletedProviderHostBeforeFetchEvent) {
377 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 374 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
378 request_ = url_request_context_.CreateRequest( 375 request_ = url_request_context_.CreateRequest(
379 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 376 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
380 &url_request_delegate_); 377 &url_request_delegate_);
381 378
382 request_->set_method("GET"); 379 request_->set_method("GET");
383 request_->Start(); 380 request_->Start();
384 helper_->context()->RemoveProviderHost(helper_->mock_render_process_id(), 381 helper_->context()->RemoveProviderHost(helper_->mock_render_process_id(),
385 kProviderID); 382 kProviderID);
386 base::RunLoop().RunUntilIdle(); 383 base::RunLoop().RunUntilIdle();
387 TestRequestResult(500, "Service Worker Response Error", std::string(), 384 TestRequestResult(500, "Service Worker Response Error", std::string(),
388 false /* expect_valid_ssl */); 385 false /* expect_valid_ssl */);
389 386
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 TEST_F(ServiceWorkerURLRequestJobTest, StreamResponse) { 508 TEST_F(ServiceWorkerURLRequestJobTest, StreamResponse) {
512 const GURL stream_url("blob://stream"); 509 const GURL stream_url("blob://stream");
513 StreamContext* stream_context = 510 StreamContext* stream_context =
514 GetStreamContextForResourceContext( 511 GetStreamContextForResourceContext(
515 browser_context_->GetResourceContext()); 512 browser_context_->GetResourceContext());
516 scoped_refptr<Stream> stream = 513 scoped_refptr<Stream> stream =
517 new Stream(stream_context->registry(), nullptr, stream_url); 514 new Stream(stream_context->registry(), nullptr, stream_url);
518 SetUpWithHelper(new StreamResponder(stream_url)); 515 SetUpWithHelper(new StreamResponder(stream_url));
519 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 516 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
520 request_ = url_request_context_.CreateRequest( 517 request_ = url_request_context_.CreateRequest(
521 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 518 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
522 &url_request_delegate_); 519 &url_request_delegate_);
523 request_->set_method("GET"); 520 request_->set_method("GET");
524 request_->Start(); 521 request_->Start();
525 522
526 std::string expected_response; 523 std::string expected_response;
527 expected_response.reserve((sizeof(kTestData) - 1) * 1024); 524 expected_response.reserve((sizeof(kTestData) - 1) * 1024);
528 for (int i = 0; i < 1024; ++i) { 525 for (int i = 0; i < 1024; ++i) {
529 expected_response += kTestData; 526 expected_response += kTestData;
530 stream->AddData(kTestData, sizeof(kTestData) - 1); 527 stream->AddData(kTestData, sizeof(kTestData) - 1);
531 } 528 }
(...skipping 27 matching lines...) Expand all
559 556
560 TEST_F(ServiceWorkerURLRequestJobTest, StreamResponse_DelayedRegistration) { 557 TEST_F(ServiceWorkerURLRequestJobTest, StreamResponse_DelayedRegistration) {
561 const GURL stream_url("blob://stream"); 558 const GURL stream_url("blob://stream");
562 StreamContext* stream_context = 559 StreamContext* stream_context =
563 GetStreamContextForResourceContext( 560 GetStreamContextForResourceContext(
564 browser_context_->GetResourceContext()); 561 browser_context_->GetResourceContext());
565 SetUpWithHelper(new StreamResponder(stream_url)); 562 SetUpWithHelper(new StreamResponder(stream_url));
566 563
567 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 564 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
568 request_ = url_request_context_.CreateRequest( 565 request_ = url_request_context_.CreateRequest(
569 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 566 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
570 &url_request_delegate_); 567 &url_request_delegate_);
571 request_->set_method("GET"); 568 request_->set_method("GET");
572 request_->Start(); 569 request_->Start();
573 570
574 scoped_refptr<Stream> stream = 571 scoped_refptr<Stream> stream =
575 new Stream(stream_context->registry(), nullptr, stream_url); 572 new Stream(stream_context->registry(), nullptr, stream_url);
576 std::string expected_response; 573 std::string expected_response;
577 expected_response.reserve((sizeof(kTestData) - 1) * 1024); 574 expected_response.reserve((sizeof(kTestData) - 1) * 1024);
578 for (int i = 0; i < 1024; ++i) { 575 for (int i = 0; i < 1024; ++i) {
579 expected_response += kTestData; 576 expected_response += kTestData;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 expected_response.reserve((sizeof(kTestData) - 1) * 1024); 616 expected_response.reserve((sizeof(kTestData) - 1) * 1024);
620 for (int i = 0; i < 1024; ++i) { 617 for (int i = 0; i < 1024; ++i) {
621 expected_response += kTestData; 618 expected_response += kTestData;
622 stream->AddData(kTestData, sizeof(kTestData) - 1); 619 stream->AddData(kTestData, sizeof(kTestData) - 1);
623 } 620 }
624 stream->Finalize(); 621 stream->Finalize();
625 SetUpWithHelper(new StreamResponder(stream_url)); 622 SetUpWithHelper(new StreamResponder(stream_url));
626 623
627 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 624 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
628 request_ = url_request_context_.CreateRequest( 625 request_ = url_request_context_.CreateRequest(
629 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 626 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
630 &url_request_delegate_); 627 &url_request_delegate_);
631 request_->set_method("GET"); 628 request_->set_method("GET");
632 request_->Start(); 629 request_->Start();
633 EXPECT_FALSE(HasInflightRequests()); 630 EXPECT_FALSE(HasInflightRequests());
634 base::RunLoop().RunUntilIdle(); 631 base::RunLoop().RunUntilIdle();
635 EXPECT_TRUE(HasInflightRequests()); 632 EXPECT_TRUE(HasInflightRequests());
636 EXPECT_TRUE(request_->status().is_success()); 633 EXPECT_TRUE(request_->status().is_success());
637 EXPECT_EQ(200, 634 EXPECT_EQ(200,
638 request_->response_headers()->response_code()); 635 request_->response_headers()->response_code());
639 EXPECT_EQ("OK", 636 EXPECT_EQ("OK",
(...skipping 21 matching lines...) Expand all
661 const GURL stream_url("blob://stream"); 658 const GURL stream_url("blob://stream");
662 StreamContext* stream_context = 659 StreamContext* stream_context =
663 GetStreamContextForResourceContext( 660 GetStreamContextForResourceContext(
664 browser_context_->GetResourceContext()); 661 browser_context_->GetResourceContext());
665 scoped_refptr<Stream> stream = 662 scoped_refptr<Stream> stream =
666 new Stream(stream_context->registry(), nullptr, stream_url); 663 new Stream(stream_context->registry(), nullptr, stream_url);
667 SetUpWithHelper(new StreamResponder(stream_url)); 664 SetUpWithHelper(new StreamResponder(stream_url));
668 665
669 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 666 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
670 request_ = url_request_context_.CreateRequest( 667 request_ = url_request_context_.CreateRequest(
671 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 668 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
672 &url_request_delegate_); 669 &url_request_delegate_);
673 request_->set_method("GET"); 670 request_->set_method("GET");
674 request_->Start(); 671 request_->Start();
675 std::string expected_response; 672 std::string expected_response;
676 expected_response.reserve((sizeof(kTestData) - 1) * 1024); 673 expected_response.reserve((sizeof(kTestData) - 1) * 1024);
677 for (int i = 0; i < 1024; ++i) { 674 for (int i = 0; i < 1024; ++i) {
678 expected_response += kTestData; 675 expected_response += kTestData;
679 stream->AddData(kTestData, sizeof(kTestData) - 1); 676 stream->AddData(kTestData, sizeof(kTestData) - 1);
680 stream->Flush(); 677 stream->Flush();
681 base::RunLoop().RunUntilIdle(); 678 base::RunLoop().RunUntilIdle();
(...skipping 27 matching lines...) Expand all
709 GetStreamContextForResourceContext( 706 GetStreamContextForResourceContext(
710 browser_context_->GetResourceContext()); 707 browser_context_->GetResourceContext());
711 scoped_refptr<Stream> stream = 708 scoped_refptr<Stream> stream =
712 new Stream(stream_context->registry(), nullptr, stream_url); 709 new Stream(stream_context->registry(), nullptr, stream_url);
713 ASSERT_EQ(stream.get(), 710 ASSERT_EQ(stream.get(),
714 stream_context->registry()->GetStream(stream_url).get()); 711 stream_context->registry()->GetStream(stream_url).get());
715 SetUpWithHelper(new StreamResponder(stream_url)); 712 SetUpWithHelper(new StreamResponder(stream_url));
716 713
717 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 714 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
718 request_ = url_request_context_.CreateRequest( 715 request_ = url_request_context_.CreateRequest(
719 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 716 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
720 &url_request_delegate_); 717 &url_request_delegate_);
721 request_->set_method("GET"); 718 request_->set_method("GET");
722 request_->Start(); 719 request_->Start();
723 EXPECT_FALSE(HasInflightRequests()); 720 EXPECT_FALSE(HasInflightRequests());
724 base::RunLoop().RunUntilIdle(); 721 base::RunLoop().RunUntilIdle();
725 EXPECT_TRUE(HasInflightRequests()); 722 EXPECT_TRUE(HasInflightRequests());
726 723
727 std::string expected_response; 724 std::string expected_response;
728 expected_response.reserve((sizeof(kTestData) - 1) * 1024); 725 expected_response.reserve((sizeof(kTestData) - 1) * 1024);
729 for (int i = 0; i < 512; ++i) { 726 for (int i = 0; i < 512; ++i) {
(...skipping 29 matching lines...) Expand all
759 TEST_F(ServiceWorkerURLRequestJobTest, 756 TEST_F(ServiceWorkerURLRequestJobTest,
760 StreamResponse_DelayedRegistrationAndCancel) { 757 StreamResponse_DelayedRegistrationAndCancel) {
761 const GURL stream_url("blob://stream"); 758 const GURL stream_url("blob://stream");
762 StreamContext* stream_context = 759 StreamContext* stream_context =
763 GetStreamContextForResourceContext( 760 GetStreamContextForResourceContext(
764 browser_context_->GetResourceContext()); 761 browser_context_->GetResourceContext());
765 SetUpWithHelper(new StreamResponder(stream_url)); 762 SetUpWithHelper(new StreamResponder(stream_url));
766 763
767 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 764 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
768 request_ = url_request_context_.CreateRequest( 765 request_ = url_request_context_.CreateRequest(
769 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 766 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
770 &url_request_delegate_); 767 &url_request_delegate_);
771 request_->set_method("GET"); 768 request_->set_method("GET");
772 request_->Start(); 769 request_->Start();
773 EXPECT_FALSE(HasInflightRequests()); 770 EXPECT_FALSE(HasInflightRequests());
774 base::RunLoop().RunUntilIdle(); 771 base::RunLoop().RunUntilIdle();
775 EXPECT_TRUE(HasInflightRequests()); 772 EXPECT_TRUE(HasInflightRequests());
776 request_->Cancel(); 773 request_->Cancel();
777 EXPECT_FALSE(HasInflightRequests()); 774 EXPECT_FALSE(HasInflightRequests());
778 775
779 scoped_refptr<Stream> stream = 776 scoped_refptr<Stream> stream =
(...skipping 26 matching lines...) Expand all
806 803
807 private: 804 private:
808 DISALLOW_COPY_AND_ASSIGN(FailFetchHelper); 805 DISALLOW_COPY_AND_ASSIGN(FailFetchHelper);
809 }; 806 };
810 807
811 TEST_F(ServiceWorkerURLRequestJobTest, FailFetchDispatch) { 808 TEST_F(ServiceWorkerURLRequestJobTest, FailFetchDispatch) {
812 SetUpWithHelper(new FailFetchHelper); 809 SetUpWithHelper(new FailFetchHelper);
813 810
814 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 811 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
815 request_ = url_request_context_.CreateRequest( 812 request_ = url_request_context_.CreateRequest(
816 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 813 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
817 &url_request_delegate_); 814 &url_request_delegate_);
818 request_->set_method("GET"); 815 request_->set_method("GET");
819 request_->Start(); 816 request_->Start();
820 817
821 base::RunLoop().RunUntilIdle(); 818 base::RunLoop().RunUntilIdle();
822 EXPECT_TRUE(request_->status().is_success()); 819 EXPECT_TRUE(request_->status().is_success());
823 // We should have fallen back to network. 820 // We should have fallen back to network.
824 EXPECT_EQ(200, request_->GetResponseCode()); 821 EXPECT_EQ(200, request_->GetResponseCode());
825 EXPECT_EQ("PASS", url_request_delegate_.response_data()); 822 EXPECT_EQ("PASS", url_request_delegate_.response_data());
826 EXPECT_FALSE(HasInflightRequests()); 823 EXPECT_FALSE(HasInflightRequests());
827 ServiceWorkerProviderHost* host = helper_->context()->GetProviderHost( 824 ServiceWorkerProviderHost* host = helper_->context()->GetProviderHost(
828 helper_->mock_render_process_id(), kProviderID); 825 helper_->mock_render_process_id(), kProviderID);
829 ASSERT_TRUE(host); 826 ASSERT_TRUE(host);
830 EXPECT_EQ(host->controlling_version(), nullptr); 827 EXPECT_EQ(host->controlling_version(), nullptr);
831 828
832 EXPECT_EQ(1, times_prepare_to_restart_invoked_); 829 EXPECT_EQ(1, times_prepare_to_restart_invoked_);
833 ServiceWorkerResponseInfo* info = 830 ServiceWorkerResponseInfo* info =
834 ServiceWorkerResponseInfo::ForRequest(request_.get()); 831 ServiceWorkerResponseInfo::ForRequest(request_.get());
835 ASSERT_TRUE(info); 832 ASSERT_TRUE(info);
836 EXPECT_FALSE(info->service_worker_start_time().is_null()); 833 EXPECT_FALSE(info->service_worker_start_time().is_null());
837 EXPECT_FALSE(info->service_worker_ready_time().is_null()); 834 EXPECT_FALSE(info->service_worker_ready_time().is_null());
838 } 835 }
839 836
840 // TODO(horo): Remove this test when crbug.com/485900 is fixed. 837 // TODO(horo): Remove this test when crbug.com/485900 is fixed.
841 TEST_F(ServiceWorkerURLRequestJobTest, MainScriptHTTPResponseInfoNotSet) { 838 TEST_F(ServiceWorkerURLRequestJobTest, MainScriptHTTPResponseInfoNotSet) {
842 // Shouldn't crash if MainScriptHttpResponseInfo is not set. 839 // Shouldn't crash if MainScriptHttpResponseInfo is not set.
843 SetUpWithHelper(new EmbeddedWorkerTestHelper(base::FilePath()), false); 840 SetUpWithHelper(new EmbeddedWorkerTestHelper(base::FilePath()), false);
844 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 841 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
845 request_ = url_request_context_.CreateRequest( 842 request_ = url_request_context_.CreateRequest(
846 GURL("http://example.com/foo.html"), net::DEFAULT_PRIORITY, 843 GURL("https://example.com/foo.html"), net::DEFAULT_PRIORITY,
847 &url_request_delegate_); 844 &url_request_delegate_);
848 request_->set_method("GET"); 845 request_->set_method("GET");
849 request_->Start(); 846 request_->Start();
850 base::RunLoop().RunUntilIdle(); 847 base::RunLoop().RunUntilIdle();
851 EXPECT_TRUE(request_->status().is_success()); 848 EXPECT_TRUE(request_->status().is_success());
852 EXPECT_EQ(200, request_->GetResponseCode()); 849 EXPECT_EQ(200, request_->GetResponseCode());
853 EXPECT_EQ("", url_request_delegate_.response_data()); 850 EXPECT_EQ("", url_request_delegate_.response_data());
854 851
855 EXPECT_EQ(0, times_prepare_to_restart_invoked_); 852 EXPECT_EQ(0, times_prepare_to_restart_invoked_);
856 ServiceWorkerResponseInfo* info = 853 ServiceWorkerResponseInfo* info =
857 ServiceWorkerResponseInfo::ForRequest(request_.get()); 854 ServiceWorkerResponseInfo::ForRequest(request_.get());
858 ASSERT_TRUE(info); 855 ASSERT_TRUE(info);
859 EXPECT_TRUE(info->was_fetched_via_service_worker()); 856 EXPECT_TRUE(info->was_fetched_via_service_worker());
860 EXPECT_FALSE(info->was_fallback_required()); 857 EXPECT_FALSE(info->was_fallback_required());
861 EXPECT_EQ(GURL(), info->original_url_via_service_worker()); 858 EXPECT_EQ(GURL(), info->original_url_via_service_worker());
862 EXPECT_EQ(blink::WebServiceWorkerResponseTypeDefault, 859 EXPECT_EQ(blink::WebServiceWorkerResponseTypeDefault,
863 info->response_type_via_service_worker()); 860 info->response_type_via_service_worker());
864 EXPECT_FALSE(info->service_worker_start_time().is_null()); 861 EXPECT_FALSE(info->service_worker_start_time().is_null());
865 EXPECT_FALSE(info->service_worker_ready_time().is_null()); 862 EXPECT_FALSE(info->service_worker_ready_time().is_null());
866 } 863 }
867 864
868 // TODO(kinuko): Add more tests with different response data and also for 865 // TODO(kinuko): Add more tests with different response data and also for
869 // FallbackToNetwork case. 866 // FallbackToNetwork case.
870 867
871 } // namespace content 868 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698