Skip to content

Commit

Permalink
Add test for the no fetch handler case
Browse files Browse the repository at this point in the history
This adds the test for crrev.com/c/5119144/. Even if there is no fetch
handler in SW, this test confirms the router is always evaluated.

Bug: 1519727, 1511459
Change-Id: I20353cf9b076e3d225047f42df1557c1fbd4f5ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5233868
Commit-Queue: Shunya Shishido <[email protected]>
Reviewed-by: Yoshisato Yanagisawa <[email protected]>
Reviewed-by: Minoru Chikamune <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1252109}
  • Loading branch information
sisidovski authored and chromium-wpt-export-bot committed Jan 25, 2024
1 parent ea4555b commit 46c16b1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

import {routerRules} from './router-rules.js';
import {
recordError,
getRecords,
resetRecords } from './static-router-sw.sub.js';

self.addEventListener('install', async e => {
e.waitUntil(caches.open('v1').then(
cache => {cache.put('cache.txt', new Response('From cache'))}));

const params = new URLSearchParams(location.search);
const key = params.get('key');
try {
await e.addRoutes(routerRules[key]);
} catch (e) {
recordError(e);
}
self.skipWaiting();
});

self.addEventListener('activate', e => {
e.waitUntil(clients.claim());
});

self.addEventListener('message', function(event) {
if (event.data.reset) {
resetRecords();
}
if (event.data.port) {
const {requests, errors} = getRecords();
event.data.port.postMessage({requests, errors});
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>
Static Router: routers are evaluated when there is no fetch handler.
</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 RULE_KEY = 'condition-urlpattern-string-source-cache';
const SW_SRC = 'resources/static-router-no-fetch-handler-sw.js';
const CACHED_FILE = 'cache.txt';

promise_test(async t => {
const worker = await registerAndActivate(t, RULE_KEY, SW_SRC);

// Matched with the main reosurce load.
const {contentWindow} = await createIframe(t, `resources/${CACHED_FILE}`);
assert_equals(contentWindow.document.body.innerText, "From cache");

// TODO: Matched with the subreosurce load.
}, 'The router rule is evaluated without fetch handlers in service worker');
</script>
</body>

0 comments on commit 46c16b1

Please sign in to comment.