michael@0: Cu.import("resource://testing-common/httpd.js"); michael@0: michael@0: var httpserver = new HttpServer(); michael@0: var currentTestIndex = 0; michael@0: michael@0: XPCOMUtils.defineLazyGetter(this, "port", function() { michael@0: return httpserver.identity.primaryPort; michael@0: }); michael@0: michael@0: XPCOMUtils.defineLazyGetter(this, "tests", function() { michael@0: return [ michael@0: // this is valid michael@0: {url: "/assoc/assoctest?valid", michael@0: responseheader: ["Assoc-Req: GET http://localhost:" + port + michael@0: "/assoc/assoctest?valid", michael@0: "Pragma: X-Verify-Assoc-Req"], michael@0: flags: 0}, michael@0: michael@0: // this is invalid because the method is wrong michael@0: {url: "/assoc/assoctest?invalid", michael@0: responseheader: ["Assoc-Req: POST http://localhost:" + port + michael@0: "/assoc/assoctest?invalid", michael@0: "Pragma: X-Verify-Assoc-Req"], michael@0: flags: CL_EXPECT_LATE_FAILURE}, michael@0: michael@0: // this is invalid because the url is wrong michael@0: {url: "/assoc/assoctest?notvalid", michael@0: responseheader: ["Assoc-Req: GET http://localhost:" + port + michael@0: "/wrongpath/assoc/assoctest?notvalid", michael@0: "Pragma: X-Verify-Assoc-Req"], michael@0: flags: CL_EXPECT_LATE_FAILURE}, michael@0: michael@0: // this is invalid because the space between method and URL is missing michael@0: {url: "/assoc/assoctest?invalid2", michael@0: responseheader: ["Assoc-Req: GEThttp://localhost:" + port + michael@0: "/assoc/assoctest?invalid2", michael@0: "Pragma: X-Verify-Assoc-Req"], michael@0: flags: CL_EXPECT_LATE_FAILURE}, michael@0: ]; michael@0: }); michael@0: michael@0: var oldPrefVal; michael@0: var domBranch; michael@0: michael@0: function setupChannel(url) michael@0: { michael@0: var ios = Components.classes["@mozilla.org/network/io-service;1"]. michael@0: getService(Ci.nsIIOService); michael@0: var chan = ios.newChannel("http://localhost:" + port + url, "", null); michael@0: return chan; michael@0: } michael@0: michael@0: function startIter() michael@0: { michael@0: var channel = setupChannel(tests[currentTestIndex].url); michael@0: channel.asyncOpen(new ChannelListener(completeIter, michael@0: channel, tests[currentTestIndex].flags), null); michael@0: } michael@0: michael@0: function completeIter(request, data, ctx) michael@0: { michael@0: if (++currentTestIndex < tests.length ) { michael@0: startIter(); michael@0: } else { michael@0: domBranch.setBoolPref("enforce", oldPrefVal); michael@0: httpserver.stop(do_test_finished); michael@0: } michael@0: } michael@0: michael@0: function run_test() michael@0: { michael@0: var prefService = michael@0: Components.classes["@mozilla.org/preferences-service;1"] michael@0: .getService(Components.interfaces.nsIPrefService); michael@0: domBranch = prefService.getBranch("network.http.assoc-req."); michael@0: oldPrefVal = domBranch.getBoolPref("enforce"); michael@0: domBranch.setBoolPref("enforce", true); michael@0: michael@0: httpserver.registerPathHandler("/assoc/assoctest", handler); michael@0: httpserver.start(-1); michael@0: michael@0: startIter(); michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function handler(metadata, response) michael@0: { michael@0: var body = "thequickbrownfox"; michael@0: response.setHeader("Content-Type", "text/plain", false); michael@0: michael@0: var header = tests[currentTestIndex].responseheader; michael@0: if (header != undefined) { michael@0: for (var i = 0; i < header.length; i++) { michael@0: var splitHdr = header[i].split(": "); michael@0: response.setHeader(splitHdr[0], splitHdr[1], false); michael@0: } michael@0: } michael@0: michael@0: response.setStatusLine(metadata.httpVersion, 200, "OK"); michael@0: response.bodyOutputStream.write(body, body.length); michael@0: }