Skip to content

Commit 979dccd

Browse files
KhafraDevronag
authored andcommitted
wpt: add redirect-back-to-original-origin.any.js
1 parent 21281de commit 979dccd

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

test/wpt/server/server.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const server = createServer(async (req, res) => {
3232
const fullUrl = new URL(req.url, `http://localhost:${server.address().port}`)
3333

3434
switch (fullUrl.pathname) {
35+
case '/fetch/api/resources/cors-top.txt':
3536
case '/fetch/api/resources/top.txt':
3637
case '/mimesniff/mime-types/resources/generated-mime-types.json':
3738
case '/mimesniff/mime-types/resources/mime-types.json':
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// META: global=window,worker
2+
// META: script=/common/get-host-info.sub.js
3+
4+
const BASE = location.href;
5+
const IS_HTTPS = new URL(BASE).protocol === 'https:';
6+
const REMOTE_HOST = get_host_info()['REMOTE_HOST'];
7+
const REMOTE_PORT =
8+
IS_HTTPS ? get_host_info()['HTTPS_PORT'] : get_host_info()['HTTP_PORT'];
9+
10+
const REMOTE_ORIGIN =
11+
new URL(`//${REMOTE_HOST}:${REMOTE_PORT}`, BASE).origin;
12+
const DESTINATION = new URL('../resources/cors-top.txt', BASE);
13+
14+
function CreateURL(url, BASE, params) {
15+
const u = new URL(url, BASE);
16+
for (const {name, value} of params) {
17+
u.searchParams.append(name, value);
18+
}
19+
return u;
20+
}
21+
22+
const redirect =
23+
CreateURL('/fetch/api/resources/redirect.py', REMOTE_ORIGIN,
24+
[{name: 'redirect_status', value: 303},
25+
{name: 'location', value: DESTINATION.href}]);
26+
27+
promise_test(async (test) => {
28+
const res = await fetch(redirect.href, {mode: 'no-cors'});
29+
// This is discussed at https://github.com/whatwg/fetch/issues/737.
30+
assert_equals(res.type, 'opaque');
31+
}, 'original => remote => original with mode: "no-cors"');
32+
33+
promise_test(async (test) => {
34+
const res = await fetch(redirect.href, {mode: 'cors'});
35+
assert_equals(res.type, 'cors');
36+
}, 'original => remote => original with mode: "cors"');
37+
38+
done();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
top

0 commit comments

Comments
 (0)