michael@0: Cu.import("resource://testing-common/httpd.js"); michael@0: michael@0: const BUGID = "369787"; michael@0: var server = null; michael@0: var channel = null; michael@0: michael@0: function change_content_type() { michael@0: var origType = channel.contentType; michael@0: const newType = "x-foo/x-bar"; michael@0: channel.contentType = newType; michael@0: do_check_eq(channel.contentType, newType); michael@0: channel.contentType = origType; michael@0: do_check_eq(channel.contentType, origType); michael@0: } michael@0: michael@0: function TestListener() { michael@0: } michael@0: TestListener.prototype.onStartRequest = function(request, context) { michael@0: try { michael@0: // request might be different from channel michael@0: channel = request.QueryInterface(Components.interfaces.nsIChannel); michael@0: michael@0: change_content_type(); michael@0: } catch (ex) { michael@0: print(ex); michael@0: throw ex; michael@0: } michael@0: } michael@0: TestListener.prototype.onStopRequest = function(request, context, status) { michael@0: try { michael@0: change_content_type(); michael@0: } catch (ex) { michael@0: print(ex); michael@0: // don't re-throw ex to avoid hanging the test michael@0: } michael@0: michael@0: do_timeout(0, after_channel_closed); michael@0: } michael@0: michael@0: function after_channel_closed() { michael@0: try { michael@0: change_content_type(); michael@0: } finally { michael@0: server.stop(do_test_finished); michael@0: } michael@0: } michael@0: michael@0: function run_test() { michael@0: // start server michael@0: server = new HttpServer(); michael@0: michael@0: server.registerPathHandler("/bug" + BUGID, bug369787); michael@0: michael@0: server.start(-1); michael@0: michael@0: // make request michael@0: channel = michael@0: Components.classes["@mozilla.org/network/io-service;1"]. michael@0: getService(Components.interfaces.nsIIOService). michael@0: newChannel("http://localhost:" + michael@0: server.identity.primaryPort + "/bug" + BUGID, null, null); michael@0: michael@0: channel.QueryInterface(Components.interfaces.nsIHttpChannel); michael@0: channel.asyncOpen(new TestListener(), null); michael@0: michael@0: do_test_pending(); michael@0: } michael@0: michael@0: // PATH HANDLER FOR /bug369787 michael@0: function bug369787(metadata, response) { michael@0: /* do nothing */ michael@0: }