From 494c3c5806902cf1c9e5829b5dec2bf5f50427db Mon Sep 17 00:00:00 2001 From: sisidovski Date: Thu, 30 Nov 2023 04:40:59 +0000 Subject: [PATCH] Bug 1866956 [wpt PR 43272] - Add baseURL to the URLPattern condition while routing rule registration, a=testonly Automatic update from web-platform-tests Add baseURL to the URLPattern condition while routing rule registration This behavior change was originally started in https://github.com/whatwg/urlpattern/issues/182, and follows the spec change in https://github.com/whatwg/urlpattern/pull/199. This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition receives URLPatternInit or USVString. Before this CL, the URLPatternInit input was accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, the SW script URL is internally treated as baseURL. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if it's not explicitly provided. This is achieved by the helper method `URLPattern::From()`, which was added in [1]. This change doesn't affect the case when the input is URLPattern, which means the input is the object constructed via `new URLPattern()`. [1] crrev.com/c/5053645 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5039680 Reviewed-by: Takashi Toyoshima Reviewed-by: Kouhei Ueno Commit-Queue: Shunya Shishido Reviewed-by: Yoshisato Yanagisawa Auto-Submit: Shunya Shishido Cr-Commit-Position: refs/heads/main@{#1229724} -- wpt-commits: ffe06ef95d4d48be147e640fd9d1c489b810f929 wpt-pr: 43272 --- .../static-router/resources/router-rules.js | 57 +++++-------- .../static-router-main-resource.https.html | 2 +- .../static-router-subresource.https.html | 82 +++++++++++++++++-- 3 files changed, 99 insertions(+), 42 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 7b6a7144dbb6..67871a2d4fd3 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 @@ -2,44 +2,29 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. const routerRules = { - 'condition-url-pattern-source-network': [ - { - condition: { - urlPattern: new URLPattern({ - pathname: '/**/direct.txt' - }) - }, - source: 'network' - }, - + 'condition-urlpattern-constructed-source-network': [{ + condition: {urlPattern: new URLPattern({pathname: '/**/direct.txt'})}, + source: 'network' + }], + 'condition-urlpattern-urlpatterninit-source-network': [ + {condition: {urlPattern: {pathname: '/**/direct.txt'}}, source: 'network'}, ], - 'condition-request-source-network': [ - { - condition: { - requestMode: 'no-cors' - }, - source: 'network' - } - ], - 'condition-or-source-network': [ - { - condition: { - or: [ - { - or: [ - { - urlPattern: '/**/or-test/direct1.*??*' - } - ], - }, - { - urlPattern: '/**/or-test/direct2.*??*' - } - ] - }, - source: 'network' - } + 'condition-urlpattern-string-source-network': [ + {condition: {urlPattern: '/**/direct.txt'}, source: 'network'}, ], + 'condition-request-source-network': + [{condition: {requestMode: 'no-cors'}, source: 'network'}], + 'condition-or-source-network': [{ + condition: { + or: [ + { + or: [{urlPattern: '/**/or-test/direct1.*??*'}], + }, + {urlPattern: '/**/or-test/direct2.*??*'} + ] + }, + source: 'network' + }], }; export {routerRules}; 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 dda75f20f4bc..523ececf317e 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 @@ -10,7 +10,7 @@ +