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

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

Issue 385143002: ServiceWorker: Stop a worker thread on unregistration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: modify unittests Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_version.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/files/scoped_temp_dir.h" 5 #include "base/files/scoped_temp_dir.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "content/browser/browser_thread_impl.h" 8 #include "content/browser/browser_thread_impl.h"
9 #include "content/browser/service_worker/embedded_worker_registry.h" 9 #include "content/browser/service_worker/embedded_worker_registry.h"
10 #include "content/browser/service_worker/embedded_worker_test_helper.h" 10 #include "content/browser/service_worker/embedded_worker_test_helper.h"
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 EXPECT_EQ(ServiceWorkerVersion::RUNNING, 728 EXPECT_EQ(ServiceWorkerVersion::RUNNING,
729 version->running_status()); 729 version->running_status());
730 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); 730 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status());
731 731
732 called = false; 732 called = false;
733 job_coordinator()->Unregister(GURL("http://www.example.com/*"), 733 job_coordinator()->Unregister(GURL("http://www.example.com/*"),
734 SaveUnregistration(SERVICE_WORKER_OK, &called)); 734 SaveUnregistration(SERVICE_WORKER_OK, &called));
735 base::RunLoop().RunUntilIdle(); 735 base::RunLoop().RunUntilIdle();
736 ASSERT_TRUE(called); 736 ASSERT_TRUE(called);
737 737
738 EXPECT_EQ(ServiceWorkerVersion::RUNNING, 738 // The version should be stopped since there is no controllee after
739 version->running_status()); 739 // unregistration.
740 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status());
740 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); 741 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status());
741 } 742 }
742 743
743 // Tests that the active worker enters the 'redundant' state upon 744 // Tests that the active worker enters the 'redundant' state upon
744 // unregistration. 745 // unregistration.
745 TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { 746 TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) {
746 scoped_refptr<ServiceWorkerRegistration> registration; 747 scoped_refptr<ServiceWorkerRegistration> registration;
747 bool called = false; 748 bool called = false;
748 job_coordinator()->Register( 749 job_coordinator()->Register(
749 GURL("http://www.example.com/*"), 750 GURL("http://www.example.com/*"),
750 GURL("http://www.example.com/service_worker.js"), 751 GURL("http://www.example.com/service_worker.js"),
751 render_process_id_, 752 render_process_id_,
752 SaveRegistration(SERVICE_WORKER_OK, &called, &registration)); 753 SaveRegistration(SERVICE_WORKER_OK, &called, &registration));
753 base::RunLoop().RunUntilIdle(); 754 base::RunLoop().RunUntilIdle();
754 ASSERT_TRUE(called); 755 ASSERT_TRUE(called);
755 ASSERT_TRUE(registration); 756 ASSERT_TRUE(registration);
756 757
757 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); 758 scoped_refptr<ServiceWorkerVersion> version = registration->active_version();
758 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); 759 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status());
759 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); 760 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status());
760 761
761 called = false; 762 called = false;
762 job_coordinator()->Unregister(GURL("http://www.example.com/*"), 763 job_coordinator()->Unregister(GURL("http://www.example.com/*"),
763 SaveUnregistration(SERVICE_WORKER_OK, &called)); 764 SaveUnregistration(SERVICE_WORKER_OK, &called));
764 base::RunLoop().RunUntilIdle(); 765 base::RunLoop().RunUntilIdle();
765 ASSERT_TRUE(called); 766 ASSERT_TRUE(called);
766 767
767 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); 768 // The version should be stopped since there is no controllee after
769 // unregistration.
770 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status());
768 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); 771 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status());
769 } 772 }
770 773
771 // Tests that the active worker enters the 'redundant' state upon 774 // Tests that the active worker enters the 'redundant' state upon
772 // unregistration. 775 // unregistration.
773 TEST_F(ServiceWorkerJobTest, 776 TEST_F(ServiceWorkerJobTest,
774 UnregisterActiveSetsRedundant_WaitForNoControllee) { 777 UnregisterActiveSetsRedundant_WaitForNoControllee) {
775 scoped_refptr<ServiceWorkerRegistration> registration; 778 scoped_refptr<ServiceWorkerRegistration> registration;
776 bool called = false; 779 bool called = false;
777 job_coordinator()->Register( 780 job_coordinator()->Register(
(...skipping 15 matching lines...) Expand all
793 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); 796 scoped_refptr<ServiceWorkerVersion> version = registration->active_version();
794 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); 797 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status());
795 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); 798 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status());
796 799
797 called = false; 800 called = false;
798 job_coordinator()->Unregister(GURL("http://www.example.com/*"), 801 job_coordinator()->Unregister(GURL("http://www.example.com/*"),
799 SaveUnregistration(SERVICE_WORKER_OK, &called)); 802 SaveUnregistration(SERVICE_WORKER_OK, &called));
800 base::RunLoop().RunUntilIdle(); 803 base::RunLoop().RunUntilIdle();
801 ASSERT_TRUE(called); 804 ASSERT_TRUE(called);
802 805
806 // The version should be running since there is still a controllee.
803 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); 807 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status());
804 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); 808 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status());
805 809
806 registration->active_version()->RemoveControllee(host.get()); 810 registration->active_version()->RemoveControllee(host.get());
807 base::RunLoop().RunUntilIdle(); 811 base::RunLoop().RunUntilIdle();
808 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); 812
813 // The version should be stopped since there is no controllee.
814 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status());
809 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); 815 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status());
810 } 816 }
811 817
812 } // namespace content 818 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_version.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698