diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /netwerk/test/unit/test_multipart_streamconv_empty.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_multipart_streamconv_empty.js')
-rw-r--r-- | netwerk/test/unit/test_multipart_streamconv_empty.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_multipart_streamconv_empty.js b/netwerk/test/unit/test_multipart_streamconv_empty.js new file mode 100644 index 0000000000..68bc5e6be8 --- /dev/null +++ b/netwerk/test/unit/test_multipart_streamconv_empty.js @@ -0,0 +1,68 @@ +"use strict"; + +function make_channel(url) { + return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true }); +} + +add_task(async function test_empty() { + let uri = "http://localhost"; + let httpChan = make_channel(uri); + + let channel = Cc["@mozilla.org/network/input-stream-channel;1"] + .createInstance(Ci.nsIInputStreamChannel) + .QueryInterface(Ci.nsIChannel); + + channel.setURI(httpChan.URI); + channel.loadInfo = httpChan.loadInfo; + + let inputStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance( + Ci.nsIStringInputStream + ); + inputStream.setUTF8Data(""); // Pass an empty string + + channel.contentStream = inputStream; + + let [status, buffer] = await new Promise(resolve => { + let streamConv = Cc["@mozilla.org/streamConverters;1"].getService( + Ci.nsIStreamConverterService + ); + let multipartListener = { + _buffer: "", + + QueryInterface: ChromeUtils.generateQI([ + "nsIStreamListener", + "nsIRequestObserver", + ]), + + onStartRequest(request) {}, + onDataAvailable(request, stream, offset, count) { + try { + this._buffer = this._buffer.concat(read_stream(stream, count)); + dump("BUFFEEE: " + this._buffer + "\n\n"); + } catch (ex) { + do_throw("Error in onDataAvailable: " + ex); + } + }, + + onStopRequest(request, status) { + resolve([status, this._buffer]); + }, + }; + let conv = streamConv.asyncConvertData( + "multipart/mixed", + "*/*", + multipartListener, + null + ); + + let chan = make_channel(uri); + chan.asyncOpen(conv); + }); + + Assert.notEqual( + status, + Cr.NS_OK, + "Should be an error code because content has no boundary" + ); + Assert.equal(buffer, "", "Should have received no content"); +}); |