summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-06-10 21:51:44 +0000
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-06-13 11:51:41 +0200
commita04d67dd12d4999b28e74744150770482a3c5a3d (patch)
treedcbb29403e938f6b14140d15e9077c6188ca81c8 /dom/tests/mochitest
parent9e2da53a02356244c5dc0a3e7b7ec916740d3d51 (diff)
downloadUXP-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')
-rw-r--r--dom/tests/mochitest/fetch/file_fetch_controller.html81
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() {