michael@0: // michael@0: // Simple HTTP test: fetches page michael@0: // michael@0: michael@0: // Note: sets Cc and Ci variables michael@0: michael@0: Cu.import("resource://testing-common/httpd.js"); michael@0: michael@0: var httpserver = new HttpServer(); michael@0: var testpath = "/simple"; michael@0: var httpbody = "0123456789"; michael@0: var buffer = ""; michael@0: michael@0: var dbg=0 michael@0: if (dbg) { print("============== START =========="); } michael@0: michael@0: function run_test() { michael@0: setup_test(); michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function setup_test() { michael@0: if (dbg) { print("============== setup_test: in"); } michael@0: httpserver.registerPathHandler(testpath, serverHandler); michael@0: httpserver.start(-1); michael@0: var channel = setupChannel(testpath); michael@0: // ChannelListener defined in head_channels.js michael@0: channel.asyncOpen(new ChannelListener(checkRequest, channel), null); michael@0: if (dbg) { print("============== setup_test: out"); } michael@0: } michael@0: michael@0: function setupChannel(path) { michael@0: var ios = Cc["@mozilla.org/network/io-service;1"]. michael@0: getService(Ci.nsIIOService); michael@0: var chan = ios.newChannel("http://localhost:" + michael@0: httpserver.identity.primaryPort + path, "", null); michael@0: chan.QueryInterface(Ci.nsIHttpChannel); michael@0: chan.requestMethod = "GET"; michael@0: return chan; michael@0: } michael@0: michael@0: function serverHandler(metadata, response) { michael@0: if (dbg) { print("============== serverHandler: in"); } michael@0: response.setHeader("Content-Type", "text/plain", false); michael@0: response.bodyOutputStream.write(httpbody, httpbody.length); michael@0: if (dbg) { print("============== serverHandler: out"); } michael@0: } michael@0: michael@0: function checkRequest(request, data, context) { michael@0: if (dbg) { print("============== checkRequest: in"); } michael@0: do_check_eq(data, httpbody); michael@0: httpserver.stop(do_test_finished); michael@0: if (dbg) { print("============== checkRequest: out"); } michael@0: } michael@0: