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

Unified Diff: content/browser/service_worker/service_worker_registration_unittest.cc

Issue 2455493002: service worker: Propagate navigation preload flag to SWVersion. (Closed)
Patch Set: more comment Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_registration_unittest.cc
diff --git a/content/browser/service_worker/service_worker_registration_unittest.cc b/content/browser/service_worker/service_worker_registration_unittest.cc
index e06387b3f76d0851ff701227aeb8088b9ae5cb73..c7924b63f720f8b48de3de3be1f71f3d0c8c7374 100644
--- a/content/browser/service_worker/service_worker_registration_unittest.cc
+++ b/content/browser/service_worker/service_worker_registration_unittest.cc
@@ -184,6 +184,42 @@ TEST_P(ServiceWorkerRegistrationTestP, FailedRegistrationNoCrash) {
// Don't crash when handle gets destructed.
}
+TEST_P(ServiceWorkerRegistrationTestP, NavigationPreload) {
+ const GURL kScope("http://www.example.not/");
+ const GURL kScript("https://www.example.not/service_worker.js");
+ // Setup.
+ scoped_refptr<ServiceWorkerRegistration> registration =
+ new ServiceWorkerRegistration(kScope, storage()->NewRegistrationId(),
+ context()->AsWeakPtr());
+ scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion(
+ registration.get(), kScript, storage()->NewVersionId(),
+ context()->AsWeakPtr());
+ version_1->set_fetch_handler_existence(
+ ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
+ registration->SetActiveVersion(version_1);
+ version_1->SetStatus(ServiceWorkerVersion::ACTIVATED);
+ scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion(
+ registration.get(), kScript, storage()->NewVersionId(),
+ context()->AsWeakPtr());
+ version_2->set_fetch_handler_existence(
+ ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
+ registration->SetWaitingVersion(version_2);
+ version_2->SetStatus(ServiceWorkerVersion::INSTALLED);
+
+ // Navigation preload is disabled by default.
+ EXPECT_FALSE(version_1->navigation_preload_enabled());
+ // Enabling it sets the flag on the active version.
+ registration->EnableNavigationPreload(true);
+ EXPECT_TRUE(version_1->navigation_preload_enabled());
+ // A new active version gets the flag.
+ registration->SetActiveVersion(version_2);
+ version_2->SetStatus(ServiceWorkerVersion::ACTIVATING);
+ EXPECT_TRUE(version_2->navigation_preload_enabled());
+ // Disabling it unsets the flag on the active version.
+ registration->EnableNavigationPreload(false);
+ EXPECT_FALSE(version_2->navigation_preload_enabled());
+}
+
// Sets up a registration with a waiting worker, and an active worker
// with a controllee and an inflight request.
class ServiceWorkerActivationTest : public ServiceWorkerRegistrationTestP {
« no previous file with comments | « content/browser/service_worker/service_worker_registration.cc ('k') | content/browser/service_worker/service_worker_version.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698