netwerk/test/unit/test_proxy-failover_canceled.js

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

michael@0 1 Cu.import("resource://testing-common/httpd.js");
michael@0 2
michael@0 3 var httpServer = null;
michael@0 4
michael@0 5 function make_channel(url, callback, ctx) {
michael@0 6 var ios = Cc["@mozilla.org/network/io-service;1"].
michael@0 7 getService(Ci.nsIIOService);
michael@0 8 return ios.newChannel(url, "", null);
michael@0 9 }
michael@0 10
michael@0 11 const responseBody = "response body";
michael@0 12
michael@0 13 function contentHandler(metadata, response)
michael@0 14 {
michael@0 15 response.setHeader("Content-Type", "text/plain");
michael@0 16 response.bodyOutputStream.write(responseBody, responseBody.length);
michael@0 17 }
michael@0 18
michael@0 19 function finish_test(request, buffer)
michael@0 20 {
michael@0 21 do_check_eq(buffer, "");
michael@0 22 httpServer.stop(do_test_finished);
michael@0 23 }
michael@0 24
michael@0 25 function run_test()
michael@0 26 {
michael@0 27 httpServer = new HttpServer();
michael@0 28 httpServer.registerPathHandler("/content", contentHandler);
michael@0 29 httpServer.start(-1);
michael@0 30
michael@0 31 // we want to cancel the failover proxy engage, so, do not allow
michael@0 32 // redirects from now.
michael@0 33
michael@0 34 var nc = new ChannelEventSink();
michael@0 35 nc._flags = ES_ABORT_REDIRECT;
michael@0 36
michael@0 37 var prefserv = Cc["@mozilla.org/preferences-service;1"].
michael@0 38 getService(Ci.nsIPrefService);
michael@0 39 var prefs = prefserv.getBranch("network.proxy.");
michael@0 40 prefs.setIntPref("type", 2);
michael@0 41 prefs.setCharPref("autoconfig_url", "data:text/plain," +
michael@0 42 "function FindProxyForURL(url, host) {return 'PROXY a_non_existent_domain_x7x6c572v:80; PROXY localhost:" +
michael@0 43 httpServer.identity.primaryPort + "';}"
michael@0 44 );
michael@0 45
michael@0 46 var chan = make_channel("http://localhost:" +
michael@0 47 httpServer.identity.primaryPort + "/content");
michael@0 48 chan.notificationCallbacks = nc;
michael@0 49 chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE), null);
michael@0 50 do_test_pending();
michael@0 51 }

mercurial