From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001
From: Daniel Baumann
Date: Wed, 15 May 2024 05:35:49 +0200
Subject: Merging upstream version 126.0.
Signed-off-by: Daniel Baumann
---
.../static-router/resources/router-rules.js | 27 ++++-
.../static-router/resources/static-router-sw.js | 4 +-
.../static-router-main-resource.https.html | 7 ++
.../static-router-mutiple-conditions.https.html | 112 +++++++++++++++++++++
.../static-router-subresource.https.html | 54 ++++++++--
5 files changed, 190 insertions(+), 14 deletions(-)
create mode 100644 testing/web-platform/tests/service-workers/service-worker/tentative/static-router/static-router-mutiple-conditions.https.html
(limited to 'testing/web-platform/tests/service-workers')
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');
+
+