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

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

Issue 2958753003: Revert "Create ServiceWorkerProviderHost before starting worker" (Closed)
Patch Set: Created 3 years, 5 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 #include <utility> 9 #include <utility>
10 10
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
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( 273 void OnStartWorker(int embedded_worker_id,
274 int embedded_worker_id, 274 int64_t service_worker_version_id,
275 int64_t service_worker_version_id, 275 const GURL& scope,
276 const GURL& scope, 276 const GURL& script_url,
277 const GURL& script_url, 277 bool pause_after_download,
278 bool pause_after_download, 278 mojom::ServiceWorkerEventDispatcherRequest request,
279 mojom::ServiceWorkerEventDispatcherRequest request, 279 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo
280 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, 280 instance_host) override {
281 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info)
282 override {
283 switch (mode_) { 281 switch (mode_) {
284 case StartMode::STALL: 282 case StartMode::STALL:
285 // Prepare for OnStopWorker(). 283 // Prepare for OnStopWorker().
286 instance_host_ptr_map_[embedded_worker_id].Bind( 284 instance_host_ptr_map_[embedded_worker_id].Bind(
287 std::move(instance_host)); 285 std::move(instance_host));
288 // Just keep the connection alive. 286 // Just keep the connection alive.
289 event_dispatcher_request_map_[embedded_worker_id] = std::move(request); 287 event_dispatcher_request_map_[embedded_worker_id] = std::move(request);
290 break; 288 break;
291 case StartMode::FAIL: 289 case StartMode::FAIL:
292 ASSERT_EQ(current_mock_instance_index_ + 1, 290 ASSERT_EQ(current_mock_instance_index_ + 1,
293 mock_instance_clients()->size()); 291 mock_instance_clients()->size());
294 // Remove the connection by peer 292 // Remove the connection by peer
295 mock_instance_clients()->at(current_mock_instance_index_).reset(); 293 mock_instance_clients()->at(current_mock_instance_index_).reset();
296 std::move(request); 294 std::move(request);
297 break; 295 break;
298 case StartMode::SUCCEED: 296 case StartMode::SUCCEED:
299 MessageReceiver::OnStartWorker( 297 MessageReceiver::OnStartWorker(
300 embedded_worker_id, service_worker_version_id, scope, script_url, 298 embedded_worker_id, service_worker_version_id, scope, script_url,
301 pause_after_download, std::move(request), std::move(instance_host), 299 pause_after_download, std::move(request), std::move(instance_host));
302 std::move(provider_info));
303 break; 300 break;
304 } 301 }
305 current_mock_instance_index_++; 302 current_mock_instance_index_++;
306 } 303 }
307 304
308 void OnStopWorker(int embedded_worker_id) override { 305 void OnStopWorker(int embedded_worker_id) override {
309 if (instance_host_ptr_map_[embedded_worker_id]) { 306 if (instance_host_ptr_map_[embedded_worker_id]) {
310 instance_host_ptr_map_[embedded_worker_id]->OnStopped(); 307 instance_host_ptr_map_[embedded_worker_id]->OnStopped();
311 base::RunLoop().RunUntilIdle(); 308 base::RunLoop().RunUntilIdle();
312 return; 309 return;
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 version_->AddListener(&listener); 697 version_->AddListener(&listener);
701 698
702 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 699 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
703 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, 700 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN,
704 CreateReceiverOnCurrentThread(&status)); 701 CreateReceiverOnCurrentThread(&status));
705 base::RunLoop().RunUntilIdle(); 702 base::RunLoop().RunUntilIdle();
706 EXPECT_EQ(SERVICE_WORKER_OK, status); 703 EXPECT_EQ(SERVICE_WORKER_OK, status);
707 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status()); 704 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status());
708 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, listener.last_status); 705 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, listener.last_status);
709 706
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());
715 version_ = nullptr; 707 version_ = nullptr;
716 EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, listener.last_status); 708 EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, listener.last_status);
717 } 709 }
718 710
719 // Test that update isn't triggered for a non-stale worker. 711 // Test that update isn't triggered for a non-stale worker.
720 TEST_F(ServiceWorkerVersionTest, StaleUpdate_FreshWorker) { 712 TEST_F(ServiceWorkerVersionTest, StaleUpdate_FreshWorker) {
721 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 713 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
722 registration_->SetActiveVersion(version_); 714 registration_->SetActiveVersion(version_);
723 registration_->set_last_update_check(base::Time::Now()); 715 registration_->set_last_update_check(base::Time::Now());
724 SimulateDispatchEvent(ServiceWorkerMetrics::EventType::PUSH); 716 SimulateDispatchEvent(ServiceWorkerMetrics::EventType::PUSH);
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 // OnStarted. 1442 // OnStarted.
1451 version_->StopWorker(CreateReceiverOnCurrentThread(&status2)); 1443 version_->StopWorker(CreateReceiverOnCurrentThread(&status2));
1452 base::RunLoop().RunUntilIdle(); 1444 base::RunLoop().RunUntilIdle();
1453 1445
1454 EXPECT_EQ(SERVICE_WORKER_OK, status1); 1446 EXPECT_EQ(SERVICE_WORKER_OK, status1);
1455 EXPECT_EQ(SERVICE_WORKER_OK, status2); 1447 EXPECT_EQ(SERVICE_WORKER_OK, status2);
1456 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status()); 1448 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status());
1457 } 1449 }
1458 1450
1459 } // namespace content 1451 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698