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 0372e783adb30..3ec9c81674204 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 @@ -5,9 +5,9 @@ routerRules ' condition - -url +urlpattern - -pattern +constructed - source - @@ -49,6 +49,82 @@ network ' condition - +urlpattern +- +urlpatterninit +- +source +- +network +' +: +[ +{ +condition +: +{ +urlPattern +: +{ +pathname +: +' +/ +* +* +/ +direct +. +txt +' +} +} +source +: +' +network +' +} +] +' +condition +- +urlpattern +- +string +- +source +- +network +' +: +[ +{ +condition +: +{ +urlPattern +: +' +/ +* +* +/ +direct +. +txt +' +} +source +: +' +network +' +} +] +' +condition +- request - source 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 59ae240e853a2..c1a97e0592014 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 @@ -137,14 +137,15 @@ ' condition - -url +urlpattern - -pattern +constructed - source - network ' +; const SCOPE = 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 7afcc9f563360..8491e375b8d61 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 @@ -85,6 +85,29 @@ script > < +script +src += +" +/ +common +/ +get +- +host +- +info +. +sub +. +js +" +> +< +/ +script +> +< body > < @@ -106,19 +129,50 @@ ' ; const -ROUTER_RULE_KEY_URL_PATTERN +ROUTER_RULE_KEY_URL_PATTERN_CONSTRUCTED = ' condition - -url +urlpattern - -pattern +constructed +- +source +- +network +' +; +const +ROUTER_RULE_KEY_URL_PATTERN_URLPATTERNINIT += +' +condition +- +urlpattern +- +urlpatterninit +- +source +- +network +' +; +const +ROUTER_RULE_KEY_URL_PATTERN_STRING += +' +condition +- +urlpattern +- +string - source - network ' +; const ROUTER_RULE_KEY_REQUEST = @@ -332,13 +386,18 @@ ) ) ; +const +worker += +reg +. +installing +; await wait_for_state ( t -reg -. -installing +worker ' activated ' @@ -380,6 +439,7 @@ ( t iwin +worker ) ; } @@ -442,10 +502,73 @@ result ; } +function +get_fetched_urls +( +worker +) +{ +return +new +Promise +( +function +( +resolve +) +{ +var +channel += +new +MessageChannel +( +) +; +channel +. +port1 +. +onmessage += +function +( +msg +) +{ +resolve +( +msg +) +; +} +; +worker +. +postMessage +( +{ +port +: +channel +. +port2 +} +[ +channel +. +port2 +] +) +; +} +) +; +} iframeTest ( HTML_FILE -ROUTER_RULE_KEY_URL_PATTERN +ROUTER_RULE_KEY_URL_PATTERN_CONSTRUCTED async ( t @@ -504,7 +627,7 @@ iframeTest ( TXT_FILE -ROUTER_RULE_KEY_URL_PATTERN +ROUTER_RULE_KEY_URL_PATTERN_CONSTRUCTED async ( t @@ -565,6 +688,660 @@ ; 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 +/ +/ +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 +/ +/ +network +request +and +the +fetch +handler +doesn +' +t +capture +the +response +. +/ +/ +The +response +is +going +to +be +a +opaque +. +const +origin += +get_host_info +( +) +. +HTTPS_REMOTE_ORIGIN +; +const +response += +await +iwin +. +fetch +( +{ +origin +} +/ +{ +TXT_FILE +} +? +nonce += +{ +rnd +} +{ +mode +: +' +no +- +cors +' +} +) +; +const +fetched_urls += +await +get_fetched_urls +( +worker +) +; +const +{ +requests +} += +fetched_urls +. +data +; +assert_equals +( +requests +. +length +0 +) +; +assert_equals +( +response +. +type +' +opaque +' +) +; +} +' +Subresource +cross +origin +load +matched +with +URLPattern +condition +via +constructed +object +' +) +; +iframeTest +( +TXT_FILE +ROUTER_RULE_KEY_URL_PATTERN_URLPATTERNINIT +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 +' +) +; +iframeTest +( +TXT_FILE +ROUTER_RULE_KEY_URL_PATTERN_URLPATTERNINIT +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 +. +const +rnd += +randomString +( +) +; +const +origin += +get_host_info +( +) +. +HTTPS_REMOTE_ORIGIN +; +const +response += +await +iwin +. +fetch +( +{ +origin +} +/ +{ +TXT_FILE +} +? +nonce += +{ +rnd +} +) +; +const +fetched_urls += +await +get_fetched_urls +( +worker +) +; +const +{ +requests +} += +fetched_urls +. +data +; +assert_equals +( +requests +. +length +1 +) +; +assert_equals +( +await +response +. +text +( +) +rnd +) +; +} +' +Subresource +cross +origin +load +not +matched +with +URLPattern +condition +via +URLPatternInit +' +) +; +iframeTest +( +TXT_FILE +ROUTER_RULE_KEY_URL_PATTERN_STRING +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 +string +' +) +; +iframeTest +( +TXT_FILE +ROUTER_RULE_KEY_URL_PATTERN_STRING +async +( +t +iwin +worker +) += +> +{ +/ +/ +The +SW +script +URL +is +added +as +a +baseURL +when +| +urlPattern +| +is +passed +via +/ +/ +string +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 +fetched_urls += +await +get_fetched_urls +( +worker +) +; +const +{ +requests +} += +fetched_urls +. +data +; +assert_equals +( +requests +. +length +1 +) +; +assert_equals +( +await +response +. +text +( +) +rnd +) +; +} +' +Subresource +cross +origin +load +not +matched +with +URLPattern +condition +via +string +' +) +; +iframeTest +( CSV_FILE ROUTER_RULE_KEY_REQUEST async