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 "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 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersionTest); | 263 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersionTest); |
264 }; | 264 }; |
265 | 265 |
266 class MessageReceiverDisallowStart : public MessageReceiver { | 266 class MessageReceiverDisallowStart : public MessageReceiver { |
267 public: | 267 public: |
268 MessageReceiverDisallowStart() : MessageReceiver() {} | 268 MessageReceiverDisallowStart() : MessageReceiver() {} |
269 ~MessageReceiverDisallowStart() override {} | 269 ~MessageReceiverDisallowStart() override {} |
270 | 270 |
271 enum class StartMode { STALL, FAIL, SUCCEED }; | 271 enum class StartMode { STALL, FAIL, SUCCEED }; |
272 | 272 |
273 void OnStartWorker(int embedded_worker_id, | 273 void OnStartWorker( |
274 int64_t service_worker_version_id, | 274 int embedded_worker_id, |
275 const GURL& scope, | 275 int64_t service_worker_version_id, |
276 const GURL& script_url, | 276 const GURL& scope, |
277 bool pause_after_download, | 277 const GURL& script_url, |
278 mojom::ServiceWorkerEventDispatcherRequest request, | 278 bool pause_after_download, |
279 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo | 279 mojom::ServiceWorkerEventDispatcherRequest request, |
280 instance_host) override { | 280 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, |
| 281 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info) |
| 282 override { |
281 switch (mode_) { | 283 switch (mode_) { |
282 case StartMode::STALL: | 284 case StartMode::STALL: |
283 // Prepare for OnStopWorker(). | 285 // Prepare for OnStopWorker(). |
284 instance_host_ptr_map_[embedded_worker_id].Bind( | 286 instance_host_ptr_map_[embedded_worker_id].Bind( |
285 std::move(instance_host)); | 287 std::move(instance_host)); |
286 // Just keep the connection alive. | 288 // Just keep the connection alive. |
287 event_dispatcher_request_map_[embedded_worker_id] = std::move(request); | 289 event_dispatcher_request_map_[embedded_worker_id] = std::move(request); |
288 break; | 290 break; |
289 case StartMode::FAIL: | 291 case StartMode::FAIL: |
290 ASSERT_EQ(current_mock_instance_index_ + 1, | 292 ASSERT_EQ(current_mock_instance_index_ + 1, |
291 mock_instance_clients()->size()); | 293 mock_instance_clients()->size()); |
292 // Remove the connection by peer | 294 // Remove the connection by peer |
293 mock_instance_clients()->at(current_mock_instance_index_).reset(); | 295 mock_instance_clients()->at(current_mock_instance_index_).reset(); |
294 std::move(request); | 296 std::move(request); |
295 break; | 297 break; |
296 case StartMode::SUCCEED: | 298 case StartMode::SUCCEED: |
297 MessageReceiver::OnStartWorker( | 299 MessageReceiver::OnStartWorker( |
298 embedded_worker_id, service_worker_version_id, scope, script_url, | 300 embedded_worker_id, service_worker_version_id, scope, script_url, |
299 pause_after_download, std::move(request), std::move(instance_host)); | 301 pause_after_download, std::move(request), std::move(instance_host), |
| 302 std::move(provider_info)); |
300 break; | 303 break; |
301 } | 304 } |
302 current_mock_instance_index_++; | 305 current_mock_instance_index_++; |
303 } | 306 } |
304 | 307 |
305 void OnStopWorker(int embedded_worker_id) override { | 308 void OnStopWorker(int embedded_worker_id) override { |
306 if (instance_host_ptr_map_[embedded_worker_id]) { | 309 if (instance_host_ptr_map_[embedded_worker_id]) { |
307 instance_host_ptr_map_[embedded_worker_id]->OnStopped(); | 310 instance_host_ptr_map_[embedded_worker_id]->OnStopped(); |
308 base::RunLoop().RunUntilIdle(); | 311 base::RunLoop().RunUntilIdle(); |
309 return; | 312 return; |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 version_->AddListener(&listener); | 700 version_->AddListener(&listener); |
698 | 701 |
699 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 702 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
700 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, | 703 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, |
701 CreateReceiverOnCurrentThread(&status)); | 704 CreateReceiverOnCurrentThread(&status)); |
702 base::RunLoop().RunUntilIdle(); | 705 base::RunLoop().RunUntilIdle(); |
703 EXPECT_EQ(SERVICE_WORKER_OK, status); | 706 EXPECT_EQ(SERVICE_WORKER_OK, status); |
704 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status()); | 707 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status()); |
705 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, listener.last_status); | 708 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, listener.last_status); |
706 | 709 |
| 710 // Destruct |version_| by releasing all references, including the provider |
| 711 // host's. |
| 712 helper_->context()->RemoveProviderHost( |
| 713 version_->provider_host()->process_id(), |
| 714 version_->provider_host()->provider_id()); |
707 version_ = nullptr; | 715 version_ = nullptr; |
708 EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, listener.last_status); | 716 EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, listener.last_status); |
709 } | 717 } |
710 | 718 |
711 // Test that update isn't triggered for a non-stale worker. | 719 // Test that update isn't triggered for a non-stale worker. |
712 TEST_F(ServiceWorkerVersionTest, StaleUpdate_FreshWorker) { | 720 TEST_F(ServiceWorkerVersionTest, StaleUpdate_FreshWorker) { |
713 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 721 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
714 registration_->SetActiveVersion(version_); | 722 registration_->SetActiveVersion(version_); |
715 registration_->set_last_update_check(base::Time::Now()); | 723 registration_->set_last_update_check(base::Time::Now()); |
716 SimulateDispatchEvent(ServiceWorkerMetrics::EventType::PUSH); | 724 SimulateDispatchEvent(ServiceWorkerMetrics::EventType::PUSH); |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 // OnStarted. | 1457 // OnStarted. |
1450 version_->StopWorker(CreateReceiverOnCurrentThread(&status2)); | 1458 version_->StopWorker(CreateReceiverOnCurrentThread(&status2)); |
1451 base::RunLoop().RunUntilIdle(); | 1459 base::RunLoop().RunUntilIdle(); |
1452 | 1460 |
1453 EXPECT_EQ(SERVICE_WORKER_OK, status1); | 1461 EXPECT_EQ(SERVICE_WORKER_OK, status1); |
1454 EXPECT_EQ(SERVICE_WORKER_OK, status2); | 1462 EXPECT_EQ(SERVICE_WORKER_OK, status2); |
1455 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status()); | 1463 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status()); |
1456 } | 1464 } |
1457 | 1465 |
1458 } // namespace content | 1466 } // namespace content |
OLD | NEW |