Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 2 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 3 | var httpserver = new HttpServer(); |
michael@0 | 4 | |
michael@0 | 5 | function setupChannel(suffix) |
michael@0 | 6 | { |
michael@0 | 7 | var ios = |
michael@0 | 8 | Components.classes["@mozilla.org/network/io-service;1"] |
michael@0 | 9 | .getService(Ci.nsIIOService); |
michael@0 | 10 | var chan = ios.newChannel("http://localhost:" + |
michael@0 | 11 | httpserver.identity.primaryPort + |
michael@0 | 12 | suffix, "", null); |
michael@0 | 13 | return chan; |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | function checkValueAndTrigger(request, data, ctx) |
michael@0 | 17 | { |
michael@0 | 18 | do_check_eq("Ok", data); |
michael@0 | 19 | httpserver.stop(do_test_finished); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | function run_test() |
michael@0 | 23 | { |
michael@0 | 24 | // Allow all cookies. |
michael@0 | 25 | Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); |
michael@0 | 26 | |
michael@0 | 27 | httpserver.registerPathHandler("/redirect1", redirectHandler1); |
michael@0 | 28 | httpserver.registerPathHandler("/redirect2", redirectHandler2); |
michael@0 | 29 | httpserver.start(-1); |
michael@0 | 30 | |
michael@0 | 31 | // clear cache |
michael@0 | 32 | evict_cache_entries(); |
michael@0 | 33 | |
michael@0 | 34 | // load first time |
michael@0 | 35 | var channel = setupChannel("/redirect1"); |
michael@0 | 36 | channel.asyncOpen(new ChannelListener(checkValueAndTrigger, null), null); |
michael@0 | 37 | do_test_pending(); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | function redirectHandler1(metadata, response) |
michael@0 | 41 | { |
michael@0 | 42 | if (!metadata.hasHeader("Cookie")) { |
michael@0 | 43 | response.setStatusLine(metadata.httpVersion, 302, "Found"); |
michael@0 | 44 | response.setHeader("Cache-Control", "max-age=600", false); |
michael@0 | 45 | response.setHeader("Location", "/redirect2?query", false); |
michael@0 | 46 | response.setHeader("Set-Cookie", "MyCookie=1", false); |
michael@0 | 47 | } else { |
michael@0 | 48 | response.setStatusLine(metadata.httpVersion, 200, "Ok"); |
michael@0 | 49 | response.setHeader("Content-Type", "text/plain"); |
michael@0 | 50 | response.bodyOutputStream.write("Ok", "Ok".length); |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | function redirectHandler2(metadata, response) |
michael@0 | 55 | { |
michael@0 | 56 | response.setStatusLine(metadata.httpVersion, 302, "Found"); |
michael@0 | 57 | response.setHeader("Location", "/redirect1", false); |
michael@0 | 58 | } |