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, ®istration)); |
+ 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, ®istration)); |
+ 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 |