Wed, 31 Dec 2014 06:55:46 +0100
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 = new HttpServer(); |
michael@0 | 4 | var index = 0; |
michael@0 | 5 | var tests = [ |
michael@0 | 6 | { url : "/bug510359", server : "0", expected : "0"}, |
michael@0 | 7 | { url : "/bug510359", server : "1", expected : "1"}, |
michael@0 | 8 | ]; |
michael@0 | 9 | |
michael@0 | 10 | function setupChannel(suffix, value) { |
michael@0 | 11 | var ios = Components.classes["@mozilla.org/network/io-service;1"] |
michael@0 | 12 | .getService(Ci.nsIIOService); |
michael@0 | 13 | var chan = ios.newChannel("http://localhost:" + |
michael@0 | 14 | httpserver.identity.primaryPort + |
michael@0 | 15 | suffix, "", null); |
michael@0 | 16 | var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); |
michael@0 | 17 | httpChan.requestMethod = "GET"; |
michael@0 | 18 | httpChan.setRequestHeader("x-request", value, false); |
michael@0 | 19 | httpChan.setRequestHeader("Cookie", "c="+value, false); |
michael@0 | 20 | return httpChan; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function triggerNextTest() { |
michael@0 | 24 | var channel = setupChannel(tests[index].url, tests[index].server); |
michael@0 | 25 | channel.asyncOpen(new ChannelListener(checkValueAndTrigger, null), null); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function checkValueAndTrigger(request, data, ctx) { |
michael@0 | 29 | do_check_eq(tests[index].expected, data); |
michael@0 | 30 | |
michael@0 | 31 | if (index < tests.length - 1) { |
michael@0 | 32 | index++; |
michael@0 | 33 | triggerNextTest(); |
michael@0 | 34 | } else { |
michael@0 | 35 | httpserver.stop(do_test_finished); |
michael@0 | 36 | } |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function run_test() { |
michael@0 | 40 | httpserver.registerPathHandler("/bug510359", handler); |
michael@0 | 41 | httpserver.start(-1); |
michael@0 | 42 | |
michael@0 | 43 | // clear cache |
michael@0 | 44 | evict_cache_entries(); |
michael@0 | 45 | |
michael@0 | 46 | triggerNextTest(); |
michael@0 | 47 | |
michael@0 | 48 | do_test_pending(); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | function handler(metadata, response) { |
michael@0 | 52 | try { |
michael@0 | 53 | var IMS = metadata.getHeader("If-Modified-Since"); |
michael@0 | 54 | response.setStatusLine(metadata.httpVersion, 500, "Failed"); |
michael@0 | 55 | var msg = "Client should not set If-Modified-Since header"; |
michael@0 | 56 | response.bodyOutputStream.write(msg, msg.length); |
michael@0 | 57 | } catch(ex) { |
michael@0 | 58 | response.setStatusLine(metadata.httpVersion, 200, "Ok"); |
michael@0 | 59 | response.setHeader("Content-Type", "text/plain", false); |
michael@0 | 60 | response.setHeader("Last-Modified", getDateString(-1), false); |
michael@0 | 61 | response.setHeader("Vary", "Cookie", false); |
michael@0 | 62 | var body = metadata.getHeader("x-request"); |
michael@0 | 63 | response.bodyOutputStream.write(body, body.length); |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | function getDateString(yearDelta) { |
michael@0 | 68 | var months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', |
michael@0 | 69 | 'Sep', 'Oct', 'Nov', 'Dec' ]; |
michael@0 | 70 | var days = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ]; |
michael@0 | 71 | |
michael@0 | 72 | var d = new Date(); |
michael@0 | 73 | return days[d.getUTCDay()] + ", " + d.getUTCDate() + " " |
michael@0 | 74 | + months[d.getUTCMonth()] + " " + (d.getUTCFullYear() + yearDelta) |
michael@0 | 75 | + " " + d.getUTCHours() + ":" + d.getUTCMinutes() + ":" |
michael@0 | 76 | + d.getUTCSeconds() + " UTC"; |
michael@0 | 77 | } |