diff options
author | Moonchild <moonchild@palemoon.org> | 2020-06-10 21:51:44 +0000 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-06-13 11:51:41 +0200 |
commit | a04d67dd12d4999b28e74744150770482a3c5a3d (patch) | |
tree | dcbb29403e938f6b14140d15e9077c6188ca81c8 /dom/tests/mochitest/fetch | |
parent | 9e2da53a02356244c5dc0a3e7b7ec916740d3d51 (diff) | |
download | UXP-a04d67dd12d4999b28e74744150770482a3c5a3d.tar UXP-a04d67dd12d4999b28e74744150770482a3c5a3d.tar.gz UXP-a04d67dd12d4999b28e74744150770482a3c5a3d.tar.lz UXP-a04d67dd12d4999b28e74744150770482a3c5a3d.tar.xz UXP-a04d67dd12d4999b28e74744150770482a3c5a3d.zip |
Issue #1587 - Part 3: Hook FetchSignal up to the Fetch API
Diffstat (limited to 'dom/tests/mochitest/fetch')
-rw-r--r-- | dom/tests/mochitest/fetch/file_fetch_controller.html | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/dom/tests/mochitest/fetch/file_fetch_controller.html b/dom/tests/mochitest/fetch/file_fetch_controller.html index 791d21b2b..026ff16a8 100644 --- a/dom/tests/mochitest/fetch/file_fetch_controller.html +++ b/dom/tests/mochitest/fetch/file_fetch_controller.html @@ -84,13 +84,94 @@ function testAbortEvent() { fc.abort(); } +function testAbortedFetch() { + var fc = new FetchController(); + fc.abort(); + + fetch('data:,foo', { signal: fc.signal }).then(() => { + ok(false, "Fetch should not return a resolved promise"); + }, e => { + is(e.name, "AbortError", "We have an abort error"); + }).then(next); +} + +function testFetchAndAbort() { + var fc = new FetchController(); + + var p = fetch('data:,foo', { signal: fc.signal }); + fc.abort(); + + p.then(() => { + ok(false, "Fetch should not return a resolved promise"); + }, e => { + is(e.name, "AbortError", "We have an abort error"); + }).then(next); +} + +function testWorkerAbortedFetch() { + function worker() { + var fc = new FetchController(); + fc.abort(); + + fetch('data:,foo', { signal: fc.signal }).then(() => { + postMessage(false); + }, e => { + postMessage(e.name == "AbortError"); + }); + } + + var str = worker.toString(); + var content = str.substring(0, str.length - 1).split('\n').splice(1).join(' '); + var url = URL.createObjectURL(new Blob([content], { type: "application/javascript" })); + var w = new Worker(url); + w.onmessage = function(e) { + ok(e.data, "Abort + Fetch works in workers"); + next(); + } +} + +function testWorkerFetchAndAbort() { + function worker() { + var fc = new FetchController(); + + var p = fetch('data:,foo', { signal: fc.signal }); + fc.abort(); + + p.then(() => { + postMessage(false); + }, e => { + postMessage(e.name == "AbortError"); + }); + } + + var str = worker.toString(); + var content = str.substring(0, str.length - 1).split('\n').splice(1).join(' '); + var url = URL.createObjectURL(new Blob([content], { type: "application/javascript" })); + var w = new Worker(url); + w.onmessage = function(e) { + ok(e.data, "Abort + Fetch works in workers"); + next(); + } +} + var steps = [ + // Simple stuff testWebIDL, testUpdateData, + + // Following algorithm testFollowingOurself, testFollowingOther, testFollowingLoop, + + // Event propagation testAbortEvent, + + // fetch + signaling + testAbortedFetch, + testFetchAndAbort, + testWorkerAbortedFetch, + testWorkerFetchAndAbort, ]; function next() { |