-
Notifications
You must be signed in to change notification settings - Fork 3k
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 multiple RouterCondition
This CL add the test to ensure multiple RouterConditions in one `condition` work with "and" condition. All RouterConditions should be matched. We don't have RunningStatus, those are tested separately because that needs an internal API. Bug: 40943429 Change-Id: Ieeb2ccc03baffe2ea2cfd0a88d4ea091de708ef9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5379636 Reviewed-by: Yoshisato Yanagisawa <yyanagisawa@chromium.org> Commit-Queue: Shunya Shishido <sisidovski@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/main@{#1276082}
- Loading branch information
1 parent
b6d4a0e
commit 847ab63
Showing
2 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
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
112 changes: 112 additions & 0 deletions
112
...orkers/service-worker/tentative/static-router/static-router-mutiple-conditions.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,112 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title> | ||
Static Router: routers are evaluated with the request method condition. | ||
</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 = 'multiple-conditions-network'; | ||
const ROUTER_KEY_WITH_DESTINATION = | ||
'multiple-conditions-with-destination-network'; | ||
const HTML_FILE = 'resources/simple.html'; | ||
const REQUEST_SRC = 'resources/direct.py'; | ||
|
||
const is_matched = async (worker) => { | ||
const {requests} = await get_info_from_worker(worker); | ||
return requests.length == 0; | ||
} | ||
|
||
const appendCSS = async (iwin, src) => { | ||
const promise = new Promise(resolve => { | ||
const link = iwin.document.createElement('link'); | ||
link.rel = 'stylesheet'; | ||
link.href = src; | ||
iwin.document.head.appendChild(link); | ||
link.onload = () => { | ||
resolve(link); | ||
}; | ||
}); | ||
|
||
return promise; | ||
}; | ||
|
||
const appendScript = async (iwin, src) => { | ||
const promise = new Promise(resolve => { | ||
const script = iwin.document.createElement('script'); | ||
script.src = src; | ||
iwin.document.body.appendChild(script); | ||
script.onload = () => { | ||
resolve(script); | ||
}; | ||
}); | ||
|
||
return promise; | ||
}; | ||
|
||
iframeTest(HTML_FILE, ROUTER_KEY, async (t, iwin, worker) => { | ||
// Reset the fetch count created by the setup process. | ||
await reset_info_in_worker(worker); | ||
const {requests} = await get_info_from_worker(worker); | ||
assert_equals(requests.length, 0); | ||
|
||
// Expected condtion: | ||
// - urlPattern: { search: 'test' } | ||
// - mode: 'cors' | ||
// - method: POST | ||
|
||
// Expect match. | ||
let response = await iwin.fetch(`../${REQUEST_SRC}?test`, {mode: 'cors', method: 'post'}); | ||
assert_equals(response.status, 200); | ||
assert_true(await is_matched(worker)); | ||
await reset_info_in_worker(worker); | ||
|
||
// mode: 'no-cors' won't match. | ||
response = await iwin.fetch(`../${REQUEST_SRC}?test`, {mode: 'no-cors', method: 'post'}); | ||
assert_false(await is_matched(worker)); | ||
await reset_info_in_worker(worker); | ||
|
||
// method: GET won't match. | ||
response = await iwin.fetch(`../${REQUEST_SRC}?test`, {mode: 'cors', method: 'get'}); | ||
assert_false(await is_matched(worker)); | ||
await reset_info_in_worker(worker); | ||
|
||
// No seqarch query won't match. | ||
response = await iwin.fetch(`../${REQUEST_SRC}`, {mode: 'cors', method: 'post'}); | ||
assert_false(await is_matched(worker)); | ||
await reset_info_in_worker(worker); | ||
}, 'Multiple conditions work with `and` operation'); | ||
|
||
iframeTest(HTML_FILE, ROUTER_KEY_WITH_DESTINATION, async (t, iwin, worker) => { | ||
// Reset the fetch count created by the setup process. | ||
await reset_info_in_worker(worker); | ||
const {requests} = await get_info_from_worker(worker); | ||
assert_equals(requests.length, 0); | ||
|
||
// Expected condtion: | ||
// - urlPattern: { search: 'test' } | ||
// - destination: style | ||
|
||
// Expect match. | ||
await appendCSS(iwin, `../${REQUEST_SRC}?test`); | ||
assert_true(await is_matched(worker)); | ||
await reset_info_in_worker(worker); | ||
|
||
// Other request destination won't match. | ||
await appendScript(iwin, `../${REQUEST_SRC}?test`); | ||
assert_false(await is_matched(worker)); | ||
await reset_info_in_worker(worker); | ||
|
||
// No seqarch query won't match. | ||
await appendCSS(iwin, `../${REQUEST_SRC}`); | ||
assert_false(await is_matched(worker)); | ||
await reset_info_in_worker(worker); | ||
}, 'Multiple conditions including requestDestination work with `and` operation'); | ||
</script> | ||
</body> |