From 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:33 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- .../local-url-inherit-controller.https.html | 18 +++++++ .../local-url-inherit-controller-frame.html | 60 +++++++++++++++++++++- .../static-router/resources/router-rules.js | 19 +++++++ .../static-router-invalid-rules.https.html | 20 +++++++- 4 files changed, 114 insertions(+), 3 deletions(-) (limited to 'testing/web-platform/tests/service-workers') diff --git a/testing/web-platform/tests/service-workers/service-worker/local-url-inherit-controller.https.html b/testing/web-platform/tests/service-workers/service-worker/local-url-inherit-controller.https.html index 6702abcadb..867e1b006d 100644 --- a/testing/web-platform/tests/service-workers/service-worker/local-url-inherit-controller.https.html +++ b/testing/web-platform/tests/service-workers/service-worker/local-url-inherit-controller.https.html @@ -79,6 +79,24 @@ promise_test(function(t) { }); }, 'Same-origin blob URL worker should intercept fetch().'); +promise_test(function(t) { + return doAsyncTest(t, { + scheme: 'blob', + child: 'sharedworker', + check: 'controller', + expect: 'inherit', + }); +}, 'Same-origin blob URL sharedworker should inherit service worker controller.'); + +promise_test(function(t) { + return doAsyncTest(t, { + scheme: 'blob', + child: 'sharedworker', + check: 'fetch', + expect: 'intercept', + }); +}, 'Same-origin blob URL sharedworker should intercept fetch().'); + promise_test(function(t) { return doAsyncTest(t, { scheme: 'data', diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/local-url-inherit-controller-frame.html b/testing/web-platform/tests/service-workers/service-worker/resources/local-url-inherit-controller-frame.html index b1e554d220..3a5d9b51e7 100644 --- a/testing/web-platform/tests/service-workers/service-worker/resources/local-url-inherit-controller-frame.html +++ b/testing/web-platform/tests/service-workers/service-worker/resources/local-url-inherit-controller-frame.html @@ -42,7 +42,33 @@ const workerFetchText = self.postMessage(text); }).catch(e => { self.postMessage(e.message); -});` +});`; + +const sharedWorkerControllerText = +`const ports = []; +self.onconnect = evt => { + const port = evt.ports[0]; + ports.push(port); + const t = navigator.serviceWorker.controller + ? navigator.serviceWorker.controller.scriptURL + : null; + port.postMessage(t); +}; +self.onerror = msg => { + ports.forEach(port => {port.postMessage(msg);}); +};`; + +const sharedWorkerFetchText = +`self.onconnect = evt => { + const port = evt.ports[0]; + fetch('${fetchURL}', { mode: 'no-cors' }).then(response => { + return response.text(); + }).then(text => { + port.postMessage(text); + }).catch(e => { + port.postMessage(e.message); + }); +};`; function getChildText(opts) { if (opts.child === 'iframe') { @@ -69,6 +95,18 @@ function getChildText(opts) { throw('unexpected feature to check: ' + opts.check); } + if (opts.child === 'sharedworker') { + if (opts.check === 'controller') { + return sharedWorkerControllerText; + } + + if (opts.check === 'fetch') { + return sharedWorkerFetchText; + } + + throw('unexpected feature to check: ' + opts.check); + } + throw('unexpected child type ' + opts.child); } @@ -98,6 +136,22 @@ function testWorkerChild(url) { }); } +function testSharedWorkerChild(url) { + let w = new SharedWorker(url); + return new Promise((resolve, reject) => { + w.port.onmessage = m => { + if (m.data.includes("Error")) { + reject(m.data); + return; + } + resolve(m); + } + w.onerror = evt => { + reject(evt.message); + } + }); +} + function testIframeChild(url) { let frame = document.createElement('iframe'); frame.src = url; @@ -115,6 +169,10 @@ function testURL(opts, url) { return testWorkerChild(url); } + if (opts.child === 'sharedworker') { + return testSharedWorkerChild(url); + } + if (opts.child === 'iframe') { return testIframeChild(url); } 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 4e6f8bb955..c3aef4272f 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 @@ -39,6 +39,25 @@ const routerRules = { condition: {requestMethod: String.fromCodePoint(0x3042)}, source: 'network' }], + 'condition-invalid-or-condition-depth': (() => { + const max = 10; + const addOrCondition = (obj, depth) => { + if (depth > max) { + return obj; + } + return { + urlPattern: `/foo-${depth}`, + or: [addOrCondition(obj, depth + 1)] + }; + }; + return {condition: addOrCondition({}, 0), source: 'network'}; + })(), + 'condition-invalid-router-size': [...Array(512)].map((val, i) => { + return { + condition: {urlPattern: `/foo-${i}`}, + source: 'network' + }; + }), 'condition-request-destination-script-network': [{condition: {requestDestination: 'script'}, source: 'network'}], 'condition-or-source-network': [{ 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 4ed4ad4b3c..9ef7cfdc9f 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 @@ -15,8 +15,10 @@ const ROUTER_RULE_KEY_INVALID_REQUEST_METHOD = 'condition-invalid-request-method'; -const ROUTER_RULE_KEY_SOURCE_FETCH_EVENT = - 'condition-request-source-fetch-event'; +const ROUTER_RULE_KEY_INVALID_OR_CONDITION_DEPTH = + 'condition-invalid-or-condition-depth'; +const ROUTER_RULE_KEY_INVALID_ROUTER_SIZE = + 'condition-invalid-router-size'; promise_test(async t => { const worker = await registerAndActivate(t, ROUTER_RULE_KEY_INVALID_REQUEST_METHOD); @@ -25,5 +27,19 @@ promise_test(async t => { assert_equals(errors.length, 1); }, 'addRoutes should raise for invalid request method.'); +promise_test(async t => { + const worker = await registerAndActivate(t, ROUTER_RULE_KEY_INVALID_OR_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 or 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'); + -- cgit v1.2.3