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

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

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

Powered by Google App Engine
This is Rietveld 408576698