test_proxy-failover_canceled.js (1550B)
1 "use strict"; 2 3 const { HttpServer } = ChromeUtils.importESModule( 4 "resource://testing-common/httpd.sys.mjs" 5 ); 6 7 var httpServer = null; 8 9 function make_channel(url) { 10 return NetUtil.newChannel({ 11 uri: url, 12 loadUsingSystemPrincipal: true, 13 }); 14 } 15 16 const responseBody = "response body"; 17 18 function contentHandler(metadata, response) { 19 response.setHeader("Content-Type", "text/plain"); 20 response.bodyOutputStream.write(responseBody, responseBody.length); 21 } 22 23 function finish_test(request, buffer) { 24 Assert.equal(buffer, ""); 25 httpServer.stop(do_test_finished); 26 } 27 28 function run_test() { 29 httpServer = new HttpServer(); 30 httpServer.registerPathHandler("/content", contentHandler); 31 httpServer.start(-1); 32 33 // we want to cancel the failover proxy engage, so, do not allow 34 // redirects from now. 35 36 var nc = new ChannelEventSink(); 37 nc._flags = ES_ABORT_REDIRECT; 38 39 var prefs = Services.prefs.getBranch("network.proxy."); 40 prefs.setIntPref("type", 2); 41 prefs.setCharPref("no_proxies_on", "nothing"); 42 prefs.setBoolPref("allow_hijacking_localhost", true); 43 prefs.setCharPref( 44 "autoconfig_url", 45 "data:text/plain," + 46 "function FindProxyForURL(url, host) {return 'PROXY a_non_existent_domain_x7x6c572v:80; PROXY localhost:" + 47 httpServer.identity.primaryPort + 48 "';}" 49 ); 50 51 var chan = make_channel( 52 "http://localhost:" + httpServer.identity.primaryPort + "/content" 53 ); 54 chan.notificationCallbacks = nc; 55 chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE)); 56 do_test_pending(); 57 }