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