OLD | NEW |
---|---|
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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "content/browser/service_worker/embedded_worker_registry.h" | 7 #include "content/browser/service_worker/embedded_worker_registry.h" |
8 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 8 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
9 #include "content/browser/service_worker/service_worker_context_core.h" | 9 #include "content/browser/service_worker/service_worker_context_core.h" |
10 #include "content/browser/service_worker/service_worker_registration.h" | 10 #include "content/browser/service_worker/service_worker_registration.h" |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 status = SERVICE_WORKER_ERROR_FAILED; | 374 status = SERVICE_WORKER_ERROR_FAILED; |
375 version_->StopWorker(CreateReceiverOnCurrentThread(&status)); | 375 version_->StopWorker(CreateReceiverOnCurrentThread(&status)); |
376 base::RunLoop().RunUntilIdle(); | 376 base::RunLoop().RunUntilIdle(); |
377 EXPECT_EQ(SERVICE_WORKER_OK, status); | 377 EXPECT_EQ(SERVICE_WORKER_OK, status); |
378 status = SERVICE_WORKER_ERROR_FAILED; | 378 status = SERVICE_WORKER_ERROR_FAILED; |
379 version_->StartWorker(CreateReceiverOnCurrentThread(&status)); | 379 version_->StartWorker(CreateReceiverOnCurrentThread(&status)); |
380 base::RunLoop().RunUntilIdle(); | 380 base::RunLoop().RunUntilIdle(); |
381 EXPECT_EQ(SERVICE_WORKER_OK, status); | 381 EXPECT_EQ(SERVICE_WORKER_OK, status); |
382 EXPECT_TRUE(version_->stop_worker_timer_.IsRunning()); | 382 EXPECT_TRUE(version_->stop_worker_timer_.IsRunning()); |
383 | 383 |
384 // The timer should not be running if a controllee is added. | 384 base::TimeDelta delay = version_->stop_worker_timer_.GetCurrentDelay(); |
385 | |
386 // Adding controllee doesn't stop the stop-worker-timer, but... | |
385 scoped_ptr<ServiceWorkerProviderHost> host( | 387 scoped_ptr<ServiceWorkerProviderHost> host( |
386 new ServiceWorkerProviderHost(33 /* dummy render process id */, | 388 new ServiceWorkerProviderHost(33 /* dummy render process id */, |
387 MSG_ROUTING_NONE /* render_frame_id */, | 389 MSG_ROUTING_NONE /* render_frame_id */, |
388 1 /* dummy provider_id */, | 390 1 /* dummy provider_id */, |
389 helper_->context()->AsWeakPtr(), | 391 helper_->context()->AsWeakPtr(), |
390 NULL)); | 392 NULL)); |
391 version_->AddControllee(host.get()); | 393 version_->AddControllee(host.get()); |
392 EXPECT_FALSE(version_->stop_worker_timer_.IsRunning()); | 394 EXPECT_TRUE(version_->stop_worker_timer_.IsRunning()); |
393 | 395 |
394 // The timer should be running if the controllee is removed. | 396 // ...it resets the timer if it's running so that the worker is kept |
395 version_->RemoveControllee(host.get()); | 397 // alive for a while right after a new controlee is attached. |
396 EXPECT_TRUE(version_->stop_worker_timer_.IsRunning()); | 398 EXPECT_GE(delay, version_->stop_worker_timer_.GetCurrentDelay()); |
falken
2014/12/18 08:26:40
I don't quite get this, what does GetCurrentDelay(
kinuko
2014/12/18 08:31:40
Um, nvm, this line is not right (I wanted to compa
| |
397 } | 399 } |
398 | 400 |
399 TEST_F(ServiceWorkerVersionTest, ListenerAvailability) { | 401 TEST_F(ServiceWorkerVersionTest, ListenerAvailability) { |
400 // Initially the worker is not running. There should be no cache_listener_. | 402 // Initially the worker is not running. There should be no cache_listener_. |
401 EXPECT_FALSE(version_->cache_listener_.get()); | 403 EXPECT_FALSE(version_->cache_listener_.get()); |
402 | 404 |
403 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 405 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
404 version_->StartWorker( | 406 version_->StartWorker( |
405 CreateReceiverOnCurrentThread(&status)); | 407 CreateReceiverOnCurrentThread(&status)); |
406 base::RunLoop().RunUntilIdle(); | 408 base::RunLoop().RunUntilIdle(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 helper_->context()->embedded_worker_registry()->RemoveChildProcessSender( | 442 helper_->context()->embedded_worker_registry()->RemoveChildProcessSender( |
441 process_id); | 443 process_id); |
442 base::RunLoop().RunUntilIdle(); | 444 base::RunLoop().RunUntilIdle(); |
443 | 445 |
444 // Callback completed. | 446 // Callback completed. |
445 EXPECT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status); | 447 EXPECT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status); |
446 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status()); | 448 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status()); |
447 } | 449 } |
448 | 450 |
449 } // namespace content | 451 } // namespace content |
OLD | NEW |