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 });
18 "--boundary\r\nSet-Cookie: foo=bar\r\n\r\nSome text\r\n--boundary--";
20 function contentHandler(metadata
, response
) {
23 'multipart/x-mixed-replace; boundary="boundary"'
25 response
.bodyOutputStream
.write(multipartBody
, multipartBody
.length
);
30 function responseHandler(request
, buffer
) {
31 let channel
= request
.QueryInterface(Ci
.nsIChannel
);
32 Assert
.equal(buffer
, "Some text");
33 Assert
.equal(channel
.contentType
, "text/plain");
35 // two runs: pref on and off
37 // foo=bar should not be visible here
39 Services
.cookies
.getCookieStringFromHttp(channel
.URI
, channel
),
43 Services
.prefs
.setBoolPref(
44 "network.cookie.prevent_set_cookie_from_multipart",
47 createConverterAndRequest();
49 // validate that the pref is working
51 Services
.cookies
.getCookieStringFromHttp(channel
.URI
, channel
),
54 httpserver
.stop(do_test_finished
);
58 var multipartListener
= {
61 QueryInterface
: ChromeUtils
.generateQI([
70 onDataAvailable(request
, stream
, offset
, count
) {
72 this._buffer
= this._buffer
.concat(read_stream(stream
, count
));
73 dump("BUFFEEE: " + this._buffer
+ "\n\n");
75 do_throw("Error in onDataAvailable: " + ex
);
79 onStopRequest(request
) {
81 responseHandler(request
, this._buffer
);
83 do_throw("Error in closure function: " + ex
);
88 function createConverterAndRequest() {
89 var streamConv
= Cc
["@mozilla.org/streamConverters;1"].getService(
90 Ci
.nsIStreamConverterService
92 var conv
= streamConv
.asyncConvertData(
93 "multipart/x-mixed-replace",
99 var chan
= make_channel(uri
);
100 chan
.asyncOpen(conv
);
103 function run_test() {
104 Services
.prefs
.setBoolPref(
105 "network.cookieJarSettings.unblocked_for_testing",
109 httpserver
= new HttpServer();
110 httpserver
.registerPathHandler("/multipart", contentHandler
);
111 httpserver
.start(-1);
113 createConverterAndRequest();