# HG changeset patch # User Andrea Marchesini # Parent c8705bdf03f64f22341e991a336f03ff78339c64 diff --git a/dom/xhr/tests/common_temporaryFileBlob.js b/dom/xhr/tests/common_temporaryFileBlob.js new file mode 100644 --- /dev/null +++ b/dom/xhr/tests/common_temporaryFileBlob.js @@ -0,0 +1,46 @@ +var data = ""; +for (var i = 0; i < 256; ++i) data += "1234567890ABCDEF"; + +function createXHR() { + var xhr = new XMLHttpRequest(); + xhr.responseType = 'blob'; + xhr.open("POST", "temporaryFileBlob.sjs"); + xhr.send({toString: function() { return data; }}); + return xhr; +} + +function test_simple() { + info("Simple test"); + + var xhr = createXHR(); + + xhr.onprogress = function() { + } + + 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(); + } +} diff --git a/dom/xhr/tests/mochitest.ini b/dom/xhr/tests/mochitest.ini --- a/dom/xhr/tests/mochitest.ini +++ b/dom/xhr/tests/mochitest.ini @@ -1,11 +1,12 @@ [DEFAULT] support-files = echo.sjs + temporaryFileBlob.sjs file_html_in_xhr.html file_html_in_xhr.sjs file_html_in_xhr2.html file_html_in_xhr3.html file_XHRDocURI.text file_XHRDocURI.text^headers^ file_XHRDocURI.xml file_XHRDocURI.xml^headers^ @@ -51,16 +52,18 @@ support-files = xhr_implicit_cancel_worker.js relativeLoad_import.js relativeLoad_worker.js relativeLoad_worker2.js responseIdentical.sjs subdir/relativeLoad_sub_worker.js subdir/relativeLoad_sub_worker2.js subdir/relativeLoad_sub_import.js + common_temporaryFileBlob.js + worker_temporaryFileBlob.js [test_xhr_overridemimetype_throws_on_invalid_state.html] skip-if = buildapp == 'b2g' # Requires webgl support [test_html_in_xhr.html] [test_sync_xhr_timer.xhtml] skip-if = toolkit == 'android' [test_xhr_abort_after_load.html] skip-if = toolkit == 'android' @@ -96,8 +99,9 @@ skip-if = buildapp == 'b2g' [test_worker_xhr_parameters.html] skip-if = buildapp == 'b2g' [test_worker_xhr_responseURL.html] [test_worker_xhr_system.html] [test_worker_xhr_timeout.html] skip-if = (os == "win") || (os == "mac") || toolkit == 'android' #bug 798220 [test_relativeLoad.html] skip-if = buildapp == 'b2g' # b2g(Failed to load script: relativeLoad_import.js) b2g-debug(Failed to load script: relativeLoad_import.js) b2g-desktop(Failed to load script: relativeLoad_import.js) +[test_temporaryFileBlob.html] diff --git a/dom/xhr/tests/temporaryFileBlob.sjs b/dom/xhr/tests/temporaryFileBlob.sjs new file mode 100644 --- /dev/null +++ b/dom/xhr/tests/temporaryFileBlob.sjs @@ -0,0 +1,30 @@ +const CC = Components.Constructor; + +const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1", + "nsIBinaryInputStream", + "setInputStream"); +const BinaryOutputStream = CC("@mozilla.org/binaryoutputstream;1", + "nsIBinaryOutputStream", + "setOutputStream"); +const Timer = CC("@mozilla.org/timer;1", + "nsITimer", + "initWithCallback"); + +function handleRequest(request, response) { + var bodyStream = new BinaryInputStream(request.bodyInputStream); + var bodyBytes = []; + while ((bodyAvail = bodyStream.available()) > 0) + Array.prototype.push.apply(bodyBytes, bodyStream.readByteArray(bodyAvail)); + + var bos = new BinaryOutputStream(response.bodyOutputStream); + + response.processAsync(); + + var part = bodyBytes.splice(0, 256); + bos.writeByteArray(part, part.length); + + var timer = new Timer(function(timer) { + bos.writeByteArray(bodyBytes, bodyBytes.length); + response.finish(); + }, 1000, Components.interfaces.nsITimer.TYPE_ONE_SHOT); +} diff --git a/dom/xhr/tests/test_temporaryFileBlob.html b/dom/xhr/tests/test_temporaryFileBlob.html new file mode 100644 --- /dev/null +++ b/dom/xhr/tests/test_temporaryFileBlob.html @@ -0,0 +1,65 @@ + + + + + Test for Bug 1202006 + + + + + + + + diff --git a/dom/xhr/tests/worker_temporaryFileBlob.js b/dom/xhr/tests/worker_temporaryFileBlob.js new file mode 100644 --- /dev/null +++ b/dom/xhr/tests/worker_temporaryFileBlob.js @@ -0,0 +1,27 @@ +importScripts('common_temporaryFileBlob.js'); + +function info(msg) { + postMessage({type: 'info', msg: msg}); +} + +function ok(a, msg) { + postMessage({type: 'check', what: !!a, msg: msg}); +} + +function is(a, b, msg) { + ok(a === b, msg); +} + +function next() { + postMessage({type: 'finish'}); +} + +onmessage = function(e) { + if (e.data == 'simple') { + test_simple(); + } else if (e.data == 'abort') { + test_abort(); + } else { + ok(false, 'Something wrong happened'); + } +}