diff options
Diffstat (limited to 'testing/web-platform/tests/service-workers/service-worker/tentative/static-router')
4 files changed, 88 insertions, 7 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 014cd2ec95..fdc1c9e063 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,10 +1,17 @@ const TEST_CACHE_NAME = 'v1'; +// The value is coming from: +// https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/public/common/service_worker/service_worker_router_rule.h;l=28;drc=6f3f85b321146cfc0f9eb81a74c7c2257821461e +const CONDITION_MAX_RECURSION_DEPTH = 10; const routerRules = { 'condition-urlpattern-constructed-source-network': [{ condition: {urlPattern: new URLPattern({pathname: '/**/direct.txt'})}, source: 'network' }], + 'condition-urlpattern-not-source-network': [{ + condition: {not: {urlPattern: new URLPattern({pathname: '/**/not.txt'})}}, + source: 'network' + }], 'condition-urlpattern-constructed-match-all-source-cache': [ {condition: {urlPattern: new URLPattern({})}, source: 'cache'}, ], @@ -43,22 +50,37 @@ const routerRules = { [{condition: {requestMethod: 'PUT'}, source: 'network'}], 'condition-request-method-delete-network': [{condition: {requestMethod: 'DELETE'}, source: 'network'}], + 'condition-lack-of-condition': [{ + source: 'network' + }], + 'condition-lack-of-source': [{ + condition: {requestMode: 'no-cors'}, + }], 'condition-invalid-request-method': [{ condition: {requestMethod: String.fromCodePoint(0x3042)}, source: 'network' }], 'condition-invalid-or-condition-depth': (() => { - const max = 10; - const addOrCondition = (obj, depth) => { - if (depth > max) { - return obj; + const addOrCondition = (depth) => { + if (depth > CONDITION_MAX_RECURSION_DEPTH) { + return {urlPattern: '/foo'}; } return { - urlPattern: `/foo-${depth}`, - or: [addOrCondition(obj, depth + 1)] + or: [addOrCondition(depth + 1)] }; }; - return {condition: addOrCondition({}, 0), source: 'network'}; + return {condition: addOrCondition(1), source: 'network'}; + })(), + 'condition-invalid-not-condition-depth': (() => { + const generateNotCondition = (depth) => { + if (depth > CONDITION_MAX_RECURSION_DEPTH) { + return { + urlPattern: '/**/example.txt', + }; + } + return {not: generateNotCondition(depth + 1)}; + }; + return {condition: generateNotCondition(1), source: 'network'}; })(), 'condition-invalid-router-size': [...Array(512)].map((val, i) => { return { 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 9ef7cfdc9f..15b8ef5742 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 @@ -17,8 +17,14 @@ const ROUTER_RULE_KEY_INVALID_REQUEST_METHOD = 'condition-invalid-request-method'; const ROUTER_RULE_KEY_INVALID_OR_CONDITION_DEPTH = 'condition-invalid-or-condition-depth'; +const ROUTER_RULE_KEY_INVALID_NOT_CONDITION_DEPTH = + 'condition-invalid-not-condition-depth'; const ROUTER_RULE_KEY_INVALID_ROUTER_SIZE = 'condition-invalid-router-size'; +const ROUTER_RULE_KEY_LACK_OF_CONDITION = + 'condition-lack-of-condition'; +const ROUTER_RULE_KEY_LACK_OF_SOURCE = + 'condition-lack-of-source'; promise_test(async t => { const worker = await registerAndActivate(t, ROUTER_RULE_KEY_INVALID_REQUEST_METHOD); @@ -35,11 +41,33 @@ promise_test(async t => { }, 'addRoutes should raise if or condition exceeds the depth limit'); promise_test(async t => { + const worker = await registerAndActivate(t, ROUTER_RULE_KEY_INVALID_NOT_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 not 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'); +promise_test(async t => { + const worker = await registerAndActivate(t, ROUTER_RULE_KEY_LACK_OF_CONDITION); + 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 conditon does not exist in the rule'); + +promise_test(async t => { + const worker = await registerAndActivate(t, ROUTER_RULE_KEY_LACK_OF_SOURCE); + 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 source does not exiswt in the rule'); + + </script> </body> 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 7998af3f99..71bc0697f9 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 @@ -11,6 +11,7 @@ <body> <script> const ROUTER_RULE_KEY = 'condition-urlpattern-constructed-source-network'; +const ROUTER_RULE_NOT_KEY = 'condition-urlpattern-not-source-network'; const ROUTER_RULE_KEY_IGNORE_CASE = 'condition-urlpattern-constructed-ignore-case-source-network'; const ROUTER_RULE_KEY_RESPECT_CASE = @@ -23,6 +24,7 @@ const ROUTER_RULE_KEY_URLPATTERN_CACHE_WITH_NAME = const REGISTERED_ROUTE = 'resources/direct.txt'; const CACHED_ROUTE = 'resources/cache.txt'; const NON_REGISTERED_ROUTE = 'resources/simple.html'; +const NOT_ROUTE = 'resources/not.txt'; const host_info = get_host_info(); const path = new URL(".", window.location).pathname; @@ -72,5 +74,20 @@ iframeTest(CACHED_ROUTE, ROUTER_RULE_KEY_URLPATTERN_CACHE_WITH_NAME, async (t, i 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'); + +iframeTest(NOT_ROUTE, ROUTER_RULE_NOT_KEY, async (t, iwin, worker) => { + const {requests} = await get_info_from_worker(worker); + assert_equals(requests.length, 1); + assert_equals( + requests[0].url, + `${host_info['HTTPS_ORIGIN']}${path}${NOT_ROUTE}`); + assert_equals(requests[0].mode, 'navigate'); +}, 'Main resource load should not match the condition with not'); + +iframeTest(REGISTERED_ROUTE, ROUTER_RULE_NOT_KEY, async (t, iwin, worker) => { + const {requests} = await get_info_from_worker(worker); + assert_equals(requests.length, 0); + assert_equals(iwin.document.body.innerText, "Network\n"); +}, 'Main resource load should match the condition without not'); </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 00b9070bf1..ab05a3d252 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 @@ -27,10 +27,12 @@ const ROUTER_RULE_KEY_URL_PATTERN_CONSTRUCTED_MATCH_ALL_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 ROUTER_RULE_KEY_NOT = 'condition-urlpattern-not-source-network'; const SCOPE = 'resources/'; const HTML_FILE = 'resources/simple.html'; const TXT_FILE = 'resources/direct.txt'; const CSV_FILE = 'resources/simple.csv'; +const NOT_FILE = 'resources/not.txt'; // Warning: please prepare the corresponding `*.text.headers` files, otherwise // iframeTest() fails to load the following files due to MIME mismatches. const OR_TEST_FILES = [ @@ -184,5 +186,17 @@ iframeTest(HTML_FILE, ROUTER_RULE_KEY_URLPATTERN_CACHE_WITH_NAME, async (t, iwin assert_equals(response_with_param.status, 404); }, 'Subresource load matched with the cache source, with specifying the cache name'); +iframeTest(TXT_FILE, ROUTER_RULE_KEY_NOT, async (t, iwin) => { + const rnd = randomString(); + const response = await iwin.fetch(`${NOT_FILE}?nonce=${rnd}`); + assert_equals(await response.text(), rnd); +}, 'Subresource load should not match with the not condition'); + +iframeTest(TXT_FILE, ROUTER_RULE_KEY_NOT, async (t, iwin) => { + const rnd = randomString(); + const response = await iwin.fetch('?nonce=' + rnd); + assert_equals(await response.text(), "Network\n"); +}, 'Subresource load should match with a file other than not'); + </script> </body> |