2012-08-14 07:06:04 -07:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
const Cr = Components.results;
|
|
|
|
|
|
|
|
Cu.import("resource://testing-common/httpd.js");
|
2007-05-13 10:09:52 -07: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 15:41:21 -08: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 10:09:52 -07:00
|
|
|
}
|
|
|
|
TestListener.prototype.onStopRequest = function(request, context, status) {
|
2010-11-29 15:41:21 -08:00
|
|
|
try {
|
|
|
|
change_content_type();
|
|
|
|
} catch (ex) {
|
|
|
|
print(ex);
|
|
|
|
// don't re-throw ex to avoid hanging the test
|
|
|
|
}
|
2007-05-13 10:09:52 -07:00
|
|
|
|
2009-11-24 11:58:42 -08:00
|
|
|
do_timeout(0, after_channel_closed);
|
2007-05-13 10:09:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function after_channel_closed() {
|
|
|
|
try {
|
|
|
|
change_content_type();
|
|
|
|
} finally {
|
2009-04-15 13:19:35 -07:00
|
|
|
server.stop(do_test_finished);
|
2007-05-13 10:09:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
// start server
|
2012-08-14 07:06:04 -07:00
|
|
|
server = new HttpServer();
|
2007-05-13 10:09:52 -07:00
|
|
|
|
|
|
|
server.registerPathHandler("/bug" + BUGID, bug369787);
|
|
|
|
|
|
|
|
server.start(4444);
|
|
|
|
|
|
|
|
// make request
|
|
|
|
channel =
|
|
|
|
Components.classes["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Components.interfaces.nsIIOService).
|
|
|
|
newChannel("http://localhost:4444/bug" + BUGID, null, null);
|
|
|
|
|
|
|
|
channel.QueryInterface(Components.interfaces.nsIHttpChannel);
|
|
|
|
channel.asyncOpen(new TestListener(), null);
|
|
|
|
|
|
|
|
do_test_pending();
|
|
|
|
}
|
|
|
|
|
|
|
|
// PATH HANDLER FOR /bug369787
|
|
|
|
function bug369787(metadata, response) {
|
|
|
|
/* do nothing */
|
|
|
|
}
|