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

Unified Diff: content/browser/service_worker/service_worker_job_unittest.cc

Issue 377153003: Service Worker: set active worker to REDUNDANT when unregistered (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_register_job.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/service_worker/service_worker_job_unittest.cc
diff --git a/content/browser/service_worker/service_worker_job_unittest.cc b/content/browser/service_worker/service_worker_job_unittest.cc
index b1054ba7ba731699f14d6d450d0969672ccaa693..514d34b3edfb7da6f621fee8046fd0a2631122c1 100644
--- a/content/browser/service_worker/service_worker_job_unittest.cc
+++ b/content/browser/service_worker/service_worker_job_unittest.cc
@@ -702,7 +702,7 @@ TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) {
// Tests that the waiting worker enters the 'redundant' state upon
// unregistration.
-TEST_F(ServiceWorkerJobTest, UnregisterSetsRedundant) {
+TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) {
scoped_refptr<ServiceWorkerRegistration> registration;
bool called = false;
job_coordinator()->Register(
@@ -740,4 +740,73 @@ TEST_F(ServiceWorkerJobTest, UnregisterSetsRedundant) {
EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status());
}
+// Tests that the active worker enters the 'redundant' state upon
+// unregistration.
+TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) {
+ scoped_refptr<ServiceWorkerRegistration> registration;
+ bool called = false;
+ job_coordinator()->Register(
+ GURL("http://www.example.com/*"),
+ GURL("http://www.example.com/service_worker.js"),
+ render_process_id_,
+ SaveRegistration(SERVICE_WORKER_OK, &called, &registration));
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(called);
+ ASSERT_TRUE(registration);
+
+ scoped_refptr<ServiceWorkerVersion> version = registration->active_version();
+ EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status());
+ EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status());
+
+ called = false;
+ job_coordinator()->Unregister(GURL("http://www.example.com/*"),
+ SaveUnregistration(SERVICE_WORKER_OK, &called));
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(called);
+
+ EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status());
+ EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status());
+}
+
+// Tests that the active worker enters the 'redundant' state upon
+// unregistration.
+TEST_F(ServiceWorkerJobTest,
+ UnregisterActiveSetsRedundant_WaitForNoControllee) {
+ scoped_refptr<ServiceWorkerRegistration> registration;
+ bool called = false;
+ job_coordinator()->Register(
+ GURL("http://www.example.com/*"),
+ GURL("http://www.example.com/service_worker.js"),
+ render_process_id_,
+ SaveRegistration(SERVICE_WORKER_OK, &called, &registration));
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(called);
+ ASSERT_TRUE(registration);
+
+ scoped_ptr<ServiceWorkerProviderHost> host(
+ new ServiceWorkerProviderHost(33 /* dummy render process id */,
+ 1 /* dummy provider_id */,
+ context()->AsWeakPtr(),
+ NULL));
+ registration->active_version()->AddControllee(host.get());
+
+ scoped_refptr<ServiceWorkerVersion> version = registration->active_version();
+ EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status());
+ EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status());
+
+ called = false;
+ job_coordinator()->Unregister(GURL("http://www.example.com/*"),
+ SaveUnregistration(SERVICE_WORKER_OK, &called));
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(called);
+
+ EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status());
+ EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status());
+
+ registration->active_version()->RemoveControllee(host.get());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status());
+ EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status());
+}
+
} // namespace content
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_register_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698