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