From 8dd16259287f58f9273002717ec4d27e97127719 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:43:14 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- .../service-worker/WEB_FEATURES.yml | 5 ++ .../navigation-timing-sizes.https.html | 80 ++++++++++++++++++++++ .../range-request-with-synth-head-worker.js | 2 +- .../static-router/resources/router-rules.js | 36 ++++++++-- .../static-router-invalid-rules.https.html | 28 ++++++++ .../static-router-main-resource.https.html | 17 +++++ .../static-router-subresource.https.html | 14 ++++ 7 files changed, 174 insertions(+), 8 deletions(-) create mode 100644 testing/web-platform/tests/service-workers/service-worker/WEB_FEATURES.yml create mode 100644 testing/web-platform/tests/service-workers/service-worker/navigation-timing-sizes.https.html (limited to 'testing/web-platform/tests/service-workers') 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 @@ + + +Service Worker Navigation Timing + + + + + + + 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); @@ -34,6 +40,13 @@ promise_test(async t => { assert_equals(errors.length, 1); }, '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)}); @@ -41,5 +54,20 @@ promise_test(async t => { 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'); + + 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 @@ 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'); + -- cgit v1.2.3