From 6dcb43a12a3f5f4612661d04d658a99a50b830bb Mon Sep 17 00:00:00 2001 From: "jwalden%mit.edu" Date: Thu, 16 Nov 2006 21:44:46 +0000 Subject: [PATCH] Bug 360930 - test_file_protocol.js can fail based on execution environment (where TmpD contains a particularly large number of files). r+sr=biesi --- netwerk/test/unit/test_file_protocol.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/netwerk/test/unit/test_file_protocol.js b/netwerk/test/unit/test_file_protocol.js index 3ce8329a0d3c..ebe7fad38b10 100644 --- a/netwerk/test/unit/test_file_protocol.js +++ b/netwerk/test/unit/test_file_protocol.js @@ -33,13 +33,18 @@ function read_stream(stream, count) { Cc["@mozilla.org/binaryinputstream;1"]. createInstance(Ci.nsIBinaryInputStream); wrapper.setInputStream(stream); - var bytes = wrapper.readByteArray(count); - /* assume that the stream is going to give us all of the data. - not all streams conform to this. */ - if (bytes.length != count) - do_throw("Partial read from input stream!"); - /* convert array of bytes to a String object (by no means efficient) */ - return eval("String.fromCharCode(" + bytes.toString() + ")"); + /* JS methods can be called with a maximum of 65535 arguments, and input + streams don't have to return all the data they make .available() when + asked to .read() that number of bytes. */ + var data = []; + while (count > 0) { + var bytes = wrapper.readByteArray(Math.min(65535, count)); + data.push(String.fromCharCode.apply(null, bytes)); + count -= bytes.length; + if (bytes.length == 0) + do_throw("Nothing read from input stream!"); + } + return data.join(''); } function new_file_input_stream(file, buffered) {