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