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

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

Issue 1108253002: (Reland) Evict Service Worker when reading it from disk cache fails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 5 years, 8 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
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_read_from_cache_job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/browser/fileapi/chrome_blob_storage_context.h" 10 #include "content/browser/fileapi/chrome_blob_storage_context.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 ServiceWorkerVersion::FetchCallback CreateResponseReceiver( 124 ServiceWorkerVersion::FetchCallback CreateResponseReceiver(
125 BrowserThread::ID run_quit_thread, 125 BrowserThread::ID run_quit_thread,
126 const base::Closure& quit, 126 const base::Closure& quit,
127 ChromeBlobStorageContext* blob_context, 127 ChromeBlobStorageContext* blob_context,
128 FetchResult* result) { 128 FetchResult* result) {
129 return base::Bind(&ReceiveFetchResult, run_quit_thread, quit, 129 return base::Bind(&ReceiveFetchResult, run_quit_thread, quit,
130 make_scoped_refptr<ChromeBlobStorageContext>(blob_context), 130 make_scoped_refptr<ChromeBlobStorageContext>(blob_context),
131 result); 131 result);
132 } 132 }
133 133
134 void ReceiveFindRegistrationStatus(
135 BrowserThread::ID run_quit_thread,
136 const base::Closure& quit,
137 ServiceWorkerStatusCode* out_status,
138 ServiceWorkerStatusCode status,
139 const scoped_refptr<ServiceWorkerRegistration>& registration) {
140 *out_status = status;
141 if (!quit.is_null())
142 BrowserThread::PostTask(run_quit_thread, FROM_HERE, quit);
143 }
144
145 ServiceWorkerStorage::FindRegistrationCallback CreateFindRegistrationReceiver(
146 BrowserThread::ID run_quit_thread,
147 const base::Closure& quit,
148 ServiceWorkerStatusCode* status) {
149 return base::Bind(&ReceiveFindRegistrationStatus, run_quit_thread, quit,
150 status);
151 }
152
134 void ReadResponseBody(std::string* body, 153 void ReadResponseBody(std::string* body,
135 storage::BlobDataHandle* blob_data_handle) { 154 storage::BlobDataHandle* blob_data_handle) {
136 ASSERT_TRUE(blob_data_handle); 155 ASSERT_TRUE(blob_data_handle);
137 scoped_ptr<storage::BlobDataSnapshot> data = 156 scoped_ptr<storage::BlobDataSnapshot> data =
138 blob_data_handle->CreateSnapshot(); 157 blob_data_handle->CreateSnapshot();
139 ASSERT_EQ(1U, data->items().size()); 158 ASSERT_EQ(1U, data->items().size());
140 *body = std::string(data->items()[0]->bytes(), data->items()[0]->length()); 159 *body = std::string(data->items()[0]->bytes(), data->items()[0]->length());
141 } 160 }
142 161
143 void ExpectResultAndRun(bool expected, 162 void ExpectResultAndRun(bool expected,
144 const base::Closure& continuation, 163 const base::Closure& continuation,
145 bool actual) { 164 bool actual) {
146 EXPECT_EQ(expected, actual); 165 EXPECT_EQ(expected, actual);
147 continuation.Run(); 166 continuation.Run();
148 } 167 }
149 168
150 class WorkerActivatedObserver 169 class WorkerActivatedObserver
151 : public ServiceWorkerContextObserver, 170 : public ServiceWorkerContextObserver,
152 public base::RefCountedThreadSafe<WorkerActivatedObserver> { 171 public base::RefCountedThreadSafe<WorkerActivatedObserver> {
153 public: 172 public:
154 explicit WorkerActivatedObserver(ServiceWorkerContextWrapper* context) 173 explicit WorkerActivatedObserver(ServiceWorkerContextWrapper* context)
155 : context_(context) {} 174 : context_(context) {}
156 void Init() { 175 void Init() {
157 RunOnIOThread(base::Bind(&WorkerActivatedObserver::InitOnIOThread, this)); 176 RunOnIOThread(base::Bind(&WorkerActivatedObserver::InitOnIOThread, this));
158 } 177 }
159 // ServiceWorkerContextObserver overrides. 178 // ServiceWorkerContextObserver overrides.
160 void OnVersionStateChanged(int64 version_id, 179 void OnVersionStateChanged(int64 version_id,
161 ServiceWorkerVersion::Status) override { 180 ServiceWorkerVersion::Status) override {
162 DCHECK_CURRENTLY_ON(BrowserThread::IO); 181 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
163 const ServiceWorkerVersion* version = context_->GetLiveVersion(version_id); 182 const ServiceWorkerVersion* version = context_->GetLiveVersion(version_id);
164 if (version->status() == ServiceWorkerVersion::ACTIVATED) { 183 if (version->status() == ServiceWorkerVersion::ACTIVATED) {
165 context_->RemoveObserver(this); 184 context_->RemoveObserver(this);
166 BrowserThread::PostTask(BrowserThread::UI, 185 BrowserThread::PostTask(BrowserThread::UI,
167 FROM_HERE, 186 FROM_HERE,
168 base::Bind(&WorkerActivatedObserver::Quit, this)); 187 base::Bind(&WorkerActivatedObserver::Quit, this));
169 } 188 }
170 } 189 }
171 void Wait() { run_loop_.Run(); } 190 void Wait() { run_loop_.Run(); }
172 191
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 request, network_delegate, headers, body_, true); 239 request, network_delegate, headers, body_, true);
221 } 240 }
222 241
223 private: 242 private:
224 std::string body_; 243 std::string body_;
225 DISALLOW_COPY_AND_ASSIGN(LongLivedResourceInterceptor); 244 DISALLOW_COPY_AND_ASSIGN(LongLivedResourceInterceptor);
226 }; 245 };
227 246
228 void CreateLongLivedResourceInterceptors( 247 void CreateLongLivedResourceInterceptors(
229 const GURL& worker_url, const GURL& import_url) { 248 const GURL& worker_url, const GURL& import_url) {
230 DCHECK_CURRENTLY_ON(BrowserThread::IO); 249 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
231 scoped_ptr<net::URLRequestInterceptor> interceptor; 250 scoped_ptr<net::URLRequestInterceptor> interceptor;
232 251
233 interceptor.reset(new LongLivedResourceInterceptor( 252 interceptor.reset(new LongLivedResourceInterceptor(
234 "importScripts('long_lived_import.js');")); 253 "importScripts('long_lived_import.js');"));
235 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 254 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
236 worker_url, interceptor.Pass()); 255 worker_url, interceptor.Pass());
237 256
238 interceptor.reset(new LongLivedResourceInterceptor( 257 interceptor.reset(new LongLivedResourceInterceptor(
239 "// the imported script does nothing")); 258 "// the imported script does nothing"));
240 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 259 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 void FetchTestHelper(const std::string& worker_url, 560 void FetchTestHelper(const std::string& worker_url,
542 ServiceWorkerFetchEventResult* result, 561 ServiceWorkerFetchEventResult* result,
543 ServiceWorkerResponse* response, 562 ServiceWorkerResponse* response,
544 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { 563 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) {
545 RunOnIOThread( 564 RunOnIOThread(
546 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); 565 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url));
547 FetchOnRegisteredWorker(result, response, blob_data_handle); 566 FetchOnRegisteredWorker(result, response, blob_data_handle);
548 } 567 }
549 568
550 void SetUpRegistrationOnIOThread(const std::string& worker_url) { 569 void SetUpRegistrationOnIOThread(const std::string& worker_url) {
570 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
551 const GURL pattern = embedded_test_server()->GetURL("/service_worker/"); 571 const GURL pattern = embedded_test_server()->GetURL("/service_worker/");
552 registration_ = new ServiceWorkerRegistration( 572 registration_ = new ServiceWorkerRegistration(
553 pattern, 573 pattern,
554 wrapper()->context()->storage()->NewRegistrationId(), 574 wrapper()->context()->storage()->NewRegistrationId(),
555 wrapper()->context()->AsWeakPtr()); 575 wrapper()->context()->AsWeakPtr());
556 version_ = new ServiceWorkerVersion( 576 version_ = new ServiceWorkerVersion(
557 registration_.get(), 577 registration_.get(),
558 embedded_test_server()->GetURL(worker_url), 578 embedded_test_server()->GetURL(worker_url),
559 wrapper()->context()->storage()->NewVersionId(), 579 wrapper()->context()->storage()->NewVersionId(),
560 wrapper()->context()->AsWeakPtr()); 580 wrapper()->context()->AsWeakPtr());
561 581
562 // Make the registration findable via storage functions. 582 // Make the registration findable via storage functions.
563 wrapper()->context()->storage()->NotifyInstallingRegistration( 583 wrapper()->context()->storage()->NotifyInstallingRegistration(
564 registration_.get()); 584 registration_.get());
565 585
566 AssociateRendererProcessToPattern(pattern); 586 AssociateRendererProcessToPattern(pattern);
567 } 587 }
568 588
569 void TimeoutWorkerOnIOThread() { 589 void TimeoutWorkerOnIOThread() {
570 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 590 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
571 version_->PingWorker(); 591 version_->PingWorker();
572 version_->OnPingTimeout(); 592 version_->OnPingTimeout();
573 } 593 }
574 594
595 void AddControlleeOnIOThread() {
596 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
597 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
598 33 /* dummy render process id */,
599 MSG_ROUTING_NONE /* render_frame_id */, 1 /* dummy provider_id */,
600 SERVICE_WORKER_PROVIDER_FOR_WINDOW, wrapper()->context()->AsWeakPtr(),
601 NULL));
602 host->SetDocumentUrl(
603 embedded_test_server()->GetURL("/service_worker/host"));
604 host->AssociateRegistration(registration_.get(),
605 false /* notify_controllerchange */);
606 wrapper()->context()->AddProviderHost(host.Pass());
607 }
608
609 void AddWaitingWorkerOnIOThread(const std::string& worker_url) {
610 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
611 scoped_refptr<ServiceWorkerVersion> waiting_version(
612 new ServiceWorkerVersion(
613 registration_.get(), embedded_test_server()->GetURL(worker_url),
614 wrapper()->context()->storage()->NewVersionId(),
615 wrapper()->context()->AsWeakPtr()));
616 waiting_version->SetStatus(ServiceWorkerVersion::INSTALLED);
617 registration_->SetWaitingVersion(waiting_version.get());
618 registration_->ActivateWaitingVersionWhenReady();
619 }
620
575 void StartWorker(ServiceWorkerStatusCode expected_status) { 621 void StartWorker(ServiceWorkerStatusCode expected_status) {
576 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); 622 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
577 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 623 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
578 base::RunLoop start_run_loop; 624 base::RunLoop start_run_loop;
579 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 625 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
580 base::Bind(&self::StartOnIOThread, this, 626 base::Bind(&self::StartOnIOThread, this,
581 start_run_loop.QuitClosure(), 627 start_run_loop.QuitClosure(),
582 &status)); 628 &status));
583 start_run_loop.Run(); 629 start_run_loop.Run();
584 ASSERT_EQ(expected_status, status); 630 ASSERT_EQ(expected_status, status);
585 } 631 }
586 632
587 void StopWorker(ServiceWorkerStatusCode expected_status) { 633 void StopWorker(ServiceWorkerStatusCode expected_status) {
588 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); 634 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
589 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 635 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
590 base::RunLoop stop_run_loop; 636 base::RunLoop stop_run_loop;
591 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 637 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
592 base::Bind(&self::StopOnIOThread, this, 638 base::Bind(&self::StopOnIOThread, this,
593 stop_run_loop.QuitClosure(), 639 stop_run_loop.QuitClosure(),
594 &status)); 640 &status));
595 stop_run_loop.Run(); 641 stop_run_loop.Run();
596 ASSERT_EQ(expected_status, status); 642 ASSERT_EQ(expected_status, status);
597 } 643 }
598 644
645 void StoreRegistration(int64 version_id,
646 ServiceWorkerStatusCode expected_status) {
647 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
648 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
649 base::RunLoop store_run_loop;
650 BrowserThread::PostTask(
651 BrowserThread::IO, FROM_HERE,
652 base::Bind(&self::StoreOnIOThread, this, store_run_loop.QuitClosure(),
653 &status, version_id));
654 store_run_loop.Run();
655 ASSERT_EQ(expected_status, status);
656
657 RunOnIOThread(base::Bind(&self::NotifyDoneInstallingRegistrationOnIOThread,
658 this, status));
659 }
660
661 void FindRegistrationForId(int64 id,
662 const GURL& origin,
663 ServiceWorkerStatusCode expected_status) {
664 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
665 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
666 base::RunLoop run_loop;
667 BrowserThread::PostTask(
668 BrowserThread::IO, FROM_HERE,
669 base::Bind(&self::FindRegistrationForIdOnIOThread, this,
670 run_loop.QuitClosure(), &status, id, origin));
671 run_loop.Run();
672 ASSERT_EQ(expected_status, status);
673 }
674
675 void FindRegistrationForIdOnIOThread(const base::Closure& done,
676 ServiceWorkerStatusCode* result,
677 int64 id,
678 const GURL& origin) {
679 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
680 wrapper()->context()->storage()->FindRegistrationForId(
681 id, origin,
682 CreateFindRegistrationReceiver(BrowserThread::UI, done, result));
683 }
684
685 void NotifyDoneInstallingRegistrationOnIOThread(
686 ServiceWorkerStatusCode status) {
687 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
688 wrapper()->context()->storage()->NotifyDoneInstallingRegistration(
689 registration_.get(), version_.get(), status);
690 }
691
692 void RemoveLiveRegistrationOnIOThread(int64 id) {
693 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
694 wrapper()->context()->RemoveLiveRegistration(id);
695 }
696
599 void StartOnIOThread(const base::Closure& done, 697 void StartOnIOThread(const base::Closure& done,
600 ServiceWorkerStatusCode* result) { 698 ServiceWorkerStatusCode* result) {
601 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 699 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
602 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); 700 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result));
603 } 701 }
604 702
605 void InstallOnIOThread(const base::Closure& done, 703 void InstallOnIOThread(const base::Closure& done,
606 ServiceWorkerStatusCode* result) { 704 ServiceWorkerStatusCode* result) {
607 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 705 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
608 version_->SetStatus(ServiceWorkerVersion::INSTALLING); 706 version_->SetStatus(ServiceWorkerVersion::INSTALLING);
609 version_->DispatchInstallEvent( 707 version_->DispatchInstallEvent(
610 CreateReceiver(BrowserThread::UI, done, result)); 708 CreateReceiver(BrowserThread::UI, done, result));
611 } 709 }
612 710
711 void StoreOnIOThread(const base::Closure& done,
712 ServiceWorkerStatusCode* result,
713 int64 version_id) {
714 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
715 ServiceWorkerVersion* version =
716 wrapper()->context()->GetLiveVersion(version_id);
717 wrapper()->context()->storage()->StoreRegistration(
718 registration_.get(), version,
719 CreateReceiver(BrowserThread::UI, done, result));
720 }
721
613 void ActivateOnIOThread(const base::Closure& done, 722 void ActivateOnIOThread(const base::Closure& done,
614 ServiceWorkerStatusCode* result) { 723 ServiceWorkerStatusCode* result) {
615 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 724 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
616 version_->SetStatus(ServiceWorkerVersion::ACTIVATING); 725 version_->SetStatus(ServiceWorkerVersion::ACTIVATING);
726 registration_->SetActiveVersion(version_.get());
617 version_->DispatchActivateEvent( 727 version_->DispatchActivateEvent(
618 CreateReceiver(BrowserThread::UI, done, result)); 728 CreateReceiver(BrowserThread::UI, done, result));
619 } 729 }
620 730
621 void FetchOnIOThread(const base::Closure& done, 731 void FetchOnIOThread(const base::Closure& done,
622 bool* prepare_result, 732 bool* prepare_result,
623 FetchResult* result) { 733 FetchResult* result) {
624 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 734 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
625 ServiceWorkerFetchRequest request( 735 ServiceWorkerFetchRequest request(
626 embedded_test_server()->GetURL("/service_worker/empty.html"), 736 embedded_test_server()->GetURL("/service_worker/empty.html"),
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 } 833 }
724 834
725 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, StartNotFound) { 835 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, StartNotFound) {
726 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, 836 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this,
727 "/service_worker/nonexistent.js")); 837 "/service_worker/nonexistent.js"));
728 838
729 // Start a worker for nonexistent URL. 839 // Start a worker for nonexistent URL.
730 StartWorker(SERVICE_WORKER_ERROR_NETWORK); 840 StartWorker(SERVICE_WORKER_ERROR_NETWORK);
731 } 841 }
732 842
843 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, ReadResourceFailure) {
844 // Create and store a registration.
845 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this,
846 "/service_worker/worker.js"));
847 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
848 StoreRegistration(version_->version_id(), SERVICE_WORKER_OK);
849
850 // Add a non-existent resource to the version.
851 std::vector<ServiceWorkerDatabase::ResourceRecord> records;
852 records.push_back(
853 ServiceWorkerDatabase::ResourceRecord(30, version_->script_url(), 100));
854 version_->script_cache_map()->SetResources(records);
855
856 // Start the worker. We'll fail to read the resource.
857 StartWorker(SERVICE_WORKER_ERROR_DISK_CACHE);
858 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version_->status());
859
860 // The registration should be deleted from storage since the broken worker was
861 // the stored one.
862 RunOnIOThread(base::Bind(&self::RemoveLiveRegistrationOnIOThread, this,
863 registration_->id()));
864 FindRegistrationForId(registration_->id(),
865 registration_->pattern().GetOrigin(),
866 SERVICE_WORKER_ERROR_NOT_FOUND);
867 }
868
869 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
870 ReadResourceFailure_WaitingWorker) {
871 // Create a registration and active version.
872 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this,
873 "/service_worker/worker.js"));
874 base::RunLoop activate_run_loop;
875 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
876 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
877 base::Bind(&self::ActivateOnIOThread, this,
878 activate_run_loop.QuitClosure(), &status));
879 activate_run_loop.Run();
880 EXPECT_EQ(SERVICE_WORKER_OK, status);
881 ASSERT_TRUE(registration_->active_version());
882
883 // Give the version a controllee.
884 RunOnIOThread(base::Bind(&self::AddControlleeOnIOThread, this));
885
886 // Add a non-existent resource to the version.
887 std::vector<ServiceWorkerDatabase::ResourceRecord> records;
888 records.push_back(
889 ServiceWorkerDatabase::ResourceRecord(30, version_->script_url(), 100));
890 version_->script_cache_map()->SetResources(records);
891
892 // Make a waiting version and store it.
893 RunOnIOThread(base::Bind(&self::AddWaitingWorkerOnIOThread, this,
894 "/service_worker/worker.js"));
895 StoreRegistration(registration_->waiting_version()->version_id(),
896 SERVICE_WORKER_OK);
897
898 // Start the broken worker. We'll fail to read from disk and the worker should
899 // be doomed.
900 StopWorker(SERVICE_WORKER_OK); // in case it's already running
901 StartWorker(SERVICE_WORKER_ERROR_DISK_CACHE);
902 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version_->status());
903
904 // The registration should still be in storage since the waiting worker was
905 // the stored one.
906 RunOnIOThread(base::Bind(&self::RemoveLiveRegistrationOnIOThread, this,
907 registration_->id()));
908 FindRegistrationForId(registration_->id(),
909 registration_->pattern().GetOrigin(),
910 SERVICE_WORKER_OK);
911 }
912
733 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Install) { 913 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Install) {
734 InstallTestHelper("/service_worker/worker.js", SERVICE_WORKER_OK); 914 InstallTestHelper("/service_worker/worker.js", SERVICE_WORKER_OK);
735 } 915 }
736 916
737 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, 917 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
738 InstallWithWaitUntil_Fulfilled) { 918 InstallWithWaitUntil_Fulfilled) {
739 InstallTestHelper("/service_worker/worker_install_fulfilled.js", 919 InstallTestHelper("/service_worker/worker_install_fulfilled.js",
740 SERVICE_WORKER_OK); 920 SERVICE_WORKER_OK);
741 } 921 }
742 922
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 1451
1272 // Start a worker. 1452 // Start a worker.
1273 StartWorker(SERVICE_WORKER_OK); 1453 StartWorker(SERVICE_WORKER_OK);
1274 1454
1275 // Wait for the matadata is stored. This run loop should finish when 1455 // Wait for the matadata is stored. This run loop should finish when
1276 // OnCachedMetadataUpdated() is called. 1456 // OnCachedMetadataUpdated() is called.
1277 cached_metadata_run_loop.Run(); 1457 cached_metadata_run_loop.Run();
1278 1458
1279 // Activate the worker. 1459 // Activate the worker.
1280 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 1460 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
1281 base::RunLoop acrivate_run_loop; 1461 base::RunLoop activate_run_loop;
1282 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 1462 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
1283 base::Bind(&self::ActivateOnIOThread, this, 1463 base::Bind(&self::ActivateOnIOThread, this,
1284 acrivate_run_loop.QuitClosure(), &status)); 1464 activate_run_loop.QuitClosure(), &status));
1285 acrivate_run_loop.Run(); 1465 activate_run_loop.Run();
1286 ASSERT_EQ(SERVICE_WORKER_OK, status); 1466 ASSERT_EQ(SERVICE_WORKER_OK, status);
1287 // Stop the worker. 1467 // Stop the worker.
1288 StopWorker(SERVICE_WORKER_OK); 1468 StopWorker(SERVICE_WORKER_OK);
1289 // Restart the worker. 1469 // Restart the worker.
1290 StartWorker(SERVICE_WORKER_OK); 1470 StartWorker(SERVICE_WORKER_OK);
1291 // Stop the worker. 1471 // Stop the worker.
1292 StopWorker(SERVICE_WORKER_OK); 1472 StopWorker(SERVICE_WORKER_OK);
1293 } 1473 }
1294 1474
1295 } // namespace content 1475 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_read_from_cache_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698