empty-payload.https.window.js (1301B)
1 // META: script=/common/get-host-info.sub.js 2 // META: script=/common/utils.js 3 // META: script=/fetch/fetch-later/resources/fetch-later-helper.js 4 'use strict'; 5 6 const {HTTPS_ORIGIN, HTTPS_NOTSAMESITE_ORIGIN} = get_host_info(); 7 8 // Test making a HTTP POST request with empty payload, which is not accepted by 9 // fetchLater API. 10 for (const dataType in BeaconDataType) { 11 const requestInit = { 12 activateAfter: 0, 13 method: 'POST', 14 body: makeBeaconData('', dataType) 15 }; 16 17 if (dataType === BeaconDataType.FormData) { 18 // An empty FormData object serializes to non-empty String. Hence, there 19 // will be no error thrown from fetchLater. 20 parallelPromiseTest(async _ => { 21 expectFetchLater(requestInit); 22 }, `fetchLater() accepts a non-empty POST request body of ${dataType}.`); 23 continue; 24 } 25 test( 26 () => assert_throws_js(TypeError, () => fetchLater('/', requestInit)), 27 `fetchLater() does not accept an empty POST request body of ${ 28 dataType}.`); 29 } 30 31 // Test making HTTP non-POST requests, which has no payload and should be 32 // accepted by fetchLater API. 33 for (const method of ['GET', 'DELETE', 'PUT']) { 34 parallelPromiseTest( 35 async _ => expectFetchLater({activateAfter: 0, method: method}), 36 `fetchLater() accept a ${method} request.`); 37 }