OLD | NEW |
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_registration.h" | 5 #include "content/browser/service_worker/service_worker_registration.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 new ServiceWorkerRegistration(kScope, kRegistrationId, | 177 new ServiceWorkerRegistration(kScope, kRegistrationId, |
178 context()->AsWeakPtr()); | 178 context()->AsWeakPtr()); |
179 std::unique_ptr<ServiceWorkerRegistrationHandle> handle( | 179 std::unique_ptr<ServiceWorkerRegistrationHandle> handle( |
180 new ServiceWorkerRegistrationHandle( | 180 new ServiceWorkerRegistrationHandle( |
181 context()->AsWeakPtr(), base::WeakPtr<ServiceWorkerProviderHost>(), | 181 context()->AsWeakPtr(), base::WeakPtr<ServiceWorkerProviderHost>(), |
182 registration.get())); | 182 registration.get())); |
183 registration->NotifyRegistrationFailed(); | 183 registration->NotifyRegistrationFailed(); |
184 // Don't crash when handle gets destructed. | 184 // Don't crash when handle gets destructed. |
185 } | 185 } |
186 | 186 |
| 187 TEST_P(ServiceWorkerRegistrationTestP, NavigationPreload) { |
| 188 const GURL kScope("http://www.example.not/"); |
| 189 const GURL kScript("https://www.example.not/service_worker.js"); |
| 190 // Setup. |
| 191 scoped_refptr<ServiceWorkerRegistration> registration = |
| 192 new ServiceWorkerRegistration(kScope, storage()->NewRegistrationId(), |
| 193 context()->AsWeakPtr()); |
| 194 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( |
| 195 registration.get(), kScript, storage()->NewVersionId(), |
| 196 context()->AsWeakPtr()); |
| 197 version_1->set_fetch_handler_existence( |
| 198 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); |
| 199 registration->SetActiveVersion(version_1); |
| 200 version_1->SetStatus(ServiceWorkerVersion::ACTIVATED); |
| 201 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion( |
| 202 registration.get(), kScript, storage()->NewVersionId(), |
| 203 context()->AsWeakPtr()); |
| 204 version_2->set_fetch_handler_existence( |
| 205 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); |
| 206 registration->SetWaitingVersion(version_2); |
| 207 version_2->SetStatus(ServiceWorkerVersion::INSTALLED); |
| 208 |
| 209 // Navigation preload is disabled by default. |
| 210 EXPECT_FALSE(version_1->navigation_preload_enabled()); |
| 211 // Enabling it sets the flag on the active version. |
| 212 registration->EnableNavigationPreload(true); |
| 213 EXPECT_TRUE(version_1->navigation_preload_enabled()); |
| 214 // A new active version gets the flag. |
| 215 registration->SetActiveVersion(version_2); |
| 216 version_2->SetStatus(ServiceWorkerVersion::ACTIVATING); |
| 217 EXPECT_TRUE(version_2->navigation_preload_enabled()); |
| 218 // Disabling it unsets the flag on the active version. |
| 219 registration->EnableNavigationPreload(false); |
| 220 EXPECT_FALSE(version_2->navigation_preload_enabled()); |
| 221 } |
| 222 |
187 // Sets up a registration with a waiting worker, and an active worker | 223 // Sets up a registration with a waiting worker, and an active worker |
188 // with a controllee and an inflight request. | 224 // with a controllee and an inflight request. |
189 class ServiceWorkerActivationTest : public ServiceWorkerRegistrationTestP { | 225 class ServiceWorkerActivationTest : public ServiceWorkerRegistrationTestP { |
190 public: | 226 public: |
191 ServiceWorkerActivationTest() : ServiceWorkerRegistrationTestP() {} | 227 ServiceWorkerActivationTest() : ServiceWorkerRegistrationTestP() {} |
192 | 228 |
193 void SetUp() override { | 229 void SetUp() override { |
194 ServiceWorkerRegistrationTest::SetUp(); | 230 ServiceWorkerRegistrationTest::SetUp(); |
195 | 231 |
196 const GURL kScope("https://www.example.not/"); | 232 const GURL kScope("https://www.example.not/"); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 377 |
342 INSTANTIATE_TEST_CASE_P(ServiceWorkerRegistrationTest, | 378 INSTANTIATE_TEST_CASE_P(ServiceWorkerRegistrationTest, |
343 ServiceWorkerRegistrationTestP, | 379 ServiceWorkerRegistrationTestP, |
344 testing::Bool()); | 380 testing::Bool()); |
345 | 381 |
346 INSTANTIATE_TEST_CASE_P(ServiceWorkerActivationTest, | 382 INSTANTIATE_TEST_CASE_P(ServiceWorkerActivationTest, |
347 ServiceWorkerActivationTest, | 383 ServiceWorkerActivationTest, |
348 testing::Bool()); | 384 testing::Bool()); |
349 | 385 |
350 } // namespace content | 386 } // namespace content |
OLD | NEW |