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

Side by Side Diff: content/browser/service_worker/service_worker_version_unittest.cc

Issue 1004913003: ServiceWorker: Don't start the timeout timer when DevTools is detached (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 unified diff | Download patch
OLDNEW
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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 EXPECT_FALSE(version_->cache_listener_.get()); 431 EXPECT_FALSE(version_->cache_listener_.get());
432 432
433 version_->StartWorker( 433 version_->StartWorker(
434 CreateReceiverOnCurrentThread(&status)); 434 CreateReceiverOnCurrentThread(&status));
435 base::RunLoop().RunUntilIdle(); 435 base::RunLoop().RunUntilIdle();
436 436
437 // Recreated when the worker starts again. 437 // Recreated when the worker starts again.
438 EXPECT_TRUE(version_->cache_listener_.get()); 438 EXPECT_TRUE(version_->cache_listener_.get());
439 } 439 }
440 440
441 TEST_F(ServiceWorkerVersionTest, SetDevToolsAttached) {
442 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
443 version_->StartWorker(CreateReceiverOnCurrentThread(&status));
444
445 ASSERT_EQ(ServiceWorkerVersion::STARTING, version_->running_status());
446
447 ASSERT_TRUE(version_->timeout_timer_.IsRunning());
448 ASSERT_FALSE(version_->start_time_.is_null());
449 ASSERT_FALSE(version_->skip_recording_startup_time_);
450
451 // Simulate DevTools is attached. This should deactivate the timer for start
452 // timeout, but not stop the timer itself.
453 version_->SetDevToolsAttached(true);
454 EXPECT_TRUE(version_->timeout_timer_.IsRunning());
455 EXPECT_TRUE(version_->start_time_.is_null());
456 EXPECT_TRUE(version_->skip_recording_startup_time_);
457
458 // Simulate DevTools is detached. This should reactivate the timer for start
459 // timeout.
460 version_->SetDevToolsAttached(false);
461 EXPECT_TRUE(version_->timeout_timer_.IsRunning());
462 EXPECT_FALSE(version_->start_time_.is_null());
463 EXPECT_TRUE(version_->skip_recording_startup_time_);
464
465 base::RunLoop().RunUntilIdle();
466 EXPECT_EQ(SERVICE_WORKER_OK, status);
467 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version_->running_status());
468 }
469
441 TEST_F(ServiceWorkerFailToStartTest, RendererCrash) { 470 TEST_F(ServiceWorkerFailToStartTest, RendererCrash) {
442 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value 471 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value
443 version_->StartWorker( 472 version_->StartWorker(
444 CreateReceiverOnCurrentThread(&status)); 473 CreateReceiverOnCurrentThread(&status));
445 base::RunLoop().RunUntilIdle(); 474 base::RunLoop().RunUntilIdle();
446 475
447 // Callback has not completed yet. 476 // Callback has not completed yet.
448 EXPECT_EQ(SERVICE_WORKER_ERROR_NETWORK, status); 477 EXPECT_EQ(SERVICE_WORKER_ERROR_NETWORK, status);
449 EXPECT_EQ(ServiceWorkerVersion::STARTING, version_->running_status()); 478 EXPECT_EQ(ServiceWorkerVersion::STARTING, version_->running_status());
450 479
(...skipping 29 matching lines...) Expand all
480 base::TimeTicks::Now() - 509 base::TimeTicks::Now() -
481 base::TimeDelta::FromMinutes( 510 base::TimeDelta::FromMinutes(
482 ServiceWorkerVersion::kStartWorkerTimeoutMinutes + 1); 511 ServiceWorkerVersion::kStartWorkerTimeoutMinutes + 1);
483 version_->timeout_timer_.user_task().Run(); 512 version_->timeout_timer_.user_task().Run();
484 base::RunLoop().RunUntilIdle(); 513 base::RunLoop().RunUntilIdle();
485 EXPECT_EQ(SERVICE_WORKER_ERROR_TIMEOUT, status); 514 EXPECT_EQ(SERVICE_WORKER_ERROR_TIMEOUT, status);
486 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status()); 515 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status());
487 } 516 }
488 517
489 } // namespace content 518 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698