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

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

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

Powered by Google App Engine
This is Rietveld 408576698