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

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

Issue 2933793002: ServiceWorker: keep dispatcher hosts for unittests in the test helper (Closed)
Patch Set: RegisterMockDispatcherHost -> RegisterDispatcherHost Created 3 years, 6 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
« no previous file with comments | « content/browser/service_worker/service_worker_handle_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <utility> 9 #include <utility>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/test/histogram_tester.h" 14 #include "base/test/histogram_tester.h"
15 #include "base/test/simple_test_tick_clock.h" 15 #include "base/test/simple_test_tick_clock.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "content/browser/service_worker/embedded_worker_registry.h" 17 #include "content/browser/service_worker/embedded_worker_registry.h"
18 #include "content/browser/service_worker/embedded_worker_status.h" 18 #include "content/browser/service_worker/embedded_worker_status.h"
19 #include "content/browser/service_worker/embedded_worker_test_helper.h" 19 #include "content/browser/service_worker/embedded_worker_test_helper.h"
20 #include "content/browser/service_worker/service_worker_context_core.h" 20 #include "content/browser/service_worker/service_worker_context_core.h"
21 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
21 #include "content/browser/service_worker/service_worker_registration.h" 22 #include "content/browser/service_worker/service_worker_registration.h"
22 #include "content/browser/service_worker/service_worker_test_utils.h" 23 #include "content/browser/service_worker/service_worker_test_utils.h"
23 #include "content/common/service_worker/service_worker_utils.h" 24 #include "content/common/service_worker/service_worker_utils.h"
24 #include "content/public/test/mock_render_process_host.h" 25 #include "content/public/test/mock_render_process_host.h"
25 #include "content/public/test/test_browser_thread_bundle.h" 26 #include "content/public/test/test_browser_thread_bundle.h"
26 #include "content/public/test/test_service.mojom.h" 27 #include "content/public/test/test_service.mojom.h"
27 #include "content/public/test/test_utils.h" 28 #include "content/public/test/test_utils.h"
28 #include "mojo/public/cpp/bindings/strong_binding.h" 29 #include "mojo/public/cpp/bindings/strong_binding.h"
29 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
30 31
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 TEST_F(ServiceWorkerFailToStartTest, RendererCrash) { 1103 TEST_F(ServiceWorkerFailToStartTest, RendererCrash) {
1103 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value 1104 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value
1104 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, 1105 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN,
1105 CreateReceiverOnCurrentThread(&status)); 1106 CreateReceiverOnCurrentThread(&status));
1106 base::RunLoop().RunUntilIdle(); 1107 base::RunLoop().RunUntilIdle();
1107 1108
1108 // Callback has not completed yet. 1109 // Callback has not completed yet.
1109 EXPECT_EQ(SERVICE_WORKER_ERROR_NETWORK, status); 1110 EXPECT_EQ(SERVICE_WORKER_ERROR_NETWORK, status);
1110 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, version_->running_status()); 1111 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, version_->running_status());
1111 1112
1112 // Simulate renderer crash: do what 1113 // Simulate renderer crash: remove DispatcherHost like what
1113 // ServiceWorkerDispatcherHost::OnFilterRemoved does. 1114 // ServiceWorkerDispatcherHost::OnFilterRemoved does.
1114 helper_->context()->RemoveDispatcherHost(helper_->mock_render_process_id()); 1115 helper_->RegisterDispatcherHost(helper_->mock_render_process_id(), nullptr);
1115 base::RunLoop().RunUntilIdle(); 1116 base::RunLoop().RunUntilIdle();
1116 1117
1117 // Callback completed. 1118 // Callback completed.
1118 EXPECT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status); 1119 EXPECT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status);
1119 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version_->running_status()); 1120 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version_->running_status());
1120 } 1121 }
1121 1122
1122 TEST_F(ServiceWorkerFailToStartTest, Timeout) { 1123 TEST_F(ServiceWorkerFailToStartTest, Timeout) {
1123 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value 1124 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value
1124 1125
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status()); 1313 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status());
1313 1314
1314 int request_id = 1315 int request_id =
1315 version_->StartRequest(ServiceWorkerMetrics::EventType::SYNC, 1316 version_->StartRequest(ServiceWorkerMetrics::EventType::SYNC,
1316 CreateReceiverOnCurrentThread(&status)); 1317 CreateReceiverOnCurrentThread(&status));
1317 base::RunLoop().RunUntilIdle(); 1318 base::RunLoop().RunUntilIdle();
1318 1319
1319 // Callback has not completed yet. 1320 // Callback has not completed yet.
1320 EXPECT_EQ(SERVICE_WORKER_OK, status); 1321 EXPECT_EQ(SERVICE_WORKER_OK, status);
1321 1322
1322 // Simulate renderer crash: do what 1323 // Simulate renderer crash: remove DispatcherHost like what
1323 // ServiceWorkerDispatcherHost::OnFilterRemoved does. 1324 // ServiceWorkerDispatcherHost::OnFilterRemoved does.
1324 helper_->context()->RemoveDispatcherHost(helper_->mock_render_process_id()); 1325 helper_->RegisterDispatcherHost(helper_->mock_render_process_id(), nullptr);
1325 base::RunLoop().RunUntilIdle(); 1326 base::RunLoop().RunUntilIdle();
1326 1327
1327 // Callback completed. 1328 // Callback completed.
1328 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED, status); 1329 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED, status);
1329 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version_->running_status()); 1330 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version_->running_status());
1330 1331
1331 // Request already failed, calling finsh should return false. 1332 // Request already failed, calling finsh should return false.
1332 EXPECT_FALSE(version_->FinishRequest(request_id, true /* was_handled */, 1333 EXPECT_FALSE(version_->FinishRequest(request_id, true /* was_handled */,
1333 base::Time::Now())); 1334 base::Time::Now()));
1334 } 1335 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 // OnStarted. 1449 // OnStarted.
1449 version_->StopWorker(CreateReceiverOnCurrentThread(&status2)); 1450 version_->StopWorker(CreateReceiverOnCurrentThread(&status2));
1450 base::RunLoop().RunUntilIdle(); 1451 base::RunLoop().RunUntilIdle();
1451 1452
1452 EXPECT_EQ(SERVICE_WORKER_OK, status1); 1453 EXPECT_EQ(SERVICE_WORKER_OK, status1);
1453 EXPECT_EQ(SERVICE_WORKER_OK, status2); 1454 EXPECT_EQ(SERVICE_WORKER_OK, status2);
1454 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status()); 1455 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status());
1455 } 1456 }
1456 1457
1457 } // namespace content 1458 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_handle_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698