summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/fetch
diff options
context:
space:
mode:
Diffstat (limited to 'dom/tests/mochitest/fetch')
-rw-r--r--dom/tests/mochitest/fetch/file_fetch_controller.html40
-rw-r--r--dom/tests/mochitest/fetch/file_fetch_observer.html115
-rw-r--r--dom/tests/mochitest/fetch/mochitest.ini2
-rw-r--r--dom/tests/mochitest/fetch/slow.sjs11
-rw-r--r--dom/tests/mochitest/fetch/test_fetch_observer.html3
-rw-r--r--dom/tests/mochitest/fetch/worker_fetch_controller.js27
6 files changed, 162 insertions, 36 deletions
diff --git a/dom/tests/mochitest/fetch/file_fetch_controller.html b/dom/tests/mochitest/fetch/file_fetch_controller.html
index 026ff16a8..e4137aac9 100644
--- a/dom/tests/mochitest/fetch/file_fetch_controller.html
+++ b/dom/tests/mochitest/fetch/file_fetch_controller.html
@@ -88,7 +88,7 @@ function testAbortedFetch() {
var fc = new FetchController();
fc.abort();
- fetch('data:,foo', { signal: fc.signal }).then(() => {
+ 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");
@@ -98,7 +98,7 @@ function testAbortedFetch() {
function testFetchAndAbort() {
var fc = new FetchController();
- var p = fetch('data:,foo', { signal: fc.signal });
+ var p = fetch('slow.sjs', { signal: fc.signal });
fc.abort();
p.then(() => {
@@ -109,49 +109,21 @@ function testFetchAndAbort() {
}
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);
+ 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() {
- 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);
+ 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 = [
diff --git a/dom/tests/mochitest/fetch/file_fetch_observer.html b/dom/tests/mochitest/fetch/file_fetch_observer.html
index 97af584ec..a172a18dc 100644
--- a/dom/tests/mochitest/fetch/file_fetch_observer.html
+++ b/dom/tests/mochitest/fetch/file_fetch_observer.html
@@ -10,12 +10,125 @@ function is(a, b, msg) {
function testObserver() {
ok("FetchObserver" in self, "We have a FetchObserver prototype");
- fetch('data:,foo', { observe: o => {
+ fetch('http://mochi.test:8888/tests/dom/tests/mochitest/fetch/slow.sjs', { observe: o => {
+ ok(!!o, "We have an observer");
+ ok(o instanceof FetchObserver, "The correct object has been passed");
+ is(o.state, "requesting", "By default the state is requesting");
+ next();
}});
}
+function testObserveAbort() {
+ var fc = new FetchController();
+
+ fetch('http://mochi.test:8888/tests/dom/tests/mochitest/fetch/slow.sjs', {
+ signal: fc.signal,
+ observe: o => {
+ o.onstatechange = () => {
+ ok(true, "StateChange event dispatched");
+ if (o.state == "aborted") {
+ ok(true, "Aborted!");
+ next();
+ }
+ }
+ fc.abort();
+ }
+ });
+}
+
+function testObserveComplete() {
+ var fc = new FetchController();
+
+ fetch('http://mochi.test:8888/tests/dom/tests/mochitest/fetch/slow.sjs', {
+ signal: fc.signal,
+ observe: o => {
+ o.onstatechange = () => {
+ ok(true, "StateChange event dispatched");
+ if (o.state == "complete") {
+ ok(true, "Operation completed");
+ next();
+ }
+ }
+ }
+ });
+}
+
+function testObserveErrored() {
+ var fc = new FetchController();
+
+ fetch('foo: bar', {
+ signal: fc.signal,
+ observe: o => {
+ o.onstatechange = () => {
+ ok(true, "StateChange event dispatched");
+ if (o.state == "errored") {
+ ok(true, "Operation completed");
+ next();
+ }
+ }
+ }
+ });
+}
+
+function testObserveResponding() {
+ var fc = new FetchController();
+
+ fetch('http://mochi.test:8888/tests/dom/tests/mochitest/fetch/slow.sjs', {
+ signal: fc.signal,
+ observe: o => {
+ o.onstatechange = () => {
+ if (o.state == "responding") {
+ ok(true, "We have responding events");
+ next();
+ }
+ }
+ }
+ });
+}
+
+function workify(worker) {
+ function methods() {
+ function ok(a, msg) {
+ postMessage( { type: 'check', state: !!a, message: msg });
+ };
+ function is(a, b, msg) {
+ postMessage( { type: 'check', state: a === b, message: msg });
+ };
+ function next() {
+ postMessage( { type: 'finish' });
+ };
+ }
+
+ var str = methods.toString();
+ var methodsContent = str.substring(0, str.length - 1).split('\n').splice(1).join('\n');
+
+ str = worker.toString();
+ var workerContent = str.substring(0, str.length - 1).split('\n').splice(1).join('\n');
+
+ var content = methodsContent + workerContent;
+ var url = URL.createObjectURL(new Blob([content], { type: "application/javascript" }));
+ var w = new Worker(url);
+ w.onmessage = e => {
+ if (e.data.type == 'check') {
+ ok(e.data.state, "WORKER: " + e.data.message);
+ } else if (e.data.type == 'finish') {
+ next();
+ } else {
+ ok(false, "Something went wrong");
+ }
+ }
+}
+
var steps = [
testObserver,
+ testObserveAbort,
+ function() { workify(testObserveAbort); },
+ testObserveComplete,
+ function() { workify(testObserveComplete); },
+ testObserveErrored,
+ function() { workify(testObserveErrored); },
+ testObserveResponding,
+ function() { workify(testObserveResponding); },
];
function next() {
diff --git a/dom/tests/mochitest/fetch/mochitest.ini b/dom/tests/mochitest/fetch/mochitest.ini
index 60fa454f4..7493ede50 100644
--- a/dom/tests/mochitest/fetch/mochitest.ini
+++ b/dom/tests/mochitest/fetch/mochitest.ini
@@ -17,11 +17,13 @@ support-files =
reroute.html
reroute.js
reroute.js^headers^
+ slow.sjs
sw_reroute.js
empty.js
empty.js^headers^
worker_temporaryFileBlob.js
common_temporaryFileBlob.js
+ worker_fetch_controller.js
!/dom/xhr/tests/file_XHR_binary1.bin
!/dom/xhr/tests/file_XHR_binary1.bin^headers^
!/dom/xhr/tests/file_XHR_binary2.bin
diff --git a/dom/tests/mochitest/fetch/slow.sjs b/dom/tests/mochitest/fetch/slow.sjs
new file mode 100644
index 000000000..feab0f1fc
--- /dev/null
+++ b/dom/tests/mochitest/fetch/slow.sjs
@@ -0,0 +1,11 @@
+function handleRequest(request, response)
+{
+ response.processAsync();
+
+ timer = Components.classes["@mozilla.org/timer;1"].
+ createInstance(Components.interfaces.nsITimer);
+ timer.init(function() {
+ response.write("Here the content. But slowly.");
+ response.finish();
+ }, 1000, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
+}
diff --git a/dom/tests/mochitest/fetch/test_fetch_observer.html b/dom/tests/mochitest/fetch/test_fetch_observer.html
index 2b6c0362d..2af86977c 100644
--- a/dom/tests/mochitest/fetch/test_fetch_observer.html
+++ b/dom/tests/mochitest/fetch/test_fetch_observer.html
@@ -12,7 +12,8 @@
<body>
<script class="testbody" type="text/javascript">
-SpecialPowers.pushPrefEnv({"set": [["dom.fetchObserver.enabled", true ]]}, () => {
+SpecialPowers.pushPrefEnv({"set": [["dom.fetchObserver.enabled", true ],
+ ["dom.fetchController.enabled", true ]]}, () => {
let ifr = document.createElement('iframe');
ifr.src = "file_fetch_observer.html";
document.body.appendChild(ifr);
diff --git a/dom/tests/mochitest/fetch/worker_fetch_controller.js b/dom/tests/mochitest/fetch/worker_fetch_controller.js
new file mode 100644
index 000000000..6b008fea8
--- /dev/null
+++ b/dom/tests/mochitest/fetch/worker_fetch_controller.js
@@ -0,0 +1,27 @@
+function testWorkerAbortedFetch() {
+ var fc = new FetchController();
+ fc.abort();
+
+ fetch('slow.sjs', { signal: fc.signal }).then(() => {
+ postMessage(false);
+ }, e => {
+ postMessage(e.name == "AbortError");
+ });
+}
+
+function testWorkerFetchAndAbort() {
+ var fc = new FetchController();
+
+ var p = fetch('slow.sjs', { signal: fc.signal });
+ fc.abort();
+
+ p.then(() => {
+ postMessage(false);
+ }, e => {
+ postMessage(e.name == "AbortError");
+ });
+}
+
+onmessage = function(e) {
+ self[e.data]();
+}