OLD | NEW |
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_provider_host.h" | 5 #include "content/browser/service_worker/service_worker_provider_host.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 CreateProviderHostForWindow(helper_->mock_render_process_id(), | 91 CreateProviderHostForWindow(helper_->mock_render_process_id(), |
92 next_provider_id_++, | 92 next_provider_id_++, |
93 false /* is_parent_frame_secure */, | 93 false /* is_parent_frame_secure */, |
94 helper_->context()->AsWeakPtr()); | 94 helper_->context()->AsWeakPtr()); |
95 ServiceWorkerProviderHost* host_raw = host.get(); | 95 ServiceWorkerProviderHost* host_raw = host.get(); |
96 host->SetDocumentUrl(document_url); | 96 host->SetDocumentUrl(document_url); |
97 context_->AddProviderHost(std::move(host)); | 97 context_->AddProviderHost(std::move(host)); |
98 return host_raw; | 98 return host_raw; |
99 } | 99 } |
100 | 100 |
| 101 ServiceWorkerProviderHost* CreateProviderHostWithMojo( |
| 102 const GURL& document_url, |
| 103 mojom::ServiceWorkerProviderHostAssociatedPtr* host_ptr, |
| 104 mojom::ServiceWorkerProviderAssociatedPtr client_ptr) { |
| 105 ServiceWorkerProviderHostInfo info(next_provider_id_++, MSG_ROUTING_NONE, |
| 106 SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| 107 true /* is_parent_frame_secure */); |
| 108 info.host_request = mojo::MakeIsolatedRequest(host_ptr); |
| 109 info.client_ptr_info = client_ptr.PassInterface(); |
| 110 std::unique_ptr<ServiceWorkerProviderHost> host = |
| 111 ServiceWorkerProviderHost::Create( |
| 112 helper_->mock_render_process_id(), std::move(info), |
| 113 helper_->context()->AsWeakPtr(), nullptr); |
| 114 ServiceWorkerProviderHost* host_raw = host.get(); |
| 115 host->SetDocumentUrl(document_url); |
| 116 context_->AddProviderHost(std::move(host)); |
| 117 return host_raw; |
| 118 } |
| 119 |
101 TestBrowserThreadBundle thread_bundle_; | 120 TestBrowserThreadBundle thread_bundle_; |
102 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 121 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
103 ServiceWorkerContextCore* context_; | 122 ServiceWorkerContextCore* context_; |
104 scoped_refptr<ServiceWorkerRegistration> registration1_; | 123 scoped_refptr<ServiceWorkerRegistration> registration1_; |
105 scoped_refptr<ServiceWorkerRegistration> registration2_; | 124 scoped_refptr<ServiceWorkerRegistration> registration2_; |
106 scoped_refptr<ServiceWorkerRegistration> registration3_; | 125 scoped_refptr<ServiceWorkerRegistration> registration3_; |
107 GURL script_url_; | 126 GURL script_url_; |
108 ServiceWorkerTestContentClient test_content_client_; | 127 ServiceWorkerTestContentClient test_content_client_; |
109 TestContentBrowserClient test_content_browser_client_; | 128 TestContentBrowserClient test_content_browser_client_; |
110 ContentBrowserClient* old_content_browser_client_; | 129 ContentBrowserClient* old_content_browser_client_; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 EXPECT_TRUE(OriginCanAccessServiceWorkers(url)); | 236 EXPECT_TRUE(OriginCanAccessServiceWorkers(url)); |
218 provider_host_secure_parent->SetDocumentUrl(url); | 237 provider_host_secure_parent->SetDocumentUrl(url); |
219 EXPECT_TRUE(provider_host_secure_parent->IsContextSecureForServiceWorker()); | 238 EXPECT_TRUE(provider_host_secure_parent->IsContextSecureForServiceWorker()); |
220 | 239 |
221 // Exceptional service worker scheme with insecure parent frame. | 240 // Exceptional service worker scheme with insecure parent frame. |
222 provider_host_insecure_parent->SetDocumentUrl(url); | 241 provider_host_insecure_parent->SetDocumentUrl(url); |
223 EXPECT_FALSE( | 242 EXPECT_FALSE( |
224 provider_host_insecure_parent->IsContextSecureForServiceWorker()); | 243 provider_host_insecure_parent->IsContextSecureForServiceWorker()); |
225 } | 244 } |
226 | 245 |
| 246 class MockServiceWorkerProvider : public mojom::ServiceWorkerProvider { |
| 247 public: |
| 248 MockServiceWorkerProvider( |
| 249 mojom::ServiceWorkerProviderAssociatedRequest request) |
| 250 : binding_(this, std::move(request)) {} |
| 251 bool is_bound() const { return binding_.is_bound(); } |
| 252 |
| 253 private: |
| 254 mojo::AssociatedBinding<mojom::ServiceWorkerProvider> binding_; |
| 255 }; |
| 256 |
| 257 TEST_F(ServiceWorkerProviderHostTest, RemoveProvider) { |
| 258 // Prepare mojo pointers living on the renderer side. |
| 259 mojom::ServiceWorkerProviderAssociatedPtr provider_client_ptr; |
| 260 MockServiceWorkerProvider provider_client( |
| 261 mojo::MakeIsolatedRequest(&provider_client_ptr)); |
| 262 mojom::ServiceWorkerProviderHostAssociatedPtr provider_host_ptr; |
| 263 |
| 264 // Create a provider host connected with the renderer process. |
| 265 ServiceWorkerProviderHost* provider_host = CreateProviderHostWithMojo( |
| 266 GURL("https://www.example.com/example1.html"), &provider_host_ptr, |
| 267 std::move(provider_client_ptr)); |
| 268 int process_id = provider_host->process_id(); |
| 269 int provider_id = provider_host->provider_id(); |
| 270 EXPECT_TRUE(context_->GetProviderHost(process_id, provider_id)); |
| 271 |
| 272 // Disconnect the mojo pipe from the renderer side. |
| 273 provider_host_ptr.reset(); |
| 274 base::RunLoop().RunUntilIdle(); |
| 275 EXPECT_FALSE(context_->GetProviderHost(process_id, provider_id)); |
| 276 } |
| 277 |
227 } // namespace content | 278 } // namespace content |
OLD | NEW |