2005-08-21 18:20:40 +04:00
|
|
|
// This file tests bug 250375
|
|
|
|
|
2012-08-14 18:06:04 +04:00
|
|
|
Cu.import("resource://testing-common/httpd.js");
|
2013-02-22 20:16:01 +04:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
2013-07-19 21:19:28 +04:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "URL", function() {
|
|
|
|
return "http://localhost:" + httpserv.identity.primaryPort + "/";
|
|
|
|
});
|
|
|
|
|
2013-02-22 20:16:01 +04:00
|
|
|
function inChildProcess() {
|
|
|
|
return Cc["@mozilla.org/xre/app-info;1"]
|
|
|
|
.getService(Ci.nsIXULRuntime)
|
|
|
|
.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
|
|
|
}
|
2006-12-15 05:13:54 +03:00
|
|
|
|
2005-08-13 15:46:11 +04:00
|
|
|
function check_request_header(chan, name, value) {
|
|
|
|
var chanValue;
|
|
|
|
try {
|
|
|
|
chanValue = chan.getRequestHeader(name);
|
|
|
|
} catch (e) {
|
2009-11-03 21:39:41 +03:00
|
|
|
do_throw("Expected to find header '" + name + "' but didn't find it, got exception: " + e);
|
2005-08-13 15:46:11 +04:00
|
|
|
}
|
|
|
|
dump("Value for header '" + name + "' is '" + chanValue + "'\n");
|
|
|
|
do_check_eq(chanValue, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
var cookieVal = "C1=V1";
|
|
|
|
|
|
|
|
var listener = {
|
|
|
|
onStartRequest: function test_onStartR(request, ctx) {
|
|
|
|
try {
|
2009-11-03 21:39:41 +03:00
|
|
|
var chan = request.QueryInterface(Components.interfaces.nsIHttpChannel);
|
2005-08-13 15:46:11 +04:00
|
|
|
check_request_header(chan, "Cookie", cookieVal);
|
|
|
|
} catch (e) {
|
|
|
|
do_throw("Unexpected exception: " + e);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw Components.results.NS_ERROR_ABORT;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDataAvailable: function test_ODA() {
|
|
|
|
throw Components.results.NS_ERROR_UNEXPECTED;
|
|
|
|
},
|
|
|
|
|
|
|
|
onStopRequest: function test_onStopR(request, ctx, status) {
|
2009-04-16 00:19:35 +04:00
|
|
|
if (this._iteration == 1) {
|
2005-08-13 15:46:11 +04:00
|
|
|
run_test_continued();
|
2009-04-16 00:19:35 +04:00
|
|
|
} else {
|
|
|
|
do_test_pending();
|
|
|
|
httpserv.stop(do_test_finished);
|
|
|
|
}
|
2005-08-13 15:46:11 +04:00
|
|
|
do_test_finished();
|
|
|
|
},
|
|
|
|
|
|
|
|
_iteration: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
function makeChan() {
|
|
|
|
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
2013-07-19 21:19:28 +04:00
|
|
|
var chan = ios.newChannel(URL, null, null)
|
2005-08-13 15:46:11 +04:00
|
|
|
.QueryInterface(Components.interfaces.nsIHttpChannel);
|
|
|
|
|
|
|
|
return chan;
|
|
|
|
}
|
|
|
|
|
2006-08-02 06:02:37 +04:00
|
|
|
var httpserv = null;
|
|
|
|
|
2005-08-13 15:46:11 +04:00
|
|
|
function run_test() {
|
2013-02-22 20:16:01 +04:00
|
|
|
// Allow all cookies if the pref service is available in this process.
|
|
|
|
if (!inChildProcess())
|
|
|
|
Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
|
|
|
|
|
2012-08-14 18:06:04 +04:00
|
|
|
httpserv = new HttpServer();
|
2013-07-19 21:19:28 +04:00
|
|
|
httpserv.start(-1);
|
2005-08-13 15:46:11 +04:00
|
|
|
|
|
|
|
var chan = makeChan();
|
|
|
|
|
|
|
|
chan.setRequestHeader("Cookie", cookieVal, false);
|
|
|
|
|
|
|
|
chan.asyncOpen(listener, null);
|
|
|
|
|
|
|
|
do_test_pending();
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_test_continued() {
|
|
|
|
var chan = makeChan();
|
|
|
|
|
|
|
|
var cookServ = Components.classes["@mozilla.org/cookieService;1"]
|
|
|
|
.getService(Components.interfaces.nsICookieService);
|
|
|
|
var cookie2 = "C2=V2";
|
|
|
|
cookServ.setCookieString(chan.URI, null, cookie2, chan);
|
|
|
|
chan.setRequestHeader("Cookie", cookieVal, false);
|
|
|
|
|
|
|
|
// We expect that the setRequestHeader overrides the
|
|
|
|
// automatically-added one, so insert cookie2 in front
|
|
|
|
cookieVal = cookie2 + "; " + cookieVal;
|
|
|
|
|
|
|
|
listener._iteration++;
|
|
|
|
chan.asyncOpen(listener, null);
|
|
|
|
|
|
|
|
do_test_pending();
|
|
|
|
}
|