Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // |
michael@0 | 2 | // Simple HTTP test: fetches page |
michael@0 | 3 | // |
michael@0 | 4 | |
michael@0 | 5 | // Note: sets Cc and Ci variables |
michael@0 | 6 | |
michael@0 | 7 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 8 | |
michael@0 | 9 | var httpserver = new HttpServer(); |
michael@0 | 10 | var testpath = "/simple"; |
michael@0 | 11 | var httpbody = "0123456789"; |
michael@0 | 12 | var buffer = ""; |
michael@0 | 13 | |
michael@0 | 14 | var dbg=0 |
michael@0 | 15 | if (dbg) { print("============== START =========="); } |
michael@0 | 16 | |
michael@0 | 17 | function run_test() { |
michael@0 | 18 | setup_test(); |
michael@0 | 19 | do_test_pending(); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | function setup_test() { |
michael@0 | 23 | if (dbg) { print("============== setup_test: in"); } |
michael@0 | 24 | httpserver.registerPathHandler(testpath, serverHandler); |
michael@0 | 25 | httpserver.start(-1); |
michael@0 | 26 | var channel = setupChannel(testpath); |
michael@0 | 27 | // ChannelListener defined in head_channels.js |
michael@0 | 28 | channel.asyncOpen(new ChannelListener(checkRequest, channel), null); |
michael@0 | 29 | if (dbg) { print("============== setup_test: out"); } |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function setupChannel(path) { |
michael@0 | 33 | var ios = Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 34 | getService(Ci.nsIIOService); |
michael@0 | 35 | var chan = ios.newChannel("http://localhost:" + |
michael@0 | 36 | httpserver.identity.primaryPort + path, "", null); |
michael@0 | 37 | chan.QueryInterface(Ci.nsIHttpChannel); |
michael@0 | 38 | chan.requestMethod = "GET"; |
michael@0 | 39 | return chan; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | function serverHandler(metadata, response) { |
michael@0 | 43 | if (dbg) { print("============== serverHandler: in"); } |
michael@0 | 44 | response.setHeader("Content-Type", "text/plain", false); |
michael@0 | 45 | response.bodyOutputStream.write(httpbody, httpbody.length); |
michael@0 | 46 | if (dbg) { print("============== serverHandler: out"); } |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function checkRequest(request, data, context) { |
michael@0 | 50 | if (dbg) { print("============== checkRequest: in"); } |
michael@0 | 51 | do_check_eq(data, httpbody); |
michael@0 | 52 | httpserver.stop(do_test_finished); |
michael@0 | 53 | if (dbg) { print("============== checkRequest: out"); } |
michael@0 | 54 | } |
michael@0 | 55 |