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

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

Issue 2771823002: Implement updateViaCache flag and no-cache by default for main service worker scripts
Patch Set: fix IPC Created 3 years, 4 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/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 3213df6a7d2939ad96847334190e12a2d648a5aa..83e62a3e8cb17d165ff0856640f9d4262979b61f 100644
--- a/content/browser/service_worker/link_header_support_unittest.cc
+++ b/content/browser/service_worker/link_header_support_unittest.cc
@@ -192,6 +192,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) {
@@ -209,6 +211,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) {
@@ -228,6 +232,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) {
@@ -286,6 +292,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,
@@ -303,14 +311,88 @@ 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(
CreateSubresourceRequest(GURL("https://example.com/foobar/"),
provider_host()->provider_id())
.get(),
- "<bar.js>; rel=serviceworker; scope=foo, <baz.js>; "
- "rel=serviceworker; scope=scope",
+ "<bar.js>; rel=serviceworker; updateviacache=none; scope=foo, <baz.js>; "
+ "rel=serviceworker; scope=scope; updateviacache=all",
context_wrapper());
base::RunLoop().RunUntilIdle();
@@ -319,9 +401,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::kNone,
+ 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,
@@ -377,6 +463,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,
« no previous file with comments | « content/browser/service_worker/link_header_support.cc ('k') | content/browser/service_worker/service_worker_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698