Skip to content

Commit

Permalink
WPTs for fetch-event source in the static routing API
Browse files Browse the repository at this point in the history
This CL adds tests to the case if the service worker has router rules
containing `fetch-event` source.

Bug: 1519727
Change-Id: I3ddff71418c7c50d95b089bcd87362b263fd1e8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5252633
Reviewed-by: Yoshisato Yanagisawa <[email protected]>
Commit-Queue: Shunya Shishido <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1254403}
  • Loading branch information
sisidovski authored and chromium-wpt-export-bot committed Jan 31, 2024
1 parent ef0aff0 commit 3087c1e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const routerRules = {
}],
'condition-request-source-fetch-event':
[{condition: {requestMode: 'no-cors'}, source: 'fetch-event'}],
'condition-urlpattern-string-source-fetch-event':
[{condition: {urlPattern: '/**/*'}, source: 'fetch-event'}],
'multiple-router-rules': [
{
condition: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>
Static Router: routers are evaluated with the fetch-event source.
</title>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js">
</script>
<script src="resources/static-router-helpers.sub.js">
</script>
<body>
<script>
const ROUTER_KEY = 'condition-urlpattern-string-source-fetch-event';
const REGISTERED_ROUTE = 'resources/simple.html';

promise_test(async t => {
const worker = await registerAndActivate(t, ROUTER_KEY);
const rnd = randomString();
const iframe = await createIframe(t, `${REGISTERED_ROUTE}?nonce=${rnd}`);
const {errors, requests} = await get_info_from_worker(worker);

assert_equals(errors.length, 0);
assert_equals(requests.length, 1);
assert_equals(iframe.contentWindow.document.body.innerText, rnd);
}, 'Main resource matched the rule with fetch-event source');

iframeTest(REGISTERED_ROUTE, ROUTER_KEY, async (t, iwin, worker) => {
const rnd = randomString();
const response = await iwin.fetch(`?nonce=${rnd}`);
assert_equals(response.status, 200);
assert_equals(await response.text(), rnd);
const {requests} = await get_info_from_worker(worker);
// Main resource request + subreosurce request = 2.
assert_equals(requests.length, 2);
}, 'Subresource load matched the rule fetch-event source');
</script>
</body>

0 comments on commit 3087c1e

Please sign in to comment.