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

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

Issue 2154663002: service worker: Relax the BadMessageReceived call in OnSetHostedVersionId (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: patch Created 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_dispatcher_host.h" 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 bool called = false; 136 bool called = false;
137 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; 137 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
138 helper_->context()->storage()->StoreRegistration( 138 helper_->context()->storage()->StoreRegistration(
139 registration_.get(), version_.get(), 139 registration_.get(), version_.get(),
140 base::Bind(&SaveStatusCallback, &called, &status)); 140 base::Bind(&SaveStatusCallback, &called, &status));
141 base::RunLoop().RunUntilIdle(); 141 base::RunLoop().RunUntilIdle();
142 EXPECT_TRUE(called); 142 EXPECT_TRUE(called);
143 EXPECT_EQ(SERVICE_WORKER_OK, status); 143 EXPECT_EQ(SERVICE_WORKER_OK, status);
144 } 144 }
145 145
146 void SendSetHostedVersionId(int provider_id, int64_t version_id) { 146 void SendSetHostedVersionId(int provider_id,
147 dispatcher_host_->OnMessageReceived( 147 int64_t version_id,
148 ServiceWorkerHostMsg_SetVersionId(provider_id, version_id)); 148 int embedded_worker_id) {
149 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_SetVersionId(
150 provider_id, version_id, embedded_worker_id));
149 } 151 }
150 152
151 void SendProviderCreated(ServiceWorkerProviderType type, 153 void SendProviderCreated(ServiceWorkerProviderType type,
152 const GURL& pattern) { 154 const GURL& pattern) {
153 const int64_t kProviderId = 99; 155 const int64_t kProviderId = 99;
154 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( 156 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated(
155 kProviderId, MSG_ROUTING_NONE, type, 157 kProviderId, MSG_ROUTING_NONE, type,
156 true /* is_parent_frame_secure */)); 158 true /* is_parent_frame_secure */));
157 helper_->SimulateAddProcessToPattern(pattern, 159 helper_->SimulateAddProcessToPattern(pattern,
158 helper_->mock_render_process_id()); 160 helper_->mock_render_process_id());
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 const int64_t kProviderId = 99; // Dummy value 758 const int64_t kProviderId = 99; // Dummy value
757 bool called; 759 bool called;
758 ServiceWorkerStatusCode status; 760 ServiceWorkerStatusCode status;
759 // StartWorker puts the worker in STARTING state but it will have no 761 // StartWorker puts the worker in STARTING state but it will have no
760 // process id yet. 762 // process id yet.
761 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, 763 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN,
762 base::Bind(&SaveStatusCallback, &called, &status)); 764 base::Bind(&SaveStatusCallback, &called, &status));
763 EXPECT_NE(version_->embedded_worker()->process_id(), 765 EXPECT_NE(version_->embedded_worker()->process_id(),
764 provider_host_->process_id()); 766 provider_host_->process_id());
765 // SendSetHostedVersionId should reject because the provider host process id 767 // SendSetHostedVersionId should reject because the provider host process id
766 // is different. 768 // is different. It should call BadMessageReceived because it's not an
767 SendSetHostedVersionId(kProviderId, version_->version_id()); 769 // expected error state.
770 SendSetHostedVersionId(kProviderId, version_->version_id(),
771 version_->embedded_worker()->embedded_worker_id());
768 base::RunLoop().RunUntilIdle(); 772 base::RunLoop().RunUntilIdle();
769 EXPECT_FALSE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( 773 EXPECT_FALSE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching(
770 ServiceWorkerMsg_AssociateRegistration::ID)); 774 ServiceWorkerMsg_AssociateRegistration::ID));
775 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
776 }
777
778 TEST_F(ServiceWorkerDispatcherHostTest, OnSetHostedVersionId_DetachedWorker) {
779 GURL pattern = GURL("http://www.example.com/");
780 GURL script_url = GURL("http://www.example.com/service_worker.js");
781
782 Initialize(base::WrapUnique(new FailToStartWorkerTestHelper));
783 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, pattern);
784 SetUpRegistration(pattern, script_url);
785
786 const int64_t kProviderId = 99; // Dummy value
787 bool called;
788 ServiceWorkerStatusCode status;
789 // StartWorker puts the worker in STARTING state.
790 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN,
791 base::Bind(&SaveStatusCallback, &called, &status));
792
793 // SendSetHostedVersionId should bail because the embedded worker is
794 // different. It shouldn't call BadMessageReceived because receiving a message
795 // for a detached worker is a legitimite possibility.
796 int bad_embedded_worker_id =
797 version_->embedded_worker()->embedded_worker_id() + 1;
798 SendSetHostedVersionId(kProviderId, version_->version_id(),
799 bad_embedded_worker_id);
800 base::RunLoop().RunUntilIdle();
801 EXPECT_FALSE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching(
802 ServiceWorkerMsg_AssociateRegistration::ID));
803 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_);
771 } 804 }
772 805
773 TEST_F(ServiceWorkerDispatcherHostTest, ReceivedTimedOutRequestResponse) { 806 TEST_F(ServiceWorkerDispatcherHostTest, ReceivedTimedOutRequestResponse) {
774 GURL pattern = GURL("https://www.example.com/"); 807 GURL pattern = GURL("https://www.example.com/");
775 GURL script_url = GURL("https://www.example.com/service_worker.js"); 808 GURL script_url = GURL("https://www.example.com/service_worker.js");
776 809
777 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_WINDOW, pattern); 810 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_WINDOW, pattern);
778 SetUpRegistration(pattern, script_url); 811 SetUpRegistration(pattern, script_url);
779 812
780 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, 813 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN,
781 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 814 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
782 base::RunLoop().RunUntilIdle(); 815 base::RunLoop().RunUntilIdle();
783 816
784 // Set the worker status to STOPPING. 817 // Set the worker status to STOPPING.
785 version_->embedded_worker()->Stop(); 818 version_->embedded_worker()->Stop();
786 EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, version_->running_status()); 819 EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, version_->running_status());
787 820
788 // Receive a response for a timed out request. The bad message count should 821 // Receive a response for a timed out request. The bad message count should
789 // not increase. 822 // not increase.
790 const int kRequestId = 91; // Dummy value 823 const int kRequestId = 91; // Dummy value
791 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse( 824 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse(
792 version_->embedded_worker()->embedded_worker_id(), kRequestId, 825 version_->embedded_worker()->embedded_worker_id(), kRequestId,
793 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse())); 826 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse()));
794 827
795 base::RunLoop().RunUntilIdle(); 828 base::RunLoop().RunUntilIdle();
796 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); 829 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_);
797 } 830 }
798 831
799 } // namespace content 832 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698