1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_proxy-failover_canceled.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,51 @@ 1.4 +Cu.import("resource://testing-common/httpd.js"); 1.5 + 1.6 +var httpServer = null; 1.7 + 1.8 +function make_channel(url, callback, ctx) { 1.9 + var ios = Cc["@mozilla.org/network/io-service;1"]. 1.10 + getService(Ci.nsIIOService); 1.11 + return ios.newChannel(url, "", null); 1.12 +} 1.13 + 1.14 +const responseBody = "response body"; 1.15 + 1.16 +function contentHandler(metadata, response) 1.17 +{ 1.18 + response.setHeader("Content-Type", "text/plain"); 1.19 + response.bodyOutputStream.write(responseBody, responseBody.length); 1.20 +} 1.21 + 1.22 +function finish_test(request, buffer) 1.23 +{ 1.24 + do_check_eq(buffer, ""); 1.25 + httpServer.stop(do_test_finished); 1.26 +} 1.27 + 1.28 +function run_test() 1.29 +{ 1.30 + httpServer = new HttpServer(); 1.31 + httpServer.registerPathHandler("/content", contentHandler); 1.32 + httpServer.start(-1); 1.33 + 1.34 + // we want to cancel the failover proxy engage, so, do not allow 1.35 + // redirects from now. 1.36 + 1.37 + var nc = new ChannelEventSink(); 1.38 + nc._flags = ES_ABORT_REDIRECT; 1.39 + 1.40 + var prefserv = Cc["@mozilla.org/preferences-service;1"]. 1.41 + getService(Ci.nsIPrefService); 1.42 + var prefs = prefserv.getBranch("network.proxy."); 1.43 + prefs.setIntPref("type", 2); 1.44 + prefs.setCharPref("autoconfig_url", "data:text/plain," + 1.45 + "function FindProxyForURL(url, host) {return 'PROXY a_non_existent_domain_x7x6c572v:80; PROXY localhost:" + 1.46 + httpServer.identity.primaryPort + "';}" 1.47 + ); 1.48 + 1.49 + var chan = make_channel("http://localhost:" + 1.50 + httpServer.identity.primaryPort + "/content"); 1.51 + chan.notificationCallbacks = nc; 1.52 + chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE), null); 1.53 + do_test_pending(); 1.54 +}