diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
commit | d8bbc7858622b6d9c278469aab701ca0b609cddf (patch) | |
tree | eff41dc61d9f714852212739e6b3738b82a2af87 /testing/web-platform/tests/service-workers | |
parent | Releasing progress-linux version 125.0.3-1~progress7.99u1. (diff) | |
download | firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip |
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/service-workers')
5 files changed, 190 insertions, 14 deletions
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 c3aef4272f..014cd2ec95 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,9 +1,14 @@ +const TEST_CACHE_NAME = 'v1'; + const routerRules = { 'condition-urlpattern-constructed-source-network': [{ condition: {urlPattern: new URLPattern({pathname: '/**/direct.txt'})}, source: 'network' }], - 'condition-urlpattern-urlpatterninit-source-network': [ + 'condition-urlpattern-constructed-match-all-source-cache': [ + {condition: {urlPattern: new URLPattern({})}, source: 'cache'}, + ], + 'condition-urlpattern-urlpatterncompatible-source-network': [ {condition: {urlPattern: {pathname: '/**/direct.txt'}}, source: 'network'}, ], 'condition-urlpattern-string-source-network': [ @@ -12,6 +17,9 @@ const routerRules = { 'condition-urlpattern-string-source-cache': [ {condition: {urlPattern: '/**/cache.txt'}, source: 'cache'}, ], + 'condition-urlpattern-string-source-cache-with-name': [ + {condition: {urlPattern: '/**/cache.txt'}, source: {cacheName: TEST_CACHE_NAME}}, + ], 'condition-urlpattern-constructed-ignore-case-source-network': [{ condition: { urlPattern: @@ -90,6 +98,21 @@ const routerRules = { source: 'race-network-and-fetch-handler' }, ], + 'multiple-conditions-network': { + condition: { + urlPattern: new URLPattern({search: 'test'}), + requestMode: 'cors', + requestMethod: 'post', + }, + source: 'network' + }, + 'multiple-conditions-with-destination-network' : { + condition: { + urlPattern: new URLPattern({search: 'test'}), + requestDestination: 'style' + }, + source: 'network' + } }; -export {routerRules}; +export {routerRules, TEST_CACHE_NAME as cacheName}; diff --git a/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/resources/static-router-sw.js b/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/resources/static-router-sw.js index 07409ec42c..c0bd683f91 100644 --- a/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/resources/static-router-sw.js +++ b/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/resources/static-router-sw.js @@ -1,6 +1,6 @@ 'use strict'; -import {routerRules} from './router-rules.js'; +import {routerRules, cacheName} from './router-rules.js'; import { recordRequest, recordError, @@ -10,7 +10,7 @@ import { import './imported-sw.js'; self.addEventListener('install', async e => { - e.waitUntil(caches.open('v1').then( + e.waitUntil(caches.open(cacheName).then( cache => {cache.put('cache.txt', new Response('From cache'))})); const params = new URLSearchParams(location.search); 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 fc93a4f7c9..7998af3f99 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 @@ -18,6 +18,8 @@ const ROUTER_RULE_KEY_RESPECT_CASE = const ROUTER_RULE_KEY_URLPATTERN_CACHE = 'condition-urlpattern-string-source-cache'; const ROUTER_RULE_KEY_REQUEST_CACHE = 'condition-request-navigate-source-cache'; +const ROUTER_RULE_KEY_URLPATTERN_CACHE_WITH_NAME = + 'condition-urlpattern-string-source-cache-with-name'; const REGISTERED_ROUTE = 'resources/direct.txt'; const CACHED_ROUTE = 'resources/cache.txt'; const NON_REGISTERED_ROUTE = 'resources/simple.html'; @@ -65,5 +67,10 @@ iframeTest(NON_REGISTERED_ROUTE, ROUTER_RULE_KEY_REQUEST_CACHE, async (t, iwin, assert_equals(iwin.document.body.innerText, "Here's a simple html file."); }, 'Main resource fallback to the network when there is no cache entry'); +iframeTest(CACHED_ROUTE, ROUTER_RULE_KEY_URLPATTERN_CACHE_WITH_NAME, async (t, iwin, worker) => { + const {requests} = await get_info_from_worker(worker); + 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'); </script> </body> diff --git a/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-mutiple-conditions.https.html b/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-mutiple-conditions.https.html new file mode 100644 index 0000000000..3d69411843 --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-mutiple-conditions.https.html @@ -0,0 +1,112 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title> + Static Router: routers are evaluated with the request method condition. +</title> +<script src="/common/get-host-info.sub.js"></script> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/service-workers/service-worker/resources/test-helpers.sub.js"> +</script> +<script src="resources/static-router-helpers.sub.js"> +</script> +<body> +<script> +const ROUTER_KEY = 'multiple-conditions-network'; +const ROUTER_KEY_WITH_DESTINATION = + 'multiple-conditions-with-destination-network'; +const HTML_FILE = 'resources/simple.html'; +const REQUEST_SRC = 'resources/direct.py'; + +const is_matched = async (worker) => { + const {requests} = await get_info_from_worker(worker); + return requests.length == 0; +} + +const appendCSS = async (iwin, src) => { + const promise = new Promise(resolve => { + const link = iwin.document.createElement('link'); + link.rel = 'stylesheet'; + link.href = src; + iwin.document.head.appendChild(link); + link.onload = () => { + resolve(link); + }; + }); + + return promise; +}; + +const appendScript = async (iwin, src) => { + const promise = new Promise(resolve => { + const script = iwin.document.createElement('script'); + script.src = src; + iwin.document.body.appendChild(script); + script.onload = () => { + resolve(script); + }; + }); + + return promise; +}; + +iframeTest(HTML_FILE, ROUTER_KEY, async (t, iwin, worker) => { + // Reset the fetch count created by the setup process. + await reset_info_in_worker(worker); + const {requests} = await get_info_from_worker(worker); + assert_equals(requests.length, 0); + + // Expected condtion: + // - urlPattern: { search: 'test' } + // - mode: 'cors' + // - method: POST + + // Expect match. + let response = await iwin.fetch(`../${REQUEST_SRC}?test`, {mode: 'cors', method: 'post'}); + assert_equals(response.status, 200); + assert_true(await is_matched(worker)); + await reset_info_in_worker(worker); + + // mode: 'no-cors' won't match. + response = await iwin.fetch(`../${REQUEST_SRC}?test`, {mode: 'no-cors', method: 'post'}); + assert_false(await is_matched(worker)); + await reset_info_in_worker(worker); + + // method: GET won't match. + response = await iwin.fetch(`../${REQUEST_SRC}?test`, {mode: 'cors', method: 'get'}); + assert_false(await is_matched(worker)); + await reset_info_in_worker(worker); + + // No seqarch query won't match. + response = await iwin.fetch(`../${REQUEST_SRC}`, {mode: 'cors', method: 'post'}); + assert_false(await is_matched(worker)); + await reset_info_in_worker(worker); +}, 'Multiple conditions work with `and` operation'); + +iframeTest(HTML_FILE, ROUTER_KEY_WITH_DESTINATION, async (t, iwin, worker) => { + // Reset the fetch count created by the setup process. + await reset_info_in_worker(worker); + const {requests} = await get_info_from_worker(worker); + assert_equals(requests.length, 0); + + // Expected condtion: + // - urlPattern: { search: 'test' } + // - destination: style + + // Expect match. + await appendCSS(iwin, `../${REQUEST_SRC}?test`); + assert_true(await is_matched(worker)); + await reset_info_in_worker(worker); + + // Other request destination won't match. + await appendScript(iwin, `../${REQUEST_SRC}?test`); + assert_false(await is_matched(worker)); + await reset_info_in_worker(worker); + + // No seqarch query won't match. + await appendCSS(iwin, `../${REQUEST_SRC}`); + assert_false(await is_matched(worker)); + await reset_info_in_worker(worker); +}, 'Multiple conditions including requestDestination work with `and` operation'); +</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 3f7902a872..00b9070bf1 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 @@ -15,13 +15,17 @@ const ROUTER_RULE_KEY_URL_PATTERN_CONSTRUCTED_IGNORE_CASE = 'condition-urlpattern-constructed-ignore-case-source-network'; const ROUTER_RULE_KEY_URL_PATTERN_CONSTRUCTED_RESPECT_CASE = 'condition-urlpattern-constructed-respect-case-source-network'; -const ROUTER_RULE_KEY_URL_PATTERN_URLPATTERNINIT = - 'condition-urlpattern-urlpatterninit-source-network'; +const ROUTER_RULE_KEY_URL_PATTERN_URLPATTERNCOMPATIBLE = + 'condition-urlpattern-urlpatterncompatible-source-network'; const ROUTER_RULE_KEY_URL_PATTERN_STRING = 'condition-urlpattern-string-source-network'; const ROUTER_RULE_KEY_REQUEST = 'condition-request-source-network' const ROUTER_RULE_KEY_URL_PATTERN_STRING_CACHE = 'condition-urlpattern-string-source-cache'; +const ROUTER_RULE_KEY_URL_PATTERN_CONSTRUCTED_MATCH_ALL_CACHE = + 'condition-urlpattern-constructed-match-all-source-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 SCOPE = 'resources/'; const HTML_FILE = 'resources/simple.html'; @@ -49,7 +53,7 @@ iframeTest(TXT_FILE, ROUTER_RULE_KEY_URL_PATTERN_CONSTRUCTED, async (t, iwin) => iframeTest(TXT_FILE, ROUTER_RULE_KEY_URL_PATTERN_CONSTRUCTED, async (t, iwin, worker) => { const rnd = randomString(); - // Confirm that the given URLPatternInit has a wildcard pattern for the + // Confirm that the given URLPatternCompatible has a wildcard pattern for the // hostname. Also, if |urlPattern| is a consutructed URLPattern object, // baseURL won't be set while adding router rules, thus it matches the cross // origin request as far as other components matches. So expecting the direct @@ -75,24 +79,24 @@ iframeTest(TXT_FILE, ROUTER_RULE_KEY_URL_PATTERN_CONSTRUCTED_RESPECT_CASE, async assert_equals(await response.text(), rnd); }, 'Subresource load matched without ignoreCase URLPattern condition'); -iframeTest(TXT_FILE, ROUTER_RULE_KEY_URL_PATTERN_URLPATTERNINIT, async (t, iwin) => { +iframeTest(TXT_FILE, ROUTER_RULE_KEY_URL_PATTERN_URLPATTERNCOMPATIBLE, async (t, iwin) => { const rnd = randomString(); const response = await iwin.fetch('?nonce=' + rnd); assert_equals(await response.text(), "Network\n"); -}, 'Subresource load matched with URLPattern condition via URLPatternInit'); +}, 'Subresource load matched with URLPattern condition via URLPatternCompatible'); -iframeTest(TXT_FILE, ROUTER_RULE_KEY_URL_PATTERN_URLPATTERNINIT, async (t, iwin, worker) => { +iframeTest(TXT_FILE, ROUTER_RULE_KEY_URL_PATTERN_URLPATTERNCOMPATIBLE, async (t, iwin, worker) => { // The SW script URL is added as a baseURL when |urlPattern| is passed via - // URLPatternInit, and there is not |baseURL| in it. Cross origin request will - // go through the fetch handler because |baseURL| info complements hostname - // with the hostname of the SW script. + // URLPatternCompatible, and there is not |baseURL| in it. Cross + // origin request will go through the fetch handler because |baseURL| info + // complements hostname with the hostname of the SW script. const rnd = randomString(); const origin = get_host_info().HTTPS_REMOTE_ORIGIN; const response = await iwin.fetch(`${origin}/${TXT_FILE}?nonce=${rnd}`); const {requests} = await get_info_from_worker(worker); assert_equals(requests.length, 1); assert_equals(await response.text(), rnd); -}, 'Subresource cross origin load not matched with URLPattern condition via URLPatternInit'); +}, 'Subresource cross origin load not matched with URLPattern condition via URLPatternCompatible'); iframeTest(TXT_FILE, ROUTER_RULE_KEY_URL_PATTERN_STRING, async (t, iwin) => { const rnd = randomString(); @@ -150,5 +154,35 @@ iframeTest(HTML_FILE, ROUTER_RULE_KEY_URL_PATTERN_STRING_CACHE, async (t, iwin) assert_equals(response_with_param.status, 404); }, 'Subresource load matched with the cache source rule'); +iframeTest(TXT_FILE, ROUTER_RULE_KEY_URL_PATTERN_CONSTRUCTED_MATCH_ALL_CACHE, async (t, iwin, worker) => { + // Send a request, which is not stored in the cache, but it exists over the network. + const rnd = randomString(); + let response = await iwin.fetch(`?nonce=${rnd}`); + assert_equals(await response.text(), "Network\n"); + assert_equals(response.status, 200); + + // Send a request, which is not stored in the cache, and does not exist over the network. + const NON_EXISTING_FILE = 'not-found.txt'; + response = await iwin.fetch(`${NON_EXISTING_FILE}?nonce=${randomString()}`); + assert_equals(response.status, 404); + + // Both requests are not handled by ServiceWorker. + const {requests} = await get_info_from_worker(worker); + assert_equals(requests.length, 0); +}, 'Subresource load did not match with the cache and fallback to the network'); + +iframeTest(HTML_FILE, ROUTER_RULE_KEY_URLPATTERN_CACHE_WITH_NAME, async (t, iwin, worker) => { + // No need to set `resources/` because the request is dispatched from iframe. + const CACHED_FILE = 'cache.txt'; + const response = await iwin.fetch(CACHED_FILE); + assert_equals(response.status, 200); + assert_equals(await response.text(), "From cache"); + + // This doesn't match because the cache key is wrong. + const rnd = randomString(); + const response_with_param = await iwin.fetch(`${CACHED_FILE}?nonce=${rnd}`); + assert_equals(response_with_param.status, 404); +}, 'Subresource load matched with the cache source, with specifying the cache name'); + </script> </body> |