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

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

Issue 2653493009: Add two interfaces for ServiceWorkerProviderContext/ProviderHost (Closed)
Patch Set: Addressed comments from falken Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/link_header_support.h" 5 #include "content/browser/service_worker/link_header_support.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "content/browser/loader/resource_request_info_impl.h" 10 #include "content/browser/loader/resource_request_info_impl.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 ServiceWorkerContextCore* context() { return helper_->context(); } 73 ServiceWorkerContextCore* context() { return helper_->context(); }
74 ServiceWorkerContextWrapper* context_wrapper() { 74 ServiceWorkerContextWrapper* context_wrapper() {
75 return helper_->context_wrapper(); 75 return helper_->context_wrapper();
76 } 76 }
77 ServiceWorkerProviderHost* provider_host() { return provider_host_.get(); } 77 ServiceWorkerProviderHost* provider_host() { return provider_host_.get(); }
78 int render_process_id() const { return helper_->mock_render_process_id(); } 78 int render_process_id() const { return helper_->mock_render_process_id(); }
79 79
80 void CreateDocumentProviderHost() { 80 void CreateDocumentProviderHost() {
81 // An empty host. 81 // An empty host.
82 remote_endpoints_.emplace_back();
82 std::unique_ptr<ServiceWorkerProviderHost> host = 83 std::unique_ptr<ServiceWorkerProviderHost> host =
83 CreateProviderHostForWindow(render_process_id(), kMockProviderId, 84 CreateProviderHostForWindow(render_process_id(), kMockProviderId,
84 true /* is_parent_frame_secure */, 85 true /* is_parent_frame_secure */,
85 context()->AsWeakPtr()); 86 context()->AsWeakPtr(),
87 &remote_endpoints_.back());
86 provider_host_ = host->AsWeakPtr(); 88 provider_host_ = host->AsWeakPtr();
87 EXPECT_FALSE( 89 EXPECT_FALSE(
88 context()->GetProviderHost(host->process_id(), host->provider_id())); 90 context()->GetProviderHost(host->process_id(), host->provider_id()));
89 context()->AddProviderHost(std::move(host)); 91 context()->AddProviderHost(std::move(host));
90 } 92 }
91 93
92 void CreateInsecureDocumentProviderHost() { 94 void CreateInsecureDocumentProviderHost() {
93 // An empty host. 95 // An empty host.
96 remote_endpoints_.emplace_back();
94 std::unique_ptr<ServiceWorkerProviderHost> host = 97 std::unique_ptr<ServiceWorkerProviderHost> host =
95 CreateProviderHostForWindow(render_process_id(), kMockProviderId, 98 CreateProviderHostForWindow(render_process_id(), kMockProviderId,
96 false /* is_parent_frame_secure */, 99 false /* is_parent_frame_secure */,
97 context()->AsWeakPtr()); 100 context()->AsWeakPtr(),
101 &remote_endpoints_.back());
98 provider_host_ = host->AsWeakPtr(); 102 provider_host_ = host->AsWeakPtr();
99 EXPECT_FALSE( 103 EXPECT_FALSE(
100 context()->GetProviderHost(host->process_id(), host->provider_id())); 104 context()->GetProviderHost(host->process_id(), host->provider_id()));
101 context()->AddProviderHost(std::move(host)); 105 context()->AddProviderHost(std::move(host));
102 } 106 }
103 107
104 void CreateServiceWorkerProviderHost() { 108 void CreateServiceWorkerProviderHost() {
109 remote_endpoints_.emplace_back();
105 std::unique_ptr<ServiceWorkerProviderHost> host = 110 std::unique_ptr<ServiceWorkerProviderHost> host =
106 CreateProviderHostForServiceWorkerContext( 111 CreateProviderHostForServiceWorkerContext(
107 render_process_id(), kMockProviderId, 112 render_process_id(), kMockProviderId,
108 true /* is_parent_frame_secure */, context()->AsWeakPtr()); 113 true /* is_parent_frame_secure */, context()->AsWeakPtr(),
114 &remote_endpoints_.back());
109 provider_host_ = host->AsWeakPtr(); 115 provider_host_ = host->AsWeakPtr();
110 EXPECT_FALSE( 116 EXPECT_FALSE(
111 context()->GetProviderHost(host->process_id(), host->provider_id())); 117 context()->GetProviderHost(host->process_id(), host->provider_id()));
112 context()->AddProviderHost(std::move(host)); 118 context()->AddProviderHost(std::move(host));
113 119
114 scoped_refptr<ServiceWorkerRegistration> registration = 120 scoped_refptr<ServiceWorkerRegistration> registration =
115 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, 121 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L,
116 context()->AsWeakPtr()); 122 context()->AsWeakPtr());
117 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 123 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
118 registration.get(), GURL("https://host/script.js"), 1L, 124 registration.get(), GURL("https://host/script.js"), 1L,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 std::vector<ServiceWorkerRegistrationInfo> GetRegistrations() { 160 std::vector<ServiceWorkerRegistrationInfo> GetRegistrations() {
155 bool called; 161 bool called;
156 std::vector<ServiceWorkerRegistrationInfo> registrations; 162 std::vector<ServiceWorkerRegistrationInfo> registrations;
157 context_wrapper()->GetAllRegistrations( 163 context_wrapper()->GetAllRegistrations(
158 SaveFoundRegistrations(SERVICE_WORKER_OK, &called, &registrations)); 164 SaveFoundRegistrations(SERVICE_WORKER_OK, &called, &registrations));
159 base::RunLoop().RunUntilIdle(); 165 base::RunLoop().RunUntilIdle();
160 EXPECT_TRUE(called); 166 EXPECT_TRUE(called);
161 return registrations; 167 return registrations;
162 } 168 }
163 169
164 private: 170 protected:
165 TestBrowserThreadBundle thread_bundle_; 171 TestBrowserThreadBundle thread_bundle_;
166 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; 172 std::unique_ptr<EmbeddedWorkerTestHelper> helper_;
167 net::TestURLRequestContext request_context_; 173 net::TestURLRequestContext request_context_;
168 net::TestDelegate request_delegate_; 174 net::TestDelegate request_delegate_;
169 MockResourceContext resource_context_; 175 MockResourceContext resource_context_;
170 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; 176 base::WeakPtr<ServiceWorkerProviderHost> provider_host_;
171 storage::BlobStorageContext blob_storage_context_; 177 storage::BlobStorageContext blob_storage_context_;
178 std::vector<ServiceWorkerRemoteProviderEndpoint> remote_endpoints_;
172 }; 179 };
173 180
174 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_Basic) { 181 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_Basic) {
175 CreateDocumentProviderHost(); 182 CreateDocumentProviderHost();
176 ProcessLinkHeaderForRequest( 183 ProcessLinkHeaderForRequest(
177 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), 184 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(),
178 "<../foo.js>; rel=serviceworker", context_wrapper()); 185 "<../foo.js>; rel=serviceworker", context_wrapper());
179 base::RunLoop().RunUntilIdle(); 186 base::RunLoop().RunUntilIdle();
180 187
181 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); 188 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 base::RunLoop().RunUntilIdle(); 397 base::RunLoop().RunUntilIdle();
391 398
392 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); 399 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
393 ASSERT_EQ(0u, registrations.size()); 400 ASSERT_EQ(0u, registrations.size());
394 } 401 }
395 402
396 TEST_F(LinkHeaderServiceWorkerTest, 403 TEST_F(LinkHeaderServiceWorkerTest,
397 InstallServiceWorker_FromWorkerWithControllees) { 404 InstallServiceWorker_FromWorkerWithControllees) {
398 CreateServiceWorkerProviderHost(); 405 CreateServiceWorkerProviderHost();
399 406
407 remote_endpoints_.emplace_back();
400 std::unique_ptr<ServiceWorkerProviderHost> controllee = 408 std::unique_ptr<ServiceWorkerProviderHost> controllee =
401 CreateProviderHostForWindow(render_process_id(), kMockProviderId, 409 CreateProviderHostForWindow(render_process_id(), kMockProviderId,
402 true /* is_parent_frame_secure */, 410 true /* is_parent_frame_secure */,
403 context()->AsWeakPtr()); 411 context()->AsWeakPtr(),
412 &remote_endpoints_.back());
404 provider_host()->running_hosted_version()->AddControllee(controllee.get()); 413 provider_host()->running_hosted_version()->AddControllee(controllee.get());
405 414
406 ProcessLinkHeaderForRequest( 415 ProcessLinkHeaderForRequest(
407 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), 416 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(),
408 "<../foo.js>; rel=serviceworker", context_wrapper()); 417 "<../foo.js>; rel=serviceworker", context_wrapper());
409 base::RunLoop().RunUntilIdle(); 418 base::RunLoop().RunUntilIdle();
410 419
411 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); 420 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
412 ASSERT_EQ(1u, registrations.size()); 421 ASSERT_EQ(1u, registrations.size());
413 } 422 }
414 423
415 } // namespace content 424 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698