netwerk/test/unit/test_bug369787.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 Cu.import("resource://testing-common/httpd.js");
michael@0 2
michael@0 3 const BUGID = "369787";
michael@0 4 var server = null;
michael@0 5 var channel = null;
michael@0 6
michael@0 7 function change_content_type() {
michael@0 8 var origType = channel.contentType;
michael@0 9 const newType = "x-foo/x-bar";
michael@0 10 channel.contentType = newType;
michael@0 11 do_check_eq(channel.contentType, newType);
michael@0 12 channel.contentType = origType;
michael@0 13 do_check_eq(channel.contentType, origType);
michael@0 14 }
michael@0 15
michael@0 16 function TestListener() {
michael@0 17 }
michael@0 18 TestListener.prototype.onStartRequest = function(request, context) {
michael@0 19 try {
michael@0 20 // request might be different from channel
michael@0 21 channel = request.QueryInterface(Components.interfaces.nsIChannel);
michael@0 22
michael@0 23 change_content_type();
michael@0 24 } catch (ex) {
michael@0 25 print(ex);
michael@0 26 throw ex;
michael@0 27 }
michael@0 28 }
michael@0 29 TestListener.prototype.onStopRequest = function(request, context, status) {
michael@0 30 try {
michael@0 31 change_content_type();
michael@0 32 } catch (ex) {
michael@0 33 print(ex);
michael@0 34 // don't re-throw ex to avoid hanging the test
michael@0 35 }
michael@0 36
michael@0 37 do_timeout(0, after_channel_closed);
michael@0 38 }
michael@0 39
michael@0 40 function after_channel_closed() {
michael@0 41 try {
michael@0 42 change_content_type();
michael@0 43 } finally {
michael@0 44 server.stop(do_test_finished);
michael@0 45 }
michael@0 46 }
michael@0 47
michael@0 48 function run_test() {
michael@0 49 // start server
michael@0 50 server = new HttpServer();
michael@0 51
michael@0 52 server.registerPathHandler("/bug" + BUGID, bug369787);
michael@0 53
michael@0 54 server.start(-1);
michael@0 55
michael@0 56 // make request
michael@0 57 channel =
michael@0 58 Components.classes["@mozilla.org/network/io-service;1"].
michael@0 59 getService(Components.interfaces.nsIIOService).
michael@0 60 newChannel("http://localhost:" +
michael@0 61 server.identity.primaryPort + "/bug" + BUGID, null, null);
michael@0 62
michael@0 63 channel.QueryInterface(Components.interfaces.nsIHttpChannel);
michael@0 64 channel.asyncOpen(new TestListener(), null);
michael@0 65
michael@0 66 do_test_pending();
michael@0 67 }
michael@0 68
michael@0 69 // PATH HANDLER FOR /bug369787
michael@0 70 function bug369787(metadata, response) {
michael@0 71 /* do nothing */
michael@0 72 }

mercurial