Index: content/browser/service_worker/link_header_support_unittest.cc |
diff --git a/content/browser/service_worker/link_header_support_unittest.cc b/content/browser/service_worker/link_header_support_unittest.cc |
index e77c68d9517028742911f3d5173f06adc8a90dbd..47226e8e38bf6c95042d13b5c697be58d1082ce2 100644 |
--- a/content/browser/service_worker/link_header_support_unittest.cc |
+++ b/content/browser/service_worker/link_header_support_unittest.cc |
@@ -118,8 +118,9 @@ class LinkHeaderServiceWorkerTest : public ::testing::Test { |
context()->AddProviderHost(std::move(host)); |
scoped_refptr<ServiceWorkerRegistration> registration = |
- new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, |
- context()->AsWeakPtr()); |
+ new ServiceWorkerRegistration( |
+ ServiceWorkerRegistrationOptions(GURL("https://host/scope")), 1L, |
+ context()->AsWeakPtr()); |
scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( |
registration.get(), GURL("https://host/script.js"), 1L, |
context()->AsWeakPtr()); |
@@ -194,6 +195,8 @@ TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_Basic) { |
EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); |
EXPECT_EQ(GURL("https://example.com/foo/foo.js"), |
registrations[0].active_version.script_url); |
+ EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kImports, |
+ registrations[0].update_via_cache); |
} |
TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeWithFragment) { |
@@ -211,6 +214,8 @@ TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeWithFragment) { |
registrations[0].pattern); |
EXPECT_EQ(GURL("https://example.com/foo/bar.js"), |
registrations[0].active_version.script_url); |
+ EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kImports, |
+ registrations[0].update_via_cache); |
} |
TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeAbsoluteUrl) { |
@@ -230,6 +235,8 @@ TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeAbsoluteUrl) { |
registrations[0].pattern); |
EXPECT_EQ(GURL("https://example.com/foo/bar/bar.js"), |
registrations[0].active_version.script_url); |
+ EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kImports, |
+ registrations[0].update_via_cache); |
} |
TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeDifferentOrigin) { |
@@ -288,6 +295,8 @@ TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScriptAbsoluteUrl) { |
EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); |
EXPECT_EQ(GURL("https://example.com/bar.js"), |
registrations[0].active_version.script_url); |
+ EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kImports, |
+ registrations[0].update_via_cache); |
} |
TEST_F(LinkHeaderServiceWorkerTest, |
@@ -305,6 +314,80 @@ TEST_F(LinkHeaderServiceWorkerTest, |
ASSERT_EQ(0u, registrations.size()); |
} |
+TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_CacheNone) { |
+ CreateDocumentProviderHost(); |
+ ProcessLinkHeaderForRequest( |
+ CreateSubresourceRequest(GURL("https://example.com/foo/bar/"), |
+ provider_host()->provider_id()) |
+ .get(), |
+ "<../foo.js>; rel=serviceworker; updateviacache=none", context_wrapper()); |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
+ ASSERT_EQ(1u, registrations.size()); |
+ EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); |
+ EXPECT_EQ(GURL("https://example.com/foo/foo.js"), |
+ registrations[0].active_version.script_url); |
+ EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kNone, |
+ registrations[0].update_via_cache); |
+} |
+ |
+TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_CacheImports) { |
+ CreateDocumentProviderHost(); |
+ ProcessLinkHeaderForRequest( |
+ CreateSubresourceRequest(GURL("https://example.com/foo/bar/"), |
+ provider_host()->provider_id()) |
+ .get(), |
+ "<../foo.js>; rel=serviceworker; updateviacache=imports", |
+ context_wrapper()); |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
+ ASSERT_EQ(1u, registrations.size()); |
+ EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); |
+ EXPECT_EQ(GURL("https://example.com/foo/foo.js"), |
+ registrations[0].active_version.script_url); |
+ EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kImports, |
+ registrations[0].update_via_cache); |
+} |
+ |
+TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_CacheAll) { |
+ CreateDocumentProviderHost(); |
+ ProcessLinkHeaderForRequest( |
+ CreateSubresourceRequest(GURL("https://example.com/foo/bar/"), |
+ provider_host()->provider_id()) |
+ .get(), |
+ "<../foo.js>; rel=serviceworker; updateviacache=all", context_wrapper()); |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
+ ASSERT_EQ(1u, registrations.size()); |
+ EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); |
+ EXPECT_EQ(GURL("https://example.com/foo/foo.js"), |
+ registrations[0].active_version.script_url); |
+ EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kAll, |
+ registrations[0].update_via_cache); |
+} |
+ |
+TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_CacheInvalidValue) { |
+ CreateDocumentProviderHost(); |
+ ProcessLinkHeaderForRequest( |
+ CreateSubresourceRequest(GURL("https://example.com/foo/bar/"), |
+ provider_host()->provider_id()) |
+ .get(), |
+ "<../foo.js>; rel=serviceworker; updateviacache=invalidvalue", |
+ context_wrapper()); |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); |
+ ASSERT_EQ(1u, registrations.size()); |
+ EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); |
+ EXPECT_EQ(GURL("https://example.com/foo/foo.js"), |
+ registrations[0].active_version.script_url); |
+ EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kImports, |
+ registrations[0].update_via_cache); |
+} |
+ |
TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_MultipleWorkers) { |
CreateDocumentProviderHost(); |
ProcessLinkHeaderForRequest( |
@@ -312,7 +395,7 @@ TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_MultipleWorkers) { |
provider_host()->provider_id()) |
.get(), |
"<bar.js>; rel=serviceworker; scope=foo, <baz.js>; " |
- "rel=serviceworker; scope=scope", |
+ "rel=serviceworker; scope=scope; updateviacache=all", |
context_wrapper()); |
base::RunLoop().RunUntilIdle(); |
@@ -321,9 +404,13 @@ TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_MultipleWorkers) { |
EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); |
EXPECT_EQ(GURL("https://example.com/foobar/bar.js"), |
registrations[0].active_version.script_url); |
+ EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kAll, |
+ registrations[0].update_via_cache); |
EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[1].pattern); |
EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), |
registrations[1].active_version.script_url); |
+ EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kAll, |
+ registrations[1].update_via_cache); |
} |
TEST_F(LinkHeaderServiceWorkerTest, |
@@ -379,6 +466,8 @@ TEST_F(LinkHeaderServiceWorkerTest, |
EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); |
EXPECT_EQ(GURL("https://example.com/foo/foo.js"), |
registrations[0].active_version.script_url); |
+ EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kImports, |
+ registrations[0].update_via_cache); |
} |
TEST_F(LinkHeaderServiceWorkerTest, |