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

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

Issue 2055433002: Revert of service worker: Don't control a subframe of an insecure context (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 143
144 void SendSetHostedVersionId(int provider_id, int64_t version_id) { 144 void SendSetHostedVersionId(int provider_id, int64_t version_id) {
145 dispatcher_host_->OnMessageReceived( 145 dispatcher_host_->OnMessageReceived(
146 ServiceWorkerHostMsg_SetVersionId(provider_id, version_id)); 146 ServiceWorkerHostMsg_SetVersionId(provider_id, version_id));
147 } 147 }
148 148
149 void SendProviderCreated(ServiceWorkerProviderType type, 149 void SendProviderCreated(ServiceWorkerProviderType type,
150 const GURL& pattern) { 150 const GURL& pattern) {
151 const int64_t kProviderId = 99; 151 const int64_t kProviderId = 99;
152 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( 152 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated(
153 kProviderId, MSG_ROUTING_NONE, type, 153 kProviderId, MSG_ROUTING_NONE, type));
154 true /* is_parent_frame_secure */));
155 helper_->SimulateAddProcessToPattern(pattern, 154 helper_->SimulateAddProcessToPattern(pattern,
156 helper_->mock_render_process_id()); 155 helper_->mock_render_process_id());
157 provider_host_ = context()->GetProviderHost( 156 provider_host_ = context()->GetProviderHost(
158 helper_->mock_render_process_id(), kProviderId); 157 helper_->mock_render_process_id(), kProviderId);
159 } 158 }
160 159
161 void SendRegister(int64_t provider_id, GURL pattern, GURL worker_url) { 160 void SendRegister(int64_t provider_id, GURL pattern, GURL worker_url) {
162 dispatcher_host_->OnMessageReceived( 161 dispatcher_host_->OnMessageReceived(
163 ServiceWorkerHostMsg_RegisterServiceWorker( 162 ServiceWorkerHostMsg_RegisterServiceWorker(
164 -1, -1, provider_id, pattern, worker_url)); 163 -1, -1, provider_id, pattern, worker_url));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 ServiceWorkerProviderHost* sender_provider_host, 227 ServiceWorkerProviderHost* sender_provider_host,
229 const ServiceWorkerDispatcherHost::StatusCallback& callback) { 228 const ServiceWorkerDispatcherHost::StatusCallback& callback) {
230 dispatcher_host_->DispatchExtendableMessageEvent( 229 dispatcher_host_->DispatchExtendableMessageEvent(
231 std::move(worker), message, source_origin, sent_message_ports, 230 std::move(worker), message, source_origin, sent_message_ports,
232 sender_provider_host, callback); 231 sender_provider_host, callback);
233 } 232 }
234 233
235 ServiceWorkerProviderHost* CreateServiceWorkerProviderHost(int provider_id) { 234 ServiceWorkerProviderHost* CreateServiceWorkerProviderHost(int provider_id) {
236 return new ServiceWorkerProviderHost( 235 return new ServiceWorkerProviderHost(
237 helper_->mock_render_process_id(), kRenderFrameId, provider_id, 236 helper_->mock_render_process_id(), kRenderFrameId, provider_id,
238 SERVICE_WORKER_PROVIDER_FOR_WINDOW, 237 SERVICE_WORKER_PROVIDER_FOR_WINDOW, context()->AsWeakPtr(),
239 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, 238 dispatcher_host_.get());
240 context()->AsWeakPtr(), dispatcher_host_.get());
241 } 239 }
242 240
243 TestBrowserThreadBundle browser_thread_bundle_; 241 TestBrowserThreadBundle browser_thread_bundle_;
244 content::MockResourceContext resource_context_; 242 content::MockResourceContext resource_context_;
245 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; 243 std::unique_ptr<EmbeddedWorkerTestHelper> helper_;
246 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; 244 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_;
247 scoped_refptr<ServiceWorkerRegistration> registration_; 245 scoped_refptr<ServiceWorkerRegistration> registration_;
248 scoped_refptr<ServiceWorkerVersion> version_; 246 scoped_refptr<ServiceWorkerVersion> version_;
249 ServiceWorkerProviderHost* provider_host_; 247 ServiceWorkerProviderHost* provider_host_;
250 }; 248 };
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 GURL(), 489 GURL(),
492 GURL(), 490 GURL(),
493 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); 491 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID);
494 } 492 }
495 493
496 TEST_F(ServiceWorkerDispatcherHostTest, ProviderCreatedAndDestroyed) { 494 TEST_F(ServiceWorkerDispatcherHostTest, ProviderCreatedAndDestroyed) {
497 const int kProviderId = 1001; 495 const int kProviderId = 1001;
498 int process_id = helper_->mock_render_process_id(); 496 int process_id = helper_->mock_render_process_id();
499 497
500 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( 498 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated(
501 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW, 499 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW));
502 true /* is_parent_frame_secure */));
503 EXPECT_TRUE(context()->GetProviderHost(process_id, kProviderId)); 500 EXPECT_TRUE(context()->GetProviderHost(process_id, kProviderId));
504 501
505 // Two with the same ID should be seen as a bad message. 502 // Two with the same ID should be seen as a bad message.
506 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( 503 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated(
507 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW, 504 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW));
508 true /* is_parent_frame_secure */));
509 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); 505 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
510 506
511 dispatcher_host_->OnMessageReceived( 507 dispatcher_host_->OnMessageReceived(
512 ServiceWorkerHostMsg_ProviderDestroyed(kProviderId)); 508 ServiceWorkerHostMsg_ProviderDestroyed(kProviderId));
513 EXPECT_FALSE(context()->GetProviderHost(process_id, kProviderId)); 509 EXPECT_FALSE(context()->GetProviderHost(process_id, kProviderId));
514 510
515 // Destroying an ID that does not exist warrants a bad message. 511 // Destroying an ID that does not exist warrants a bad message.
516 dispatcher_host_->OnMessageReceived( 512 dispatcher_host_->OnMessageReceived(
517 ServiceWorkerHostMsg_ProviderDestroyed(kProviderId)); 513 ServiceWorkerHostMsg_ProviderDestroyed(kProviderId));
518 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); 514 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_);
519 515
520 // Deletion of the dispatcher_host should cause providers for that 516 // Deletion of the dispatcher_host should cause providers for that
521 // process to get deleted as well. 517 // process to get deleted as well.
522 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( 518 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated(
523 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW, 519 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW));
524 true /* is_parent_frame_secure */));
525 EXPECT_TRUE(context()->GetProviderHost(process_id, kProviderId)); 520 EXPECT_TRUE(context()->GetProviderHost(process_id, kProviderId));
526 EXPECT_TRUE(dispatcher_host_->HasOneRef()); 521 EXPECT_TRUE(dispatcher_host_->HasOneRef());
527 dispatcher_host_ = NULL; 522 dispatcher_host_ = NULL;
528 EXPECT_FALSE(context()->GetProviderHost(process_id, kProviderId)); 523 EXPECT_FALSE(context()->GetProviderHost(process_id, kProviderId));
529 } 524 }
530 525
531 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_SameOrigin) { 526 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_SameOrigin) {
532 const int64_t kProviderId = 99; // Dummy value 527 const int64_t kProviderId = 99; // Dummy value
533 std::unique_ptr<ServiceWorkerProviderHost> host( 528 std::unique_ptr<ServiceWorkerProviderHost> host(
534 CreateServiceWorkerProviderHost(kProviderId)); 529 CreateServiceWorkerProviderHost(kProviderId));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 // is not yet destroyed. This is what the browser does when reusing a crashed 645 // is not yet destroyed. This is what the browser does when reusing a crashed
651 // render process. 646 // render process.
652 scoped_refptr<TestingServiceWorkerDispatcherHost> new_dispatcher_host( 647 scoped_refptr<TestingServiceWorkerDispatcherHost> new_dispatcher_host(
653 new TestingServiceWorkerDispatcherHost( 648 new TestingServiceWorkerDispatcherHost(
654 process_id, context_wrapper(), &resource_context_, helper_.get())); 649 process_id, context_wrapper(), &resource_context_, helper_.get()));
655 650
656 // To show the new dispatcher can operate, simulate provider creation. Since 651 // To show the new dispatcher can operate, simulate provider creation. Since
657 // the old dispatcher cleaned up the old provider host, the new one won't 652 // the old dispatcher cleaned up the old provider host, the new one won't
658 // complain. 653 // complain.
659 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( 654 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated(
660 provider_id, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW, 655 provider_id, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW));
661 true /* is_parent_frame_secure */));
662 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); 656 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_);
663 } 657 }
664 658
665 TEST_F(ServiceWorkerDispatcherHostTest, DispatchExtendableMessageEvent) { 659 TEST_F(ServiceWorkerDispatcherHostTest, DispatchExtendableMessageEvent) {
666 GURL pattern = GURL("http://www.example.com/"); 660 GURL pattern = GURL("http://www.example.com/");
667 GURL script_url = GURL("http://www.example.com/service_worker.js"); 661 GURL script_url = GURL("http://www.example.com/service_worker.js");
668 662
669 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, pattern); 663 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, pattern);
670 SetUpRegistration(pattern, script_url); 664 SetUpRegistration(pattern, script_url);
671 665
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 provider_host_->process_id()); 756 provider_host_->process_id());
763 // SendSetHostedVersionId should reject because the provider host process id 757 // SendSetHostedVersionId should reject because the provider host process id
764 // is different. 758 // is different.
765 SendSetHostedVersionId(kProviderId, version_->version_id()); 759 SendSetHostedVersionId(kProviderId, version_->version_id());
766 base::RunLoop().RunUntilIdle(); 760 base::RunLoop().RunUntilIdle();
767 EXPECT_FALSE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( 761 EXPECT_FALSE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching(
768 ServiceWorkerMsg_AssociateRegistration::ID)); 762 ServiceWorkerMsg_AssociateRegistration::ID));
769 } 763 }
770 764
771 } // namespace content 765 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698