2012-08-14 18:06:04 +04:00
|
|
|
Cu.import("resource://testing-common/httpd.js");
|
2015-12-19 00:31:16 +03:00
|
|
|
Cu.import("resource://gre/modules/NetUtil.jsm");
|
2015-03-04 03:46:00 +03:00
|
|
|
Cu.import("resource://testing-common/MockRegistrar.jsm");
|
2010-10-26 02:47:40 +04:00
|
|
|
|
|
|
|
var httpserv = null;
|
|
|
|
|
|
|
|
const CID = Components.ID("{5645d2c1-d6d8-4091-b117-fe7ee4027db7}");
|
2013-07-19 21:19:28 +04:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "systemSettings", function() {
|
|
|
|
return {
|
|
|
|
QueryInterface: function (iid) {
|
|
|
|
if (iid.equals(Components.interfaces.nsISupports) ||
|
|
|
|
iid.equals(Components.interfaces.nsISystemProxySettings))
|
|
|
|
return this;
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
|
|
|
|
|
|
|
mainThreadOnly: true,
|
|
|
|
PACURI: "http://localhost:" + httpserv.identity.primaryPort + "/redirect",
|
|
|
|
getProxyForURI: function(aURI) {
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2010-10-26 02:47:40 +04:00
|
|
|
|
|
|
|
function checkValue(request, data, ctx) {
|
|
|
|
do_check_true(called);
|
|
|
|
do_check_eq("ok", data);
|
|
|
|
httpserv.stop(do_test_finished);
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeChan(url) {
|
2015-12-19 00:31:16 +03:00
|
|
|
return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true})
|
2010-10-26 02:47:40 +04:00
|
|
|
.QueryInterface(Components.interfaces.nsIHttpChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
2012-08-14 18:06:04 +04:00
|
|
|
httpserv = new HttpServer();
|
2010-10-26 02:47:40 +04:00
|
|
|
httpserv.registerPathHandler("/redirect", redirect);
|
|
|
|
httpserv.registerPathHandler("/pac", pac);
|
|
|
|
httpserv.registerPathHandler("/target", target);
|
2013-07-19 21:19:28 +04:00
|
|
|
httpserv.start(-1);
|
2010-10-26 02:47:40 +04:00
|
|
|
|
2015-03-04 03:46:00 +03:00
|
|
|
MockRegistrar.register("@mozilla.org/system-proxy-settings;1",
|
|
|
|
systemSettings);
|
2010-10-26 02:47:40 +04:00
|
|
|
|
|
|
|
// Ensure we're using system-properties
|
|
|
|
const prefs = Cc["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Ci.nsIPrefBranch);
|
|
|
|
prefs.setIntPref(
|
|
|
|
"network.proxy.type",
|
|
|
|
Components.interfaces.nsIProtocolProxyService.PROXYCONFIG_SYSTEM);
|
|
|
|
|
|
|
|
// clear cache
|
2012-06-13 01:23:32 +04:00
|
|
|
evict_cache_entries();
|
2010-10-26 02:47:40 +04:00
|
|
|
|
2013-07-19 21:19:28 +04:00
|
|
|
var chan = makeChan("http://localhost:" + httpserv.identity.primaryPort +
|
|
|
|
"/target");
|
2015-12-19 00:31:16 +03:00
|
|
|
chan.asyncOpen2(new ChannelListener(checkValue, null));
|
2010-10-26 02:47:40 +04:00
|
|
|
|
|
|
|
do_test_pending();
|
|
|
|
}
|
|
|
|
|
|
|
|
var called = false, failed = false;
|
|
|
|
function redirect(metadata, response) {
|
|
|
|
// If called second time, just return the PAC but set failed-flag
|
|
|
|
if (called) {
|
|
|
|
failed = true;
|
|
|
|
return pac(metadata, response);
|
|
|
|
}
|
|
|
|
|
|
|
|
called = true;
|
|
|
|
response.setStatusLine(metadata.httpVersion, 302, "Found");
|
|
|
|
response.setHeader("Location", "/pac", false);
|
|
|
|
var body = "Moved\n";
|
|
|
|
response.bodyOutputStream.write(body, body.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
function pac(metadata, response) {
|
|
|
|
var PAC = 'function FindProxyForURL(url, host) { return "DIRECT"; }';
|
|
|
|
response.setStatusLine(metadata.httpVersion, 200, "Ok");
|
|
|
|
response.setHeader("Content-Type", "application/x-ns-proxy-autoconfig", false);
|
|
|
|
response.bodyOutputStream.write(PAC, PAC.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
function target(metadata, response) {
|
|
|
|
var retval = "ok";
|
|
|
|
if (failed) retval = "failed";
|
|
|
|
|
|
|
|
response.setStatusLine(metadata.httpVersion, 200, "Ok");
|
|
|
|
response.setHeader("Content-Type", "text/plain", false);
|
|
|
|
response.bodyOutputStream.write(retval, retval.length);
|
|
|
|
}
|