-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add main resource tests for the static router and small test js fix
This CL adds WPT to ensure if the matched main resource request skips ServiceWorker fetch handler. Also this test removed unnecessary "async" from the BestEffortServiceWorker browser test js. Bug: 1371756, 1420517 Change-Id: Iab72cd2835f000312c2c0cd41b78799261038356 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4707378 Reviewed-by: Minoru Chikamune <[email protected]> Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Shunya Shishido <[email protected]> Reviewed-by: Yoshisato Yanagisawa <[email protected]> Cr-Commit-Position: refs/heads/main@{#1174243}
- Loading branch information
1 parent
c1a0c70
commit 13ef5f8
Showing
3 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...ice-worker/tentative/static-router/resources/simple-test-for-condition-main-resource.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,3 @@ | ||
<!DOCTYPE html> | ||
<title>Simple</title> | ||
Here's a simple html file. |
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
58 changes: 58 additions & 0 deletions
58
...ice-workers/service-worker/tentative/static-router/static-router-main-resource.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,58 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Static Router: simply skip fetch handler for main resource if pattern matches</title> | ||
<script src="/common/get-host-info.sub.js"></script> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/test-helpers.sub.js"></script> | ||
<body> | ||
<script> | ||
const SCRIPT = 'resources/static-router-sw.js'; | ||
const SCOPE = 'resources/'; | ||
const REGISTERED_ROUTE_HTML = | ||
'resources/simple-test-for-condition-main-resource.html'; | ||
const NON_REGISTERED_ROUTE_HTML = 'resources/simple.html'; | ||
const host_info = get_host_info(); | ||
const path = new URL(".", window.location).pathname; | ||
|
||
// Register a service worker, then create an iframe at url. | ||
function iframeTest(url, callback, name) { | ||
return promise_test(async t => { | ||
const reg = await service_worker_unregister_and_register(t, SCRIPT, SCOPE); | ||
add_completion_callback(() => reg.unregister()); | ||
const worker = reg.installing; | ||
await wait_for_state(t, worker, 'activated'); | ||
const iframe = await with_iframe(url); | ||
const iwin = iframe.contentWindow; | ||
t.add_cleanup(() => iframe.remove()); | ||
await callback(t, iwin, worker); | ||
}, name); | ||
} | ||
|
||
function get_fetched_urls(worker) { | ||
return new Promise(function(resolve) { | ||
var channel = new MessageChannel(); | ||
channel.port1.onmessage = function(msg) { resolve(msg); }; | ||
worker.postMessage({port: channel.port2}, [channel.port2]); | ||
}); | ||
} | ||
|
||
iframeTest(REGISTERED_ROUTE_HTML, async (t, iwin, worker) => { | ||
const fetched_urls = await get_fetched_urls(worker); | ||
const {requests} = fetched_urls.data; | ||
assert_equals(requests.length, 0); | ||
assert_equals(iwin.document.body.innerText, "Here's a simple html file."); | ||
}, 'Main resource load matched with the condition'); | ||
|
||
iframeTest(NON_REGISTERED_ROUTE_HTML, async (t, iwin, worker) => { | ||
const fetched_urls = await get_fetched_urls(worker); | ||
const {requests} = fetched_urls.data; | ||
assert_equals(requests.length, 1); | ||
assert_equals( | ||
requests[0].url, | ||
`${host_info['HTTPS_ORIGIN']}${path}${NON_REGISTERED_ROUTE_HTML}`); | ||
assert_equals(requests[0].mode, 'navigate'); | ||
}, 'Main resource load not matched with the condition'); | ||
|
||
</script> | ||
</body> |