forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for the no fetch handler case
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
1 parent
ea4555b
commit 46c16b1
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...ers/service-worker/tentative/static-router/resources/static-router-no-fetch-handler-sw.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
} | ||
}); |
29 changes: 29 additions & 0 deletions
29
...-workers/service-worker/tentative/static-router/static-router-no-fetch-handler.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |