diff options
Diffstat (limited to 'dom/tests/mochitest/fetch/common_temporaryFileBlob.js')
-rw-r--r-- | dom/tests/mochitest/fetch/common_temporaryFileBlob.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/dom/tests/mochitest/fetch/common_temporaryFileBlob.js b/dom/tests/mochitest/fetch/common_temporaryFileBlob.js new file mode 100644 index 000000000..47f5695b1 --- /dev/null +++ b/dom/tests/mochitest/fetch/common_temporaryFileBlob.js @@ -0,0 +1,39 @@ +var data = new Array(256).join("1234567890ABCDEF"); + +function test_basic() { + info("Simple test"); + + fetch("/tests/dom/xhr/tests/temporaryFileBlob.sjs", + { method: "POST", body: data }) + .then(response => { + return response.blob(); + }).then(blob => { + ok(blob instanceof Blob, "We have a blob!"); + is(blob.size, data.length, "Data length matches"); + + var fr = new FileReader(); + fr.readAsText(blob); + fr.onload = function() { + is(fr.result, data, "Data content matches"); + next(); + } + }); +} + +function test_worker() { + info("XHR in workers"); + 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(42); +} |