3 const { HttpServer
} = ChromeUtils
.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
9 ChromeUtils
.defineLazyGetter(this, "uri", function () {
10 return "http://localhost:" + httpserver
.identity
.primaryPort
+ "/multipart";
13 function make_channel(url
) {
14 return NetUtil
.newChannel({ uri
: url
, loadUsingSystemPrincipal
: true });
19 "Content-type: text/plain\r\n" +
20 "Content-range: bytes 0-2/10\r\n" +
24 "Content-type: text/plain\r\n" +
25 "Content-range: bytes 3-7/10\r\n" +
30 "Content-type: text/plain\r\n" +
31 "Content-range: bytes 8-9/10\r\n" +
37 function contentHandler(metadata
, response
) {
40 'multipart/byteranges; boundary="boundary"'
42 response
.bodyOutputStream
.write(multipartBody
, multipartBody
.length
);
52 isByteRangeRequest
: true,
59 isByteRangeRequest
: true,
66 isByteRangeRequest
: true,
72 function responseHandler(request
, buffer
) {
73 Assert
.equal(buffer
, testData
[testNum
].data
);
75 request
.QueryInterface(Ci
.nsIChannel
).contentType
,
76 testData
[testNum
].type
79 request
.QueryInterface(Ci
.nsIByteRangeRequest
).isByteRangeRequest
,
80 testData
[testNum
].isByteRangeRequest
83 request
.QueryInterface(Ci
.nsIByteRangeRequest
).startRange
,
84 testData
[testNum
].startRange
87 request
.QueryInterface(Ci
.nsIByteRangeRequest
).endRange
,
88 testData
[testNum
].endRange
90 if (++testNum
== numTests
) {
91 httpserver
.stop(do_test_finished
);
95 var multipartListener
= {
98 QueryInterface
: ChromeUtils
.generateQI([
100 "nsIRequestObserver",
107 onDataAvailable(request
, stream
, offset
, count
) {
109 this._buffer
= this._buffer
.concat(read_stream(stream
, count
));
110 dump("BUFFEEE: " + this._buffer
+ "\n\n");
112 do_throw("Error in onDataAvailable: " + ex
);
116 onStopRequest(request
) {
118 responseHandler(request
, this._buffer
);
120 do_throw("Error in closure function: " + ex
);
125 function run_test() {
126 httpserver
= new HttpServer();
127 httpserver
.registerPathHandler("/multipart", contentHandler
);
128 httpserver
.start(-1);
130 var streamConv
= Cc
["@mozilla.org/streamConverters;1"].getService(
131 Ci
.nsIStreamConverterService
133 var conv
= streamConv
.asyncConvertData(
134 "multipart/byteranges",
140 var chan
= make_channel(uri
);
141 chan
.asyncOpen(conv
, null);