netwerk/test/unit/test_bug586908.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 var httpserv = null;
michael@0 4
michael@0 5 const CID = Components.ID("{5645d2c1-d6d8-4091-b117-fe7ee4027db7}");
michael@0 6 const contractID = "@mozilla.org/system-proxy-settings;1"
michael@0 7
michael@0 8 XPCOMUtils.defineLazyGetter(this, "systemSettings", function() {
michael@0 9 return {
michael@0 10 QueryInterface: function (iid) {
michael@0 11 if (iid.equals(Components.interfaces.nsISupports) ||
michael@0 12 iid.equals(Components.interfaces.nsIFactory) ||
michael@0 13 iid.equals(Components.interfaces.nsISystemProxySettings))
michael@0 14 return this;
michael@0 15 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 16 },
michael@0 17 createInstance: function (outer, iid) {
michael@0 18 if (outer)
michael@0 19 throw Components.results.NS_ERROR_NO_AGGREGATION;
michael@0 20 return this.QueryInterface(iid);
michael@0 21 },
michael@0 22 lockFactory: function (lock) {
michael@0 23 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
michael@0 24 },
michael@0 25
michael@0 26 mainThreadOnly: true,
michael@0 27 PACURI: "http://localhost:" + httpserv.identity.primaryPort + "/redirect",
michael@0 28 getProxyForURI: function(aURI) {
michael@0 29 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
michael@0 30 }
michael@0 31 };
michael@0 32 });
michael@0 33
michael@0 34 function checkValue(request, data, ctx) {
michael@0 35 do_check_true(called);
michael@0 36 do_check_eq("ok", data);
michael@0 37 httpserv.stop(do_test_finished);
michael@0 38 }
michael@0 39
michael@0 40 function makeChan(url) {
michael@0 41 var ios = Components.classes["@mozilla.org/network/io-service;1"]
michael@0 42 .getService(Components.interfaces.nsIIOService);
michael@0 43 var chan = ios.newChannel(url, null, null)
michael@0 44 .QueryInterface(Components.interfaces.nsIHttpChannel);
michael@0 45
michael@0 46 return chan;
michael@0 47 }
michael@0 48
michael@0 49 function run_test() {
michael@0 50 httpserv = new HttpServer();
michael@0 51 httpserv.registerPathHandler("/redirect", redirect);
michael@0 52 httpserv.registerPathHandler("/pac", pac);
michael@0 53 httpserv.registerPathHandler("/target", target);
michael@0 54 httpserv.start(-1);
michael@0 55
michael@0 56 Components.manager.nsIComponentRegistrar.registerFactory(
michael@0 57 CID,
michael@0 58 "Fake system proxy-settings",
michael@0 59 contractID, systemSettings);
michael@0 60
michael@0 61 // Ensure we're using system-properties
michael@0 62 const prefs = Cc["@mozilla.org/preferences-service;1"]
michael@0 63 .getService(Ci.nsIPrefBranch);
michael@0 64 prefs.setIntPref(
michael@0 65 "network.proxy.type",
michael@0 66 Components.interfaces.nsIProtocolProxyService.PROXYCONFIG_SYSTEM);
michael@0 67
michael@0 68 // clear cache
michael@0 69 evict_cache_entries();
michael@0 70
michael@0 71 var chan = makeChan("http://localhost:" + httpserv.identity.primaryPort +
michael@0 72 "/target");
michael@0 73 chan.asyncOpen(new ChannelListener(checkValue, null), null);
michael@0 74
michael@0 75 do_test_pending();
michael@0 76 }
michael@0 77
michael@0 78 var called = false, failed = false;
michael@0 79 function redirect(metadata, response) {
michael@0 80 // If called second time, just return the PAC but set failed-flag
michael@0 81 if (called) {
michael@0 82 failed = true;
michael@0 83 return pac(metadata, response);
michael@0 84 }
michael@0 85
michael@0 86 called = true;
michael@0 87 response.setStatusLine(metadata.httpVersion, 302, "Found");
michael@0 88 response.setHeader("Location", "/pac", false);
michael@0 89 var body = "Moved\n";
michael@0 90 response.bodyOutputStream.write(body, body.length);
michael@0 91 }
michael@0 92
michael@0 93 function pac(metadata, response) {
michael@0 94 var PAC = 'function FindProxyForURL(url, host) { return "DIRECT"; }';
michael@0 95 response.setStatusLine(metadata.httpVersion, 200, "Ok");
michael@0 96 response.setHeader("Content-Type", "application/x-ns-proxy-autoconfig", false);
michael@0 97 response.bodyOutputStream.write(PAC, PAC.length);
michael@0 98 }
michael@0 99
michael@0 100 function target(metadata, response) {
michael@0 101 var retval = "ok";
michael@0 102 if (failed) retval = "failed";
michael@0 103
michael@0 104 response.setStatusLine(metadata.httpVersion, 200, "Ok");
michael@0 105 response.setHeader("Content-Type", "text/plain", false);
michael@0 106 response.bodyOutputStream.write(retval, retval.length);
michael@0 107 }

mercurial