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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 new ServiceWorkerProviderHost(33 /* dummy render process id */, | 393 new ServiceWorkerProviderHost(33 /* dummy render process id */, |
394 MSG_ROUTING_NONE /* render_frame_id */, | 394 MSG_ROUTING_NONE /* render_frame_id */, |
395 1 /* dummy provider_id */, | 395 1 /* dummy provider_id */, |
396 SERVICE_WORKER_PROVIDER_FOR_CONTROLLEE, | 396 SERVICE_WORKER_PROVIDER_FOR_CONTROLLEE, |
397 helper_->context()->AsWeakPtr(), | 397 helper_->context()->AsWeakPtr(), |
398 NULL)); | 398 NULL)); |
399 version_->AddControllee(host.get()); | 399 version_->AddControllee(host.get()); |
400 EXPECT_TRUE(version_->timeout_timer_.IsRunning()); | 400 EXPECT_TRUE(version_->timeout_timer_.IsRunning()); |
401 } | 401 } |
402 | 402 |
403 TEST_F(ServiceWorkerVersionTest, ListenerAvailability) { | |
404 // Initially the worker is not running. There should be no cache_listener_. | |
405 EXPECT_FALSE(version_->cache_listener_.get()); | |
406 | |
407 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | |
408 version_->StartWorker( | |
409 CreateReceiverOnCurrentThread(&status)); | |
410 base::RunLoop().RunUntilIdle(); | |
411 | |
412 // A new cache listener should be available once the worker starts. | |
413 EXPECT_TRUE(version_->cache_listener_.get()); | |
414 | |
415 version_->StopWorker( | |
416 CreateReceiverOnCurrentThread(&status)); | |
417 base::RunLoop().RunUntilIdle(); | |
418 | |
419 // Should be destroyed when the worker stops. | |
420 EXPECT_FALSE(version_->cache_listener_.get()); | |
421 | |
422 version_->StartWorker( | |
423 CreateReceiverOnCurrentThread(&status)); | |
424 base::RunLoop().RunUntilIdle(); | |
425 | |
426 // Recreated when the worker starts again. | |
427 EXPECT_TRUE(version_->cache_listener_.get()); | |
428 } | |
429 | |
430 TEST_F(ServiceWorkerFailToStartTest, RendererCrash) { | 403 TEST_F(ServiceWorkerFailToStartTest, RendererCrash) { |
431 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value | 404 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value |
432 version_->StartWorker( | 405 version_->StartWorker( |
433 CreateReceiverOnCurrentThread(&status)); | 406 CreateReceiverOnCurrentThread(&status)); |
434 base::RunLoop().RunUntilIdle(); | 407 base::RunLoop().RunUntilIdle(); |
435 | 408 |
436 // Callback has not completed yet. | 409 // Callback has not completed yet. |
437 EXPECT_EQ(SERVICE_WORKER_ERROR_NETWORK, status); | 410 EXPECT_EQ(SERVICE_WORKER_ERROR_NETWORK, status); |
438 EXPECT_EQ(ServiceWorkerVersion::STARTING, version_->running_status()); | 411 EXPECT_EQ(ServiceWorkerVersion::STARTING, version_->running_status()); |
439 | 412 |
(...skipping 29 matching lines...) Expand all Loading... |
469 base::TimeTicks::Now() - | 442 base::TimeTicks::Now() - |
470 base::TimeDelta::FromMinutes( | 443 base::TimeDelta::FromMinutes( |
471 ServiceWorkerVersion::kStartWorkerTimeoutMinutes + 1); | 444 ServiceWorkerVersion::kStartWorkerTimeoutMinutes + 1); |
472 version_->timeout_timer_.user_task().Run(); | 445 version_->timeout_timer_.user_task().Run(); |
473 base::RunLoop().RunUntilIdle(); | 446 base::RunLoop().RunUntilIdle(); |
474 EXPECT_EQ(SERVICE_WORKER_ERROR_TIMEOUT, status); | 447 EXPECT_EQ(SERVICE_WORKER_ERROR_TIMEOUT, status); |
475 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status()); | 448 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status()); |
476 } | 449 } |
477 | 450 |
478 } // namespace content | 451 } // namespace content |
OLD | NEW |