Index: content/browser/service_worker/service_worker_version_unittest.cc |
diff --git a/content/browser/service_worker/service_worker_version_unittest.cc b/content/browser/service_worker/service_worker_version_unittest.cc |
index 8ae8976b1d1b8a78af585c1c9d8f3a9e23a3ac36..6238c94c8d32c5ff860f46acf7fe2e0be3cc46fc 100644 |
--- a/content/browser/service_worker/service_worker_version_unittest.cc |
+++ b/content/browser/service_worker/service_worker_version_unittest.cc |
@@ -363,14 +363,11 @@ TEST_F(ServiceWorkerVersionTest, ScheduleStopWorker) { |
version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
EXPECT_FALSE(version_->stop_worker_timer_.IsRunning()); |
- // Verify the timer is running when version status changes frome ACTIVATING |
- // to ACTIVATED. |
+ // Verify the timer is running after the worker is started. |
ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
version_->StartWorker(CreateReceiverOnCurrentThread(&status)); |
base::RunLoop().RunUntilIdle(); |
EXPECT_EQ(SERVICE_WORKER_OK, status); |
- version_->SetStatus(ServiceWorkerVersion::ACTIVATING); |
- version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
EXPECT_TRUE(version_->stop_worker_timer_.IsRunning()); |
// The timer should be running if the worker is restarted without controllee. |
@@ -399,6 +396,53 @@ TEST_F(ServiceWorkerVersionTest, ScheduleStopWorker) { |
EXPECT_TRUE(version_->stop_worker_timer_.IsRunning()); |
} |
+TEST_F(ServiceWorkerVersionTest, KeepAlive) { |
+ // Verify the timer is not running when version initializes its status. |
+ version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
+ EXPECT_FALSE(version_->stop_worker_timer_.IsRunning()); |
+ |
+ // Verify the timer is running after the worker is started. |
+ ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
+ version_->StartWorker(CreateReceiverOnCurrentThread(&status)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(SERVICE_WORKER_OK, status); |
+ EXPECT_TRUE(version_->stop_worker_timer_.IsRunning()); |
+ |
+ // Set keep alive true. |
+ helper_->context()->SetKeepAliveMode(true); |
+ |
+ // This should have stopped the stop worker timer. |
+ EXPECT_FALSE(version_->stop_worker_timer_.IsRunning()); |
+ |
+ // The timer should not be running even after a controllee is added |
+ // and then removed (i.e. so there's no controllee) if the keep_alive |
+ // mode is true. |
+ scoped_ptr<ServiceWorkerProviderHost> host( |
+ new ServiceWorkerProviderHost(33 /* dummy render process id */, |
+ MSG_ROUTING_NONE /* render_frame_id */, |
+ 1 /* dummy provider_id */, |
+ helper_->context()->AsWeakPtr(), |
+ NULL)); |
+ version_->AddControllee(host.get()); |
+ EXPECT_FALSE(version_->stop_worker_timer_.IsRunning()); |
+ version_->RemoveControllee(host.get()); |
+ EXPECT_FALSE(version_->stop_worker_timer_.IsRunning()); |
+ |
+ // Stopping the worker. |
+ status = SERVICE_WORKER_ERROR_FAILED; |
+ version_->StopWorker(CreateReceiverOnCurrentThread(&status)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(SERVICE_WORKER_OK, status); |
+ |
+ // Restart the worker. Usually this should start the stop worker timer, |
+ // but not now as keep_alive mode is true. |
+ status = SERVICE_WORKER_ERROR_FAILED; |
+ version_->StartWorker(CreateReceiverOnCurrentThread(&status)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(SERVICE_WORKER_OK, status); |
+ EXPECT_FALSE(version_->stop_worker_timer_.IsRunning()); |
+} |
+ |
TEST_F(ServiceWorkerVersionTest, ListenerAvailability) { |
// Initially the worker is not running. There should be no cache_listener_. |
EXPECT_FALSE(version_->cache_listener_.get()); |