2012-08-14 14:06:04 +00:00
|
|
|
Cu.import("resource://testing-common/httpd.js");
|
2014-10-24 22:16:29 +00:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2007-05-13 17:09:52 +00:00
|
|
|
|
|
|
|
const BUGID = "369787";
|
|
|
|
var server = null;
|
|
|
|
var channel = null;
|
|
|
|
|
|
|
|
function change_content_type() {
|
|
|
|
var origType = channel.contentType;
|
|
|
|
const newType = "x-foo/x-bar";
|
|
|
|
channel.contentType = newType;
|
|
|
|
do_check_eq(channel.contentType, newType);
|
|
|
|
channel.contentType = origType;
|
|
|
|
do_check_eq(channel.contentType, origType);
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestListener() {
|
|
|
|
}
|
|
|
|
TestListener.prototype.onStartRequest = function(request, context) {
|
2010-11-29 23:41:21 +00:00
|
|
|
try {
|
|
|
|
// request might be different from channel
|
|
|
|
channel = request.QueryInterface(Components.interfaces.nsIChannel);
|
|
|
|
|
|
|
|
change_content_type();
|
|
|
|
} catch (ex) {
|
|
|
|
print(ex);
|
|
|
|
throw ex;
|
|
|
|
}
|
2007-05-13 17:09:52 +00:00
|
|
|
}
|
|
|
|
TestListener.prototype.onStopRequest = function(request, context, status) {
|
2010-11-29 23:41:21 +00:00
|
|
|
try {
|
|
|
|
change_content_type();
|
|
|
|
} catch (ex) {
|
|
|
|
print(ex);
|
|
|
|
// don't re-throw ex to avoid hanging the test
|
|
|
|
}
|
2007-05-13 17:09:52 +00:00
|
|
|
|
2009-11-24 19:58:42 +00:00
|
|
|
do_timeout(0, after_channel_closed);
|
2007-05-13 17:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function after_channel_closed() {
|
|
|
|
try {
|
|
|
|
change_content_type();
|
|
|
|
} finally {
|
2009-04-15 20:19:35 +00:00
|
|
|
server.stop(do_test_finished);
|
2007-05-13 17:09:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
// start server
|
2012-08-14 14:06:04 +00:00
|
|
|
server = new HttpServer();
|
2007-05-13 17:09:52 +00:00
|
|
|
|
|
|
|
server.registerPathHandler("/bug" + BUGID, bug369787);
|
|
|
|
|
2013-07-19 17:19:28 +00:00
|
|
|
server.start(-1);
|
2007-05-13 17:09:52 +00:00
|
|
|
|
|
|
|
// make request
|
|
|
|
channel =
|
|
|
|
Components.classes["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Components.interfaces.nsIIOService).
|
2014-10-24 22:16:29 +00:00
|
|
|
newChannel2("http://localhost:" +
|
|
|
|
server.identity.primaryPort + "/bug" + BUGID,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null, // aLoadingNode
|
|
|
|
Services.scriptSecurityManager.getSystemPrincipal(),
|
|
|
|
null, // aTriggeringPrincipal
|
|
|
|
Ci.nsILoadInfo.SEC_NORMAL,
|
|
|
|
Ci.nsIContentPolicy.TYPE_OTHER);
|
2007-05-13 17:09:52 +00:00
|
|
|
|
|
|
|
channel.QueryInterface(Components.interfaces.nsIHttpChannel);
|
|
|
|
channel.asyncOpen(new TestListener(), null);
|
|
|
|
|
|
|
|
do_test_pending();
|
|
|
|
}
|
|
|
|
|
|
|
|
// PATH HANDLER FOR /bug369787
|
|
|
|
function bug369787(metadata, response) {
|
|
|
|
/* do nothing */
|
|
|
|
}
|