forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeacon-redirect.https.window.js
35 lines (28 loc) · 1.12 KB
/
beacon-redirect.https.window.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// META: timeout=long
// META: script=/common/get-host-info.sub.js
// META: script=/common/utils.js
// META: script=beacon-common.sub.js
'use strict';
const {ORIGIN} = get_host_info();
// Execute each sample test per redirect status code.
// Note that status codes 307 and 308 are the only codes that will maintain POST
// data through a redirect.
for (const status of [307, 308]) {
for (const type of [STRING, ARRAYBUFFER, FORM, BLOB]) {
parallelPromiseTest(async (t) => {
const iframe = document.createElement('iframe');
document.body.appendChild(iframe);
t.add_cleanup(() => iframe.remove());
const payload = makePayload(SMALL, type);
const id = token();
const destination =
`${ORIGIN}/beacon/resources/beacon.py?cmd=store&id=${id}`;
const url = `${ORIGIN}/common/redirect.py` +
`?status=${status}&location=${encodeURIComponent(destination)}`;
assert_true(iframe.contentWindow.navigator.sendBeacon(url, payload));
iframe.remove();
await waitForResult(id);
}, `cross-origin, CORS-safelisted: status = ${status}, type = ${type}`);
}
};
done();