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

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

Issue 2638313002: Manage ServiceWorkerDispatcherHost in ServiceWorkerContextCore (Closed)
Patch Set: Rebase Created 3 years, 10 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 "content/browser/service_worker/service_worker_version.h" 5 #include "content/browser/service_worker/service_worker_version.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <tuple> 8 #include <tuple>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, 648 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN,
649 CreateReceiverOnCurrentThread(&status)); 649 CreateReceiverOnCurrentThread(&status));
650 base::RunLoop().RunUntilIdle(); 650 base::RunLoop().RunUntilIdle();
651 EXPECT_EQ(SERVICE_WORKER_OK, status); 651 EXPECT_EQ(SERVICE_WORKER_OK, status);
652 EXPECT_TRUE(version_->timeout_timer_.IsRunning()); 652 EXPECT_TRUE(version_->timeout_timer_.IsRunning());
653 EXPECT_LT(idle_time, version_->idle_time_); 653 EXPECT_LT(idle_time, version_->idle_time_);
654 654
655 // Adding a controllee resets the idle time. 655 // Adding a controllee resets the idle time.
656 version_->idle_time_ -= kOneSecond; 656 version_->idle_time_ -= kOneSecond;
657 idle_time = version_->idle_time_; 657 idle_time = version_->idle_time_;
658 std::unique_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( 658 std::unique_ptr<ServiceWorkerProviderHost> host = CreateProviderHostForWindow(
659 33 /* dummy render process id */, MSG_ROUTING_NONE /* render_frame_id */, 659 33 /* dummy render process id */, 1 /* dummy provider_id */,
660 1 /* dummy provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW, 660 true /* is_parent_frame_secure */, helper_->context()->AsWeakPtr());
661 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE,
662 helper_->context()->AsWeakPtr(), NULL));
663 version_->AddControllee(host.get()); 661 version_->AddControllee(host.get());
664 EXPECT_TRUE(version_->timeout_timer_.IsRunning()); 662 EXPECT_TRUE(version_->timeout_timer_.IsRunning());
665 EXPECT_LT(idle_time, version_->idle_time_); 663 EXPECT_LT(idle_time, version_->idle_time_);
666 664
667 // Completing an event resets the idle time. 665 // Completing an event resets the idle time.
668 version_->idle_time_ -= kOneSecond; 666 version_->idle_time_ -= kOneSecond;
669 idle_time = version_->idle_time_; 667 idle_time = version_->idle_time_;
670 SimulateDispatchEvent(ServiceWorkerMetrics::EventType::FETCH_MAIN_FRAME); 668 SimulateDispatchEvent(ServiceWorkerMetrics::EventType::FETCH_MAIN_FRAME);
671 EXPECT_LT(idle_time, version_->idle_time_); 669 EXPECT_LT(idle_time, version_->idle_time_);
672 670
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, 1121 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN,
1124 CreateReceiverOnCurrentThread(&status)); 1122 CreateReceiverOnCurrentThread(&status));
1125 base::RunLoop().RunUntilIdle(); 1123 base::RunLoop().RunUntilIdle();
1126 1124
1127 // Callback has not completed yet. 1125 // Callback has not completed yet.
1128 EXPECT_EQ(SERVICE_WORKER_ERROR_NETWORK, status); 1126 EXPECT_EQ(SERVICE_WORKER_ERROR_NETWORK, status);
1129 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, version_->running_status()); 1127 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, version_->running_status());
1130 1128
1131 // Simulate renderer crash: do what 1129 // Simulate renderer crash: do what
1132 // ServiceWorkerDispatcherHost::OnFilterRemoved does. 1130 // ServiceWorkerDispatcherHost::OnFilterRemoved does.
1133 int process_id = helper_->mock_render_process_id(); 1131 helper_->context()->RemoveDispatcherHost(helper_->mock_render_process_id());
1134 helper_->context()->RemoveAllProviderHostsForProcess(process_id);
1135 helper_->context()->embedded_worker_registry()->RemoveChildProcessSender(
1136 process_id);
1137 base::RunLoop().RunUntilIdle(); 1132 base::RunLoop().RunUntilIdle();
1138 1133
1139 // Callback completed. 1134 // Callback completed.
1140 EXPECT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status); 1135 EXPECT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status);
1141 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version_->running_status()); 1136 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version_->running_status());
1142 } 1137 }
1143 1138
1144 TEST_F(ServiceWorkerFailToStartTest, Timeout) { 1139 TEST_F(ServiceWorkerFailToStartTest, Timeout) {
1145 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value 1140 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value
1146 1141
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 int request_id = 1331 int request_id =
1337 version_->StartRequest(ServiceWorkerMetrics::EventType::SYNC, 1332 version_->StartRequest(ServiceWorkerMetrics::EventType::SYNC,
1338 CreateReceiverOnCurrentThread(&status)); 1333 CreateReceiverOnCurrentThread(&status));
1339 base::RunLoop().RunUntilIdle(); 1334 base::RunLoop().RunUntilIdle();
1340 1335
1341 // Callback has not completed yet. 1336 // Callback has not completed yet.
1342 EXPECT_EQ(SERVICE_WORKER_OK, status); 1337 EXPECT_EQ(SERVICE_WORKER_OK, status);
1343 1338
1344 // Simulate renderer crash: do what 1339 // Simulate renderer crash: do what
1345 // ServiceWorkerDispatcherHost::OnFilterRemoved does. 1340 // ServiceWorkerDispatcherHost::OnFilterRemoved does.
1346 int process_id = helper_->mock_render_process_id(); 1341 helper_->context()->RemoveDispatcherHost(helper_->mock_render_process_id());
1347 helper_->context()->RemoveAllProviderHostsForProcess(process_id);
1348 helper_->context()->embedded_worker_registry()->RemoveChildProcessSender(
1349 process_id);
1350 base::RunLoop().RunUntilIdle(); 1342 base::RunLoop().RunUntilIdle();
1351 1343
1352 // Callback completed. 1344 // Callback completed.
1353 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED, status); 1345 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED, status);
1354 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version_->running_status()); 1346 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version_->running_status());
1355 1347
1356 // Request already failed, calling finsh should return false. 1348 // Request already failed, calling finsh should return false.
1357 EXPECT_FALSE(version_->FinishRequest(request_id, true /* was_handled */, 1349 EXPECT_FALSE(version_->FinishRequest(request_id, true /* was_handled */,
1358 base::Time::Now())); 1350 base::Time::Now()));
1359 } 1351 }
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 histogram_tester_.ExpectTotalCount(kLinkMouseDown, 1); 1847 histogram_tester_.ExpectTotalCount(kLinkMouseDown, 1);
1856 histogram_tester_.ExpectTotalCount(kLinkTapDown, 0); 1848 histogram_tester_.ExpectTotalCount(kLinkTapDown, 0);
1857 EXPECT_EQ(SERVICE_WORKER_OK, status); 1849 EXPECT_EQ(SERVICE_WORKER_OK, status);
1858 StopWorker(); 1850 StopWorker();
1859 // The UMA for kLinkMouseDown must be recorded when the worker stopped. 1851 // The UMA for kLinkMouseDown must be recorded when the worker stopped.
1860 histogram_tester_.ExpectTotalCount(kLinkMouseDown, 1); 1852 histogram_tester_.ExpectTotalCount(kLinkMouseDown, 1);
1861 histogram_tester_.ExpectTotalCount(kLinkTapDown, 1); 1853 histogram_tester_.ExpectTotalCount(kLinkTapDown, 1);
1862 } 1854 }
1863 1855
1864 } // namespace content 1856 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698