Add WPT for the length of router rules (#44998)
This CL will add test to ensure the router registration will fail if
the length of router rules exceeds the limit, which is currently 256.
Bug: 1519727, 40943429
Change-Id: Id849ddcd08dc5f246436471db60b9dcc71d2324a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5348571
Reviewed-by: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
Reviewed-by: Kouhei Ueno <kouhei@chromium.org>
Reviewed-by: Minoru Chikamune <chikamune@chromium.org>
Commit-Queue: Shunya Shishido <sisidovski@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1269937}
Co-authored-by: Shunya Shishido <sisidovski@chromium.org>
diff --git a/service-workers/service-worker/tentative/static-router/resources/router-rules.js b/service-workers/service-worker/tentative/static-router/resources/router-rules.js
index 5a1c536..c3aef42 100644
--- a/service-workers/service-worker/tentative/static-router/resources/router-rules.js
+++ b/service-workers/service-worker/tentative/static-router/resources/router-rules.js
@@ -52,6 +52,12 @@
};
return {condition: addOrCondition({}, 0), source: 'network'};
})(),
+ 'condition-invalid-router-size': [...Array(512)].map((val, i) => {
+ return {
+ condition: {urlPattern: `/foo-${i}`},
+ source: 'network'
+ };
+ }),
'condition-request-destination-script-network':
[{condition: {requestDestination: 'script'}, source: 'network'}],
'condition-or-source-network': [{
diff --git a/service-workers/service-worker/tentative/static-router/static-router-invalid-rules.https.html b/service-workers/service-worker/tentative/static-router/static-router-invalid-rules.https.html
index 86a5021..9ef7cfd 100644
--- a/service-workers/service-worker/tentative/static-router/static-router-invalid-rules.https.html
+++ b/service-workers/service-worker/tentative/static-router/static-router-invalid-rules.https.html
@@ -17,6 +17,8 @@
'condition-invalid-request-method';
const ROUTER_RULE_KEY_INVALID_OR_CONDITION_DEPTH =
'condition-invalid-or-condition-depth';
+const ROUTER_RULE_KEY_INVALID_ROUTER_SIZE =
+ 'condition-invalid-router-size';
promise_test(async t => {
const worker = await registerAndActivate(t, ROUTER_RULE_KEY_INVALID_REQUEST_METHOD);
@@ -32,5 +34,12 @@
assert_equals(errors.length, 1);
}, 'addRoutes should raise if or 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');
+
</script>
</body>