1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_simple.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,55 @@ 1.4 +// 1.5 +// Simple HTTP test: fetches page 1.6 +// 1.7 + 1.8 +// Note: sets Cc and Ci variables 1.9 + 1.10 +Cu.import("resource://testing-common/httpd.js"); 1.11 + 1.12 +var httpserver = new HttpServer(); 1.13 +var testpath = "/simple"; 1.14 +var httpbody = "0123456789"; 1.15 +var buffer = ""; 1.16 + 1.17 +var dbg=0 1.18 +if (dbg) { print("============== START =========="); } 1.19 + 1.20 +function run_test() { 1.21 + setup_test(); 1.22 + do_test_pending(); 1.23 +} 1.24 + 1.25 +function setup_test() { 1.26 + if (dbg) { print("============== setup_test: in"); } 1.27 + httpserver.registerPathHandler(testpath, serverHandler); 1.28 + httpserver.start(-1); 1.29 + var channel = setupChannel(testpath); 1.30 + // ChannelListener defined in head_channels.js 1.31 + channel.asyncOpen(new ChannelListener(checkRequest, channel), null); 1.32 + if (dbg) { print("============== setup_test: out"); } 1.33 +} 1.34 + 1.35 +function setupChannel(path) { 1.36 + var ios = Cc["@mozilla.org/network/io-service;1"]. 1.37 + getService(Ci.nsIIOService); 1.38 + var chan = ios.newChannel("http://localhost:" + 1.39 + httpserver.identity.primaryPort + path, "", null); 1.40 + chan.QueryInterface(Ci.nsIHttpChannel); 1.41 + chan.requestMethod = "GET"; 1.42 + return chan; 1.43 +} 1.44 + 1.45 +function serverHandler(metadata, response) { 1.46 + if (dbg) { print("============== serverHandler: in"); } 1.47 + response.setHeader("Content-Type", "text/plain", false); 1.48 + response.bodyOutputStream.write(httpbody, httpbody.length); 1.49 + if (dbg) { print("============== serverHandler: out"); } 1.50 +} 1.51 + 1.52 +function checkRequest(request, data, context) { 1.53 + if (dbg) { print("============== checkRequest: in"); } 1.54 + do_check_eq(data, httpbody); 1.55 + httpserver.stop(do_test_finished); 1.56 + if (dbg) { print("============== checkRequest: out"); } 1.57 +} 1.58 +