summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/service-workers')
-rw-r--r--testing/web-platform/tests/service-workers/service-worker/WEB_FEATURES.yml5
-rw-r--r--testing/web-platform/tests/service-workers/service-worker/navigation-timing-sizes.https.html80
-rw-r--r--testing/web-platform/tests/service-workers/service-worker/resources/range-request-with-synth-head-worker.js2
-rw-r--r--testing/web-platform/tests/service-workers/service-worker/tentative/static-router/resources/router-rules.js36
-rw-r--r--testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-invalid-rules.https.html28
-rw-r--r--testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-main-resource.https.html17
-rw-r--r--testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-subresource.https.html14
7 files changed, 174 insertions, 8 deletions
diff --git a/testing/web-platform/tests/service-workers/service-worker/WEB_FEATURES.yml b/testing/web-platform/tests/service-workers/service-worker/WEB_FEATURES.yml
new file mode 100644
index 0000000000..9ddc5b400d
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/service-worker/WEB_FEATURES.yml
@@ -0,0 +1,5 @@
+features:
+- name: js-modules-service-workers
+ files:
+ - registration-script-module.https.html
+ - update-registration-with-type.https.html
diff --git a/testing/web-platform/tests/service-workers/service-worker/navigation-timing-sizes.https.html b/testing/web-platform/tests/service-workers/service-worker/navigation-timing-sizes.https.html
new file mode 100644
index 0000000000..a960cd57f3
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/service-worker/navigation-timing-sizes.https.html
@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Service Worker Navigation Timing</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
+
+<body>
+ <script>
+
+ promise_test(async t => {
+ var script = 'resources/pass-through-worker.js';
+ var scope = 'resources/blank.html';
+
+ const registration = await service_worker_unregister_and_register(t, script, scope);
+ t.add_cleanup(() => registration.unregister());
+ await wait_for_state(t, registration.installing, 'activated');
+
+ const iframe = await with_iframe(scope);
+
+ // Sanity, to check that we actually loaded the document.
+ assert_equals(iframe.contentWindow.document.title, "Empty doc");
+ t.add_cleanup(() => iframe.remove());
+ const navigationEntry = iframe.contentWindow.performance.getEntriesByType("navigation")[0];
+
+ const main_page_resource_timing = performance.getEntriesByType("resource").filter(
+ e => e.name.includes('blank'))[0];
+
+ assert_greater_than(navigationEntry.encodedBodySize, 0,
+ 'Navigation timing should have encodedBodySize larger than 0.');
+
+ assert_equals(navigationEntry.decodedBodySize, navigationEntry.encodedBodySize,
+ 'Navigation timing\'s decodedBodySize and encodedBodySize should be equal.');
+
+ assert_greater_than(main_page_resource_timing.encodedBodySize, 0,
+ 'Corresponding resource timing emitted on parent page should have decodedBodySize larger than 0.');
+
+ assert_equals(main_page_resource_timing.encodedBodySize, main_page_resource_timing.decodedBodySize,
+ 'Corresponding resource timing emitted on parent page should have equal\
+ decodedBodySize and encodedBodySize.');
+
+ }, 'Body sizes in a regular pass-through');
+
+ promise_test(async t => {
+ var script = 'resources/pass-through-worker.js';
+ var scope = 'resources/blank.html';
+
+ const registration = await service_worker_unregister_and_register(t, script, scope);
+ t.add_cleanup(() => registration.unregister());
+ await wait_for_state(t, registration.installing, 'activated');
+
+ const iframe = await with_iframe(scope + "?pipe=gzip");
+ // Sanity, to check that we actually loaded the document.
+ assert_equals(iframe.contentWindow.document.title, "Empty doc");
+ t.add_cleanup(() => iframe.remove());
+
+ const navigationEntry = iframe.contentWindow.performance.getEntriesByType("navigation")[0];
+
+ const main_page_resource_timing = performance.getEntriesByType("resource").filter(
+ e => e.name.includes('blank'))[0];
+
+ assert_greater_than(navigationEntry.decodedBodySize, 0,
+ 'Navigation timing should have decodedBodySize larger than 0.');
+
+ // The response body that comes from a service worker respondWith promise
+ // should have identical encoded and decoded body sizes, regardless of what
+ // the service worker itself saw, according to the spec.
+ assert_equals(navigationEntry.encodedBodySize, navigationEntry.decodedBodySize,
+ 'Navigation timing should have equal decodedBodySize and encodedBodySize.');
+
+ assert_greater_than(main_page_resource_timing.decodedBodySize, 0,
+ 'Corresponding resource timing emitted on parent page should have decodedBodySize larger than 0.');
+
+ assert_equals(main_page_resource_timing.encodedBodySize, navigationEntry.decodedBodySize,
+ 'Corresponding resource timing emitted on parent page should have equal decodedBodySize and \
+ encodedBodySize.');
+
+ }, 'Body sizes in a regular pass-through with gzip');
+ </script>
+</body>
diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/range-request-with-synth-head-worker.js b/testing/web-platform/tests/service-workers/service-worker/resources/range-request-with-synth-head-worker.js
index 6025d91b1a..6b6395aeca 100644
--- a/testing/web-platform/tests/service-workers/service-worker/resources/range-request-with-synth-head-worker.js
+++ b/testing/web-platform/tests/service-workers/service-worker/resources/range-request-with-synth-head-worker.js
@@ -24,7 +24,7 @@ self.addEventListener('fetch', e => {
headers: {
"Accept-Ranges": "bytes",
"Content-Type": "video/webm",
- "Content-Range": "bytes 0-1/44447",
+ "Content-Range": "bytes 0-1/*",
"Content-Length": "2",
},
};
diff --git a/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/resources/router-rules.js b/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/resources/router-rules.js
index 014cd2ec95..fdc1c9e063 100644
--- a/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/resources/router-rules.js
+++ b/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/resources/router-rules.js
@@ -1,10 +1,17 @@
const TEST_CACHE_NAME = 'v1';
+// The value is coming from:
+// https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/public/common/service_worker/service_worker_router_rule.h;l=28;drc=6f3f85b321146cfc0f9eb81a74c7c2257821461e
+const CONDITION_MAX_RECURSION_DEPTH = 10;
const routerRules = {
'condition-urlpattern-constructed-source-network': [{
condition: {urlPattern: new URLPattern({pathname: '/**/direct.txt'})},
source: 'network'
}],
+ 'condition-urlpattern-not-source-network': [{
+ condition: {not: {urlPattern: new URLPattern({pathname: '/**/not.txt'})}},
+ source: 'network'
+ }],
'condition-urlpattern-constructed-match-all-source-cache': [
{condition: {urlPattern: new URLPattern({})}, source: 'cache'},
],
@@ -43,22 +50,37 @@ const routerRules = {
[{condition: {requestMethod: 'PUT'}, source: 'network'}],
'condition-request-method-delete-network':
[{condition: {requestMethod: 'DELETE'}, source: 'network'}],
+ 'condition-lack-of-condition': [{
+ source: 'network'
+ }],
+ 'condition-lack-of-source': [{
+ condition: {requestMode: 'no-cors'},
+ }],
'condition-invalid-request-method': [{
condition: {requestMethod: String.fromCodePoint(0x3042)},
source: 'network'
}],
'condition-invalid-or-condition-depth': (() => {
- const max = 10;
- const addOrCondition = (obj, depth) => {
- if (depth > max) {
- return obj;
+ const addOrCondition = (depth) => {
+ if (depth > CONDITION_MAX_RECURSION_DEPTH) {
+ return {urlPattern: '/foo'};
}
return {
- urlPattern: `/foo-${depth}`,
- or: [addOrCondition(obj, depth + 1)]
+ or: [addOrCondition(depth + 1)]
};
};
- return {condition: addOrCondition({}, 0), source: 'network'};
+ return {condition: addOrCondition(1), source: 'network'};
+ })(),
+ 'condition-invalid-not-condition-depth': (() => {
+ const generateNotCondition = (depth) => {
+ if (depth > CONDITION_MAX_RECURSION_DEPTH) {
+ return {
+ urlPattern: '/**/example.txt',
+ };
+ }
+ return {not: generateNotCondition(depth + 1)};
+ };
+ return {condition: generateNotCondition(1), source: 'network'};
})(),
'condition-invalid-router-size': [...Array(512)].map((val, i) => {
return {
diff --git a/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-invalid-rules.https.html b/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-invalid-rules.https.html
index 9ef7cfdc9f..15b8ef5742 100644
--- a/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-invalid-rules.https.html
+++ b/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-invalid-rules.https.html
@@ -17,8 +17,14 @@ const ROUTER_RULE_KEY_INVALID_REQUEST_METHOD =
'condition-invalid-request-method';
const ROUTER_RULE_KEY_INVALID_OR_CONDITION_DEPTH =
'condition-invalid-or-condition-depth';
+const ROUTER_RULE_KEY_INVALID_NOT_CONDITION_DEPTH =
+ 'condition-invalid-not-condition-depth';
const ROUTER_RULE_KEY_INVALID_ROUTER_SIZE =
'condition-invalid-router-size';
+const ROUTER_RULE_KEY_LACK_OF_CONDITION =
+ 'condition-lack-of-condition';
+const ROUTER_RULE_KEY_LACK_OF_SOURCE =
+ 'condition-lack-of-source';
promise_test(async t => {
const worker = await registerAndActivate(t, ROUTER_RULE_KEY_INVALID_REQUEST_METHOD);
@@ -35,11 +41,33 @@ promise_test(async t => {
}, 'addRoutes should raise if or condition exceeds the depth limit');
promise_test(async t => {
+ const worker = await registerAndActivate(t, ROUTER_RULE_KEY_INVALID_NOT_CONDITION_DEPTH);
+ t.add_cleanup(() => {reset_info_in_worker(worker)});
+ const {errors} = await get_info_from_worker(worker);
+ assert_equals(errors.length, 1);
+}, 'addRoutes should raise if not condition exceeds the depth limit');
+
+promise_test(async t => {
const worker = await registerAndActivate(t, ROUTER_RULE_KEY_INVALID_ROUTER_SIZE);
t.add_cleanup(() => {reset_info_in_worker(worker)});
const {errors} = await get_info_from_worker(worker);
assert_equals(errors.length, 1);
}, 'addRoutes should raise if the number of router rules exceeds the length limit');
+promise_test(async t => {
+ const worker = await registerAndActivate(t, ROUTER_RULE_KEY_LACK_OF_CONDITION);
+ t.add_cleanup(() => {reset_info_in_worker(worker)});
+ const {errors} = await get_info_from_worker(worker);
+ assert_equals(errors.length, 1);
+}, 'addRoutes should raise if the conditon does not exist in the rule');
+
+promise_test(async t => {
+ const worker = await registerAndActivate(t, ROUTER_RULE_KEY_LACK_OF_SOURCE);
+ t.add_cleanup(() => {reset_info_in_worker(worker)});
+ const {errors} = await get_info_from_worker(worker);
+ assert_equals(errors.length, 1);
+}, 'addRoutes should raise if the source does not exiswt in the rule');
+
+
</script>
</body>
diff --git a/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-main-resource.https.html b/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-main-resource.https.html
index 7998af3f99..71bc0697f9 100644
--- a/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-main-resource.https.html
+++ b/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-main-resource.https.html
@@ -11,6 +11,7 @@
<body>
<script>
const ROUTER_RULE_KEY = 'condition-urlpattern-constructed-source-network';
+const ROUTER_RULE_NOT_KEY = 'condition-urlpattern-not-source-network';
const ROUTER_RULE_KEY_IGNORE_CASE =
'condition-urlpattern-constructed-ignore-case-source-network';
const ROUTER_RULE_KEY_RESPECT_CASE =
@@ -23,6 +24,7 @@ const ROUTER_RULE_KEY_URLPATTERN_CACHE_WITH_NAME =
const REGISTERED_ROUTE = 'resources/direct.txt';
const CACHED_ROUTE = 'resources/cache.txt';
const NON_REGISTERED_ROUTE = 'resources/simple.html';
+const NOT_ROUTE = 'resources/not.txt';
const host_info = get_host_info();
const path = new URL(".", window.location).pathname;
@@ -72,5 +74,20 @@ iframeTest(CACHED_ROUTE, ROUTER_RULE_KEY_URLPATTERN_CACHE_WITH_NAME, async (t, i
assert_equals(requests.length, 0);
assert_equals(iwin.document.body.innerText, "From cache");
}, 'Main resource load matched with the cache source, with specifying the cache name');
+
+iframeTest(NOT_ROUTE, ROUTER_RULE_NOT_KEY, async (t, iwin, worker) => {
+ const {requests} = await get_info_from_worker(worker);
+ assert_equals(requests.length, 1);
+ assert_equals(
+ requests[0].url,
+ `${host_info['HTTPS_ORIGIN']}${path}${NOT_ROUTE}`);
+ assert_equals(requests[0].mode, 'navigate');
+}, 'Main resource load should not match the condition with not');
+
+iframeTest(REGISTERED_ROUTE, ROUTER_RULE_NOT_KEY, async (t, iwin, worker) => {
+ const {requests} = await get_info_from_worker(worker);
+ assert_equals(requests.length, 0);
+ assert_equals(iwin.document.body.innerText, "Network\n");
+}, 'Main resource load should match the condition without not');
</script>
</body>
diff --git a/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-subresource.https.html b/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-subresource.https.html
index 00b9070bf1..ab05a3d252 100644
--- a/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-subresource.https.html
+++ b/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-subresource.https.html
@@ -27,10 +27,12 @@ const ROUTER_RULE_KEY_URL_PATTERN_CONSTRUCTED_MATCH_ALL_CACHE =
const ROUTER_RULE_KEY_URLPATTERN_CACHE_WITH_NAME =
'condition-urlpattern-string-source-cache-with-name';
const ROUTER_RULE_KEY_OR = 'condition-or-source-network'
+const ROUTER_RULE_KEY_NOT = 'condition-urlpattern-not-source-network';
const SCOPE = 'resources/';
const HTML_FILE = 'resources/simple.html';
const TXT_FILE = 'resources/direct.txt';
const CSV_FILE = 'resources/simple.csv';
+const NOT_FILE = 'resources/not.txt';
// Warning: please prepare the corresponding `*.text.headers` files, otherwise
// iframeTest() fails to load the following files due to MIME mismatches.
const OR_TEST_FILES = [
@@ -184,5 +186,17 @@ iframeTest(HTML_FILE, ROUTER_RULE_KEY_URLPATTERN_CACHE_WITH_NAME, async (t, iwin
assert_equals(response_with_param.status, 404);
}, 'Subresource load matched with the cache source, with specifying the cache name');
+iframeTest(TXT_FILE, ROUTER_RULE_KEY_NOT, async (t, iwin) => {
+ const rnd = randomString();
+ const response = await iwin.fetch(`${NOT_FILE}?nonce=${rnd}`);
+ assert_equals(await response.text(), rnd);
+}, 'Subresource load should not match with the not condition');
+
+iframeTest(TXT_FILE, ROUTER_RULE_KEY_NOT, async (t, iwin) => {
+ const rnd = randomString();
+ const response = await iwin.fetch('?nonce=' + rnd);
+ assert_equals(await response.text(), "Network\n");
+}, 'Subresource load should match with a file other than not');
+
</script>
</body>