Chromium Code Reviews| 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/service_worker/embedded_worker_test_helper.h" | 11 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 11 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 12 #include "content/browser/service_worker/service_worker_registration.h" | 13 #include "content/browser/service_worker/service_worker_registration.h" |
| 13 #include "content/public/browser/resource_request_info.h" | 14 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 14 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 15 #include "content/public/test/mock_resource_context.h" | 16 #include "content/public/test/mock_resource_context.h" |
| 16 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
| 18 #include "net/url_request/url_request_test_job.h" | 19 #include "net/url_request/url_request_test_job.h" |
| 19 #include "net/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
| 21 #include "storage/browser/blob/blob_storage_context.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 23 |
| 22 namespace content { | 24 namespace content { |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 28 const int kMockProviderId = 1; | |
| 29 | |
| 26 void SaveFoundRegistrationsCallback( | 30 void SaveFoundRegistrationsCallback( |
| 27 ServiceWorkerStatusCode expected_status, | 31 ServiceWorkerStatusCode expected_status, |
| 28 bool* called, | 32 bool* called, |
| 29 std::vector<ServiceWorkerRegistrationInfo>* registrations, | 33 std::vector<ServiceWorkerRegistrationInfo>* registrations, |
| 30 ServiceWorkerStatusCode status, | 34 ServiceWorkerStatusCode status, |
| 31 const std::vector<ServiceWorkerRegistrationInfo>& result) { | 35 const std::vector<ServiceWorkerRegistrationInfo>& result) { |
| 32 EXPECT_EQ(expected_status, status); | 36 EXPECT_EQ(expected_status, status); |
| 33 *called = true; | 37 *called = true; |
| 34 *registrations = result; | 38 *registrations = result; |
| 35 } | 39 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 49 LinkHeaderServiceWorkerTest() | 53 LinkHeaderServiceWorkerTest() |
| 50 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 54 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
| 51 resource_context_(&request_context_) { | 55 resource_context_(&request_context_) { |
| 52 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 56 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 53 switches::kEnableExperimentalWebPlatformFeatures); | 57 switches::kEnableExperimentalWebPlatformFeatures); |
| 54 } | 58 } |
| 55 ~LinkHeaderServiceWorkerTest() override {} | 59 ~LinkHeaderServiceWorkerTest() override {} |
| 56 | 60 |
| 57 void SetUp() override { | 61 void SetUp() override { |
| 58 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); | 62 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); |
| 63 | |
| 64 // An empty host. | |
| 65 std::unique_ptr<ServiceWorkerProviderHost> host( | |
| 66 new ServiceWorkerProviderHost( | |
| 67 helper_->mock_render_process_id(), MSG_ROUTING_NONE, | |
| 68 kMockProviderId, SERVICE_WORKER_PROVIDER_FOR_WINDOW, | |
| 69 ServiceWorkerProviderHost::FrameSecurityLevel::UNINITIALIZED, | |
| 70 context()->AsWeakPtr(), nullptr)); | |
| 71 provider_host_ = host->AsWeakPtr(); | |
| 72 context()->AddProviderHost(std::move(host)); | |
| 59 } | 73 } |
| 60 | 74 |
| 61 void TearDown() override { helper_.reset(); } | 75 void TearDown() override { helper_.reset(); } |
| 62 | 76 |
| 77 ServiceWorkerContextCore* context() const { return helper_->context(); } | |
|
kinuko
2016/06/23 14:42:27
nit: avoid returning non const ptr from const meth
Marijn Kruisselbrink
2016/06/23 18:02:01
removed the const. (fwiw, this particular const me
| |
| 63 ServiceWorkerContextWrapper* context_wrapper() { | 78 ServiceWorkerContextWrapper* context_wrapper() { |
| 64 return helper_->context_wrapper(); | 79 return helper_->context_wrapper(); |
| 65 } | 80 } |
| 81 ServiceWorkerProviderHost* provider_host() const { | |
|
kinuko
2016/06/23 14:42:27
ditto
Marijn Kruisselbrink
2016/06/23 18:02:01
Done
| |
| 82 return provider_host_.get(); | |
| 83 } | |
| 66 | 84 |
| 67 void ProcessLinkHeader(const GURL& request_url, | 85 void ProcessLinkHeader(const GURL& request_url, |
| 68 const std::string& link_header) { | 86 const std::string& link_header, |
| 87 bool secure_context, | |
| 88 ResourceType resource_type = RESOURCE_TYPE_SCRIPT) { | |
|
kinuko
2016/06/23 14:42:27
Adding bool parameter makes the code harder to rea
Marijn Kruisselbrink
2016/06/23 18:02:01
Yeah, having default parameters and bool parameter
| |
| 69 std::unique_ptr<net::URLRequest> request = request_context_.CreateRequest( | 89 std::unique_ptr<net::URLRequest> request = request_context_.CreateRequest( |
| 70 request_url, net::DEFAULT_PRIORITY, &request_delegate_); | 90 request_url, net::DEFAULT_PRIORITY, &request_delegate_); |
| 71 ResourceRequestInfo::AllocateForTesting( | 91 ResourceRequestInfo::AllocateForTesting( |
| 72 request.get(), RESOURCE_TYPE_SCRIPT, &resource_context_, | 92 request.get(), resource_type, &resource_context_, |
| 73 -1 /* render_process_id */, -1 /* render_view_id */, | 93 -1 /* render_process_id */, -1 /* render_view_id */, |
| 74 -1 /* render_frame_id */, false /* is_main_frame */, | 94 -1 /* render_frame_id */, resource_type == RESOURCE_TYPE_MAIN_FRAME, |
| 75 false /* parent_is_main_frame */, true /* allow_download */, | 95 false /* parent_is_main_frame */, true /* allow_download */, |
| 76 true /* is_async */, false /* is_using_lofi */); | 96 true /* is_async */, false /* is_using_lofi */); |
| 97 ResourceRequestInfoImpl::ForRequest(request.get()) | |
| 98 ->set_initiated_in_secure_context_for_testing(secure_context); | |
| 99 | |
| 100 ServiceWorkerRequestHandler::InitializeHandler( | |
| 101 request.get(), context_wrapper(), &blob_storage_context_, | |
| 102 helper_->mock_render_process_id(), kMockProviderId, | |
| 103 false /* skip_service_worker */, FETCH_REQUEST_MODE_NO_CORS, | |
| 104 FETCH_CREDENTIALS_MODE_OMIT, FetchRedirectMode::FOLLOW_MODE, | |
| 105 resource_type, REQUEST_CONTEXT_TYPE_HYPERLINK, | |
| 106 REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL, nullptr); | |
| 77 | 107 |
| 78 ProcessLinkHeaderForRequest(request.get(), link_header, context_wrapper()); | 108 ProcessLinkHeaderForRequest(request.get(), link_header, context_wrapper()); |
| 79 base::RunLoop().RunUntilIdle(); | 109 base::RunLoop().RunUntilIdle(); |
| 80 } | 110 } |
| 81 | 111 |
| 82 std::vector<ServiceWorkerRegistrationInfo> GetRegistrations() { | 112 std::vector<ServiceWorkerRegistrationInfo> GetRegistrations() { |
| 83 bool called; | 113 bool called; |
| 84 std::vector<ServiceWorkerRegistrationInfo> registrations; | 114 std::vector<ServiceWorkerRegistrationInfo> registrations; |
| 85 context_wrapper()->GetAllRegistrations( | 115 context_wrapper()->GetAllRegistrations( |
| 86 SaveFoundRegistrations(SERVICE_WORKER_OK, &called, ®istrations)); | 116 SaveFoundRegistrations(SERVICE_WORKER_OK, &called, ®istrations)); |
| 87 base::RunLoop().RunUntilIdle(); | 117 base::RunLoop().RunUntilIdle(); |
| 88 EXPECT_TRUE(called); | 118 EXPECT_TRUE(called); |
| 89 return registrations; | 119 return registrations; |
| 90 } | 120 } |
| 91 | 121 |
| 92 private: | 122 private: |
| 93 TestBrowserThreadBundle thread_bundle_; | 123 TestBrowserThreadBundle thread_bundle_; |
| 94 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 124 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
| 95 net::TestURLRequestContext request_context_; | 125 net::TestURLRequestContext request_context_; |
| 96 net::TestDelegate request_delegate_; | 126 net::TestDelegate request_delegate_; |
| 97 MockResourceContext resource_context_; | 127 MockResourceContext resource_context_; |
| 128 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | |
| 129 storage::BlobStorageContext blob_storage_context_; | |
| 98 }; | 130 }; |
| 99 | 131 |
| 100 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_Basic) { | 132 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_Basic) { |
| 101 ProcessLinkHeader(GURL("https://example.com/foo/bar/"), | 133 ProcessLinkHeader(GURL("https://example.com/foo/bar/"), |
| 102 "<../foo.js>; rel=serviceworker"); | 134 "<../foo.js>; rel=serviceworker", true); |
| 103 | 135 |
| 104 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 136 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 105 ASSERT_EQ(1u, registrations.size()); | 137 ASSERT_EQ(1u, registrations.size()); |
| 106 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); | 138 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); |
| 107 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), | 139 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), |
| 108 registrations[0].active_version.script_url); | 140 registrations[0].active_version.script_url); |
| 109 } | 141 } |
| 110 | 142 |
| 111 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeWithFragment) { | 143 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeWithFragment) { |
| 112 ProcessLinkHeader(GURL("https://example.com/foo/bar/"), | 144 ProcessLinkHeader(GURL("https://example.com/foo/bar/"), |
| 113 "<../bar.js>; rel=serviceworker; scope=\"scope#ref\""); | 145 "<../bar.js>; rel=serviceworker; scope=\"scope#ref\"", |
| 146 true); | |
| 114 | 147 |
| 115 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 148 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 116 ASSERT_EQ(1u, registrations.size()); | 149 ASSERT_EQ(1u, registrations.size()); |
| 117 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), | 150 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), |
| 118 registrations[0].pattern); | 151 registrations[0].pattern); |
| 119 EXPECT_EQ(GURL("https://example.com/foo/bar.js"), | 152 EXPECT_EQ(GURL("https://example.com/foo/bar.js"), |
| 120 registrations[0].active_version.script_url); | 153 registrations[0].active_version.script_url); |
| 121 } | 154 } |
| 122 | 155 |
| 123 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeAbsoluteUrl) { | 156 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeAbsoluteUrl) { |
| 124 ProcessLinkHeader(GURL("https://example.com/foo/bar/"), | 157 ProcessLinkHeader(GURL("https://example.com/foo/bar/"), |
| 125 "<bar.js>; rel=serviceworker; " | 158 "<bar.js>; rel=serviceworker; " |
| 126 "scope=\"https://example.com:443/foo/bar/scope\""); | 159 "scope=\"https://example.com:443/foo/bar/scope\"", |
| 160 true); | |
| 127 | 161 |
| 128 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 162 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 129 ASSERT_EQ(1u, registrations.size()); | 163 ASSERT_EQ(1u, registrations.size()); |
| 130 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), | 164 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), |
| 131 registrations[0].pattern); | 165 registrations[0].pattern); |
| 132 EXPECT_EQ(GURL("https://example.com/foo/bar/bar.js"), | 166 EXPECT_EQ(GURL("https://example.com/foo/bar/bar.js"), |
| 133 registrations[0].active_version.script_url); | 167 registrations[0].active_version.script_url); |
| 134 } | 168 } |
| 135 | 169 |
| 136 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeDifferentOrigin) { | 170 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeDifferentOrigin) { |
| 137 ProcessLinkHeader( | 171 ProcessLinkHeader( |
| 138 GURL("https://example.com/foobar/"), | 172 GURL("https://example.com/foobar/"), |
| 139 "<bar.js>; rel=serviceworker; scope=\"https://google.com/scope\""); | 173 "<bar.js>; rel=serviceworker; scope=\"https://google.com/scope\"", true); |
| 140 | 174 |
| 141 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 175 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 142 ASSERT_EQ(0u, registrations.size()); | 176 ASSERT_EQ(0u, registrations.size()); |
| 143 } | 177 } |
| 144 | 178 |
| 145 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeUrlEncodedSlash) { | 179 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeUrlEncodedSlash) { |
| 146 ProcessLinkHeader(GURL("https://example.com/foobar/"), | 180 ProcessLinkHeader(GURL("https://example.com/foobar/"), |
| 147 "<bar.js>; rel=serviceworker; scope=\"./foo%2Fbar\""); | 181 "<bar.js>; rel=serviceworker; scope=\"./foo%2Fbar\"", true); |
| 148 | 182 |
| 149 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 183 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 150 ASSERT_EQ(0u, registrations.size()); | 184 ASSERT_EQ(0u, registrations.size()); |
| 151 } | 185 } |
| 152 | 186 |
| 153 TEST_F(LinkHeaderServiceWorkerTest, | 187 TEST_F(LinkHeaderServiceWorkerTest, |
| 154 InstallServiceWorker_ScriptUrlEncodedSlash) { | 188 InstallServiceWorker_ScriptUrlEncodedSlash) { |
| 155 ProcessLinkHeader(GURL("https://example.com/foobar/"), | 189 ProcessLinkHeader(GURL("https://example.com/foobar/"), |
| 156 "<foo%2Fbar.js>; rel=serviceworker"); | 190 "<foo%2Fbar.js>; rel=serviceworker", true); |
| 157 | 191 |
| 158 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 192 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 159 ASSERT_EQ(0u, registrations.size()); | 193 ASSERT_EQ(0u, registrations.size()); |
| 160 } | 194 } |
| 161 | 195 |
| 162 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScriptAbsoluteUrl) { | 196 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScriptAbsoluteUrl) { |
| 163 ProcessLinkHeader( | 197 ProcessLinkHeader( |
| 164 GURL("https://example.com/foobar/"), | 198 GURL("https://example.com/foobar/"), |
| 165 "<https://example.com/bar.js>; rel=serviceworker; scope=foo"); | 199 "<https://example.com/bar.js>; rel=serviceworker; scope=foo", true); |
| 166 | 200 |
| 167 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 201 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 168 ASSERT_EQ(1u, registrations.size()); | 202 ASSERT_EQ(1u, registrations.size()); |
| 169 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); | 203 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); |
| 170 EXPECT_EQ(GURL("https://example.com/bar.js"), | 204 EXPECT_EQ(GURL("https://example.com/bar.js"), |
| 171 registrations[0].active_version.script_url); | 205 registrations[0].active_version.script_url); |
| 172 } | 206 } |
| 173 | 207 |
| 174 TEST_F(LinkHeaderServiceWorkerTest, | 208 TEST_F(LinkHeaderServiceWorkerTest, |
| 175 InstallServiceWorker_ScriptDifferentOrigin) { | 209 InstallServiceWorker_ScriptDifferentOrigin) { |
| 176 ProcessLinkHeader( | 210 ProcessLinkHeader(GURL("https://example.com/foobar/"), |
| 177 GURL("https://example.com/foobar/"), | 211 "<https://google.com/bar.js>; rel=serviceworker; scope=foo", |
| 178 "<https://google.com/bar.js>; rel=serviceworker; scope=foo"); | 212 true); |
| 179 | 213 |
| 180 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 214 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 181 ASSERT_EQ(0u, registrations.size()); | 215 ASSERT_EQ(0u, registrations.size()); |
| 182 } | 216 } |
| 183 | 217 |
| 184 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_MultipleWorkers) { | 218 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_MultipleWorkers) { |
| 185 ProcessLinkHeader(GURL("https://example.com/foobar/"), | 219 ProcessLinkHeader(GURL("https://example.com/foobar/"), |
| 186 "<bar.js>; rel=serviceworker; scope=foo, <baz.js>; " | 220 "<bar.js>; rel=serviceworker; scope=foo, <baz.js>; " |
| 187 "rel=serviceworker; scope=scope"); | 221 "rel=serviceworker; scope=scope", |
| 222 true); | |
| 188 | 223 |
| 189 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 224 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 190 ASSERT_EQ(2u, registrations.size()); | 225 ASSERT_EQ(2u, registrations.size()); |
| 191 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); | 226 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); |
| 192 EXPECT_EQ(GURL("https://example.com/foobar/bar.js"), | 227 EXPECT_EQ(GURL("https://example.com/foobar/bar.js"), |
| 193 registrations[0].active_version.script_url); | 228 registrations[0].active_version.script_url); |
| 194 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[1].pattern); | 229 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[1].pattern); |
| 195 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), | 230 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), |
| 196 registrations[1].active_version.script_url); | 231 registrations[1].active_version.script_url); |
| 197 } | 232 } |
| 198 | 233 |
| 199 TEST_F(LinkHeaderServiceWorkerTest, | 234 TEST_F(LinkHeaderServiceWorkerTest, |
| 200 InstallServiceWorker_ValidAndInvalidValues) { | 235 InstallServiceWorker_ValidAndInvalidValues) { |
| 201 ProcessLinkHeader( | 236 ProcessLinkHeader( |
| 202 GURL("https://example.com/foobar/"), | 237 GURL("https://example.com/foobar/"), |
| 203 "<https://google.com/bar.js>; rel=serviceworker; scope=foo, <baz.js>; " | 238 "<https://google.com/bar.js>; rel=serviceworker; scope=foo, <baz.js>; " |
| 204 "rel=serviceworker; scope=scope"); | 239 "rel=serviceworker; scope=scope", |
| 240 true); | |
| 205 | 241 |
| 206 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | 242 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
| 207 ASSERT_EQ(1u, registrations.size()); | 243 ASSERT_EQ(1u, registrations.size()); |
| 208 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[0].pattern); | 244 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[0].pattern); |
| 209 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), | 245 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), |
| 210 registrations[0].active_version.script_url); | 246 registrations[0].active_version.script_url); |
| 211 } | 247 } |
| 212 | 248 |
| 249 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_InsecureContext) { | |
| 250 ProcessLinkHeader(GURL("https://example.com/foo/bar/"), | |
| 251 "<../foo.js>; rel=serviceworker", false); | |
| 252 | |
| 253 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | |
| 254 ASSERT_EQ(0u, registrations.size()); | |
| 255 } | |
| 256 | |
| 257 TEST_F(LinkHeaderServiceWorkerTest, | |
| 258 InstallServiceWorker_NavigationFromInsecureContextToSecureContext) { | |
| 259 provider_host()->SetDocumentUrl(GURL("https://example.com/foo/bar/")); | |
| 260 provider_host()->set_parent_frame_secure(true); | |
| 261 ProcessLinkHeader(GURL("https://example.com/foo/bar/"), | |
| 262 "<../foo.js>; rel=serviceworker", false, | |
| 263 RESOURCE_TYPE_MAIN_FRAME); | |
| 264 | |
| 265 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | |
| 266 ASSERT_EQ(1u, registrations.size()); | |
| 267 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); | |
| 268 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), | |
| 269 registrations[0].active_version.script_url); | |
| 270 } | |
| 271 | |
| 272 TEST_F(LinkHeaderServiceWorkerTest, | |
| 273 InstallServiceWorker_NavigationToInsecureContext) { | |
| 274 provider_host()->SetDocumentUrl(GURL("http://example.com/foo/bar/")); | |
| 275 provider_host()->set_parent_frame_secure(true); | |
| 276 ProcessLinkHeader(GURL("http://example.com/foo/bar/"), | |
| 277 "<../foo.js>; rel=serviceworker", true, | |
| 278 RESOURCE_TYPE_MAIN_FRAME); | |
| 279 | |
| 280 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | |
| 281 ASSERT_EQ(0u, registrations.size()); | |
| 282 } | |
| 283 | |
| 284 TEST_F(LinkHeaderServiceWorkerTest, | |
| 285 InstallServiceWorker_NavigationToInsecureHttpsContext) { | |
| 286 provider_host()->SetDocumentUrl(GURL("https://example.com/foo/bar/")); | |
| 287 provider_host()->set_parent_frame_secure(false); | |
| 288 ProcessLinkHeader(GURL("http://example.com/foo/bar/"), | |
| 289 "<../foo.js>; rel=serviceworker", true, | |
| 290 RESOURCE_TYPE_MAIN_FRAME); | |
| 291 | |
| 292 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); | |
| 293 ASSERT_EQ(0u, registrations.size()); | |
| 294 } | |
| 295 | |
| 213 } // namespace | 296 } // namespace |
| 214 | 297 |
| 215 } // namespace content | 298 } // namespace content |
| OLD | NEW |