diff --git a/fetch/fetch-later/basic.tentative.https.window.js b/fetch/fetch-later/basic.tentative.https.window.js index a8ca011a7c99287..55bdbc97127a9c0 100644 --- a/fetch/fetch-later/basic.tentative.https.window.js +++ b/fetch/fetch-later/basic.tentative.https.window.js @@ -7,7 +7,29 @@ test(() => { assert_throws_js(TypeError, () => fetchLater()); }, `fetchLater() cannot be called without request.`); +test(() => { + assert_throws_js(TypeError, () => fetchLater('http://www.google.com')); + assert_throws_js(TypeError, () => fetchLater('file://tmp')); + assert_throws_js(TypeError, () => fetchLater('ssh://example.com')); + assert_throws_js(TypeError, () => fetchLater('wss://example.com')); + assert_throws_js(TypeError, () => fetchLater('about:blank')); + assert_throws_js(TypeError, () => fetchLater(`javascript:alert('');`)); +}, `fetchLater() throws TypeError on non-HTTPS URL.`); + test(() => { const result = fetchLater('/'); - assert_false(result.sent); + assert_false(result.activated); }, `fetchLater()'s return tells the deferred request is not yet sent.`); + +test(() => { + const result = fetchLater('/'); + assert_throws_js(TypeError, () => result.activated = true); +}, `fetchLater() throws TypeError when mutating its returned state.`); + +test(() => { + const controller = new AbortController(); + // Immediately aborts the controller. + controller.abort(); + assert_throws_dom( + 'AbortError', () => fetchLater('/', {signal: controller.signal})); +}, `fetchLater() throws AbortError when its initial abort signal is aborted.`); diff --git a/fetch/fetch-later/send-on-discard.tentative.https.window.js b/fetch/fetch-later/send-on-discard.tentative.https.window.js new file mode 100644 index 000000000000000..4fde4e4ceb5da12 --- /dev/null +++ b/fetch/fetch-later/send-on-discard.tentative.https.window.js @@ -0,0 +1,46 @@ +// META: script=/resources/testharness.js +// META: script=/resources/testharnessreport.js +// META: script=/common/utils.js +// META: script=/pending-beacon/resources/pending_beacon-helper.js + +'use strict'; + +parallelPromiseTest(async t => { + const uuid = token(); + const url = generateSetBeaconURL(uuid); + const numPerMethod = 20; + const total = numPerMethod * 2; + + // Loads an iframe that creates `numPerMethod` GET & POST fetchLater requests. + const iframe = await loadScriptAsIframe(` + const url = "${url}"; + for (let i = 0; i < ${numPerMethod}; i++) { + fetchLater(url); + fetchLater(url, {method: 'POST'}); + } + `); + // Delete the iframe to trigger deferred request sending. + document.body.removeChild(iframe); + + // The iframe should have sent all requests. + await expectBeacon(uuid, {count: total}); +}, 'A discarded document sends all its fetchLater requests.'); + +parallelPromiseTest(async t => { + const uuid = token(); + const url = generateSetBeaconURL(uuid); + + // Loads an iframe that creates 2 fetchLater requests. One of them is aborted. + const iframe = await loadScriptAsIframe(` + const url = "${url}"; + const controller = new AbortController(); + fetchLater(url, {signal: controller.signal}); + fetchLater(url, {method: 'POST'}); + controller.abort(); + `); + // Delete the iframe to trigger deferred request sending. + document.body.removeChild(iframe); + + // The iframe should not send the aborted request. + await expectBeacon(uuid, {count: 1}); +}, 'A discarded document does not send an already aborted fetchLater request.'); diff --git a/fetch/fetch-later/sendondiscard.tentative.https.window.js b/fetch/fetch-later/sendondiscard.tentative.https.window.js deleted file mode 100644 index 0613d18dffbfc98..000000000000000 --- a/fetch/fetch-later/sendondiscard.tentative.https.window.js +++ /dev/null @@ -1,28 +0,0 @@ -// META: script=/resources/testharness.js -// META: script=/resources/testharnessreport.js -// META: script=/common/utils.js -// META: script=/pending-beacon/resources/pending_beacon-helper.js - -'use strict'; - -parallelPromiseTest(async t => { - const uuid = token(); - const url = generateSetBeaconURL(uuid); - const numPerMethod = 20; - const total = numPerMethod * 2; - - // Loads an iframe that creates `numPerMethod` GET & POST fetchLater requests. - const iframe = await loadScriptAsIframe(` - const url = "${url}"; - for (let i = 0; i < ${numPerMethod}; i++) { - let get = fetchLater(url); - let post = fetchLater(url, {method: 'POST'}); - } - `); - - // Delete the iframe to trigger deferred request sending. - document.body.removeChild(iframe); - - // The iframe should have sent all requests. - await expectBeacon(uuid, {count: total}); -}, 'A discarded document sends all its fetchLater requests with default config.');