Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 2 | |
michael@0 | 3 | var httpserver = null; |
michael@0 | 4 | var simplePath = "/simple"; |
michael@0 | 5 | var normalPath = "/normal"; |
michael@0 | 6 | var httpbody = "<html></html>"; |
michael@0 | 7 | |
michael@0 | 8 | XPCOMUtils.defineLazyGetter(this, "uri1", function() { |
michael@0 | 9 | return "http://localhost:" + httpserver.identity.primaryPort + simplePath; |
michael@0 | 10 | }); |
michael@0 | 11 | |
michael@0 | 12 | XPCOMUtils.defineLazyGetter(this, "uri2", function() { |
michael@0 | 13 | return "http://localhost:" + httpserver.identity.primaryPort + normalPath; |
michael@0 | 14 | }); |
michael@0 | 15 | |
michael@0 | 16 | function make_channel(url) { |
michael@0 | 17 | var ios = Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 18 | getService(Ci.nsIIOService); |
michael@0 | 19 | return ios.newChannel(url, "", null); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | var listener_proto = { |
michael@0 | 23 | QueryInterface: function(iid) { |
michael@0 | 24 | if (iid.equals(Components.interfaces.nsIStreamListener) || |
michael@0 | 25 | iid.equals(Components.interfaces.nsIRequestObserver) || |
michael@0 | 26 | iid.equals(Components.interfaces.nsISupports)) |
michael@0 | 27 | return this; |
michael@0 | 28 | throw Components.results.NS_ERROR_NO_INTERFACE; |
michael@0 | 29 | }, |
michael@0 | 30 | |
michael@0 | 31 | onStartRequest: function(request, context) { |
michael@0 | 32 | do_check_eq(request.QueryInterface(Ci.nsIChannel).contentType, |
michael@0 | 33 | this.contentType); |
michael@0 | 34 | request.cancel(Cr.NS_BINDING_ABORTED); |
michael@0 | 35 | }, |
michael@0 | 36 | |
michael@0 | 37 | onDataAvailable: function(request, context, stream, offset, count) { |
michael@0 | 38 | do_throw("Unexpected onDataAvailable"); |
michael@0 | 39 | }, |
michael@0 | 40 | |
michael@0 | 41 | onStopRequest: function(request, context, status) { |
michael@0 | 42 | do_check_eq(status, Cr.NS_BINDING_ABORTED); |
michael@0 | 43 | this.termination_func(); |
michael@0 | 44 | } |
michael@0 | 45 | }; |
michael@0 | 46 | |
michael@0 | 47 | function listener(contentType, termination_func) { |
michael@0 | 48 | this.contentType = contentType; |
michael@0 | 49 | this.termination_func = termination_func; |
michael@0 | 50 | } |
michael@0 | 51 | listener.prototype = listener_proto; |
michael@0 | 52 | |
michael@0 | 53 | function run_test() |
michael@0 | 54 | { |
michael@0 | 55 | httpserver = new HttpServer(); |
michael@0 | 56 | httpserver.registerPathHandler(simplePath, simpleHandler); |
michael@0 | 57 | httpserver.registerPathHandler(normalPath, normalHandler); |
michael@0 | 58 | httpserver.start(-1); |
michael@0 | 59 | |
michael@0 | 60 | var channel = make_channel(uri1); |
michael@0 | 61 | channel.asyncOpen(new listener("text/plain", function() { |
michael@0 | 62 | run_test2(); |
michael@0 | 63 | }), null); |
michael@0 | 64 | |
michael@0 | 65 | do_test_pending(); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | function run_test2() |
michael@0 | 69 | { |
michael@0 | 70 | var channel = make_channel(uri2); |
michael@0 | 71 | channel.asyncOpen(new listener("text/html", function() { |
michael@0 | 72 | httpserver.stop(do_test_finished); |
michael@0 | 73 | }), null); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function simpleHandler(metadata, response) |
michael@0 | 77 | { |
michael@0 | 78 | response.seizePower(); |
michael@0 | 79 | response.bodyOutputStream.write(httpbody, httpbody.length); |
michael@0 | 80 | response.finish(); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | function normalHandler(metadata, response) |
michael@0 | 84 | { |
michael@0 | 85 | response.bodyOutputStream.write(httpbody, httpbody.length); |
michael@0 | 86 | response.finish(); |
michael@0 | 87 | } |