| OLD | NEW |
| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 LinkHeaderServiceWorkerTest() | 58 LinkHeaderServiceWorkerTest() |
| 59 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 59 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
| 60 resource_context_(&request_context_) { | 60 resource_context_(&request_context_) { |
| 61 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 61 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 62 switches::kEnableExperimentalWebPlatformFeatures); | 62 switches::kEnableExperimentalWebPlatformFeatures); |
| 63 } | 63 } |
| 64 ~LinkHeaderServiceWorkerTest() override {} | 64 ~LinkHeaderServiceWorkerTest() override {} |
| 65 | 65 |
| 66 void SetUp() override { | 66 void SetUp() override { |
| 67 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); | 67 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); |
| 68 | |
| 69 // An empty host. | |
| 70 std::unique_ptr<ServiceWorkerProviderHost> host( | |
| 71 new ServiceWorkerProviderHost( | |
| 72 render_process_id(), MSG_ROUTING_NONE, kMockProviderId, | |
| 73 SERVICE_WORKER_PROVIDER_FOR_WINDOW, | |
| 74 ServiceWorkerProviderHost::FrameSecurityLevel::UNINITIALIZED, | |
| 75 context()->AsWeakPtr(), nullptr)); | |
| 76 provider_host_ = host->AsWeakPtr(); | |
| 77 context()->AddProviderHost(std::move(host)); | |
| 78 } | 68 } |
| 79 | 69 |
| 80 void TearDown() override { helper_.reset(); } | 70 void TearDown() override { helper_.reset(); } |
| 81 | 71 |
| 82 ServiceWorkerContextCore* context() { return helper_->context(); } | 72 ServiceWorkerContextCore* context() { return helper_->context(); } |
| 83 ServiceWorkerContextWrapper* context_wrapper() { | 73 ServiceWorkerContextWrapper* context_wrapper() { |
| 84 return helper_->context_wrapper(); | 74 return helper_->context_wrapper(); |
| 85 } | 75 } |
| 86 ServiceWorkerProviderHost* provider_host() { return provider_host_.get(); } | 76 ServiceWorkerProviderHost* provider_host() { return provider_host_.get(); } |
| 87 int render_process_id() const { return helper_->mock_render_process_id(); } | 77 int render_process_id() const { return helper_->mock_render_process_id(); } |
| 88 | 78 |
| 79 void CreateDocumentProviderHost(bool is_parent_frame_secure = true) { |
| 80 // An empty host. |
| 81 std::unique_ptr<ServiceWorkerProviderHost> host = |
| 82 CreateProviderHostForWindow(render_process_id(), kMockProviderId, |
| 83 is_parent_frame_secure, |
| 84 context()->AsWeakPtr()); |
| 85 provider_host_ = host->AsWeakPtr(); |
| 86 EXPECT_FALSE( |
| 87 context()->GetProviderHost(host->process_id(), host->provider_id())); |
| 88 context()->AddProviderHost(std::move(host)); |
| 89 } |
| 90 |
| 89 void CreateServiceWorkerProviderHost() { | 91 void CreateServiceWorkerProviderHost() { |
| 90 std::unique_ptr<ServiceWorkerProviderHost> host( | 92 std::unique_ptr<ServiceWorkerProviderHost> host = |
| 91 new ServiceWorkerProviderHost( | 93 CreateProviderHostForServiceWorkerContext( |
| 92 render_process_id(), MSG_ROUTING_NONE, kMockProviderId, | 94 render_process_id(), kMockProviderId, |
| 93 SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, | 95 true /* is_parent_frame_secure */, context()->AsWeakPtr()); |
| 94 ServiceWorkerProviderHost::FrameSecurityLevel::UNINITIALIZED, | |
| 95 context()->AsWeakPtr(), nullptr)); | |
| 96 provider_host_ = host->AsWeakPtr(); | 96 provider_host_ = host->AsWeakPtr(); |
| 97 context()->RemoveProviderHost(host->process_id(), host->provider_id()); | 97 EXPECT_FALSE( |
| 98 context()->GetProviderHost(host->process_id(), host->provider_id())); |
| 98 context()->AddProviderHost(std::move(host)); | 99 context()->AddProviderHost(std::move(host)); |
| 99 | 100 |
| 100 scoped_refptr<ServiceWorkerRegistration> registration = | 101 scoped_refptr<ServiceWorkerRegistration> registration = |
| 101 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, | 102 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, |
| 102 context()->AsWeakPtr()); | 103 context()->AsWeakPtr()); |
| 103 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( | 104 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( |
| 104 registration.get(), GURL("https://host/script.js"), 1L, | 105 registration.get(), GURL("https://host/script.js"), 1L, |
| 105 context()->AsWeakPtr()); | 106 context()->AsWeakPtr()); |
| 106 | 107 |
| 107 provider_host_->running_hosted_version_ = version; | 108 provider_host_->running_hosted_version_ = version; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 TestBrowserThreadBundle thread_bundle_; | 151 TestBrowserThreadBundle thread_bundle_; |
| 151 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 152 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
| 152 net::TestURLRequestContext request_context_; | 153 net::TestURLRequestContext request_context_; |
| 153 net::TestDelegate request_delegate_; | 154 net::TestDelegate request_delegate_; |
| 154 MockResourceContext resource_context_; | 155 MockResourceContext resource_context_; |
| 155 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | 156 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
| 156 storage::BlobStorageContext blob_storage_context_; | 157 storage::BlobStorageContext blob_storage_context_; |
| 157 }; | 158 }; |
| 158 | 159 |
| 159 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_Basic) { | 160 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_Basic) { |
| 161 CreateDocumentProviderHost(); |
| 160 ProcessLinkHeaderForRequest( | 162 ProcessLinkHeaderForRequest( |
| 161 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), | 163 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), |
| 162 "<../foo.js>; rel=serviceworker", context_wrapper()); | 164 "<../foo.js>; rel=serviceworker", context_wrapper()); |
| 163 base::RunLoop().RunUntilIdle(); | 165 base::RunLoop().RunUntilIdle(); |
| 164 | 166 |
| 165 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 167 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 166 ASSERT_EQ(1u, registrations.size()); | 168 ASSERT_EQ(1u, registrations.size()); |
| 167 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); | 169 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); |
| 168 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), | 170 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), |
| 169 registrations[0].active_version.script_url); | 171 registrations[0].active_version.script_url); |
| 170 } | 172 } |
| 171 | 173 |
| 172 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeWithFragment) { | 174 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeWithFragment) { |
| 175 CreateDocumentProviderHost(); |
| 173 ProcessLinkHeaderForRequest( | 176 ProcessLinkHeaderForRequest( |
| 174 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), | 177 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), |
| 175 "<../bar.js>; rel=serviceworker; scope=\"scope#ref\"", context_wrapper()); | 178 "<../bar.js>; rel=serviceworker; scope=\"scope#ref\"", context_wrapper()); |
| 176 base::RunLoop().RunUntilIdle(); | 179 base::RunLoop().RunUntilIdle(); |
| 177 | 180 |
| 178 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 181 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 179 ASSERT_EQ(1u, registrations.size()); | 182 ASSERT_EQ(1u, registrations.size()); |
| 180 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), | 183 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), |
| 181 registrations[0].pattern); | 184 registrations[0].pattern); |
| 182 EXPECT_EQ(GURL("https://example.com/foo/bar.js"), | 185 EXPECT_EQ(GURL("https://example.com/foo/bar.js"), |
| 183 registrations[0].active_version.script_url); | 186 registrations[0].active_version.script_url); |
| 184 } | 187 } |
| 185 | 188 |
| 186 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeAbsoluteUrl) { | 189 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeAbsoluteUrl) { |
| 190 CreateDocumentProviderHost(); |
| 187 ProcessLinkHeaderForRequest( | 191 ProcessLinkHeaderForRequest( |
| 188 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), | 192 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), |
| 189 "<bar.js>; rel=serviceworker; " | 193 "<bar.js>; rel=serviceworker; " |
| 190 "scope=\"https://example.com:443/foo/bar/scope\"", | 194 "scope=\"https://example.com:443/foo/bar/scope\"", |
| 191 context_wrapper()); | 195 context_wrapper()); |
| 192 base::RunLoop().RunUntilIdle(); | 196 base::RunLoop().RunUntilIdle(); |
| 193 | 197 |
| 194 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 198 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 195 ASSERT_EQ(1u, registrations.size()); | 199 ASSERT_EQ(1u, registrations.size()); |
| 196 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), | 200 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), |
| 197 registrations[0].pattern); | 201 registrations[0].pattern); |
| 198 EXPECT_EQ(GURL("https://example.com/foo/bar/bar.js"), | 202 EXPECT_EQ(GURL("https://example.com/foo/bar/bar.js"), |
| 199 registrations[0].active_version.script_url); | 203 registrations[0].active_version.script_url); |
| 200 } | 204 } |
| 201 | 205 |
| 202 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeDifferentOrigin) { | 206 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeDifferentOrigin) { |
| 207 CreateDocumentProviderHost(); |
| 203 ProcessLinkHeaderForRequest( | 208 ProcessLinkHeaderForRequest( |
| 204 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), | 209 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
| 205 "<bar.js>; rel=serviceworker; scope=\"https://google.com/scope\"", | 210 "<bar.js>; rel=serviceworker; scope=\"https://google.com/scope\"", |
| 206 context_wrapper()); | 211 context_wrapper()); |
| 207 base::RunLoop().RunUntilIdle(); | 212 base::RunLoop().RunUntilIdle(); |
| 208 | 213 |
| 209 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 214 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 210 ASSERT_EQ(0u, registrations.size()); | 215 ASSERT_EQ(0u, registrations.size()); |
| 211 } | 216 } |
| 212 | 217 |
| 213 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeUrlEncodedSlash) { | 218 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeUrlEncodedSlash) { |
| 219 CreateDocumentProviderHost(); |
| 214 ProcessLinkHeaderForRequest( | 220 ProcessLinkHeaderForRequest( |
| 215 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), | 221 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
| 216 "<bar.js>; rel=serviceworker; scope=\"./foo%2Fbar\"", context_wrapper()); | 222 "<bar.js>; rel=serviceworker; scope=\"./foo%2Fbar\"", context_wrapper()); |
| 217 base::RunLoop().RunUntilIdle(); | 223 base::RunLoop().RunUntilIdle(); |
| 218 | 224 |
| 219 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 225 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 220 ASSERT_EQ(0u, registrations.size()); | 226 ASSERT_EQ(0u, registrations.size()); |
| 221 } | 227 } |
| 222 | 228 |
| 223 TEST_F(LinkHeaderServiceWorkerTest, | 229 TEST_F(LinkHeaderServiceWorkerTest, |
| 224 InstallServiceWorker_ScriptUrlEncodedSlash) { | 230 InstallServiceWorker_ScriptUrlEncodedSlash) { |
| 231 CreateDocumentProviderHost(); |
| 225 ProcessLinkHeaderForRequest( | 232 ProcessLinkHeaderForRequest( |
| 226 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), | 233 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
| 227 "<foo%2Fbar.js>; rel=serviceworker", context_wrapper()); | 234 "<foo%2Fbar.js>; rel=serviceworker", context_wrapper()); |
| 228 base::RunLoop().RunUntilIdle(); | 235 base::RunLoop().RunUntilIdle(); |
| 229 | 236 |
| 230 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 237 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 231 ASSERT_EQ(0u, registrations.size()); | 238 ASSERT_EQ(0u, registrations.size()); |
| 232 } | 239 } |
| 233 | 240 |
| 234 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScriptAbsoluteUrl) { | 241 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScriptAbsoluteUrl) { |
| 242 CreateDocumentProviderHost(); |
| 235 ProcessLinkHeaderForRequest( | 243 ProcessLinkHeaderForRequest( |
| 236 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), | 244 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
| 237 "<https://example.com/bar.js>; rel=serviceworker; scope=foo", | 245 "<https://example.com/bar.js>; rel=serviceworker; scope=foo", |
| 238 context_wrapper()); | 246 context_wrapper()); |
| 239 base::RunLoop().RunUntilIdle(); | 247 base::RunLoop().RunUntilIdle(); |
| 240 | 248 |
| 241 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 249 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 242 ASSERT_EQ(1u, registrations.size()); | 250 ASSERT_EQ(1u, registrations.size()); |
| 243 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); | 251 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); |
| 244 EXPECT_EQ(GURL("https://example.com/bar.js"), | 252 EXPECT_EQ(GURL("https://example.com/bar.js"), |
| 245 registrations[0].active_version.script_url); | 253 registrations[0].active_version.script_url); |
| 246 } | 254 } |
| 247 | 255 |
| 248 TEST_F(LinkHeaderServiceWorkerTest, | 256 TEST_F(LinkHeaderServiceWorkerTest, |
| 249 InstallServiceWorker_ScriptDifferentOrigin) { | 257 InstallServiceWorker_ScriptDifferentOrigin) { |
| 258 CreateDocumentProviderHost(); |
| 250 ProcessLinkHeaderForRequest( | 259 ProcessLinkHeaderForRequest( |
| 251 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), | 260 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
| 252 "<https://google.com/bar.js>; rel=serviceworker; scope=foo", | 261 "<https://google.com/bar.js>; rel=serviceworker; scope=foo", |
| 253 context_wrapper()); | 262 context_wrapper()); |
| 254 base::RunLoop().RunUntilIdle(); | 263 base::RunLoop().RunUntilIdle(); |
| 255 | 264 |
| 256 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 265 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 257 ASSERT_EQ(0u, registrations.size()); | 266 ASSERT_EQ(0u, registrations.size()); |
| 258 } | 267 } |
| 259 | 268 |
| 260 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_MultipleWorkers) { | 269 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_MultipleWorkers) { |
| 270 CreateDocumentProviderHost(); |
| 261 ProcessLinkHeaderForRequest( | 271 ProcessLinkHeaderForRequest( |
| 262 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), | 272 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
| 263 "<bar.js>; rel=serviceworker; scope=foo, <baz.js>; " | 273 "<bar.js>; rel=serviceworker; scope=foo, <baz.js>; " |
| 264 "rel=serviceworker; scope=scope", | 274 "rel=serviceworker; scope=scope", |
| 265 context_wrapper()); | 275 context_wrapper()); |
| 266 base::RunLoop().RunUntilIdle(); | 276 base::RunLoop().RunUntilIdle(); |
| 267 | 277 |
| 268 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 278 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 269 ASSERT_EQ(2u, registrations.size()); | 279 ASSERT_EQ(2u, registrations.size()); |
| 270 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); | 280 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); |
| 271 EXPECT_EQ(GURL("https://example.com/foobar/bar.js"), | 281 EXPECT_EQ(GURL("https://example.com/foobar/bar.js"), |
| 272 registrations[0].active_version.script_url); | 282 registrations[0].active_version.script_url); |
| 273 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[1].pattern); | 283 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[1].pattern); |
| 274 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), | 284 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), |
| 275 registrations[1].active_version.script_url); | 285 registrations[1].active_version.script_url); |
| 276 } | 286 } |
| 277 | 287 |
| 278 TEST_F(LinkHeaderServiceWorkerTest, | 288 TEST_F(LinkHeaderServiceWorkerTest, |
| 279 InstallServiceWorker_ValidAndInvalidValues) { | 289 InstallServiceWorker_ValidAndInvalidValues) { |
| 290 CreateDocumentProviderHost(); |
| 280 ProcessLinkHeaderForRequest( | 291 ProcessLinkHeaderForRequest( |
| 281 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), | 292 CreateSubresourceRequest(GURL("https://example.com/foobar/")).get(), |
| 282 "<https://google.com/bar.js>; rel=serviceworker; scope=foo, <baz.js>; " | 293 "<https://google.com/bar.js>; rel=serviceworker; scope=foo, <baz.js>; " |
| 283 "rel=serviceworker; scope=scope", | 294 "rel=serviceworker; scope=scope", |
| 284 context_wrapper()); | 295 context_wrapper()); |
| 285 base::RunLoop().RunUntilIdle(); | 296 base::RunLoop().RunUntilIdle(); |
| 286 | 297 |
| 287 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 298 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 288 ASSERT_EQ(1u, registrations.size()); | 299 ASSERT_EQ(1u, registrations.size()); |
| 289 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[0].pattern); | 300 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[0].pattern); |
| 290 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), | 301 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), |
| 291 registrations[0].active_version.script_url); | 302 registrations[0].active_version.script_url); |
| 292 } | 303 } |
| 293 | 304 |
| 294 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_InsecureContext) { | 305 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_InsecureContext) { |
| 306 CreateDocumentProviderHost(); |
| 295 std::unique_ptr<net::URLRequest> request = | 307 std::unique_ptr<net::URLRequest> request = |
| 296 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")); | 308 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")); |
| 297 ResourceRequestInfoImpl::ForRequest(request.get()) | 309 ResourceRequestInfoImpl::ForRequest(request.get()) |
| 298 ->set_initiated_in_secure_context_for_testing(false); | 310 ->set_initiated_in_secure_context_for_testing(false); |
| 299 ProcessLinkHeaderForRequest(request.get(), "<../foo.js>; rel=serviceworker", | 311 ProcessLinkHeaderForRequest(request.get(), "<../foo.js>; rel=serviceworker", |
| 300 context_wrapper()); | 312 context_wrapper()); |
| 301 base::RunLoop().RunUntilIdle(); | 313 base::RunLoop().RunUntilIdle(); |
| 302 | 314 |
| 303 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 315 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 304 ASSERT_EQ(0u, registrations.size()); | 316 ASSERT_EQ(0u, registrations.size()); |
| 305 } | 317 } |
| 306 | 318 |
| 307 TEST_F(LinkHeaderServiceWorkerTest, | 319 TEST_F(LinkHeaderServiceWorkerTest, |
| 308 InstallServiceWorker_NavigationFromInsecureContextToSecureContext) { | 320 InstallServiceWorker_NavigationFromInsecureContextToSecureContext) { |
| 321 CreateDocumentProviderHost(); |
| 309 std::unique_ptr<net::URLRequest> request = CreateRequest( | 322 std::unique_ptr<net::URLRequest> request = CreateRequest( |
| 310 GURL("https://example.com/foo/bar/"), RESOURCE_TYPE_MAIN_FRAME); | 323 GURL("https://example.com/foo/bar/"), RESOURCE_TYPE_MAIN_FRAME); |
| 311 ResourceRequestInfoImpl::ForRequest(request.get()) | 324 ResourceRequestInfoImpl::ForRequest(request.get()) |
| 312 ->set_initiated_in_secure_context_for_testing(false); | 325 ->set_initiated_in_secure_context_for_testing(false); |
| 313 | 326 |
| 314 provider_host()->SetDocumentUrl(GURL("https://example.com/foo/bar/")); | 327 provider_host()->SetDocumentUrl(GURL("https://example.com/foo/bar/")); |
| 315 provider_host()->set_parent_frame_secure(true); | |
| 316 | 328 |
| 317 ProcessLinkHeaderForRequest(request.get(), "<../foo.js>; rel=serviceworker", | 329 ProcessLinkHeaderForRequest(request.get(), "<../foo.js>; rel=serviceworker", |
| 318 context_wrapper()); | 330 context_wrapper()); |
| 319 base::RunLoop().RunUntilIdle(); | 331 base::RunLoop().RunUntilIdle(); |
| 320 | 332 |
| 321 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 333 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 322 ASSERT_EQ(1u, registrations.size()); | 334 ASSERT_EQ(1u, registrations.size()); |
| 323 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); | 335 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); |
| 324 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), | 336 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), |
| 325 registrations[0].active_version.script_url); | 337 registrations[0].active_version.script_url); |
| 326 } | 338 } |
| 327 | 339 |
| 328 TEST_F(LinkHeaderServiceWorkerTest, | 340 TEST_F(LinkHeaderServiceWorkerTest, |
| 329 InstallServiceWorker_NavigationToInsecureContext) { | 341 InstallServiceWorker_NavigationToInsecureContext) { |
| 342 CreateDocumentProviderHost(); |
| 330 provider_host()->SetDocumentUrl(GURL("http://example.com/foo/bar/")); | 343 provider_host()->SetDocumentUrl(GURL("http://example.com/foo/bar/")); |
| 331 provider_host()->set_parent_frame_secure(true); | |
| 332 ProcessLinkHeaderForRequest(CreateRequest(GURL("http://example.com/foo/bar/"), | 344 ProcessLinkHeaderForRequest(CreateRequest(GURL("http://example.com/foo/bar/"), |
| 333 RESOURCE_TYPE_MAIN_FRAME) | 345 RESOURCE_TYPE_MAIN_FRAME) |
| 334 .get(), | 346 .get(), |
| 335 "<../foo.js>; rel=serviceworker", | 347 "<../foo.js>; rel=serviceworker", |
| 336 context_wrapper()); | 348 context_wrapper()); |
| 337 base::RunLoop().RunUntilIdle(); | 349 base::RunLoop().RunUntilIdle(); |
| 338 | 350 |
| 339 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 351 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 340 ASSERT_EQ(0u, registrations.size()); | 352 ASSERT_EQ(0u, registrations.size()); |
| 341 } | 353 } |
| 342 | 354 |
| 343 TEST_F(LinkHeaderServiceWorkerTest, | 355 TEST_F(LinkHeaderServiceWorkerTest, |
| 344 InstallServiceWorker_NavigationToInsecureHttpsContext) { | 356 InstallServiceWorker_NavigationToInsecureHttpsContext) { |
| 357 CreateDocumentProviderHost(false); |
| 345 provider_host()->SetDocumentUrl(GURL("https://example.com/foo/bar/")); | 358 provider_host()->SetDocumentUrl(GURL("https://example.com/foo/bar/")); |
| 346 provider_host()->set_parent_frame_secure(false); | |
| 347 ProcessLinkHeaderForRequest( | 359 ProcessLinkHeaderForRequest( |
| 348 CreateRequest(GURL("https://example.com/foo/bar/"), | 360 CreateRequest(GURL("https://example.com/foo/bar/"), |
| 349 RESOURCE_TYPE_MAIN_FRAME) | 361 RESOURCE_TYPE_MAIN_FRAME) |
| 350 .get(), | 362 .get(), |
| 351 "<../foo.js>; rel=serviceworker", context_wrapper()); | 363 "<../foo.js>; rel=serviceworker", context_wrapper()); |
| 352 base::RunLoop().RunUntilIdle(); | 364 base::RunLoop().RunUntilIdle(); |
| 353 | 365 |
| 354 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 366 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 355 ASSERT_EQ(0u, registrations.size()); | 367 ASSERT_EQ(0u, registrations.size()); |
| 356 } | 368 } |
| 357 | 369 |
| 358 TEST_F(LinkHeaderServiceWorkerTest, | 370 TEST_F(LinkHeaderServiceWorkerTest, |
| 359 InstallServiceWorker_FromWorkerWithoutControllees) { | 371 InstallServiceWorker_FromWorkerWithoutControllees) { |
| 360 CreateServiceWorkerProviderHost(); | 372 CreateServiceWorkerProviderHost(); |
| 361 ProcessLinkHeaderForRequest( | 373 ProcessLinkHeaderForRequest( |
| 362 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), | 374 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), |
| 363 "<../foo.js>; rel=serviceworker", context_wrapper()); | 375 "<../foo.js>; rel=serviceworker", context_wrapper()); |
| 364 base::RunLoop().RunUntilIdle(); | 376 base::RunLoop().RunUntilIdle(); |
| 365 | 377 |
| 366 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 378 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 367 ASSERT_EQ(0u, registrations.size()); | 379 ASSERT_EQ(0u, registrations.size()); |
| 368 } | 380 } |
| 369 | 381 |
| 370 TEST_F(LinkHeaderServiceWorkerTest, | 382 TEST_F(LinkHeaderServiceWorkerTest, |
| 371 InstallServiceWorker_FromWorkerWithControllees) { | 383 InstallServiceWorker_FromWorkerWithControllees) { |
| 372 CreateServiceWorkerProviderHost(); | 384 CreateServiceWorkerProviderHost(); |
| 373 | 385 |
| 374 std::unique_ptr<ServiceWorkerProviderHost> controllee( | 386 std::unique_ptr<ServiceWorkerProviderHost> controllee = |
| 375 new ServiceWorkerProviderHost( | 387 CreateProviderHostForWindow(render_process_id(), kMockProviderId, |
| 376 render_process_id(), MSG_ROUTING_NONE, kMockProviderId, | 388 true /* is_parent_frame_secure */, |
| 377 SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 389 context()->AsWeakPtr()); |
| 378 ServiceWorkerProviderHost::FrameSecurityLevel::UNINITIALIZED, | |
| 379 context()->AsWeakPtr(), nullptr)); | |
| 380 provider_host()->running_hosted_version()->AddControllee(controllee.get()); | 390 provider_host()->running_hosted_version()->AddControllee(controllee.get()); |
| 381 | 391 |
| 382 ProcessLinkHeaderForRequest( | 392 ProcessLinkHeaderForRequest( |
| 383 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), | 393 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), |
| 384 "<../foo.js>; rel=serviceworker", context_wrapper()); | 394 "<../foo.js>; rel=serviceworker", context_wrapper()); |
| 385 base::RunLoop().RunUntilIdle(); | 395 base::RunLoop().RunUntilIdle(); |
| 386 | 396 |
| 387 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 397 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 388 ASSERT_EQ(1u, registrations.size()); | 398 ASSERT_EQ(1u, registrations.size()); |
| 389 } | 399 } |
| 390 | 400 |
| 391 } // namespace content | 401 } // namespace content |
| OLD | NEW |