summaryrefslogtreecommitdiffstats
path: root/dom/abort/tests
diff options
context:
space:
mode:
Diffstat (limited to 'dom/abort/tests')
-rw-r--r--dom/abort/tests/mochitest.ini10
-rw-r--r--dom/abort/tests/moz.build9
-rw-r--r--dom/abort/tests/slow.sjs13
-rw-r--r--dom/abort/tests/test_abort_controller.html73
-rw-r--r--dom/abort/tests/test_abort_controller_fetch.html80
-rw-r--r--dom/abort/tests/test_event_listener_leaks.html43
-rw-r--r--dom/abort/tests/unit/test_abort.js8
-rw-r--r--dom/abort/tests/unit/xpcshell.ini5
-rw-r--r--dom/abort/tests/worker_abort_controller_fetch.js33
9 files changed, 274 insertions, 0 deletions
diff --git a/dom/abort/tests/mochitest.ini b/dom/abort/tests/mochitest.ini
new file mode 100644
index 0000000000..2d708e8aa2
--- /dev/null
+++ b/dom/abort/tests/mochitest.ini
@@ -0,0 +1,10 @@
+[DEFAULT]
+support-files =
+ worker_abort_controller_fetch.js
+ slow.sjs
+ !/dom/events/test/event_leak_utils.js
+
+[test_abort_controller.html]
+[test_abort_controller_fetch.html]
+[test_event_listener_leaks.html]
+skip-if = (os == "win" && processor == "aarch64") #bug 1535784
diff --git a/dom/abort/tests/moz.build b/dom/abort/tests/moz.build
new file mode 100644
index 0000000000..af8d7033c8
--- /dev/null
+++ b/dom/abort/tests/moz.build
@@ -0,0 +1,9 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+MOCHITEST_MANIFESTS += ["mochitest.ini"]
+
+XPCSHELL_TESTS_MANIFESTS += ["unit/xpcshell.ini"]
diff --git a/dom/abort/tests/slow.sjs b/dom/abort/tests/slow.sjs
new file mode 100644
index 0000000000..33a9c76b81
--- /dev/null
+++ b/dom/abort/tests/slow.sjs
@@ -0,0 +1,13 @@
+function handleRequest(request, response) {
+ response.processAsync();
+
+ let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+ timer.init(
+ function () {
+ response.write("Here the content. But slowly.");
+ response.finish();
+ },
+ 1000,
+ Ci.nsITimer.TYPE_ONE_SHOT
+ );
+}
diff --git a/dom/abort/tests/test_abort_controller.html b/dom/abort/tests/test_abort_controller.html
new file mode 100644
index 0000000000..a7181711d5
--- /dev/null
+++ b/dom/abort/tests/test_abort_controller.html
@@ -0,0 +1,73 @@
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test AbortController</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<script class="testbody" type="text/javascript">
+
+function testWebIDL() {
+ ok("AbortController" in self, "We have a AbortController prototype");
+ ok("AbortSignal" in self, "We have a AbortSignal prototype");
+
+ var ac = new AbortController();
+ ok(!!ac, "AbortController can be created");
+ ok(ac instanceof AbortController, "AbortController is a AbortController");
+
+ ok(!!ac.signal, "AbortController has a signal");
+ ok(ac.signal instanceof AbortSignal, "abortSignal is a AbortSignal");
+ is(ac.signal.aborted, false, "By default AbortSignal.aborted is false");
+ next();
+}
+
+function testUpdateData() {
+ var ac = new AbortController();
+
+ is(ac.signal.aborted, false, "By default AbortSignal.aborted is false");
+
+ ac.abort();
+ is(ac.signal.aborted, true, "Signal is aborted");
+
+ next();
+}
+
+function testAbortEvent() {
+ var ac = new AbortController();
+ ac.signal.onabort = function(e) {
+ is(e.type, "abort", "Abort received");
+ next();
+ };
+ ac.abort();
+}
+
+var steps = [
+ // Simple stuff
+ testWebIDL,
+ testUpdateData,
+
+ // Event propagation
+ testAbortEvent,
+];
+
+function next() {
+ if (!steps.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var step = steps.shift();
+ step();
+}
+
+SimpleTest.waitForExplicitFinish();
+next();
+
+</script>
+</body>
+</html>
diff --git a/dom/abort/tests/test_abort_controller_fetch.html b/dom/abort/tests/test_abort_controller_fetch.html
new file mode 100644
index 0000000000..2342ecda89
--- /dev/null
+++ b/dom/abort/tests/test_abort_controller_fetch.html
@@ -0,0 +1,80 @@
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test AbortController in Fetch API</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<script class="testbody" type="text/javascript">
+
+function testAbortedFetch() {
+ var ac = new AbortController();
+ ac.abort();
+
+ fetch("slow.sjs", { signal: ac.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 ac = new AbortController();
+
+ var p = fetch("slow.sjs", { signal: ac.signal });
+ ac.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_abort_controller_fetch.js");
+ w.onmessage = function(e) {
+ ok(e.data, "Abort + Fetch works in workers");
+ next();
+ };
+ w.postMessage("testWorkerAbortedFetch");
+}
+
+function testWorkerFetchAndAbort() {
+ var w = new Worker("worker_abort_controller_fetch.js");
+ w.onmessage = function(e) {
+ ok(e.data, "Abort + Fetch works in workers");
+ next();
+ };
+ w.postMessage("testWorkerFetchAndAbort");
+}
+
+var steps = [
+ // fetch + signaling
+ testAbortedFetch,
+ testFetchAndAbort,
+ testWorkerAbortedFetch,
+ testWorkerFetchAndAbort,
+];
+
+function next() {
+ if (!steps.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var step = steps.shift();
+ step();
+}
+
+SimpleTest.waitForExplicitFinish();
+next();
+
+</script>
+</body>
+</html>
diff --git a/dom/abort/tests/test_event_listener_leaks.html b/dom/abort/tests/test_event_listener_leaks.html
new file mode 100644
index 0000000000..f9684e2309
--- /dev/null
+++ b/dom/abort/tests/test_event_listener_leaks.html
@@ -0,0 +1,43 @@
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Bug 1450271 - Test AbortSignal event listener leak conditions</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/dom/events/test/event_leak_utils.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<p id="display"></p>
+<script class="testbody" type="text/javascript">
+
+// Manipulate AbortSignal. Its important here that we create a
+// listener callback from the DOM objects back to the frame's global
+// in order to exercise the leak condition.
+async function useAbortSignal(contentWindow) {
+ let controller = new contentWindow.AbortController();
+ let signal = controller.signal;
+ signal.onabort = _ => {
+ contentWindow.abortCount += 1;
+ };
+}
+
+async function runTest() {
+ try {
+ await checkForEventListenerLeaks("AbortSignal", useAbortSignal);
+ } catch (e) {
+ ok(false, e);
+ } finally {
+ SimpleTest.finish();
+ }
+}
+
+SimpleTest.waitForExplicitFinish();
+addEventListener("load", runTest, { once: true });
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/abort/tests/unit/test_abort.js b/dom/abort/tests/unit/test_abort.js
new file mode 100644
index 0000000000..c1586443cb
--- /dev/null
+++ b/dom/abort/tests/unit/test_abort.js
@@ -0,0 +1,8 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function run_test() {
+ let ac = new AbortController();
+ Assert.ok(ac instanceof AbortController);
+ Assert.ok(ac.signal instanceof AbortSignal);
+}
diff --git a/dom/abort/tests/unit/xpcshell.ini b/dom/abort/tests/unit/xpcshell.ini
new file mode 100644
index 0000000000..219daa771a
--- /dev/null
+++ b/dom/abort/tests/unit/xpcshell.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+head =
+support-files =
+
+[test_abort.js]
diff --git a/dom/abort/tests/worker_abort_controller_fetch.js b/dom/abort/tests/worker_abort_controller_fetch.js
new file mode 100644
index 0000000000..571d9ffc7e
--- /dev/null
+++ b/dom/abort/tests/worker_abort_controller_fetch.js
@@ -0,0 +1,33 @@
+function testWorkerAbortedFetch() {
+ var ac = new AbortController();
+ ac.abort();
+
+ fetch("slow.sjs", { signal: ac.signal }).then(
+ () => {
+ postMessage(false);
+ },
+ e => {
+ postMessage(e.name == "AbortError");
+ }
+ );
+}
+
+function testWorkerFetchAndAbort() {
+ var ac = new AbortController();
+
+ var p = fetch("slow.sjs", { signal: ac.signal });
+ ac.abort();
+
+ p.then(
+ () => {
+ postMessage(false);
+ },
+ e => {
+ postMessage(e.name == "AbortError");
+ }
+ );
+}
+
+self.onmessage = function (e) {
+ self[e.data]();
+};