summaryrefslogtreecommitdiffstats
path: root/dom/abort/tests/file_abort_controller.html
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-06-11 23:20:52 +0000
committerMoonchild <moonchild@palemoon.org>2020-06-11 23:20:52 +0000
commite97a29a6569fac73e81cf46a0e682ac926ea3456 (patch)
tree65cb4710bb2b14f6ebdbcc92fb90604b1174a20e /dom/abort/tests/file_abort_controller.html
parent1620ec19653125db78f380043a52b6da6a34c281 (diff)
downloadUXP-e97a29a6569fac73e81cf46a0e682ac926ea3456.tar
UXP-e97a29a6569fac73e81cf46a0e682ac926ea3456.tar.gz
UXP-e97a29a6569fac73e81cf46a0e682ac926ea3456.tar.lz
UXP-e97a29a6569fac73e81cf46a0e682ac926ea3456.tar.xz
UXP-e97a29a6569fac73e81cf46a0e682ac926ea3456.zip
Issue #1587 - Part 7: Rename FetchController to AbortController
Also renames FetchSignal to AbortSignal. Includes renaming the various controlling prefs to enable.
Diffstat (limited to 'dom/abort/tests/file_abort_controller.html')
-rw-r--r--dom/abort/tests/file_abort_controller.html161
1 files changed, 161 insertions, 0 deletions
diff --git a/dom/abort/tests/file_abort_controller.html b/dom/abort/tests/file_abort_controller.html
new file mode 100644
index 000000000..e4137aac9
--- /dev/null
+++ b/dom/abort/tests/file_abort_controller.html
@@ -0,0 +1,161 @@
+<script>
+function ok(a, msg) {
+ parent.postMessage({ type: "check", status: !!a, message: msg }, "*");
+}
+
+function is(a, b, msg) {
+ ok(a === b, msg);
+}
+
+function testWebIDL() {
+ ok("FetchController" in self, "We have a FetchController prototype");
+ ok("FetchSignal" in self, "We have a FetchSignal prototype");
+
+ var fc = new FetchController();
+ ok(!!fc, "FetchController can be created");
+ ok(fc instanceof FetchController, "FetchController is a FetchController");
+
+ ok(!!fc.signal, "FetchController has a signal");
+ ok(fc.signal instanceof FetchSignal, "fetchSignal is a FetchSignal");
+ is(fc.signal.aborted, false, "By default FetchSignal.aborted is false");
+ next();
+}
+
+function testUpdateData() {
+ var fc = new FetchController();
+
+ is(fc.signal.aborted, false, "By default FetchSignal.aborted is false");
+
+ fc.abort();
+ is(fc.signal.aborted, true, "Signal is aborted");
+
+ next();
+}
+
+function testFollowingOurself() {
+ // Let's follow ourself
+ var fc = new FetchController();
+ fc.follow(fc.signal);
+
+ fc.abort();
+ is(fc.signal.aborted, true, "Signal is aborted");
+
+ next();
+}
+
+function testFollowingOther() {
+ // Let's follow another one
+ var fc1 = new FetchController();
+ var fc2 = new FetchController();
+ fc1.follow(fc2.signal);
+
+ fc2.abort();
+
+ is(fc1.signal.aborted, true, "Signal is aborted");
+ is(fc2.signal.aborted, true, "Signal is aborted");
+
+ next();
+}
+
+function testFollowingLoop() {
+ // fc1 -> fc2 -> fc3 -> fc1
+ var fc1 = new FetchController();
+ var fc2 = new FetchController();
+ var fc3 = new FetchController();
+ fc1.follow(fc2.signal);
+ fc2.follow(fc3.signal);
+ fc3.follow(fc1.signal);
+
+ fc3.abort();
+
+ is(fc1.signal.aborted, true, "Signal is aborted");
+ is(fc2.signal.aborted, true, "Signal is aborted");
+ is(fc3.signal.aborted, true, "Signal is aborted");
+
+ next();
+}
+
+function testAbortEvent() {
+ var fc = new FetchController();
+ fc.signal.onabort = function(e) {
+ is(e.type, "abort", "Abort received");
+ next();
+ }
+ fc.abort();
+}
+
+function testAbortedFetch() {
+ var fc = new FetchController();
+ fc.abort();
+
+ fetch('slow.sjs', { 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('slow.sjs', { 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() {
+ var w = new Worker('worker_fetch_controller.js');
+ w.onmessage = function(e) {
+ ok(e.data, "Abort + Fetch works in workers");
+ next();
+ }
+ w.postMessage('testWorkerAbortedFetch');
+}
+
+function testWorkerFetchAndAbort() {
+ var w = new Worker('worker_fetch_controller.js');
+ w.onmessage = function(e) {
+ ok(e.data, "Abort + Fetch works in workers");
+ next();
+ }
+ w.postMessage('testWorkerFetchAndAbort');
+}
+
+var steps = [
+ // Simple stuff
+ testWebIDL,
+ testUpdateData,
+
+ // Following algorithm
+ testFollowingOurself,
+ testFollowingOther,
+ testFollowingLoop,
+
+ // Event propagation
+ testAbortEvent,
+
+ // fetch + signaling
+ testAbortedFetch,
+ testFetchAndAbort,
+ testWorkerAbortedFetch,
+ testWorkerFetchAndAbort,
+];
+
+function next() {
+ if (!steps.length) {
+ parent.postMessage({ type: "finish" }, "*");
+ return;
+ }
+
+ var step = steps.shift();
+ step();
+}
+
+next();
+
+</script>