summaryrefslogtreecommitdiffstats
path: root/dom/xhr/tests/common_temporaryFileBlob.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/xhr/tests/common_temporaryFileBlob.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/xhr/tests/common_temporaryFileBlob.js')
-rw-r--r--dom/xhr/tests/common_temporaryFileBlob.js100
1 files changed, 100 insertions, 0 deletions
diff --git a/dom/xhr/tests/common_temporaryFileBlob.js b/dom/xhr/tests/common_temporaryFileBlob.js
new file mode 100644
index 000000000..81a66238d
--- /dev/null
+++ b/dom/xhr/tests/common_temporaryFileBlob.js
@@ -0,0 +1,100 @@
+var data = new Array(256).join("1234567890ABCDEF");
+
+function createXHR() {
+ var xhr = new XMLHttpRequest();
+ xhr.open("POST", "temporaryFileBlob.sjs");
+ xhr.responseType = 'blob';
+ xhr.send({toString: function() { return data; }});
+ return xhr;
+}
+
+function test_simple() {
+ info("Simple test");
+
+ var xhr = createXHR();
+
+ xhr.onloadend = function() {
+ ok(xhr.response instanceof Blob, "We have a blob!");
+ is(xhr.response.size, data.length, "Data length matches");
+
+ var fr = new FileReader();
+ fr.readAsText(xhr.response);
+ fr.onload = function() {
+ is(fr.result, data, "Data content matches");
+ next();
+ }
+ }
+}
+
+function test_abort() {
+ info("Aborting during onloading");
+
+ var xhr = createXHR();
+
+ xhr.onprogress = function() {
+ xhr.abort();
+ }
+
+ xhr.onloadend = function() {
+ ok(!xhr.response, "We should not have a Blob!");
+ next();
+ }
+}
+
+function test_reuse() {
+ info("Reuse test");
+
+ var xhr = createXHR();
+
+ var count = 0;
+ xhr.onloadend = function() {
+ ok(xhr.response instanceof Blob, "We have a blob!");
+ is(xhr.response.size, data.length, "Data length matches");
+
+ var fr = new FileReader();
+ fr.readAsText(xhr.response);
+ fr.onload = function() {
+ is(fr.result, data, "Data content matches");
+ if (++count > 2) {
+ next();
+ return;
+ }
+
+ xhr.open("POST", "temporaryFileBlob.sjs");
+ xhr.responseType = 'blob';
+ xhr.send({toString: function() { return data; }});
+ }
+ }
+}
+
+function test_worker_generic(test) {
+ var w = new Worker('worker_temporaryFileBlob.js');
+ w.onmessage = function(e) {
+ if (e.data.type == 'info') {
+ info(e.data.msg);
+ } else if (e.data.type == 'check') {
+ ok(e.data.what, e.data.msg);
+ } else if (e.data.type == 'finish') {
+ next();
+ } else {
+ ok(false, 'Something wrong happened');
+ }
+ }
+
+ w.postMessage(test);
+}
+
+function test_worker() {
+ info("XHR in workers");
+ test_worker_generic('simple');
+}
+
+function test_worker_abort() {
+ info("XHR in workers");
+ test_worker_generic('abort');
+}
+
+function test_worker_reuse() {
+ info("XHR in workers");
+ test_worker_generic('reuse');
+}