max-payload.https.window.js (2253B)
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 // META: script=/fetch/fetch-later/quota/resources/helper.js 5 'use strict'; 6 7 const {HTTPS_ORIGIN, HTTPS_NOTSAMESITE_ORIGIN} = get_host_info(); 8 9 // Skips FormData & URLSearchParams, as browser adds extra bytes to them 10 // in addition to the user-provided content. It is difficult to test a 11 // request right at the quota limit. 12 // Skips File & Blob as it's difficult to estimate what additional data are 13 // added into them. 14 const dataType = BeaconDataType.String; 15 16 // Request headers are counted into total request size. 17 const headers = new Headers({'Content-Type': 'text/plain;charset=UTF-8'}); 18 19 // In a same-origin iframe, test making a POST request with max possible 20 // payload. 21 promise_test( 22 async _ => { 23 const uuid = token(); 24 const requestUrl = generateSetBeaconURL(uuid, {host: HTTPS_ORIGIN}); 25 26 await loadFetchLaterIframe(HTTPS_ORIGIN, { 27 targetUrl: requestUrl, 28 uuid: uuid, 29 activateAfter: 0, 30 method: 'POST', 31 bodyType: dataType, 32 bodySize: getRemainingQuota(QUOTA_PER_ORIGIN, requestUrl, headers), 33 // Required, as the size of referrer also take up quota. 34 referrer: '', 35 }); 36 }, 37 `fetchLater() accepts max payload in a POST request body of ${ 38 dataType} in same-origin iframe.`); 39 40 // In a same-origin iframe, test making a POST request with max possible 41 // payload + 1 byte. 42 promise_test( 43 async _ => { 44 const uuid = token(); 45 const requestUrl = generateSetBeaconURL(uuid, {host: HTTPS_ORIGIN}); 46 47 await loadFetchLaterIframe(HTTPS_ORIGIN, { 48 targetUrl: requestUrl, 49 uuid: uuid, 50 activateAfter: 0, 51 method: 'POST', 52 bodyType: dataType, 53 bodySize: getRemainingQuota(QUOTA_PER_ORIGIN, requestUrl, headers) + 1, 54 // Required, as the size of referrer also take up quota. 55 referrer: '', 56 expect: new FetchLaterIframeExpectation( 57 FetchLaterExpectationType.ERROR_DOM, 'QuotaExceededError'), 58 }); 59 }, 60 `fetchLater() rejects max+1 payload in a POST request body of ${ 61 dataType} in same-origin iframe.`);