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

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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 EXPECT_FALSE(version_->cache_listener_.get()); 420 EXPECT_FALSE(version_->cache_listener_.get());
421 421
422 version_->StartWorker( 422 version_->StartWorker(
423 CreateReceiverOnCurrentThread(&status)); 423 CreateReceiverOnCurrentThread(&status));
424 base::RunLoop().RunUntilIdle(); 424 base::RunLoop().RunUntilIdle();
425 425
426 // Recreated when the worker starts again. 426 // Recreated when the worker starts again.
427 EXPECT_TRUE(version_->cache_listener_.get()); 427 EXPECT_TRUE(version_->cache_listener_.get());
428 } 428 }
429 429
430 TEST_F(ServiceWorkerVersionTest, SetDevToolsAttached) {
431 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
432 version_->StartWorker(CreateReceiverOnCurrentThread(&status));
433
434 ASSERT_EQ(ServiceWorkerVersion::STARTING, version_->running_status());
435
436 ASSERT_TRUE(version_->timeout_timer_.IsRunning());
437 ASSERT_FALSE(version_->start_time_.is_null());
438 ASSERT_FALSE(version_->skip_recording_startup_time_);
439
440 // Simulate DevTools is attached. This should deactivate the timer for start
441 // timeout, but not stop the timer itself.
442 version_->SetDevToolsAttached(true);
443 EXPECT_TRUE(version_->timeout_timer_.IsRunning());
444 EXPECT_TRUE(version_->start_time_.is_null());
445
446 // Simulate DevTools is detached. This should reactivate the timer for start
447 // timeout.
448 version_->SetDevToolsAttached(false);
449 EXPECT_TRUE(version_->timeout_timer_.IsRunning());
450 EXPECT_FALSE(version_->start_time_.is_null());
451 EXPECT_TRUE(version_->skip_recording_startup_time_);
452
453 base::RunLoop().RunUntilIdle();
454 EXPECT_EQ(SERVICE_WORKER_OK, status);
455 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version_->running_status());
456 }
457
430 TEST_F(ServiceWorkerFailToStartTest, RendererCrash) { 458 TEST_F(ServiceWorkerFailToStartTest, RendererCrash) {
431 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value 459 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value
432 version_->StartWorker( 460 version_->StartWorker(
433 CreateReceiverOnCurrentThread(&status)); 461 CreateReceiverOnCurrentThread(&status));
434 base::RunLoop().RunUntilIdle(); 462 base::RunLoop().RunUntilIdle();
435 463
436 // Callback has not completed yet. 464 // Callback has not completed yet.
437 EXPECT_EQ(SERVICE_WORKER_ERROR_NETWORK, status); 465 EXPECT_EQ(SERVICE_WORKER_ERROR_NETWORK, status);
438 EXPECT_EQ(ServiceWorkerVersion::STARTING, version_->running_status()); 466 EXPECT_EQ(ServiceWorkerVersion::STARTING, version_->running_status());
439 467
(...skipping 29 matching lines...) Expand all
469 base::TimeTicks::Now() - 497 base::TimeTicks::Now() -
470 base::TimeDelta::FromMinutes( 498 base::TimeDelta::FromMinutes(
471 ServiceWorkerVersion::kStartWorkerTimeoutMinutes + 1); 499 ServiceWorkerVersion::kStartWorkerTimeoutMinutes + 1);
472 version_->timeout_timer_.user_task().Run(); 500 version_->timeout_timer_.user_task().Run();
473 base::RunLoop().RunUntilIdle(); 501 base::RunLoop().RunUntilIdle();
474 EXPECT_EQ(SERVICE_WORKER_ERROR_TIMEOUT, status); 502 EXPECT_EQ(SERVICE_WORKER_ERROR_TIMEOUT, status);
475 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status()); 503 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status());
476 } 504 }
477 505
478 } // namespace content 506 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698