Bug 888350 - Use a dynamic port in network/test/unit* xpcshell tests so they can be run in parallel. r=honzab

This commit is contained in:
Mihnea Dobrescu-Balaur 2013-07-19 10:19:28 -07:00
parent 11c04bdaa0
commit 9f146077b1
90 changed files with 717 additions and 376 deletions

View File

@ -1,3 +1,5 @@
Components.utils.import('resource://gre/modules/XPCOMUtils.jsm');
var _CSvc; var _CSvc;
function get_cache_service() { function get_cache_service() {
if (_CSvc) if (_CSvc)

View File

@ -8,10 +8,18 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpServer.identity.primaryPort;
});
var httpServer = null; var httpServer = null;
const testFileName = "test_customConditionalRequest_304"; const testFileName = "test_customConditionalRequest_304";
const basePath = "/" + testFileName + "/"; const basePath = "/" + testFileName + "/";
const baseURI = "http://localhost:4444" + basePath;
XPCOMUtils.defineLazyGetter(this, "baseURI", function() {
return URL + basePath;
});
const unexpected304 = "unexpected304"; const unexpected304 = "unexpected304";
const existingCached304 = "existingCached304"; const existingCached304 = "existingCached304";
@ -46,7 +54,7 @@ function run_test() {
alwaysReturn304Handler); alwaysReturn304Handler);
httpServer.registerPathHandler(basePath + existingCached304, httpServer.registerPathHandler(basePath + existingCached304,
alwaysReturn304Handler); alwaysReturn304Handler);
httpServer.start(4444); httpServer.start(-1);
run_next_test(); run_next_test();
} }

View File

@ -5,9 +5,19 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserver.identity.primaryPort;
});
XPCOMUtils.defineLazyGetter(this, "uri", function() {
return URL + "/redirect";
});
XPCOMUtils.defineLazyGetter(this, "noRedirectURI", function() {
return URL + "/content";
});
var httpserver = null; var httpserver = null;
var uri = "http://localhost:4444/redirect";
var noRedirectURI = "http://localhost:4444/content";
function make_channel(url) { function make_channel(url) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -69,7 +79,7 @@ function run_test()
httpserver = new HttpServer(); httpserver = new HttpServer();
httpserver.registerPathHandler("/redirect", redirectHandler); httpserver.registerPathHandler("/redirect", redirectHandler);
httpserver.registerPathHandler("/content", contentHandler); httpserver.registerPathHandler("/content", contentHandler);
httpserver.start(4444); httpserver.start(-1);
var prefs = Cc["@mozilla.org/preferences-service;1"] var prefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch); .getService(Components.interfaces.nsIPrefBranch);

View File

@ -200,11 +200,12 @@ function test_asyncFetch_with_nsIChannel()
aResponse.setHeader("Content-Type", "text/plain", false); aResponse.setHeader("Content-Type", "text/plain", false);
aResponse.write(TEST_DATA); aResponse.write(TEST_DATA);
}); });
server.start(4444); server.start(-1);
// Create our channel. // Create our channel.
let channel = NetUtil.ioService. let channel = NetUtil.ioService.
newChannel("http://localhost:4444/test", null, null); newChannel("http://localhost:" +
server.identity.primaryPort + "/test", null, null);
// Open our channel asynchronously. // Open our channel asynchronously.
NetUtil.asyncFetch(channel, function(aInputStream, aResult) { NetUtil.asyncFetch(channel, function(aInputStream, aResult) {
@ -234,10 +235,11 @@ function test_asyncFetch_with_nsIURI()
aResponse.setHeader("Content-Type", "text/plain", false); aResponse.setHeader("Content-Type", "text/plain", false);
aResponse.write(TEST_DATA); aResponse.write(TEST_DATA);
}); });
server.start(4444); server.start(-1);
// Create our URI. // Create our URI.
let uri = NetUtil.newURI("http://localhost:4444/test"); let uri = NetUtil.newURI("http://localhost:" +
server.identity.primaryPort + "/test");
// Open our URI asynchronously. // Open our URI asynchronously.
NetUtil.asyncFetch(uri, function(aInputStream, aResult) { NetUtil.asyncFetch(uri, function(aInputStream, aResult) {
@ -267,11 +269,12 @@ function test_asyncFetch_with_string()
aResponse.setHeader("Content-Type", "text/plain", false); aResponse.setHeader("Content-Type", "text/plain", false);
aResponse.write(TEST_DATA); aResponse.write(TEST_DATA);
}); });
server.start(4444); server.start(-1);
// Open our location asynchronously. // Open our location asynchronously.
NetUtil.asyncFetch("http://localhost:4444/test", function(aInputStream, NetUtil.asyncFetch("http://localhost:" +
aResult) { server.identity.primaryPort + "/test",
function(aInputStream, aResult) {
// Check that we had success. // Check that we had success.
do_check_true(Components.isSuccessCode(aResult)); do_check_true(Components.isSuccessCode(aResult));

View File

@ -17,8 +17,12 @@ var sOther;
const BUGID = "676059"; const BUGID = "676059";
const OTHERBUGID = "696849"; const OTHERBUGID = "696849";
const pSame = 4444; XPCOMUtils.defineLazyGetter(this, "pSame", function() {
const pOther = 4445; return sSame.identity.primaryPort;
});
XPCOMUtils.defineLazyGetter(this, "pOther", function() {
return sOther.identity.primaryPort;
});
function createXHR(async, method, path) function createXHR(async, method, path)
{ {
@ -63,12 +67,12 @@ function run_test() {
// same-origin target // same-origin target
sSame.registerPathHandler("/bug" + BUGID + "-target", echoMethod); sSame.registerPathHandler("/bug" + BUGID + "-target", echoMethod);
sSame.start(pSame); sSame.start(-1);
// cross-origin target // cross-origin target
sOther = new HttpServer(); sOther = new HttpServer();
sOther.registerPathHandler("/bug" + OTHERBUGID + "-target", echoMethod); sOther.registerPathHandler("/bug" + OTHERBUGID + "-target", echoMethod);
sOther.start(pOther); sOther.start(-1);
// format: redirectType, methodToSend, redirectedMethod, finalStatus // format: redirectType, methodToSend, redirectedMethod, finalStatus
// redirectType sets the URI the initial request goes to // redirectType sets the URI the initial request goes to

View File

@ -7,31 +7,42 @@ Cu.import("resource://testing-common/httpd.js");
var httpserver = new HttpServer(); var httpserver = new HttpServer();
var currentTestIndex = 0; var currentTestIndex = 0;
var tests = [
// this is valid
{url: "/assoc/assoctest?valid",
responseheader: [ "Assoc-Req: GET http://localhost:4444/assoc/assoctest?valid",
"Pragma: X-Verify-Assoc-Req" ],
flags : 0},
// this is invalid because the method is wrong XPCOMUtils.defineLazyGetter(this, "port", function() {
{url: "/assoc/assoctest?invalid", return httpserver.identity.primaryPort;
responseheader: [ "Assoc-Req: POST http://localhost:4444/assoc/assoctest?invalid", });
"Pragma: X-Verify-Assoc-Req" ],
flags : CL_EXPECT_LATE_FAILURE}, XPCOMUtils.defineLazyGetter(this, "tests", function() {
return [
// this is invalid because the url is wrong // this is valid
{url: "/assoc/assoctest?notvalid", {url: "/assoc/assoctest?valid",
responseheader: [ "Assoc-Req: GET http://localhost:4444/wrongpath/assoc/assoctest?notvalid", responseheader: ["Assoc-Req: GET http://localhost:" + port +
"Pragma: X-Verify-Assoc-Req" ], "/assoc/assoctest?valid",
flags : CL_EXPECT_LATE_FAILURE}, "Pragma: X-Verify-Assoc-Req"],
flags: 0},
// this is invalid because the method is wrong
{url: "/assoc/assoctest?invalid",
responseheader: ["Assoc-Req: POST http://localhost:" + port +
"/assoc/assoctest?invalid",
"Pragma: X-Verify-Assoc-Req"],
flags: CL_EXPECT_LATE_FAILURE},
// this is invalid because the url is wrong
{url: "/assoc/assoctest?notvalid",
responseheader: ["Assoc-Req: GET http://localhost:" + port +
"/wrongpath/assoc/assoctest?notvalid",
"Pragma: X-Verify-Assoc-Req"],
flags: CL_EXPECT_LATE_FAILURE},
// this is invalid because the space between method and URL is missing // this is invalid because the space between method and URL is missing
{url: "/assoc/assoctest?invalid2", {url: "/assoc/assoctest?invalid2",
responseheader: [ "Assoc-Req: GEThttp://localhost:4444/assoc/assoctest?invalid2", responseheader: ["Assoc-Req: GEThttp://localhost:" + port +
"Pragma: X-Verify-Assoc-Req" ], "/assoc/assoctest?invalid2",
flags : CL_EXPECT_LATE_FAILURE}, "Pragma: X-Verify-Assoc-Req"],
]; flags: CL_EXPECT_LATE_FAILURE},
];
});
var oldPrefVal; var oldPrefVal;
var domBranch; var domBranch;
@ -40,7 +51,7 @@ function setupChannel(url)
{ {
var ios = Components.classes["@mozilla.org/network/io-service;1"]. var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService); getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + url, "", null); var chan = ios.newChannel("http://localhost:" + port + url, "", null);
return chan; return chan;
} }
@ -71,7 +82,7 @@ function run_test()
domBranch.setBoolPref("enforce", true); domBranch.setBoolPref("enforce", true);
httpserver.registerPathHandler("/assoc/assoctest", handler); httpserver.registerPathHandler("/assoc/assoctest", handler);
httpserver.start(4444); httpserver.start(-1);
startIter(); startIter();
do_test_pending(); do_test_pending();

View File

@ -226,12 +226,12 @@ function run_test() {
httpserv = new HttpServer(); httpserv = new HttpServer();
httpserv.registerPathHandler("/", proxyAuthHandler); httpserv.registerPathHandler("/", proxyAuthHandler);
httpserv.identity.add("http", "somesite", 80); httpserv.identity.add("http", "somesite", 80);
httpserv.start(4444); httpserv.start(-1);
const prefs = Cc["@mozilla.org/preferences-service;1"] const prefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch); .getService(Ci.nsIPrefBranch);
prefs.setCharPref("network.proxy.http", "localhost"); prefs.setCharPref("network.proxy.http", "localhost");
prefs.setIntPref("network.proxy.http_port", 4444); prefs.setIntPref("network.proxy.http_port", httpserv.identity.primaryPort);
prefs.setCharPref("network.proxy.no_proxies_on", ""); prefs.setCharPref("network.proxy.no_proxies_on", "");
prefs.setIntPref("network.proxy.type", 1); prefs.setIntPref("network.proxy.type", 1);

View File

@ -8,6 +8,14 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserv.identity.primaryPort;
});
XPCOMUtils.defineLazyGetter(this, "PORT", function() {
return httpserv.identity.primaryPort;
});
const FLAG_RETURN_FALSE = 1 << 0; const FLAG_RETURN_FALSE = 1 << 0;
const FLAG_WRONG_PASSWORD = 1 << 1; const FLAG_WRONG_PASSWORD = 1 << 1;
const FLAG_BOGUS_USER = 1 << 2; const FLAG_BOGUS_USER = 1 << 2;
@ -42,12 +50,12 @@ AuthPrompt1.prototype = {
function ap1_promptUP(title, text, realm, savePW, user, pw) function ap1_promptUP(title, text, realm, savePW, user, pw)
{ {
// Note that the realm here isn't actually the realm. it's a pw mgr key. // Note that the realm here isn't actually the realm. it's a pw mgr key.
do_check_eq("http://localhost:4444 (" + this.expectedRealm + ")", realm); do_check_eq(URL + " (" + this.expectedRealm + ")", realm);
if (text.indexOf(this.expectedRealm) == -1) if (text.indexOf(this.expectedRealm) == -1)
do_throw("Text must indicate the realm"); do_throw("Text must indicate the realm");
if (text.indexOf("localhost") == -1) if (text.indexOf("localhost") == -1)
do_throw("Text must indicate the hostname"); do_throw("Text must indicate the hostname");
if (text.indexOf("4444") == -1) if (text.indexOf(String(PORT)) == -1)
do_throw("Text must indicate the port"); do_throw("Text must indicate the port");
if (text.indexOf("-1") != -1) if (text.indexOf("-1") != -1)
do_throw("Text must contain negative numbers"); do_throw("Text must contain negative numbers");
@ -291,13 +299,13 @@ function run_test() {
httpserv.registerPathHandler("/auth/realm", authRealm); httpserv.registerPathHandler("/auth/realm", authRealm);
httpserv.registerPathHandler("/auth/digest", authDigest); httpserv.registerPathHandler("/auth/digest", authDigest);
httpserv.start(4444); httpserv.start(-1);
tests[0](); tests[0]();
} }
function test_noauth() { function test_noauth() {
var chan = makeChan("http://localhost:4444/auth"); var chan = makeChan(URL + "/auth");
listener.expectedCode = 401; // Unauthorized listener.expectedCode = 401; // Unauthorized
chan.asyncOpen(listener, null); chan.asyncOpen(listener, null);
@ -306,7 +314,7 @@ function test_noauth() {
} }
function test_returnfalse1() { function test_returnfalse1() {
var chan = makeChan("http://localhost:4444/auth"); var chan = makeChan(URL + "/auth");
chan.notificationCallbacks = new Requestor(FLAG_RETURN_FALSE, 1); chan.notificationCallbacks = new Requestor(FLAG_RETURN_FALSE, 1);
listener.expectedCode = 401; // Unauthorized listener.expectedCode = 401; // Unauthorized
@ -316,7 +324,7 @@ function test_returnfalse1() {
} }
function test_wrongpw1() { function test_wrongpw1() {
var chan = makeChan("http://localhost:4444/auth"); var chan = makeChan(URL + "/auth");
chan.notificationCallbacks = new Requestor(FLAG_WRONG_PASSWORD, 1); chan.notificationCallbacks = new Requestor(FLAG_WRONG_PASSWORD, 1);
listener.expectedCode = 200; // OK listener.expectedCode = 200; // OK
@ -326,7 +334,7 @@ function test_wrongpw1() {
} }
function test_prompt1() { function test_prompt1() {
var chan = makeChan("http://localhost:4444/auth"); var chan = makeChan(URL + "/auth");
chan.notificationCallbacks = new Requestor(0, 1); chan.notificationCallbacks = new Requestor(0, 1);
listener.expectedCode = 200; // OK listener.expectedCode = 200; // OK
@ -336,7 +344,7 @@ function test_prompt1() {
} }
function test_returnfalse2() { function test_returnfalse2() {
var chan = makeChan("http://localhost:4444/auth"); var chan = makeChan(URL + "/auth");
chan.notificationCallbacks = new Requestor(FLAG_RETURN_FALSE, 2); chan.notificationCallbacks = new Requestor(FLAG_RETURN_FALSE, 2);
listener.expectedCode = 401; // Unauthorized listener.expectedCode = 401; // Unauthorized
@ -346,7 +354,7 @@ function test_returnfalse2() {
} }
function test_wrongpw2() { function test_wrongpw2() {
var chan = makeChan("http://localhost:4444/auth"); var chan = makeChan(URL + "/auth");
chan.notificationCallbacks = new Requestor(FLAG_WRONG_PASSWORD, 2); chan.notificationCallbacks = new Requestor(FLAG_WRONG_PASSWORD, 2);
listener.expectedCode = 200; // OK listener.expectedCode = 200; // OK
@ -356,7 +364,7 @@ function test_wrongpw2() {
} }
function test_prompt2() { function test_prompt2() {
var chan = makeChan("http://localhost:4444/auth"); var chan = makeChan(URL + "/auth");
chan.notificationCallbacks = new Requestor(0, 2); chan.notificationCallbacks = new Requestor(0, 2);
listener.expectedCode = 200; // OK listener.expectedCode = 200; // OK
@ -366,7 +374,7 @@ function test_prompt2() {
} }
function test_ntlm() { function test_ntlm() {
var chan = makeChan("http://localhost:4444/auth/ntlm/simple"); var chan = makeChan(URL + "/auth/ntlm/simple");
chan.notificationCallbacks = new Requestor(FLAG_RETURN_FALSE, 2); chan.notificationCallbacks = new Requestor(FLAG_RETURN_FALSE, 2);
listener.expectedCode = 401; // Unauthorized listener.expectedCode = 401; // Unauthorized
@ -376,7 +384,7 @@ function test_ntlm() {
} }
function test_auth() { function test_auth() {
var chan = makeChan("http://localhost:4444/auth/realm"); var chan = makeChan(URL + "/auth/realm");
chan.notificationCallbacks = new RealmTestRequestor(); chan.notificationCallbacks = new RealmTestRequestor();
listener.expectedCode = 401; // Unauthorized listener.expectedCode = 401; // Unauthorized
@ -386,7 +394,7 @@ function test_auth() {
} }
function test_digest_noauth() { function test_digest_noauth() {
var chan = makeChan("http://localhost:4444/auth/digest"); var chan = makeChan(URL + "/auth/digest");
//chan.notificationCallbacks = new Requestor(FLAG_RETURN_FALSE, 2); //chan.notificationCallbacks = new Requestor(FLAG_RETURN_FALSE, 2);
listener.expectedCode = 401; // Unauthorized listener.expectedCode = 401; // Unauthorized
@ -396,7 +404,7 @@ function test_digest_noauth() {
} }
function test_digest() { function test_digest() {
var chan = makeChan("http://localhost:4444/auth/digest"); var chan = makeChan(URL + "/auth/digest");
chan.notificationCallbacks = new Requestor(0, 2); chan.notificationCallbacks = new Requestor(0, 2);
listener.expectedCode = 200; // OK listener.expectedCode = 200; // OK
@ -406,7 +414,7 @@ function test_digest() {
} }
function test_digest_bogus_user() { function test_digest_bogus_user() {
var chan = makeChan("http://localhost:4444/auth/digest"); var chan = makeChan(URL + "/auth/digest");
chan.notificationCallbacks = new Requestor(FLAG_BOGUS_USER, 2); chan.notificationCallbacks = new Requestor(FLAG_BOGUS_USER, 2);
listener.expectedCode = 401; // unauthorized listener.expectedCode = 401; // unauthorized
chan.asyncOpen(listener, null); chan.asyncOpen(listener, null);

View File

@ -101,7 +101,9 @@ function logit(i, data, ctx) {
function setupChannel(suffix, value) { function setupChannel(suffix, value) {
var ios = Components.classes["@mozilla.org/network/io-service;1"]. var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService); getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + suffix, "", null); var chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort + suffix,
"", null);
var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
httpChan.requestMethod = "GET"; // default value, just being paranoid... httpChan.requestMethod = "GET"; // default value, just being paranoid...
httpChan.setRequestHeader("x-request", value, false); httpChan.setRequestHeader("x-request", value, false);
@ -131,7 +133,7 @@ function checkValueAndTrigger(request, data, ctx) {
function run_test() { function run_test() {
httpserver.registerPathHandler("/precedence", handler); httpserver.registerPathHandler("/precedence", handler);
httpserver.start(4444); httpserver.start(-1);
// clear cache // clear cache
evict_cache_entries(); evict_cache_entries();

View File

@ -18,7 +18,7 @@ function inChildProcess() {
} }
function makeChan(path) { function makeChan(path) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444/" + path, null, null) var chan = ios.newChannel("http://localhost:" + httpserver.identity.primaryPort + "/" + path, null, null)
.QueryInterface(Ci.nsIHttpChannel); .QueryInterface(Ci.nsIHttpChannel);
return chan; return chan;
} }
@ -73,7 +73,7 @@ function run_test() {
httpserver = new HttpServer(); httpserver = new HttpServer();
httpserver.registerPathHandler("/set", setHandler); httpserver.registerPathHandler("/set", setHandler);
httpserver.registerPathHandler("/present", presentHandler); httpserver.registerPathHandler("/present", presentHandler);
httpserver.start(4444); httpserver.start(-1);
do_test_pending(); do_test_pending();

View File

@ -40,12 +40,13 @@ var listener = {
function run_test() { function run_test() {
// start server // start server
server = new HttpServer(); server = new HttpServer();
server.start(4444); server.start(-1);
// Initialize downloader // Initialize downloader
var channel = Cc["@mozilla.org/network/io-service;1"] var channel = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService) .getService(Ci.nsIIOService)
.newChannel("http://localhost:4444/", null, null); .newChannel("http://localhost:" +
server.identity.primaryPort + "/", null, null);
var targetFile = Cc["@mozilla.org/file/directory_service;1"] var targetFile = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties) .getService(Ci.nsIProperties)

View File

@ -25,13 +25,14 @@ function run_test() {
server.registerPathHandler("/bug" + BUGID, bug331825); server.registerPathHandler("/bug" + BUGID, bug331825);
server.start(4444); server.start(-1);
// make request // make request
var channel = var channel =
Components.classes["@mozilla.org/network/io-service;1"]. Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService). getService(Components.interfaces.nsIIOService).
newChannel("http://localhost:4444/bug" + BUGID, null, null); newChannel("http://localhost:" + server.identity.primaryPort + "/bug" +
BUGID, null, null);
channel.QueryInterface(Components.interfaces.nsIHttpChannel); channel.QueryInterface(Components.interfaces.nsIHttpChannel);
channel.setRequestHeader("If-None-Match", "foobar", false); channel.setRequestHeader("If-None-Match", "foobar", false);

View File

@ -56,13 +56,14 @@ function run_test() {
server.registerPathHandler("/bug" + BUGID, bug369787); server.registerPathHandler("/bug" + BUGID, bug369787);
server.start(4444); server.start(-1);
// make request // make request
channel = channel =
Components.classes["@mozilla.org/network/io-service;1"]. Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService). getService(Components.interfaces.nsIIOService).
newChannel("http://localhost:4444/bug" + BUGID, null, null); newChannel("http://localhost:" +
server.identity.primaryPort + "/bug" + BUGID, null, null);
channel.QueryInterface(Components.interfaces.nsIHttpChannel); channel.QueryInterface(Components.interfaces.nsIHttpChannel);
channel.asyncOpen(new TestListener(), null); channel.asyncOpen(new TestListener(), null);

View File

@ -22,13 +22,14 @@ function run_test() {
httpserv.registerPathHandler("/bug412945", bug412945); httpserv.registerPathHandler("/bug412945", bug412945);
httpserv.start(4444); httpserv.start(-1);
// make request // make request
var channel = var channel =
Components.classes["@mozilla.org/network/io-service;1"]. Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService). getService(Components.interfaces.nsIIOService).
newChannel("http://localhost:4444/bug412945", null, null); newChannel("http://localhost:" + httpserv.identity.primaryPort +
"/bug412945", null, null);
channel.QueryInterface(Components.interfaces.nsIHttpChannel); channel.QueryInterface(Components.interfaces.nsIHttpChannel);
channel.requestMethod = "post"; channel.requestMethod = "post";

View File

@ -40,7 +40,8 @@ var tests = [
function setupChannel(suffix, value, cookie) { function setupChannel(suffix, value, cookie) {
var ios = Components.classes["@mozilla.org/network/io-service;1"] var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService); .getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + suffix, "", null); var chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort + suffix, "", null);
var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
httpChan.requestMethod = "GET"; httpChan.requestMethod = "GET";
httpChan.setRequestHeader("x-request", value, false); httpChan.setRequestHeader("x-request", value, false);
@ -69,7 +70,7 @@ function checkValueAndTrigger(request, data, ctx) {
function run_test() { function run_test() {
httpserver.registerPathHandler("/bug468426", handler); httpserver.registerPathHandler("/bug468426", handler);
httpserver.start(4444); httpserver.start(-1);
// Clear cache and trigger the first test // Clear cache and trigger the first test
evict_cache_entries(); evict_cache_entries();

View File

@ -62,7 +62,7 @@ function logit(i, data) {
function setupChannel(suffix, value) { function setupChannel(suffix, value) {
var ios = Components.classes["@mozilla.org/network/io-service;1"]. var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService); getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + suffix, "", null); var chan = ios.newChannel("http://localhost:" + httpserver.identity.primaryPort + suffix, "", null);
var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
httpChan.requestMethod = "GET"; httpChan.requestMethod = "GET";
httpChan.setRequestHeader("x-request", value, false); httpChan.setRequestHeader("x-request", value, false);
@ -88,7 +88,7 @@ function checkValueAndTrigger(request, data, ctx) {
function run_test() { function run_test() {
httpserver.registerPathHandler("/freshness", handler); httpserver.registerPathHandler("/freshness", handler);
httpserver.start(4444); httpserver.start(-1);
// clear cache // clear cache
evict_cache_entries(); evict_cache_entries();

View File

@ -50,7 +50,7 @@ function run_test() {
httpserv.registerPathHandler("/bug482601/partial", bug482601_partial); httpserv.registerPathHandler("/bug482601/partial", bug482601_partial);
httpserv.registerPathHandler("/bug482601/cached", bug482601_cached); httpserv.registerPathHandler("/bug482601/cached", bug482601_cached);
httpserv.registerPathHandler("/bug482601/only_from_cache", bug482601_only_from_cache); httpserv.registerPathHandler("/bug482601/only_from_cache", bug482601_only_from_cache);
httpserv.start(4444); httpserv.start(-1);
var obs = Cc["@mozilla.org/observer-service;1"].getService(); var obs = Cc["@mozilla.org/observer-service;1"].getService();
obs = obs.QueryInterface(Ci.nsIObserverService); obs = obs.QueryInterface(Ci.nsIObserverService);
@ -107,12 +107,14 @@ function storeCache(aCacheEntry, aResponseHeads, aContent) {
function test_nocache() { function test_nocache() {
observers_called = ""; observers_called = "";
var chan = makeChan("http://localhost:4444/bug482601/nocache"); var chan = makeChan("http://localhost:" + httpserv.identity.primaryPort +
"/bug482601/nocache");
chan.asyncOpen(listener, null); chan.asyncOpen(listener, null);
} }
function test_partial() { function test_partial() {
asyncOpenCacheEntry("http://localhost:4444/bug482601/partial", asyncOpenCacheEntry("http://localhost:" + httpserv.identity.primaryPort +
"/bug482601/partial",
"HTTP", "HTTP",
Ci.nsICache.STORE_ANYWHERE, Ci.nsICache.STORE_ANYWHERE,
Ci.nsICache.ACCESS_READ_WRITE, Ci.nsICache.ACCESS_READ_WRITE,
@ -133,12 +135,14 @@ function test_partial2(status, entry) {
observers_called = ""; observers_called = "";
var chan = makeChan("http://localhost:4444/bug482601/partial"); var chan = makeChan("http://localhost:" + httpserv.identity.primaryPort +
"/bug482601/partial");
chan.asyncOpen(listener, null); chan.asyncOpen(listener, null);
} }
function test_cached() { function test_cached() {
asyncOpenCacheEntry("http://localhost:4444/bug482601/cached", asyncOpenCacheEntry("http://localhost:" + httpserv.identity.primaryPort +
"/bug482601/cached",
"HTTP", "HTTP",
Ci.nsICache.STORE_ANYWHERE, Ci.nsICache.STORE_ANYWHERE,
Ci.nsICache.ACCESS_READ_WRITE, Ci.nsICache.ACCESS_READ_WRITE,
@ -159,13 +163,15 @@ function test_cached2(status, entry) {
observers_called = ""; observers_called = "";
var chan = makeChan("http://localhost:4444/bug482601/cached"); var chan = makeChan("http://localhost:" + httpserv.identity.primaryPort +
"/bug482601/cached");
chan.loadFlags = Ci.nsIRequest.VALIDATE_ALWAYS; chan.loadFlags = Ci.nsIRequest.VALIDATE_ALWAYS;
chan.asyncOpen(listener, null); chan.asyncOpen(listener, null);
} }
function test_only_from_cache() { function test_only_from_cache() {
asyncOpenCacheEntry("http://localhost:4444/bug482601/only_from_cache", asyncOpenCacheEntry("http://localhost:" + httpserv.identity.primaryPort +
"/bug482601/only_from_cache",
"HTTP", "HTTP",
Ci.nsICache.STORE_ANYWHERE, Ci.nsICache.STORE_ANYWHERE,
Ci.nsICache.ACCESS_READ_WRITE, Ci.nsICache.ACCESS_READ_WRITE,
@ -186,7 +192,8 @@ function test_only_from_cache2(status, entry) {
observers_called = ""; observers_called = "";
var chan = makeChan("http://localhost:4444/bug482601/only_from_cache"); var chan = makeChan("http://localhost:" + httpserv.identity.primaryPort +
"/bug482601/only_from_cache");
chan.loadFlags = Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE; chan.loadFlags = Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE;
chan.asyncOpen(listener, null); chan.asyncOpen(listener, null);
} }

View File

@ -49,7 +49,9 @@ function logit(i, data) {
function setupChannel(suffix, value) { function setupChannel(suffix, value) {
var ios = Components.classes["@mozilla.org/network/io-service;1"]. var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService); getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + suffix, "", null); var chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort +
suffix, "", null);
var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
httpChan.requestMethod = "GET"; httpChan.requestMethod = "GET";
httpChan.setRequestHeader("x-request", value, false); httpChan.setRequestHeader("x-request", value, false);
@ -79,7 +81,7 @@ function checkValueAndTrigger(request, data, ctx) {
function run_test() { function run_test() {
httpserver.registerPathHandler("/freshness", handler); httpserver.registerPathHandler("/freshness", handler);
httpserver.start(4444); httpserver.start(-1);
// clear cache // clear cache
evict_cache_entries(); evict_cache_entries();

View File

@ -15,7 +15,9 @@ var tests = [
function setupChannel(suffix, value) { function setupChannel(suffix, value) {
var ios = Components.classes["@mozilla.org/network/io-service;1"] var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService); .getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + suffix, "", null); var chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort +
suffix, "", null);
var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
httpChan.requestMethod = "GET"; httpChan.requestMethod = "GET";
httpChan.setRequestHeader("x-request", value, false); httpChan.setRequestHeader("x-request", value, false);
@ -41,7 +43,7 @@ function checkValueAndTrigger(request, data, ctx) {
function run_test() { function run_test() {
httpserver.registerPathHandler("/bug510359", handler); httpserver.registerPathHandler("/bug510359", handler);
httpserver.start(4444); httpserver.start(-1);
// clear cache // clear cache
evict_cache_entries(); evict_cache_entries();

View File

@ -7,11 +7,23 @@ Cu.import("resource://testing-common/httpd.js");
const sentCookieVal = "foo=bar"; const sentCookieVal = "foo=bar";
const responseBody = "response body"; const responseBody = "response body";
const baseURL = "http://localhost:4444";
XPCOMUtils.defineLazyGetter(this, "baseURL", function() {
return "http://localhost:" + httpServer.identity.primaryPort;
});
const preRedirectPath = "/528292/pre-redirect"; const preRedirectPath = "/528292/pre-redirect";
const preRedirectURL = baseURL + preRedirectPath;
XPCOMUtils.defineLazyGetter(this, "preRedirectURL", function() {
return baseURL + preRedirectPath;
});
const postRedirectPath = "/528292/post-redirect"; const postRedirectPath = "/528292/post-redirect";
const postRedirectURL = baseURL + postRedirectPath;
XPCOMUtils.defineLazyGetter(this, "postRedirectURL", function() {
return baseURL + postRedirectPath;
});
var httpServer = null; var httpServer = null;
var receivedCookieVal = null; var receivedCookieVal = null;
@ -35,7 +47,7 @@ function run_test()
httpServer = new HttpServer(); httpServer = new HttpServer();
httpServer.registerPathHandler(preRedirectPath, preRedirectHandler); httpServer.registerPathHandler(preRedirectPath, preRedirectHandler);
httpServer.registerPathHandler(postRedirectPath, postRedirectHandler); httpServer.registerPathHandler(postRedirectPath, postRedirectHandler);
httpServer.start(4444); httpServer.start(-1);
// Disable third-party cookies in general. // Disable third-party cookies in general.
Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch). Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch).

View File

@ -51,7 +51,8 @@ function hugeContentLength(metadata, response) {
function test_hugeContentLength() { function test_hugeContentLength() {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444/", null, null) var chan = ios.newChannel("http://localhost:" +
httpServer.identity.primaryPort + "/", null, null)
.QueryInterface(Ci.nsIHttpChannel); .QueryInterface(Ci.nsIHttpChannel);
chan.asyncOpen(listener, null); chan.asyncOpen(listener, null);
} }
@ -61,6 +62,6 @@ add_test(test_hugeContentLength);
function run_test() { function run_test() {
httpServer = new HttpServer(); httpServer = new HttpServer();
httpServer.registerPathHandler("/", hugeContentLength); httpServer.registerPathHandler("/", hugeContentLength);
httpServer.start(4444); httpServer.start(-1);
run_next_test(); run_next_test();
} }

View File

@ -18,7 +18,8 @@ function setupChannel(suffix)
var ios = var ios =
Components.classes["@mozilla.org/network/io-service;1"] Components.classes["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService); .getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + suffix, "", null); var chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort + suffix, "", null);
var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
httpChan.requestMethod = "GET"; httpChan.requestMethod = "GET";
return httpChan; return httpChan;
@ -34,7 +35,7 @@ function run_test()
{ {
httpserver.registerPathHandler("/redirect1", redirectHandler1); httpserver.registerPathHandler("/redirect1", redirectHandler1);
httpserver.registerPathHandler("/redirect2", redirectHandler2); httpserver.registerPathHandler("/redirect2", redirectHandler2);
httpserver.start(4444); httpserver.start(-1);
// clear cache // clear cache
evict_cache_entries(); evict_cache_entries();

View File

@ -10,29 +10,31 @@ var httpserv = null;
const CID = Components.ID("{5645d2c1-d6d8-4091-b117-fe7ee4027db7}"); const CID = Components.ID("{5645d2c1-d6d8-4091-b117-fe7ee4027db7}");
const contractID = "@mozilla.org/system-proxy-settings;1" const contractID = "@mozilla.org/system-proxy-settings;1"
var systemSettings = { XPCOMUtils.defineLazyGetter(this, "systemSettings", function() {
QueryInterface: function (iid) { return {
if (iid.equals(Components.interfaces.nsISupports) || QueryInterface: function (iid) {
iid.equals(Components.interfaces.nsIFactory) || if (iid.equals(Components.interfaces.nsISupports) ||
iid.equals(Components.interfaces.nsISystemProxySettings)) iid.equals(Components.interfaces.nsIFactory) ||
return this; iid.equals(Components.interfaces.nsISystemProxySettings))
throw Components.results.NS_ERROR_NO_INTERFACE; return this;
}, throw Components.results.NS_ERROR_NO_INTERFACE;
createInstance: function (outer, iid) { },
if (outer) createInstance: function (outer, iid) {
throw Components.results.NS_ERROR_NO_AGGREGATION; if (outer)
return this.QueryInterface(iid); throw Components.results.NS_ERROR_NO_AGGREGATION;
}, return this.QueryInterface(iid);
lockFactory: function (lock) { },
throw Components.results.NS_ERROR_NOT_IMPLEMENTED; lockFactory: function (lock) {
}, throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
},
mainThreadOnly: true,
PACURI: "http://localhost:4444/redirect", mainThreadOnly: true,
getProxyForURI: function(aURI) { PACURI: "http://localhost:" + httpserv.identity.primaryPort + "/redirect",
throw Components.results.NS_ERROR_NOT_IMPLEMENTED; getProxyForURI: function(aURI) {
} throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
}; }
};
});
function checkValue(request, data, ctx) { function checkValue(request, data, ctx) {
do_check_true(called); do_check_true(called);
@ -54,7 +56,7 @@ function run_test() {
httpserv.registerPathHandler("/redirect", redirect); httpserv.registerPathHandler("/redirect", redirect);
httpserv.registerPathHandler("/pac", pac); httpserv.registerPathHandler("/pac", pac);
httpserv.registerPathHandler("/target", target); httpserv.registerPathHandler("/target", target);
httpserv.start(4444); httpserv.start(-1);
Components.manager.nsIComponentRegistrar.registerFactory( Components.manager.nsIComponentRegistrar.registerFactory(
CID, CID,
@ -71,7 +73,8 @@ function run_test() {
// clear cache // clear cache
evict_cache_entries(); evict_cache_entries();
var chan = makeChan("http://localhost:4444/target"); var chan = makeChan("http://localhost:" + httpserv.identity.primaryPort +
"/target");
chan.asyncOpen(new ChannelListener(checkValue, null), null); chan.asyncOpen(new ChannelListener(checkValue, null), null);
do_test_pending(); do_test_pending();

View File

@ -11,7 +11,9 @@ var expectedOnStopRequests = 3;
function setupChannel(suffix, xRequest, flags) { function setupChannel(suffix, xRequest, flags) {
var ios = Components.classes["@mozilla.org/network/io-service;1"] var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService); .getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + suffix, "", null); var chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort +
suffix, "", null);
if (flags) if (flags)
chan.loadFlags |= flags; chan.loadFlags |= flags;
@ -53,7 +55,7 @@ Listener.prototype = {
function run_test() { function run_test() {
httpserver.registerPathHandler("/bug596443", handler); httpserver.registerPathHandler("/bug596443", handler);
httpserver.start(4444); httpserver.start(-1);
// make sure we have a profile so we can use the disk-cache // make sure we have a profile so we can use the disk-cache
do_get_profile(); do_get_profile();

View File

@ -34,7 +34,8 @@ InitialListener.prototype = {
onStopRequest: function(request, context, status) { onStopRequest: function(request, context, status) {
do_check_eq(1, numberOfCLHandlerCalls); do_check_eq(1, numberOfCLHandlerCalls);
do_execute_soon(function() { do_execute_soon(function() {
var channel = setupChannel("http://localhost:4444/post"); var channel = setupChannel("http://localhost:" +
httpserv.identity.primaryPort + "/post");
channel.requestMethod = "post"; channel.requestMethod = "post";
channel.asyncOpen(new RedirectingListener(), null); channel.asyncOpen(new RedirectingListener(), null);
}); });
@ -48,7 +49,8 @@ RedirectingListener.prototype = {
onStopRequest: function(request, context, status) { onStopRequest: function(request, context, status) {
do_check_eq(1, numberOfHandlerCalls); do_check_eq(1, numberOfHandlerCalls);
do_execute_soon(function() { do_execute_soon(function() {
var channel = setupChannel("http://localhost:4444/post"); var channel = setupChannel("http://localhost:" +
httpserv.identity.primaryPort + "/post");
channel.requestMethod = "post"; channel.requestMethod = "post";
channel.asyncOpen(new VerifyingListener(), null); channel.asyncOpen(new VerifyingListener(), null);
}); });
@ -62,7 +64,8 @@ VerifyingListener.prototype = {
onStartRequest: function(request, context) { }, onStartRequest: function(request, context) { },
onStopRequest: function(request, context, status) { onStopRequest: function(request, context, status) {
do_check_eq(2, numberOfHandlerCalls); do_check_eq(2, numberOfHandlerCalls);
var channel = setupChannel("http://localhost:4444/cl"); var channel = setupChannel("http://localhost:" +
httpserv.identity.primaryPort + "/cl");
channel.asyncOpen(new FinalListener(), null); channel.asyncOpen(new FinalListener(), null);
} }
}; };
@ -83,13 +86,14 @@ function run_test() {
httpserv.registerPathHandler("/cl", content_location); httpserv.registerPathHandler("/cl", content_location);
httpserv.registerPathHandler("/post", post_target); httpserv.registerPathHandler("/post", post_target);
httpserv.registerPathHandler("/redirect", redirect_target); httpserv.registerPathHandler("/redirect", redirect_target);
httpserv.start(4444); httpserv.start(-1);
// Clear cache // Clear cache
evict_cache_entries(); evict_cache_entries();
// Load Content-Location URI into cache and start the chain of loads // Load Content-Location URI into cache and start the chain of loads
var channel = setupChannel("http://localhost:4444/cl"); var channel = setupChannel("http://localhost:" +
httpserv.identity.primaryPort + "/cl");
channel.asyncOpen(new InitialListener(), null); channel.asyncOpen(new InitialListener(), null);
do_test_pending(); do_test_pending();

View File

@ -14,7 +14,9 @@ var httpserver = null;
function make_channel(flags, vary, value) { function make_channel(flags, vary, value) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService); getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444/bug633743", null, null); var chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort +
"/bug633743", null, null);
return chan.QueryInterface(Ci.nsIHttpChannel); return chan.QueryInterface(Ci.nsIHttpChannel);
} }
@ -182,7 +184,7 @@ function run_test() {
httpserver = new HttpServer(); httpserver = new HttpServer();
httpserver.registerPathHandler("/bug633743", handler); httpserver.registerPathHandler("/bug633743", handler);
httpserver.start(4444); httpserver.start(-1);
run_next_test(); run_next_test();
do_test_pending(); do_test_pending();

View File

@ -27,7 +27,9 @@ function repeatToLargerThan1K(data) {
function setupChannel(suffix, value) { function setupChannel(suffix, value) {
var ios = Components.classes["@mozilla.org/network/io-service;1"] var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService); .getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + suffix, "", null); var chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort +
suffix, "", null);
var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
httpChan.setRequestHeader("x-request", value, false); httpChan.setRequestHeader("x-request", value, false);
@ -143,7 +145,7 @@ function TestCacheEntrySize(setSizeFunc, firstRequest, secondRequest, secondExpe
function run_test() function run_test()
{ {
httpserver.registerPathHandler("/bug650995", handler); httpserver.registerPathHandler("/bug650995", handler);
httpserver.start(4444); httpserver.start(-1);
prefService.setBoolPref("browser.cache.offline.enable", false); prefService.setBoolPref("browser.cache.offline.enable", false);

View File

@ -12,7 +12,9 @@ function setupChannel(suffix)
var ios = var ios =
Components.classes["@mozilla.org/network/io-service;1"] Components.classes["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService); .getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + suffix, "", null); var chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort +
suffix, "", null);
return chan; return chan;
} }
@ -29,7 +31,7 @@ function run_test()
httpserver.registerPathHandler("/redirect1", redirectHandler1); httpserver.registerPathHandler("/redirect1", redirectHandler1);
httpserver.registerPathHandler("/redirect2", redirectHandler2); httpserver.registerPathHandler("/redirect2", redirectHandler2);
httpserver.start(4444); httpserver.start(-1);
// clear cache // clear cache
evict_cache_entries(); evict_cache_entries();

View File

@ -9,8 +9,14 @@ var httpserver = null;
var simplePath = "/simple"; var simplePath = "/simple";
var normalPath = "/normal"; var normalPath = "/normal";
var httpbody = "<html></html>"; var httpbody = "<html></html>";
var uri1 = "http://localhost:4444" + simplePath;
var uri2 = "http://localhost:4444" + normalPath; XPCOMUtils.defineLazyGetter(this, "uri1", function() {
return "http://localhost:" + httpserver.identity.primaryPort + simplePath;
});
XPCOMUtils.defineLazyGetter(this, "uri2", function() {
return "http://localhost:" + httpserver.identity.primaryPort + normalPath;
});
function make_channel(url) { function make_channel(url) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -54,7 +60,7 @@ function run_test()
httpserver = new HttpServer(); httpserver = new HttpServer();
httpserver.registerPathHandler(simplePath, simpleHandler); httpserver.registerPathHandler(simplePath, simpleHandler);
httpserver.registerPathHandler(normalPath, normalHandler); httpserver.registerPathHandler(normalPath, normalHandler);
httpserver.start(4444); httpserver.start(-1);
var channel = make_channel(uri1); var channel = make_channel(uri1);
channel.asyncOpen(new listener("text/plain", function() { channel.asyncOpen(new listener("text/plain", function() {

View File

@ -7,7 +7,10 @@ Cu.import("resource://testing-common/httpd.js");
var httpServer = null; var httpServer = null;
var path = "/bug699001"; var path = "/bug699001";
var URI = "http://localhost:4444" + path;
XPCOMUtils.defineLazyGetter(this, "URI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + path;
});
function make_channel(url) { function make_channel(url) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -93,7 +96,7 @@ function run_test()
{ {
httpServer = new HttpServer(); httpServer = new HttpServer();
httpServer.registerPathHandler(path, handler); httpServer.registerPathHandler(path, handler);
httpServer.start(4444); httpServer.start(-1);
do_test_pending(); do_test_pending();

View File

@ -20,7 +20,8 @@ function addCreds(scheme, host)
{ {
var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1'] var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1']
.getService(Ci.nsIHttpAuthManager); .getService(Ci.nsIHttpAuthManager);
authMgr.setAuthIdentity(scheme, host, 4444, "basic", "secret", "/", "", "user", "pass"); authMgr.setAuthIdentity(scheme, host, httpserv.identity.primaryPort,
"basic", "secret", "/", "", "user", "pass");
} }
function clearCreds() function clearCreds()
@ -33,7 +34,8 @@ function clearCreds()
function makeChan() { function makeChan() {
var ios = Cc["@mozilla.org/network/io-service;1"] var ios = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService); .getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444/", null, null) var chan = ios.newChannel("http://localhost:" +
httpserv.identity.primaryPort + "/", null, null)
.QueryInterface(Ci.nsIHttpChannel); .QueryInterface(Ci.nsIHttpChannel);
return chan; return chan;
} }
@ -197,12 +199,12 @@ function run_test()
httpserv = new HttpServer(); httpserv = new HttpServer();
httpserv.registerPathHandler("/", handler); httpserv.registerPathHandler("/", handler);
httpserv.start(4444); httpserv.start(-1);
const prefs = Cc["@mozilla.org/preferences-service;1"] const prefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch); .getService(Ci.nsIPrefBranch);
prefs.setCharPref("network.proxy.http", "localhost"); prefs.setCharPref("network.proxy.http", "localhost");
prefs.setIntPref("network.proxy.http_port", 4444); prefs.setIntPref("network.proxy.http_port", httpserv.identity.primaryPort);
prefs.setCharPref("network.proxy.no_proxies_on", ""); prefs.setCharPref("network.proxy.no_proxies_on", "");
prefs.setIntPref("network.proxy.type", 1); prefs.setIntPref("network.proxy.type", 1);

View File

@ -15,9 +15,16 @@ Cu.import("resource://testing-common/httpd.js");
var httpserver = null; var httpserver = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath1 = "/redirect-no-store/" + Math.random(); var randomPath1 = "/redirect-no-store/" + Math.random();
var randomURI1 = "http://localhost:4444" + randomPath1;
XPCOMUtils.defineLazyGetter(this, "randomURI1", function() {
return "http://localhost:" + httpserver.identity.primaryPort + randomPath1;
});
var randomPath2 = "/redirect-expires-past/" + Math.random(); var randomPath2 = "/redirect-expires-past/" + Math.random();
var randomURI2 = "http://localhost:4444" + randomPath2;
XPCOMUtils.defineLazyGetter(this, "randomURI2", function() {
return "http://localhost:" + httpserver.identity.primaryPort + randomPath2;
});
function make_channel(url, callback, ctx) { function make_channel(url, callback, ctx) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -30,7 +37,8 @@ const responseBody = "response body";
function redirectHandler_NoStore(metadata, response) function redirectHandler_NoStore(metadata, response)
{ {
response.setStatusLine(metadata.httpVersion, 302, "Found"); response.setStatusLine(metadata.httpVersion, 302, "Found");
response.setHeader("Location", "http://localhost:4444/content", false); response.setHeader("Location", "http://localhost:" +
httpserver.identity.primaryPort + "/content", false);
response.setHeader("Cache-control", "no-store"); response.setHeader("Cache-control", "no-store");
return; return;
} }
@ -38,7 +46,8 @@ function redirectHandler_NoStore(metadata, response)
function redirectHandler_ExpiresInPast(metadata, response) function redirectHandler_ExpiresInPast(metadata, response)
{ {
response.setStatusLine(metadata.httpVersion, 302, "Found"); response.setStatusLine(metadata.httpVersion, 302, "Found");
response.setHeader("Location", "http://localhost:4444/content", false); response.setHeader("Location", "http://localhost:" +
httpserver.identity.primaryPort + "/content", false);
response.setHeader("Expires", "-1"); response.setHeader("Expires", "-1");
return; return;
} }
@ -89,7 +98,7 @@ function run_test()
httpserver.registerPathHandler(randomPath1, redirectHandler_NoStore); httpserver.registerPathHandler(randomPath1, redirectHandler_NoStore);
httpserver.registerPathHandler(randomPath2, redirectHandler_ExpiresInPast); httpserver.registerPathHandler(randomPath2, redirectHandler_ExpiresInPast);
httpserver.registerPathHandler("/content", contentHandler); httpserver.registerPathHandler("/content", contentHandler);
httpserver.start(4444); httpserver.start(-1);
run_test_no_store(); run_test_no_store();
do_test_pending(); do_test_pending();

View File

@ -12,7 +12,11 @@ var httpServer = null;
const testFileName = "test_nsHttpChannel_CacheForOfflineUse-no-store"; const testFileName = "test_nsHttpChannel_CacheForOfflineUse-no-store";
const cacheClientID = testFileName + "|fake-group-id"; const cacheClientID = testFileName + "|fake-group-id";
const basePath = "/" + testFileName + "/"; const basePath = "/" + testFileName + "/";
const baseURI = "http://localhost:4444" + basePath;
XPCOMUtils.defineLazyGetter(this, "baseURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + basePath;
});
const normalEntry = "normal"; const normalEntry = "normal";
const noStoreEntry = "no-store"; const noStoreEntry = "no-store";
@ -119,7 +123,7 @@ function run_test()
httpServer = new HttpServer(); httpServer = new HttpServer();
httpServer.registerPathHandler(basePath + normalEntry, normalHandler); httpServer.registerPathHandler(basePath + normalEntry, normalHandler);
httpServer.registerPathHandler(basePath + noStoreEntry, noStoreHandler); httpServer.registerPathHandler(basePath + noStoreEntry, noStoreHandler);
httpServer.start(4444); httpServer.start(-1);
run_next_test(); run_next_test();
} }

View File

@ -7,6 +7,10 @@ Cu.import("resource://testing-common/httpd.js");
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserv.identity.primaryPort + "/cached";
});
var httpserv = null; var httpserv = null;
var handlers_called = 0; var handlers_called = 0;
@ -42,7 +46,7 @@ var thirdTests = [[0, false, 0], [0, true, 0], [1, false, 1], [1, true, 1]];
function run_all_tests() { function run_all_tests() {
for (let test of firstTests) { for (let test of firstTests) {
handlers_called = 0; handlers_called = 0;
var chan = makeChan("http://localhost:4444/cached", test[0], test[1]); var chan = makeChan(URL, test[0], test[1]);
chan.asyncOpen(new ChannelListener(doneFirstLoad, test[2]), null); chan.asyncOpen(new ChannelListener(doneFirstLoad, test[2]), null);
yield; yield;
} }
@ -62,7 +66,7 @@ function run_all_tests() {
for (let test of secondTests) { for (let test of secondTests) {
handlers_called = 0; handlers_called = 0;
var chan = makeChan("http://localhost:4444/cached", test[0], test[1]); var chan = makeChan(URL, test[0], test[1]);
chan.asyncOpen(new ChannelListener(doneFirstLoad, test[2]), null); chan.asyncOpen(new ChannelListener(doneFirstLoad, test[2]), null);
yield; yield;
} }
@ -76,7 +80,7 @@ function run_all_tests() {
for (let test of thirdTests) { for (let test of thirdTests) {
handlers_called = 0; handlers_called = 0;
var chan = makeChan("http://localhost:4444/cached", test[0], test[1]); var chan = makeChan(URL, test[0], test[1]);
chan.asyncOpen(new ChannelListener(doneFirstLoad, test[2]), null); chan.asyncOpen(new ChannelListener(doneFirstLoad, test[2]), null);
yield; yield;
} }
@ -88,14 +92,14 @@ function run_test() {
do_test_pending(); do_test_pending();
httpserv = new HttpServer(); httpserv = new HttpServer();
httpserv.registerPathHandler("/cached", cached_handler); httpserv.registerPathHandler("/cached", cached_handler);
httpserv.start(4444); httpserv.start(-1);
gTests = run_all_tests(); gTests = run_all_tests();
gTests.next(); gTests.next();
} }
function doneFirstLoad(req, buffer, expected) { function doneFirstLoad(req, buffer, expected) {
// Load it again, make sure it hits the cache // Load it again, make sure it hits the cache
var chan = makeChan("http://localhost:4444/cached", 0, false); var chan = makeChan(URL, 0, false);
chan.asyncOpen(new ChannelListener(doneSecondLoad, expected), null); chan.asyncOpen(new ChannelListener(doneSecondLoad, expected), null);
} }

View File

@ -5,11 +5,12 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
var httpserver = null; var httpserver = new HttpServer();
httpserver.start(-1);
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var suffix = Math.random(); var suffix = Math.random();
var httpBase = "http://localhost:4444"; var httpBase = "http://localhost:" + httpserver.identity.primaryPort;
var httpsBase = "http://localhost:4445"; var httpsBase = "http://localhost:4445";
var shortexpPath = "/shortexp" + suffix; var shortexpPath = "/shortexp" + suffix;
var longexpPath = "/longexp/" + suffix; var longexpPath = "/longexp/" + suffix;
@ -312,13 +313,11 @@ function longexp2_handler(metadata, response) {
} }
function run_test() { function run_test() {
httpserver = new HttpServer();
httpserver.registerPathHandler(shortexpPath, shortexp_handler); httpserver.registerPathHandler(shortexpPath, shortexp_handler);
httpserver.registerPathHandler(longexpPath, longexp_handler); httpserver.registerPathHandler(longexpPath, longexp_handler);
httpserver.registerPathHandler(longexp2Path, longexp2_handler); httpserver.registerPathHandler(longexp2Path, longexp2_handler);
httpserver.registerPathHandler(nocachePath, nocache_handler); httpserver.registerPathHandler(nocachePath, nocache_handler);
httpserver.registerPathHandler(nostorePath, nostore_handler); httpserver.registerPathHandler(nostorePath, nostore_handler);
httpserver.start(4444);
run_next_test(); run_next_test();
do_test_pending(); do_test_pending();

View File

@ -5,6 +5,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserver.identity.primaryPort;
});
var httpserver = new HttpServer(); var httpserver = new HttpServer();
var testpath = "/simple"; var testpath = "/simple";
var httpbody = "0123456789"; var httpbody = "0123456789";
@ -13,7 +17,7 @@ var live_channels = [];
function run_test() { function run_test() {
httpserver.registerPathHandler(testpath, serverHandler); httpserver.registerPathHandler(testpath, serverHandler);
httpserver.start(4444); httpserver.start(-1);
var local_channel; var local_channel;
@ -39,7 +43,7 @@ function run_test() {
function setupChannel(path) { function setupChannel(path) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + path, "", null); var chan = ios.newChannel(URL + path, "", null);
chan.QueryInterface(Ci.nsIHttpChannel); chan.QueryInterface(Ci.nsIHttpChannel);
chan.requestMethod = "GET"; chan.requestMethod = "GET";
return chan; return chan;

View File

@ -33,7 +33,8 @@ var tests = [
function setupChannel(url) { function setupChannel(url) {
var ios = Components.classes["@mozilla.org/network/io-service;1"]. var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService); getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + url, "", null); var chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort + url, "", null);
return chan; return chan;
} }
@ -54,7 +55,7 @@ function completeIter(request, data, ctx) {
function run_test() { function run_test() {
httpserver.registerPathHandler("/test/cegzip1", handler); httpserver.registerPathHandler("/test/cegzip1", handler);
httpserver.registerPathHandler("/test/cegzip2", handler); httpserver.registerPathHandler("/test/cegzip2", handler);
httpserver.start(4444); httpserver.start(-1);
startIter(); startIter();
do_test_pending(); do_test_pending();

View File

@ -84,21 +84,22 @@ function makeChan(url) {
return chan; return chan;
} }
var urls = [ var httpserv = null;
var urls = null;
function run_test() {
httpserv = new HttpServer();
httpserv.start(-1);
urls = [
// NOTE: First URL here runs without our content sniffer // NOTE: First URL here runs without our content sniffer
"data:" + unknownType + ", Some text", "data:" + unknownType + ", Some text",
"data:" + unknownType + ", Text", // Make sure sniffing works even if we "data:" + unknownType + ", Text", // Make sure sniffing works even if we
// used the unknown content sniffer too // used the unknown content sniffer too
"data:text/plain, Some more text", "data:text/plain, Some more text",
"http://localhost:4444" "http://localhost:" + httpserv.identity.primaryPort
]; ];
var httpserv = null;
function run_test() {
httpserv = new HttpServer();
httpserv.start(4444);
Components.manager.nsIComponentRegistrar.registerFactory(snifferCID, Components.manager.nsIComponentRegistrar.registerFactory(snifferCID,
"Unit test content sniffer", snifferContract, sniffer); "Unit test content sniffer", snifferContract, sniffer);

View File

@ -8,6 +8,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserv.identity.primaryPort + "/";
});
function inChildProcess() { function inChildProcess() {
return Cc["@mozilla.org/xre/app-info;1"] return Cc["@mozilla.org/xre/app-info;1"]
.getService(Ci.nsIXULRuntime) .getService(Ci.nsIXULRuntime)
@ -59,7 +63,7 @@ var listener = {
function makeChan() { function makeChan() {
var ios = Components.classes["@mozilla.org/network/io-service;1"] var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService); .getService(Components.interfaces.nsIIOService);
var chan = ios.newChannel("http://localhost:4444/", null, null) var chan = ios.newChannel(URL, null, null)
.QueryInterface(Components.interfaces.nsIHttpChannel); .QueryInterface(Components.interfaces.nsIHttpChannel);
return chan; return chan;
@ -73,7 +77,7 @@ function run_test() {
Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
httpserv = new HttpServer(); httpserv = new HttpServer();
httpserv.start(4444); httpserv.start(-1);
var chan = makeChan(); var chan = makeChan();

View File

@ -13,6 +13,10 @@ const Ci = Components.interfaces;
const Cu = Components.utils; const Cu = Components.utils;
const Cr = Components.results; const Cr = Components.results;
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserver.identity.primaryPort;
});
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");
var httpserver = new HttpServer(); var httpserver = new HttpServer();
@ -50,7 +54,7 @@ var i = 0;
function setupChannel(path) function setupChannel(path)
{ {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + path, "", null); var chan = ios.newChannel(URL + path, "", null);
chan.notificationCallbacks = tests[i].loadContext; chan.notificationCallbacks = tests[i].loadContext;
chan.QueryInterface(Ci.nsIHttpChannel); chan.QueryInterface(Ci.nsIHttpChannel);
return chan; return chan;
@ -122,7 +126,7 @@ function run_test()
httpserver.registerPathHandler(cookieSetPath, cookieSetHandler); httpserver.registerPathHandler(cookieSetPath, cookieSetHandler);
httpserver.registerPathHandler(cookieCheckPath, cookieCheckHandler); httpserver.registerPathHandler(cookieCheckPath, cookieCheckHandler);
httpserver.start(4444); httpserver.start(-1);
setCookie(); setCookie();
do_test_pending(); do_test_pending();

View File

@ -13,6 +13,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserver.identity.primaryPort;
});
var httpserver = new HttpServer(); var httpserver = new HttpServer();
var index = 0; var index = 0;
var test_flags = new Array(); var test_flags = new Array();
@ -20,7 +24,7 @@ var testPathBase = "/dupe_hdrs";
function run_test() function run_test()
{ {
httpserver.start(4444); httpserver.start(-1);
do_test_pending(); do_test_pending();
run_test_number(1); run_test_number(1);
@ -41,7 +45,7 @@ function setupChannel(url)
{ {
var ios = Components.classes["@mozilla.org/network/io-service;1"]. var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService); getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + url, "", null); var chan = ios.newChannel(URL + url, "", null);
var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
return httpChan; return httpChan;
} }
@ -197,7 +201,7 @@ function handler6(metadata, response)
response.write("HTTP/1.0 301 Moved\r\n"); response.write("HTTP/1.0 301 Moved\r\n");
response.write("Content-Type: text/plain\r\n"); response.write("Content-Type: text/plain\r\n");
response.write("Content-Length: 30\r\n"); response.write("Content-Length: 30\r\n");
response.write("Location: http://localhost:4444/content\r\n"); response.write("Location: " + URL + "/content\r\n");
response.write("Location: http://www.microsoft.com/\r\n"); response.write("Location: http://www.microsoft.com/\r\n");
response.write("Connection: close\r\n"); response.write("Connection: close\r\n");
response.write("\r\n"); response.write("\r\n");
@ -224,8 +228,8 @@ function handler7(metadata, response)
response.write("Content-Type: text/plain\r\n"); response.write("Content-Type: text/plain\r\n");
response.write("Content-Length: 30\r\n"); response.write("Content-Length: 30\r\n");
// redirect to previous test handler that completes OK: test 5 // redirect to previous test handler that completes OK: test 5
response.write("Location: http://localhost:4444" + testPathBase + "5\r\n"); response.write("Location: " + URL + testPathBase + "5\r\n");
response.write("Location: http://localhost:4444" + testPathBase + "5\r\n"); response.write("Location: " + URL + testPathBase + "5\r\n");
response.write("Connection: close\r\n"); response.write("Connection: close\r\n");
response.write("\r\n"); response.write("\r\n");
response.write(body); response.write(body);
@ -259,7 +263,7 @@ function handler8(metadata, response)
response.write("Content-Type: text/plain\r\n"); response.write("Content-Type: text/plain\r\n");
response.write("Content-Length: 30\r\n"); response.write("Content-Length: 30\r\n");
// redirect to previous test handler that completes OK: test 4 // redirect to previous test handler that completes OK: test 4
response.write("Location: http://localhost:4444" + testPathBase + "4\r\n"); response.write("Location: " + URL + testPathBase + "4\r\n");
response.write("Location:\r\n"); response.write("Location:\r\n");
response.write("Connection: close\r\n"); response.write("Connection: close\r\n");
response.write("\r\n"); response.write("\r\n");
@ -287,10 +291,10 @@ function handler9(metadata, response)
response.write("Content-Type: text/plain\r\n"); response.write("Content-Type: text/plain\r\n");
response.write("Content-Length: 30\r\n"); response.write("Content-Length: 30\r\n");
// redirect to previous test handler that completes OK: test 2 // redirect to previous test handler that completes OK: test 2
response.write("Location: http://localhost:4444" + testPathBase + "2\r\n"); response.write("Location: " + URL + testPathBase + "2\r\n");
response.write("Location:\r\n"); response.write("Location:\r\n");
// redirect to previous test handler that completes OK: test 4 // redirect to previous test handler that completes OK: test 4
response.write("Location: http://localhost:4444" + testPathBase + "4\r\n"); response.write("Location: " + URL + testPathBase + "4\r\n");
response.write("Connection: close\r\n"); response.write("Connection: close\r\n");
response.write("\r\n"); response.write("\r\n");
response.write(body); response.write(body);
@ -588,7 +592,7 @@ function handler20(metadata, response)
response.write("Content-Length: 30\r\n"); response.write("Content-Length: 30\r\n");
// redirect to previous test handler that completes OK: test 4 // redirect to previous test handler that completes OK: test 4
response.write("Location:\r\n"); response.write("Location:\r\n");
response.write("Location: http://localhost:4444" + testPathBase + "4\r\n"); response.write("Location: " + URL + testPathBase + "4\r\n");
response.write("Connection: close\r\n"); response.write("Connection: close\r\n");
response.write("\r\n"); response.write("\r\n");
response.write(body); response.write(body);

View File

@ -7,6 +7,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserv.identity.primaryPort;
});
const sinkCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}"); const sinkCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}");
const sinkContract = "@mozilla.org/network/unittest/channeleventsink;1"; const sinkContract = "@mozilla.org/network/unittest/channeleventsink;1";
@ -111,13 +115,13 @@ function run_test() {
httpserv = new HttpServer(); httpserv = new HttpServer();
httpserv.registerPathHandler("/redirect", redirect); httpserv.registerPathHandler("/redirect", redirect);
httpserv.registerPathHandler("/redirectfile", redirectfile); httpserv.registerPathHandler("/redirectfile", redirectfile);
httpserv.start(4444); httpserv.start(-1);
Components.manager.nsIComponentRegistrar.registerFactory(sinkCID, Components.manager.nsIComponentRegistrar.registerFactory(sinkCID,
"Unit test Event sink", sinkContract, eventsink); "Unit test Event sink", sinkContract, eventsink);
// Step 1: Set the callbacks on the listener itself // Step 1: Set the callbacks on the listener itself
var chan = makeChan("http://localhost:4444/redirect"); var chan = makeChan(URL + "/redirect");
chan.notificationCallbacks = eventsink; chan.notificationCallbacks = eventsink;
chan.asyncOpen(listener, null); chan.asyncOpen(listener, null);
@ -136,13 +140,13 @@ function run_test_continued() {
// Step 2: Category entry // Step 2: Category entry
catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test", catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test",
sinkContract, false, true); sinkContract, false, true);
chan = makeChan("http://localhost:4444/redirect") chan = makeChan(URL + "/redirect")
} else { } else {
// Step 3: Global contract id // Step 3: Global contract id
catMan.nsICategoryManager.deleteCategoryEntry(categoryName, "unit test", catMan.nsICategoryManager.deleteCategoryEntry(categoryName, "unit test",
false); false);
listener.expectSinkCall = false; listener.expectSinkCall = false;
chan = makeChan("http://localhost:4444/redirectfile"); chan = makeChan(URL + "/redirectfile");
} }
listener._iteration++; listener._iteration++;

View File

@ -8,7 +8,10 @@ Cu.import("resource://testing-common/httpd.js");
var httpServer = null; var httpServer = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random(); var randomPath = "/redirect/" + Math.random();
var randomURI = "http://localhost:4444" + randomPath;
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null; var cacheUpdateObserver = null;
@ -62,11 +65,11 @@ function run_test()
httpServer.registerPathHandler("/masterEntry", masterEntryHandler); httpServer.registerPathHandler("/masterEntry", masterEntryHandler);
httpServer.registerPathHandler("/manifest", manifestHandler); httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(4444); httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"] var pm = Cc["@mozilla.org/permissionmanager;1"]
.getService(Ci.nsIPermissionManager); .getService(Ci.nsIPermissionManager);
var uri = make_uri("http://localhost:4444"); var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"] var principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager) .getService(Ci.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri); .getNoAppCodebasePrincipal(uri);
@ -102,8 +105,10 @@ function run_test()
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"]. var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].
getService(Ci.nsIOfflineCacheUpdateService); getService(Ci.nsIOfflineCacheUpdateService);
us.scheduleUpdate(make_uri("http://localhost:4444/manifest"), us.scheduleUpdate(make_uri("http://localhost:" +
make_uri("http://localhost:4444/masterEntry"), httpServer.identity.primaryPort + "/manifest"),
make_uri("http://localhost:" +
httpServer.identity.primaryPort + "/masterEntry"),
null); null);
do_test_pending(); do_test_pending();

View File

@ -8,7 +8,10 @@ Cu.import("resource://testing-common/httpd.js");
var httpServer = null; var httpServer = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random(); var randomPath = "/redirect/" + Math.random();
var randomURI = "http://localhost:4444" + randomPath;
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null; var cacheUpdateObserver = null;
@ -62,11 +65,11 @@ function run_test()
httpServer.registerPathHandler("/masterEntry", masterEntryHandler); httpServer.registerPathHandler("/masterEntry", masterEntryHandler);
httpServer.registerPathHandler("/manifest", manifestHandler); httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(4444); httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"] var pm = Cc["@mozilla.org/permissionmanager;1"]
.getService(Ci.nsIPermissionManager); .getService(Ci.nsIPermissionManager);
var uri = make_uri("http://localhost:4444"); var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"] var principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager) .getService(Ci.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri); .getNoAppCodebasePrincipal(uri);
@ -101,8 +104,10 @@ function run_test()
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"]. var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].
getService(Ci.nsIOfflineCacheUpdateService); getService(Ci.nsIOfflineCacheUpdateService);
us.scheduleUpdate(make_uri("http://localhost:4444/manifest"), us.scheduleUpdate(make_uri("http://localhost:" +
make_uri("http://localhost:4444/masterEntry"), httpServer.identity.primaryPort + "/manifest"),
make_uri("http://localhost:" +
httpServer.identity.primaryPort + "/masterEntry"),
null); null);
do_test_pending(); do_test_pending();

View File

@ -8,7 +8,10 @@ Cu.import("resource://testing-common/httpd.js");
var httpServer = null; var httpServer = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random(); var randomPath = "/redirect/" + Math.random();
var randomURI = "http://localhost:4444" + randomPath;
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null; var cacheUpdateObserver = null;
@ -70,11 +73,11 @@ function run_test()
httpServer.registerPathHandler("/manifest", manifestHandler); httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.registerPathHandler(randomPath, redirectHandler); httpServer.registerPathHandler(randomPath, redirectHandler);
httpServer.start(4444); httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"] var pm = Cc["@mozilla.org/permissionmanager;1"]
.getService(Ci.nsIPermissionManager); .getService(Ci.nsIPermissionManager);
var uri = make_uri("http://localhost:4444"); var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = Cc["@mozilla.org/scriptsecuritymanager;1"] var principal = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager) .getService(Ci.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri); .getNoAppCodebasePrincipal(uri);
@ -106,8 +109,10 @@ function run_test()
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"]. var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].
getService(Ci.nsIOfflineCacheUpdateService); getService(Ci.nsIOfflineCacheUpdateService);
us.scheduleUpdate(make_uri("http://localhost:4444/manifest"), us.scheduleUpdate(make_uri("http://localhost:" +
make_uri("http://localhost:4444/masterEntry"), httpServer.identity.primaryPort + "/manifest"),
make_uri("http://localhost:" +
httpServer.identity.primaryPort + "/masterEntry"),
null); null);
do_test_pending(); do_test_pending();

View File

@ -8,7 +8,10 @@ Cu.import("resource://testing-common/httpd.js");
var httpServer = null; var httpServer = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random(); var randomPath = "/redirect/" + Math.random();
var randomURI = "http://localhost:4444" + randomPath;
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null; var cacheUpdateObserver = null;
@ -70,11 +73,11 @@ function run_test()
httpServer.registerPathHandler("/manifest", manifestHandler); httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.registerPathHandler(randomPath, redirectHandler); httpServer.registerPathHandler(randomPath, redirectHandler);
httpServer.start(4444); httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"] var pm = Cc["@mozilla.org/permissionmanager;1"]
.getService(Ci.nsIPermissionManager); .getService(Ci.nsIPermissionManager);
var uri = make_uri("http://localhost:4444"); var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = Cc["@mozilla.org/scriptsecuritymanager;1"] var principal = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager) .getService(Ci.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri); .getNoAppCodebasePrincipal(uri);
@ -105,8 +108,10 @@ function run_test()
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"]. var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].
getService(Ci.nsIOfflineCacheUpdateService); getService(Ci.nsIOfflineCacheUpdateService);
us.scheduleUpdate(make_uri("http://localhost:4444/manifest"), us.scheduleUpdate(make_uri("http://localhost:" +
make_uri("http://localhost:4444/masterEntry"), httpServer.identity.primaryPort + "/manifest"),
make_uri("http://localhost:" +
httpServer.identity.primaryPort + "/masterEntry"),
null); null);
do_test_pending(); do_test_pending();

View File

@ -8,7 +8,10 @@ Cu.import("resource://testing-common/httpd.js");
var httpServer = null; var httpServer = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random(); var randomPath = "/redirect/" + Math.random();
var randomURI = "http://localhost:4444" + randomPath;
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null; var cacheUpdateObserver = null;
@ -69,11 +72,11 @@ function run_test()
httpServer.registerPathHandler("/masterEntry", masterEntryHandler); httpServer.registerPathHandler("/masterEntry", masterEntryHandler);
httpServer.registerPathHandler("/manifest", manifestHandler); httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(4444); httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"] var pm = Cc["@mozilla.org/permissionmanager;1"]
.getService(Ci.nsIPermissionManager); .getService(Ci.nsIPermissionManager);
var uri = make_uri("http://localhost:4444"); var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = Cc["@mozilla.org/scriptsecuritymanager;1"] var principal = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager) .getService(Ci.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri); .getNoAppCodebasePrincipal(uri);
@ -92,6 +95,9 @@ function run_test()
cacheUpdateObserver = {observe: function() { cacheUpdateObserver = {observe: function() {
dump("got offline-cache-update-completed\n"); dump("got offline-cache-update-completed\n");
// offline cache update completed. // offline cache update completed.
// doing this to eval the lazy getter, otherwise the make_channel call would hang
randomURI;
httpServer.stop(function() { httpServer.stop(function() {
// Now shut the server down to have an error in onStartRequest // Now shut the server down to have an error in onStartRequest
var chan = make_channel(randomURI); var chan = make_channel(randomURI);
@ -109,8 +115,10 @@ function run_test()
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"]. var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].
getService(Ci.nsIOfflineCacheUpdateService); getService(Ci.nsIOfflineCacheUpdateService);
us.scheduleUpdate(make_uri("http://localhost:4444/manifest"), us.scheduleUpdate(make_uri("http://localhost:" +
make_uri("http://localhost:4444/masterEntry"), httpServer.identity.primaryPort + "/manifest"),
make_uri("http://localhost:" +
httpServer.identity.primaryPort + "/masterEntry"),
null); null);
do_test_pending(); do_test_pending();

View File

@ -8,7 +8,10 @@ Cu.import("resource://testing-common/httpd.js");
var httpServer = null; var httpServer = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random(); var randomPath = "/redirect/" + Math.random();
var randomURI = "http://localhost:4444" + randomPath;
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null; var cacheUpdateObserver = null;
@ -69,11 +72,11 @@ function run_test()
httpServer.registerPathHandler("/masterEntry", masterEntryHandler); httpServer.registerPathHandler("/masterEntry", masterEntryHandler);
httpServer.registerPathHandler("/manifest", manifestHandler); httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(4444); httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"] var pm = Cc["@mozilla.org/permissionmanager;1"]
.getService(Ci.nsIPermissionManager); .getService(Ci.nsIPermissionManager);
var uri = make_uri("http://localhost:4444"); var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = Cc["@mozilla.org/scriptsecuritymanager;1"] var principal = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager) .getService(Ci.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri); .getNoAppCodebasePrincipal(uri);
@ -92,6 +95,7 @@ function run_test()
cacheUpdateObserver = {observe: function() { cacheUpdateObserver = {observe: function() {
dump("got offline-cache-update-completed\n"); dump("got offline-cache-update-completed\n");
// offline cache update completed. // offline cache update completed.
var _x = randomURI; // doing this so the lazy value gets computed
httpServer.stop(function() { httpServer.stop(function() {
// Now shut the server down to have an error in onstartrequest // Now shut the server down to have an error in onstartrequest
var chan = make_channel(randomURI); var chan = make_channel(randomURI);
@ -108,8 +112,10 @@ function run_test()
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"]. var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].
getService(Ci.nsIOfflineCacheUpdateService); getService(Ci.nsIOfflineCacheUpdateService);
us.scheduleUpdate(make_uri("http://localhost:4444/manifest"), us.scheduleUpdate(make_uri("http://localhost:" +
make_uri("http://localhost:4444/masterEntry"), httpServer.identity.primaryPort + "/manifest"),
make_uri("http://localhost:" +
httpServer.identity.primaryPort + "/masterEntry"),
null); null);
do_test_pending(); do_test_pending();

View File

@ -8,7 +8,10 @@ Cu.import("resource://testing-common/httpd.js");
var httpServer = null; var httpServer = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath = "/error/" + Math.random(); var randomPath = "/error/" + Math.random();
var randomURI = "http://localhost:4444" + randomPath;
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null; var cacheUpdateObserver = null;
@ -69,11 +72,11 @@ function run_test()
httpServer.registerPathHandler("/manifest", manifestHandler); httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.registerPathHandler(randomPath, errorHandler); httpServer.registerPathHandler(randomPath, errorHandler);
httpServer.start(4444); httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"] var pm = Cc["@mozilla.org/permissionmanager;1"]
.getService(Ci.nsIPermissionManager); .getService(Ci.nsIPermissionManager);
var uri = make_uri("http://localhost:4444"); var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = Cc["@mozilla.org/scriptsecuritymanager;1"] var principal = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager) .getService(Ci.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri); .getNoAppCodebasePrincipal(uri);
@ -105,8 +108,10 @@ function run_test()
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"]. var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].
getService(Ci.nsIOfflineCacheUpdateService); getService(Ci.nsIOfflineCacheUpdateService);
us.scheduleUpdate(make_uri("http://localhost:4444/manifest"), us.scheduleUpdate(make_uri("http://localhost:" +
make_uri("http://localhost:4444/masterEntry"), httpServer.identity.primaryPort + "/manifest"),
make_uri("http://localhost:" +
httpServer.identity.primaryPort + "/masterEntry"),
null); null);
do_test_pending(); do_test_pending();

View File

@ -8,7 +8,10 @@ Cu.import("resource://testing-common/httpd.js");
var httpServer = null; var httpServer = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath = "/error/" + Math.random(); var randomPath = "/error/" + Math.random();
var randomURI = "http://localhost:4444" + randomPath;
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null; var cacheUpdateObserver = null;
@ -69,11 +72,11 @@ function run_test()
httpServer.registerPathHandler("/manifest", manifestHandler); httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.registerPathHandler(randomPath, errorHandler); httpServer.registerPathHandler(randomPath, errorHandler);
httpServer.start(4444); httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"] var pm = Cc["@mozilla.org/permissionmanager;1"]
.getService(Ci.nsIPermissionManager); .getService(Ci.nsIPermissionManager);
var uri = make_uri("http://localhost:4444"); var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = Cc["@mozilla.org/scriptsecuritymanager;1"] var principal = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager) .getService(Ci.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri); .getNoAppCodebasePrincipal(uri);
@ -104,8 +107,10 @@ function run_test()
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"]. var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].
getService(Ci.nsIOfflineCacheUpdateService); getService(Ci.nsIOfflineCacheUpdateService);
us.scheduleUpdate(make_uri("http://localhost:4444/manifest"), us.scheduleUpdate(make_uri("http://localhost:" +
make_uri("http://localhost:4444/masterEntry"), httpServer.identity.primaryPort + "/manifest"),
make_uri("http://localhost:" +
httpServer.identity.primaryPort + "/masterEntry"),
null); null);
do_test_pending(); do_test_pending();

View File

@ -67,14 +67,16 @@ function makeChan(url) {
return chan; return chan;
} }
var url = "http://localhost:4444/test"; XPCOMUtils.defineLazyGetter(this, "url", function() {
return "http://localhost:" + httpserv.identity.primaryPort + "/test";
});
var httpserv = null; var httpserv = null;
function run_test() { function run_test() {
httpserv = new HttpServer(); httpserv = new HttpServer();
httpserv.registerPathHandler("/test", handler); httpserv.registerPathHandler("/test", handler);
httpserv.start(4444); httpserv.start(-1);
// Register our fake sniffer that always returns the content-type we want. // Register our fake sniffer that always returns the content-type we want.
Components.manager.nsIComponentRegistrar.registerFactory(snifferCID, Components.manager.nsIComponentRegistrar.registerFactory(snifferCID,

View File

@ -61,7 +61,8 @@ function cachedHandler(metadata, response) {
function continue_test(request, data) { function continue_test(request, data) {
do_check_true(17 == data.length); do_check_true(17 == data.length);
var chan = make_channel("http://localhost:4444/cached/test.gz"); var chan = make_channel("http://localhost:" +
httpserver.identity.primaryPort + "/cached/test.gz");
chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_GZIP), null); chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_GZIP), null);
} }
@ -77,12 +78,13 @@ function finish_test(request, data, ctx) {
function run_test() { function run_test() {
httpserver = new HttpServer(); httpserver = new HttpServer();
httpserver.registerPathHandler("/cached/test.gz", cachedHandler); httpserver.registerPathHandler("/cached/test.gz", cachedHandler);
httpserver.start(4444); httpserver.start(-1);
// wipe out cached content // wipe out cached content
evict_cache_entries(); evict_cache_entries();
var chan = make_channel("http://localhost:4444/cached/test.gz"); var chan = make_channel("http://localhost:" +
httpserver.identity.primaryPort + "/cached/test.gz");
chan.asyncOpen(new ChannelListener(continue_test, null, CL_EXPECT_GZIP), null); chan.asyncOpen(new ChannelListener(continue_test, null, CL_EXPECT_GZIP), null);
do_test_pending(); do_test_pending();
} }

View File

@ -10,6 +10,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserver.identity.primaryPort;
});
var httpserver = new HttpServer(); var httpserver = new HttpServer();
var testpath = "/simple"; var testpath = "/simple";
var httpbody = "0123456789"; var httpbody = "0123456789";
@ -28,7 +32,7 @@ function setup_test() {
if (dbg) { print("============== setup_test: in"); } if (dbg) { print("============== setup_test: in"); }
httpserver.registerPathHandler(testpath, serverHandler); httpserver.registerPathHandler(testpath, serverHandler);
httpserver.start(4444); httpserver.start(-1);
channel = setupChannel(testpath); channel = setupChannel(testpath);
@ -64,7 +68,7 @@ function setup_test() {
function setupChannel(path) { function setupChannel(path) {
ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + path, "", null); var chan = ios.newChannel(URL + path, "", null);
chan.QueryInterface(Ci.nsIHttpChannel); chan.QueryInterface(Ci.nsIHttpChannel);
chan.requestMethod = "GET"; chan.requestMethod = "GET";
return chan; return chan;

View File

@ -27,6 +27,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserver.identity.primaryPort;
});
var httpserver = new HttpServer(); var httpserver = new HttpServer();
var index = 0; var index = 0;
var nextTest = firstTest; var nextTest = firstTest;
@ -35,7 +39,7 @@ var testPathBase = "/test_headers";
function run_test() function run_test()
{ {
httpserver.start(4444); httpserver.start(-1);
do_test_pending(); do_test_pending();
run_test_number(nextTest); run_test_number(nextTest);
@ -72,7 +76,7 @@ function setupChannel(url)
{ {
var ios = Components.classes["@mozilla.org/network/io-service;1"]. var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService); getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + url, "", null); var chan = ios.newChannel(URL + url, "", null);
var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
return httpChan; return httpChan;
} }

View File

@ -90,7 +90,8 @@ function makeChan(url) {
var httpserv = null; var httpserv = null;
function execute_test() { function execute_test() {
var chan = makeChan("http://localhost:4444/failtest"); var chan = makeChan("http://localhost:" +
httpserv.identity.primaryPort + "/failtest");
var obs = Components.classes["@mozilla.org/observer-service;1"].getService(); var obs = Components.classes["@mozilla.org/observer-service;1"].getService();
obs = obs.QueryInterface(Components.interfaces.nsIObserverService); obs = obs.QueryInterface(Components.interfaces.nsIObserverService);
@ -102,7 +103,7 @@ function execute_test() {
function run_test() { function run_test() {
httpserv = new HttpServer(); httpserv = new HttpServer();
httpserv.registerPathHandler("/failtest", failtest); httpserv.registerPathHandler("/failtest", failtest);
httpserv.start(4444); httpserv.start(-1);
execute_test(); execute_test();

View File

@ -8,6 +8,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserv.identity.primaryPort;
});
const MIN_TIME_DIFFERENCE = 3000; const MIN_TIME_DIFFERENCE = 3000;
const RESUME_DELAY = 5000; const RESUME_DELAY = 5000;
@ -65,9 +69,9 @@ var httpserv = null;
function run_test() { function run_test() {
httpserv = new HttpServer(); httpserv = new HttpServer();
httpserv.registerPathHandler("/woo", data); httpserv.registerPathHandler("/woo", data);
httpserv.start(4444); httpserv.start(-1);
var chan = makeChan("http://localhost:4444/woo"); var chan = makeChan(URL + "/woo");
chan.QueryInterface(Ci.nsIRequest); chan.QueryInterface(Ci.nsIRequest);
chan.asyncOpen(listener, null); chan.asyncOpen(listener, null);

View File

@ -46,7 +46,8 @@ var listener_3 = {
} }
}; };
var listener_2 = { XPCOMUtils.defineLazyGetter(this, "listener_2", function() {
return {
// this listener is used to process the revalidation of the // this listener is used to process the revalidation of the
// corrupted cache entry. its revalidation prompts it to be cleaned // corrupted cache entry. its revalidation prompts it to be cleaned
@ -73,12 +74,16 @@ var listener_2 = {
onStopRequest: function test_onStopR(request, ctx, status) { onStopRequest: function test_onStopR(request, ctx, status) {
var channel = request.QueryInterface(Ci.nsIHttpChannel); var channel = request.QueryInterface(Ci.nsIHttpChannel);
var chan = ios.newChannel("http://localhost:4444/test1", "", null); var chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort +
"/test1", "", null);
chan.asyncOpen(listener_3, null); chan.asyncOpen(listener_3, null);
} }
}; };
});
var listener_1 = { XPCOMUtils.defineLazyGetter(this, "listener_1", function() {
return {
// this listener processes the initial request from a empty cache. // this listener processes the initial request from a empty cache.
// the server responds with the wrong data ('A') // the server responds with the wrong data ('A')
@ -101,10 +106,13 @@ var listener_1 = {
onStopRequest: function test_onStopR(request, ctx, status) { onStopRequest: function test_onStopR(request, ctx, status) {
var channel = request.QueryInterface(Ci.nsIHttpChannel); var channel = request.QueryInterface(Ci.nsIHttpChannel);
var chan = ios.newChannel("http://localhost:4444/test1", "", null); var chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort +
"/test1", "", null);
chan.asyncOpen(listener_2, null); chan.asyncOpen(listener_2, null);
} }
}; };
});
function run_test() { function run_test() {
do_get_profile(); do_get_profile();
@ -114,9 +122,11 @@ function run_test() {
evict_cache_entries(); evict_cache_entries();
httpserver.registerPathHandler("/test1", handler); httpserver.registerPathHandler("/test1", handler);
httpserver.start(4444); httpserver.start(-1);
var chan = ios.newChannel("http://localhost:4444/test1", "", null); var port = httpserver.identity.primaryPort;
var chan = ios.newChannel("http://localhost:" + port + "/test1", "", null);
chan.asyncOpen(listener_1, null); chan.asyncOpen(listener_1, null);
do_test_pending(); do_test_pending();

View File

@ -6,7 +6,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
var httpserver = null; var httpserver = null;
var uri = "http://localhost:4444/multipart";
XPCOMUtils.defineLazyGetter(this, "uri", function() {
return "http://localhost:" + httpserver.identity.primaryPort + "/multipart";
});
function make_channel(url) { function make_channel(url) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -107,7 +110,7 @@ function run_test()
{ {
httpserver = new HttpServer(); httpserver = new HttpServer();
httpserver.registerPathHandler("/multipart", contentHandler); httpserver.registerPathHandler("/multipart", contentHandler);
httpserver.start(4444); httpserver.start(-1);
var streamConv = Cc["@mozilla.org/streamConverters;1"] var streamConv = Cc["@mozilla.org/streamConverters;1"]
.getService(Ci.nsIStreamConverterService); .getService(Ci.nsIStreamConverterService);

View File

@ -6,7 +6,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
var httpserver = null; var httpserver = null;
var uri = "http://localhost:4444/multipart";
XPCOMUtils.defineLazyGetter(this, "uri", function() {
return "http://localhost:" + httpserver.identity.primaryPort + "/multipart";
});
function make_channel(url) { function make_channel(url) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -83,7 +86,7 @@ function run_test()
{ {
httpserver = new HttpServer(); httpserver = new HttpServer();
httpserver.registerPathHandler("/multipart", contentHandler); httpserver.registerPathHandler("/multipart", contentHandler);
httpserver.start(4444); httpserver.start(-1);
var streamConv = Cc["@mozilla.org/streamConverters;1"] var streamConv = Cc["@mozilla.org/streamConverters;1"]
.getService(Ci.nsIStreamConverterService); .getService(Ci.nsIStreamConverterService);

View File

@ -6,7 +6,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
var httpserver = null; var httpserver = null;
var uri = "http://localhost:4444/multipart";
XPCOMUtils.defineLazyGetter(this, "uri", function() {
return "http://localhost:" + httpserver.identity.primaryPort + "/multipart";
});
function make_channel(url) { function make_channel(url) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -83,7 +86,7 @@ function run_test()
{ {
httpserver = new HttpServer(); httpserver = new HttpServer();
httpserver.registerPathHandler("/multipart", contentHandler); httpserver.registerPathHandler("/multipart", contentHandler);
httpserver.start(4444); httpserver.start(-1);
var streamConv = Cc["@mozilla.org/streamConverters;1"] var streamConv = Cc["@mozilla.org/streamConverters;1"]
.getService(Ci.nsIStreamConverterService); .getService(Ci.nsIStreamConverterService);

View File

@ -22,7 +22,8 @@ var tests = [
function setupChannel(url) { function setupChannel(url) {
var ios = Components.classes["@mozilla.org/network/io-service;1"]. var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService); getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + url, "", null); var chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort + url, "", null);
return chan; return chan;
} }
@ -42,7 +43,7 @@ function completeIter(request, data, ctx) {
function run_test() { function run_test() {
httpserver.registerPathHandler("/test/test", handler); httpserver.registerPathHandler("/test/test", handler);
httpserver.start(4444); httpserver.start(-1);
startIter(); startIter();
do_test_pending(); do_test_pending();

View File

@ -57,8 +57,14 @@ const kManifest2 = "CACHE MANIFEST\n" +
const kDataFileSize = 1024; // file size for each content page const kDataFileSize = 1024; // file size for each content page
const kCacheSize = kDataFileSize * 5; // total space for offline cache storage const kCacheSize = kDataFileSize * 5; // total space for offline cache storage
const kHttpLocation = "http://localhost:4444/";
const kHttpLocation_ip = "http://127.0.0.1:4444/"; XPCOMUtils.defineLazyGetter(this, "kHttpLocation", function() {
return "http://localhost:" + httpServer.identity.primaryPort + "/";
});
XPCOMUtils.defineLazyGetter(this, "kHttpLocation_ip", function() {
return "http://127.0.0.1:" + httpServer.identity.primaryPort + "/";
});
function manifest1_handler(metadata, response) { function manifest1_handler(metadata, response) {
do_print("manifest1\n"); do_print("manifest1\n");
@ -113,7 +119,7 @@ function init_http_server() {
for (i = 1; i <= 8; i++) { for (i = 1; i <= 8; i++) {
httpServer.registerPathHandler("/pages/foo" + i, datafile_handler); httpServer.registerPathHandler("/pages/foo" + i, datafile_handler);
} }
httpServer.start(4444); httpServer.start(-1);
} }
function init_cache_capacity() { function init_cache_capacity() {

View File

@ -81,8 +81,8 @@ function makeChan(headerIdx, bodyIdx) {
var ios = Components.classes["@mozilla.org/network/io-service;1"] var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService); .getService(Components.interfaces.nsIIOService);
var chan = var chan =
ios.newChannel("http://localhost:4444/" + headerIdx + "/" + bodyIdx, null, ios.newChannel("http://localhost:" + httpserv.identity.primaryPort +
null) "/" + headerIdx + "/" + bodyIdx, null, null)
.QueryInterface(Components.interfaces.nsIHttpChannel); .QueryInterface(Components.interfaces.nsIHttpChannel);
chan.loadFlags |= chan.loadFlags |=
@ -193,7 +193,7 @@ function run_test() {
} }
} }
httpserv.start(4444); httpserv.start(-1);
doTest(0, 0); doTest(0, 0);
} }

View File

@ -9,6 +9,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserver.identity.primaryPort;
});
var httpserver = new HttpServer(); var httpserver = new HttpServer();
var testpath = "/simple"; var testpath = "/simple";
@ -56,7 +60,7 @@ function run_test() {
mime.addContentLength = true; mime.addContentLength = true;
httpserver.registerPathHandler(testpath, serverHandler); httpserver.registerPathHandler(testpath, serverHandler);
httpserver.start(4444); httpserver.start(-1);
var channel = setupChannel(testpath); var channel = setupChannel(testpath);
@ -71,7 +75,7 @@ function run_test() {
function setupChannel(path) { function setupChannel(path) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return chan = ios.newChannel("http://localhost:4444" + path, "", null) return chan = ios.newChannel(URL + path, "", null)
.QueryInterface(Ci.nsIHttpChannel); .QueryInterface(Ci.nsIHttpChannel);
} }

View File

@ -21,7 +21,7 @@ function run_test() {
evict_cache_entries(); evict_cache_entries();
httpserver.registerPathHandler(testpath, serverHandler); httpserver.registerPathHandler(testpath, serverHandler);
httpserver.start(4444); httpserver.start(-1);
var channel = setupChannel(testpath); var channel = setupChannel(testpath);
channel.loadGroup = Cc["@mozilla.org/network/load-group;1"].createInstance(); channel.loadGroup = Cc["@mozilla.org/network/load-group;1"].createInstance();
@ -36,7 +36,8 @@ function run_test() {
function setupChannel(path) { function setupChannel(path) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return chan = ios.newChannel("http://localhost:4444" + path, "", null) return chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort + path, "", null)
.QueryInterface(Ci.nsIHttpChannel); .QueryInterface(Ci.nsIHttpChannel);
} }

View File

@ -5,6 +5,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserver.identity.primaryPort;
});
var httpserver = new HttpServer(); var httpserver = new HttpServer();
var testpath = "/simple"; var testpath = "/simple";
var httpbody = "0123456789"; var httpbody = "0123456789";
@ -98,7 +102,7 @@ var progressCallback = {
function run_test() { function run_test() {
httpserver.registerPathHandler(testpath, serverHandler); httpserver.registerPathHandler(testpath, serverHandler);
httpserver.start(4444); httpserver.start(-1);
var channel = setupChannel(testpath); var channel = setupChannel(testpath);
channel.asyncOpen(progressCallback, null); channel.asyncOpen(progressCallback, null);
do_test_pending(); do_test_pending();
@ -107,7 +111,7 @@ function run_test() {
function setupChannel(path) { function setupChannel(path) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService); getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + path, "", null); var chan = ios.newChannel(URL + path, "", null);
chan.QueryInterface(Ci.nsIHttpChannel); chan.QueryInterface(Ci.nsIHttpChannel);
chan.requestMethod = "GET"; chan.requestMethod = "GET";
chan.notificationCallbacks = progressCallback; chan.notificationCallbacks = progressCallback;

View File

@ -31,7 +31,7 @@ function run_test()
{ {
httpServer = new HttpServer(); httpServer = new HttpServer();
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(4444); httpServer.start(-1);
// we want to cancel the failover proxy engage, so, do not allow // we want to cancel the failover proxy engage, so, do not allow
// redirects from now. // redirects from now.
@ -44,10 +44,12 @@ function run_test()
var prefs = prefserv.getBranch("network.proxy."); var prefs = prefserv.getBranch("network.proxy.");
prefs.setIntPref("type", 2); prefs.setIntPref("type", 2);
prefs.setCharPref("autoconfig_url", "data:text/plain," + prefs.setCharPref("autoconfig_url", "data:text/plain," +
"function FindProxyForURL(url, host) {return 'PROXY a_non_existent_domain_x7x6c572v:80; PROXY localhost:4444';}" "function FindProxyForURL(url, host) {return 'PROXY a_non_existent_domain_x7x6c572v:80; PROXY localhost:" +
httpServer.identity.primaryPort + "';}"
); );
var chan = make_channel("http://localhost:4444/content"); var chan = make_channel("http://localhost:" +
httpServer.identity.primaryPort + "/content");
chan.notificationCallbacks = nc; chan.notificationCallbacks = nc;
chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE), null); chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE), null);
do_test_pending(); do_test_pending();

View File

@ -31,17 +31,19 @@ function run_test()
{ {
httpServer = new HttpServer(); httpServer = new HttpServer();
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(4444); httpServer.start(-1);
var prefserv = Cc["@mozilla.org/preferences-service;1"]. var prefserv = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService); getService(Ci.nsIPrefService);
var prefs = prefserv.getBranch("network.proxy."); var prefs = prefserv.getBranch("network.proxy.");
prefs.setIntPref("type", 2); prefs.setIntPref("type", 2);
prefs.setCharPref("autoconfig_url", "data:text/plain," + prefs.setCharPref("autoconfig_url", "data:text/plain," +
"function FindProxyForURL(url, host) {return 'PROXY a_non_existent_domain_x7x6c572v:80; PROXY localhost:4444';}" "function FindProxyForURL(url, host) {return 'PROXY a_non_existent_domain_x7x6c572v:80; PROXY localhost:" +
httpServer.identity.primaryPort + "';}"
); );
var chan = make_channel("http://localhost:4444/content"); var chan = make_channel("http://localhost:" +
httpServer.identity.primaryPort + "/content");
chan.asyncOpen(new ChannelListener(finish_test, null), null); chan.asyncOpen(new ChannelListener(finish_test, null), null);
do_test_pending(); do_test_pending();
} }

View File

@ -31,14 +31,15 @@ function run_test()
{ {
httpServer = new HttpServer(); httpServer = new HttpServer();
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(4444); httpServer.start(-1);
var prefserv = Cc["@mozilla.org/preferences-service;1"]. var prefserv = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService); getService(Ci.nsIPrefService);
var prefs = prefserv.getBranch("network.proxy."); var prefs = prefserv.getBranch("network.proxy.");
prefs.setIntPref("type", 2); prefs.setIntPref("type", 2);
prefs.setCharPref("autoconfig_url", "data:text/plain," + prefs.setCharPref("autoconfig_url", "data:text/plain," +
"function FindProxyForURL(url, host) {return 'PROXY localhost:4444';}" "function FindProxyForURL(url, host) {return 'PROXY localhost:" +
httpServer.identity.primaryPort + "';}"
); );
// this test assumed that a AsyncOnChannelRedirect query is made for // this test assumed that a AsyncOnChannelRedirect query is made for
@ -49,7 +50,8 @@ function run_test()
// internal redirect used to setup the initial proxy/channel as that isn't // internal redirect used to setup the initial proxy/channel as that isn't
// a redirect in any sense. // a redirect in any sense.
var chan = make_channel("http://localhost:4444/content"); var chan = make_channel("http://localhost:" +
httpServer.identity.primaryPort + "/content");
chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE), null); chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE), null);
chan.cancel(Cr.NS_BINDING_ABORTED); chan.cancel(Cr.NS_BINDING_ABORTED);
do_test_pending(); do_test_pending();

View File

@ -31,17 +31,19 @@ function run_test()
{ {
httpServer = new HttpServer(); httpServer = new HttpServer();
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(4444); httpServer.start(-1);
var prefserv = Cc["@mozilla.org/preferences-service;1"]. var prefserv = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService); getService(Ci.nsIPrefService);
var prefs = prefserv.getBranch("network.proxy."); var prefs = prefserv.getBranch("network.proxy.");
prefs.setIntPref("type", 2); prefs.setIntPref("type", 2);
prefs.setCharPref("autoconfig_url", "data:text/plain," + prefs.setCharPref("autoconfig_url", "data:text/plain," +
"function FindProxyForURL(url, host) {return 'PROXY localhost:4444';}" "function FindProxyForURL(url, host) {return 'PROXY localhost:" +
httpServer.identity.primaryPort + "';}"
); );
var chan = make_channel("http://localhost:4444/content"); var chan = make_channel("http://localhost:" +
httpServer.identity.primaryPort + "/content");
chan.asyncOpen(new ChannelListener(finish_test, null), null); chan.asyncOpen(new ChannelListener(finish_test, null), null);
do_test_pending(); do_test_pending();
} }

View File

@ -33,6 +33,7 @@ const decodedBody = [0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20,
0x6c, 0x79, 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x20, 0x74, 0x65, 0x73, 0x74, 0x0a, 0x0a]; 0x6c, 0x79, 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x20, 0x74, 0x65, 0x73, 0x74, 0x0a, 0x0a];
const partial_data_length = 4; const partial_data_length = 4;
var port = null; // set in run_test
function make_channel(url, callback, ctx) { function make_channel(url, callback, ctx) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -107,7 +108,7 @@ function handler_2(metadata, response) {
} }
function received_partial_2(request, data) { function received_partial_2(request, data) {
do_check_eq(data, undefined); do_check_eq(data, undefined);
var chan = make_channel("http://localhost:4444/test_2"); var chan = make_channel("http://localhost:" + port + "/test_2");
chan.asyncOpen(new ChannelListener(received_cleartext, null), null); chan.asyncOpen(new ChannelListener(received_cleartext, null), null);
} }
@ -135,7 +136,7 @@ function handler_3(metadata, response) {
} }
function received_partial_3(request, data) { function received_partial_3(request, data) {
do_check_eq(partial_data_length, data.length); do_check_eq(partial_data_length, data.length);
var chan = make_channel("http://localhost:4444/test_3"); var chan = make_channel("http://localhost:" + port + "/test_3");
chan.asyncOpen(new ChannelListener(received_cleartext, null), null); chan.asyncOpen(new ChannelListener(received_cleartext, null), null);
} }
@ -168,7 +169,7 @@ function handler_4(metadata, response) {
function received_partial_4(request, data) { function received_partial_4(request, data) {
// checking length does not work with encoded data // checking length does not work with encoded data
// do_check_eq(partial_data_length, data.length); // do_check_eq(partial_data_length, data.length);
var chan = make_channel("http://localhost:4444/test_4"); var chan = make_channel("http://localhost:" + port + "/test_4");
chan.asyncOpen(new MyListener(received_cleartext), null); chan.asyncOpen(new MyListener(received_cleartext), null);
} }
@ -195,7 +196,7 @@ function handler_5(metadata, response) {
} }
function received_partial_5(request, data) { function received_partial_5(request, data) {
do_check_eq(partial_data_length, data.length); do_check_eq(partial_data_length, data.length);
var chan = make_channel("http://localhost:4444/test_5"); var chan = make_channel("http://localhost:" + port + "/test_5");
chan.setRequestHeader("If-Match", "Some eTag", false); chan.setRequestHeader("If-Match", "Some eTag", false);
chan.asyncOpen(new ChannelListener(received_cleartext, null), null); chan.asyncOpen(new ChannelListener(received_cleartext, null), null);
} }
@ -226,7 +227,7 @@ function handler_6(metadata, response) {
function received_partial_6(request, data) { function received_partial_6(request, data) {
// would like to verify that the response does not have Accept-Ranges // would like to verify that the response does not have Accept-Ranges
do_check_eq(partial_data_length, data.length); do_check_eq(partial_data_length, data.length);
var chan = make_channel("http://localhost:4444/test_6"); var chan = make_channel("http://localhost:" + port + "/test_6");
chan.asyncOpen(new ChannelListener(received_cleartext, null), null); chan.asyncOpen(new ChannelListener(received_cleartext, null), null);
} }
@ -244,29 +245,31 @@ function run_test() {
httpserver.registerPathHandler("/test_4", handler_4); httpserver.registerPathHandler("/test_4", handler_4);
httpserver.registerPathHandler("/test_5", handler_5); httpserver.registerPathHandler("/test_5", handler_5);
httpserver.registerPathHandler("/test_6", handler_6); httpserver.registerPathHandler("/test_6", handler_6);
httpserver.start(4444); httpserver.start(-1);
port = httpserver.identity.primaryPort;
// wipe out cached content // wipe out cached content
evict_cache_entries(); evict_cache_entries();
// Case 2: zero-length partial entry must not trigger range-request // Case 2: zero-length partial entry must not trigger range-request
var chan = make_channel("http://localhost:4444/test_2"); var chan = make_channel("http://localhost:" + port + "/test_2");
chan.asyncOpen(new Canceler(received_partial_2), null); chan.asyncOpen(new Canceler(received_partial_2), null);
// Case 3: no-store response must not trigger range-request // Case 3: no-store response must not trigger range-request
var chan = make_channel("http://localhost:4444/test_3"); var chan = make_channel("http://localhost:" + port + "/test_3");
chan.asyncOpen(new MyListener(received_partial_3), null); chan.asyncOpen(new MyListener(received_partial_3), null);
// Case 4: response with content-encoding must not trigger range-request // Case 4: response with content-encoding must not trigger range-request
var chan = make_channel("http://localhost:4444/test_4"); var chan = make_channel("http://localhost:" + port + "/test_4");
chan.asyncOpen(new MyListener(received_partial_4), null); chan.asyncOpen(new MyListener(received_partial_4), null);
// Case 5: conditional request-header set by client // Case 5: conditional request-header set by client
var chan = make_channel("http://localhost:4444/test_5"); var chan = make_channel("http://localhost:" + port + "/test_5");
chan.asyncOpen(new MyListener(received_partial_5), null); chan.asyncOpen(new MyListener(received_partial_5), null);
// Case 6: response is not resumable (drop the Accept-Ranges header) // Case 6: response is not resumable (drop the Accept-Ranges header)
var chan = make_channel("http://localhost:4444/test_6"); var chan = make_channel("http://localhost:" + port + "/test_6");
chan.asyncOpen(new MyListener(received_partial_6), null); chan.asyncOpen(new MyListener(received_partial_6), null);
do_test_pending(); do_test_pending();

View File

@ -5,10 +5,17 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpServer.identity.primaryPort;
});
var httpServer = null; var httpServer = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random(); var randomPath = "/redirect/" + Math.random();
var randomURI = "http://localhost:4444" + randomPath;
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return URL + randomPath;
});
function make_channel(url, callback, ctx) { function make_channel(url, callback, ctx) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -21,7 +28,7 @@ const responseBody = "response body";
function redirectHandler(metadata, response) function redirectHandler(metadata, response)
{ {
response.setStatusLine(metadata.httpVersion, 301, "Moved"); response.setStatusLine(metadata.httpVersion, 301, "Moved");
response.setHeader("Location", "http://localhost:4444/content", false); response.setHeader("Location", URL + "/content", false);
response.setHeader("Cache-control", "max-age=1000", false); response.setHeader("Cache-control", "max-age=1000", false);
return; return;
} }
@ -59,7 +66,7 @@ function run_test()
httpServer = new HttpServer(); httpServer = new HttpServer();
httpServer.registerPathHandler(randomPath, redirectHandler); httpServer.registerPathHandler(randomPath, redirectHandler);
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(4444); httpServer.start(-1);
var chan = make_channel(randomURI); var chan = make_channel(randomURI);
chan.asyncOpen(new ChannelListener(firstTimeThrough, null), null); chan.asyncOpen(new ChannelListener(firstTimeThrough, null), null);

View File

@ -5,10 +5,17 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpServer.identity.primaryPort;
});
var httpServer = null; var httpServer = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random(); var randomPath = "/redirect/" + Math.random();
var randomURI = "http://localhost:4444" + randomPath;
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return URL + randomPath;
});
function make_channel(url, callback, ctx) { function make_channel(url, callback, ctx) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -19,7 +26,8 @@ function make_channel(url, callback, ctx) {
function redirectHandler(metadata, response) function redirectHandler(metadata, response)
{ {
response.setStatusLine(metadata.httpVersion, 301, "Moved"); response.setStatusLine(metadata.httpVersion, 301, "Moved");
response.setHeader("Location", "httpx://localhost:4444/content", false); response.setHeader("Location", "httpx://localhost:" +
httpServer.identity.primaryPort + "/content", false);
response.setHeader("Cache-control", "max-age=1000", false); response.setHeader("Cache-control", "max-age=1000", false);
} }
@ -45,7 +53,7 @@ function run_test()
{ {
httpServer = new HttpServer(); httpServer = new HttpServer();
httpServer.registerPathHandler(randomPath, redirectHandler); httpServer.registerPathHandler(randomPath, redirectHandler);
httpServer.start(4444); httpServer.start(-1);
var chan = make_channel(randomURI); var chan = make_channel(randomURI);
chan.asyncOpen(new ChannelListener(makeSureNotInCache, null, CL_EXPECT_FAILURE), null); chan.asyncOpen(new ChannelListener(makeSureNotInCache, null, CL_EXPECT_FAILURE), null);

View File

@ -5,10 +5,17 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserver.identity.primaryPort;
});
var httpserver = null; var httpserver = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random(); var randomPath = "/redirect/" + Math.random();
var randomURI = "http://localhost:4444" + randomPath;
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return URL + randomPath;
});
function make_channel(url, callback, ctx) { function make_channel(url, callback, ctx) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -21,7 +28,7 @@ const responseBody = "response body";
function redirectHandler(metadata, response) function redirectHandler(metadata, response)
{ {
response.setStatusLine(metadata.httpVersion, 301, "Moved"); response.setStatusLine(metadata.httpVersion, 301, "Moved");
response.setHeader("Location", "http://localhost:4444/content", false); response.setHeader("Location", URL + "/content", false);
return; return;
} }
@ -50,7 +57,7 @@ function run_test()
httpserver = new HttpServer(); httpserver = new HttpServer();
httpserver.registerPathHandler(randomPath, redirectHandler); httpserver.registerPathHandler(randomPath, redirectHandler);
httpserver.registerPathHandler("/content", contentHandler); httpserver.registerPathHandler("/content", contentHandler);
httpserver.start(4444); httpserver.start(-1);
var chan = make_channel(randomURI); var chan = make_channel(randomURI);
chan.asyncOpen(new ChannelListener(firstTimeThrough, null), null); chan.asyncOpen(new ChannelListener(firstTimeThrough, null), null);

View File

@ -12,7 +12,9 @@ Cu.import("resource://testing-common/httpd.js");
var httpServer = null; var httpServer = null;
var BadRedirectPath = "/BadRedirect"; var BadRedirectPath = "/BadRedirect";
var BadRedirectURI = "http://localhost:4444" + BadRedirectPath; XPCOMUtils.defineLazyGetter(this, "BadRedirectURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + BadRedirectPath;
});
function make_channel(url, callback, ctx) { function make_channel(url, callback, ctx) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -38,7 +40,7 @@ function run_test()
{ {
httpServer = new HttpServer(); httpServer = new HttpServer();
httpServer.registerPathHandler(BadRedirectPath, BadRedirectHandler); httpServer.registerPathHandler(BadRedirectPath, BadRedirectHandler);
httpServer.start(4444); httpServer.start(-1);
var chan = make_channel(BadRedirectURI); var chan = make_channel(BadRedirectURI);
chan.asyncOpen(new ChannelListener(checkFailed, null, CL_EXPECT_FAILURE), chan.asyncOpen(new ChannelListener(checkFailed, null, CL_EXPECT_FAILURE),

View File

@ -5,10 +5,17 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpServer.identity.primaryPort;
});
var httpServer = null; var httpServer = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random(); var randomPath = "/redirect/" + Math.random();
var randomURI = "http://localhost:4444" + randomPath;
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return URL + randomPath;
});
function make_channel(url, callback, ctx) { function make_channel(url, callback, ctx) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -21,7 +28,7 @@ const responseBody = "response body";
function redirectHandler(metadata, response) function redirectHandler(metadata, response)
{ {
response.setStatusLine(metadata.httpVersion, 301, "Moved"); response.setStatusLine(metadata.httpVersion, 301, "Moved");
response.setHeader("Location", "http://localhost:4444/content", false); response.setHeader("Location", URL + "/content", false);
} }
function contentHandler(metadata, response) function contentHandler(metadata, response)
@ -41,7 +48,7 @@ function run_test()
httpServer = new HttpServer(); httpServer = new HttpServer();
httpServer.registerPathHandler(randomPath, redirectHandler); httpServer.registerPathHandler(randomPath, redirectHandler);
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(4444); httpServer.start(-1);
var chan = make_channel(randomURI); var chan = make_channel(randomURI);
chan.notificationCallbacks = new ChannelEventSink(ES_ABORT_REDIRECT); chan.notificationCallbacks = new ChannelEventSink(ES_ABORT_REDIRECT);

View File

@ -5,10 +5,17 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpServer.identity.primaryPort;
});
var httpServer = null; var httpServer = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random(); var randomPath = "/redirect/" + Math.random();
var randomURI = "http://localhost:4444" + randomPath;
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return URL + randomPath;
});
function make_channel(url, callback, ctx) { function make_channel(url, callback, ctx) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -19,7 +26,8 @@ function make_channel(url, callback, ctx) {
function redirectHandler(metadata, response) function redirectHandler(metadata, response)
{ {
response.setStatusLine(metadata.httpVersion, 301, "Moved"); response.setStatusLine(metadata.httpVersion, 301, "Moved");
response.setHeader("Location", "httpx://localhost:4444/content", false); response.setHeader("Location", "httpx://localhost:" +
httpServer.identity.primaryPort + "/content", false);
response.setHeader("Cache-Control", "no-cache", false); response.setHeader("Cache-Control", "no-cache", false);
} }
@ -35,7 +43,7 @@ function run_test()
{ {
httpServer = new HttpServer(); httpServer = new HttpServer();
httpServer.registerPathHandler(randomPath, redirectHandler); httpServer.registerPathHandler(randomPath, redirectHandler);
httpServer.start(4444); httpServer.start(-1);
var chan = make_channel(randomURI); var chan = make_channel(randomURI);
chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE), null); chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE), null);

View File

@ -36,31 +36,52 @@ redirectHook = "http-on-modify-request";
var httpServer = null, httpServer2 = null; var httpServer = null, httpServer2 = null;
XPCOMUtils.defineLazyGetter(this, "port1", function() {
return httpServer.identity.primaryPort;
});
XPCOMUtils.defineLazyGetter(this, "port2", function() {
return httpServer2.identity.primaryPort;
});
// Test Part 1: a cross-path redirect on a single HTTP server // Test Part 1: a cross-path redirect on a single HTTP server
// http://localhost:4444/bait -> http://localhost:4444/switch // http://localhost:port1/bait -> http://localhost:port1/switch
var baitPath = "/bait"; var baitPath = "/bait";
var baitURI = "http://localhost:4444" + baitPath; XPCOMUtils.defineLazyGetter(this, "baitURI", function() {
return "http://localhost:" + port1 + baitPath;
});
var baitText = "you got the worm"; var baitText = "you got the worm";
var redirectedPath = "/switch"; var redirectedPath = "/switch";
var redirectedURI = "http://localhost:4444" + redirectedPath; XPCOMUtils.defineLazyGetter(this, "redirectedURI", function() {
return "http://localhost:" + port1 + redirectedPath;
});
var redirectedText = "worms are not tasty"; var redirectedText = "worms are not tasty";
// Test Part 2: Now, a redirect to a different server // Test Part 2: Now, a redirect to a different server
// http://localhost:4444/bait2 -> http://localhost:4445/switch // http://localhost:port1/bait2 -> http://localhost:port2/switch
var bait2Path = "/bait2"; var bait2Path = "/bait2";
var bait2URI = "http://localhost:4444" + bait2Path; XPCOMUtils.defineLazyGetter(this, "bait2URI", function() {
var redirected2URI = "http://localhost:4445" + redirectedPath; return "http://localhost:" + port1 + bait2Path;
});
XPCOMUtils.defineLazyGetter(this, "redirected2URI", function() {
return "http://localhost:" + port2 + redirectedPath;
});
// Test Part 3, begin with a serverside redirect that itself turns into an instance // Test Part 3, begin with a serverside redirect that itself turns into an instance
// of Test Part 1 // of Test Part 1
var bait3Path = "/bait3"; var bait3Path = "/bait3";
var bait3URI = "http://localhost:4444" + bait3Path; XPCOMUtils.defineLazyGetter(this, "bait3URI", function() {
return "http://localhost:" + port1 + bait3Path;
});
// Test Part 4, begin with this client-side redirect and which then redirects // Test Part 4, begin with this client-side redirect and which then redirects
// to an instance of Test Part 1 // to an instance of Test Part 1
var bait4Path = "/bait4"; var bait4Path = "/bait4";
var bait4URI = "http://localhost:4444" + bait4Path; XPCOMUtils.defineLazyGetter(this, "bait4URI", function() {
return "http://localhost:" + port1 + bait4Path;
});
var testHeaderName = "X-Redirected-By-Script" var testHeaderName = "X-Redirected-By-Script"
var testHeaderVal = "Success"; var testHeaderVal = "Success";
@ -175,15 +196,12 @@ function makeAsyncTest(uri, headerValue, nextTask)
return test; return test;
} }
// will be defined in run_test because of the lazy getters,
// The tests depend on each other, and therefore need to be defined in the // since the server's port is defined dynamically
// reverse of the order they are called in. It is therefore best to read this var testViaAsyncOpen4 = null;
// stanza backwards! var testViaAsyncOpen3 = null;
var testViaAsyncOpen2 = null;
var testViaAsyncOpen4 = makeAsyncTest(bait4URI, testHeaderVal, done); var testViaAsyncOpen = null;
var testViaAsyncOpen3 = makeAsyncTest(bait3URI, testHeaderVal, testViaAsyncOpen4);
var testViaAsyncOpen2 = makeAsyncTest(bait2URI, testHeaderVal2, testViaAsyncOpen3);
var testViaAsyncOpen = makeAsyncTest(baitURI, testHeaderVal, testViaAsyncOpen2);
function testViaXHR() function testViaXHR()
{ {
@ -226,10 +244,18 @@ function run_test()
httpServer.registerPathHandler(bait3Path, bait3Handler); httpServer.registerPathHandler(bait3Path, bait3Handler);
httpServer.registerPathHandler(bait4Path, baitHandler); httpServer.registerPathHandler(bait4Path, baitHandler);
httpServer.registerPathHandler(redirectedPath, redirectedHandler); httpServer.registerPathHandler(redirectedPath, redirectedHandler);
httpServer.start(4444); httpServer.start(-1);
httpServer2 = new HttpServer(); httpServer2 = new HttpServer();
httpServer2.registerPathHandler(redirectedPath, redirected2Handler); httpServer2.registerPathHandler(redirectedPath, redirected2Handler);
httpServer2.start(4445); httpServer2.start(-1);
// The tests depend on each other, and therefore need to be defined in the
// reverse of the order they are called in. It is therefore best to read this
// stanza backwards!
testViaAsyncOpen4 = makeAsyncTest(bait4URI, testHeaderVal, done);
testViaAsyncOpen3 = makeAsyncTest(bait3URI, testHeaderVal, testViaAsyncOpen4);
testViaAsyncOpen2 = makeAsyncTest(bait2URI, testHeaderVal2, testViaAsyncOpen3);
testViaAsyncOpen = makeAsyncTest(baitURI, testHeaderVal, testViaAsyncOpen2);
testViaXHR(); testViaXHR();
testViaAsyncOpen(); // will call done() asynchronously for cleanup testViaAsyncOpen(); // will call done() asynchronously for cleanup

View File

@ -12,17 +12,19 @@ Cu.import("resource://testing-common/httpd.js");
* URI when the original URI ends in a slash). * URI when the original URI ends in a slash).
*/ */
var httpServer = null; var httpServer = new HttpServer();
httpServer.start(-1);
const PORT = httpServer.identity.primaryPort;
var fullLoopPath = "/fullLoop"; var fullLoopPath = "/fullLoop";
var fullLoopURI = "http://localhost:4444" + fullLoopPath; var fullLoopURI = "http://localhost:" + PORT + fullLoopPath;
var relativeLoopPath = "/relativeLoop"; var relativeLoopPath = "/relativeLoop";
var relativeLoopURI = "http://localhost:4444" + relativeLoopPath; var relativeLoopURI = "http://localhost:" + PORT + relativeLoopPath;
// must use directory-style URI, so empty Location redirects back to self // must use directory-style URI, so empty Location redirects back to self
var emptyLoopPath = "/empty/"; var emptyLoopPath = "/empty/";
var emptyLoopURI = "http://localhost:4444" + emptyLoopPath; var emptyLoopURI = "http://localhost:" + PORT + emptyLoopPath;
function make_channel(url, callback, ctx) { function make_channel(url, callback, ctx) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -33,7 +35,7 @@ function make_channel(url, callback, ctx) {
function fullLoopHandler(metadata, response) function fullLoopHandler(metadata, response)
{ {
response.setStatusLine(metadata.httpVersion, 301, "Moved"); response.setStatusLine(metadata.httpVersion, 301, "Moved");
response.setHeader("Location", "http://localhost:4444/fullLoop", false); response.setHeader("Location", "http://localhost:" + PORT + "/fullLoop", false);
} }
function relativeLoopHandler(metadata, response) function relativeLoopHandler(metadata, response)
@ -82,11 +84,9 @@ function testEmptyLoop(request, buffer)
function run_test() function run_test()
{ {
httpServer = new HttpServer();
httpServer.registerPathHandler(fullLoopPath, fullLoopHandler); httpServer.registerPathHandler(fullLoopPath, fullLoopHandler);
httpServer.registerPathHandler(relativeLoopPath, relativeLoopHandler); httpServer.registerPathHandler(relativeLoopPath, relativeLoopHandler);
httpServer.registerPathHandler(emptyLoopPath, emptyLoopHandler); httpServer.registerPathHandler(emptyLoopPath, emptyLoopHandler);
httpServer.start(4444);
var chan = make_channel(fullLoopURI); var chan = make_channel(fullLoopURI);
chan.asyncOpen(new ChannelListener(testFullLoop, null, CL_EXPECT_FAILURE), chan.asyncOpen(new ChannelListener(testFullLoop, null, CL_EXPECT_FAILURE),

View File

@ -5,10 +5,17 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpServer.identity.primaryPort;
});
var httpServer = null; var httpServer = null;
// Need to randomize, because apparently no one clears our cache // Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random(); var randomPath = "/redirect/" + Math.random();
var randomURI = "http://localhost:4444" + randomPath;
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return URL + randomPath;
});
function make_channel(url, callback, ctx) { function make_channel(url, callback, ctx) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
@ -21,7 +28,7 @@ const responseBody = "response body";
function redirectHandler(metadata, response) function redirectHandler(metadata, response)
{ {
response.setStatusLine(metadata.httpVersion, 301, "Moved"); response.setStatusLine(metadata.httpVersion, 301, "Moved");
response.setHeader("Location", "http://localhost:4444/content", false); response.setHeader("Location", URL + "/content", false);
} }
function contentHandler(metadata, response) function contentHandler(metadata, response)
@ -48,7 +55,7 @@ function run_test()
httpServer = new HttpServer(); httpServer = new HttpServer();
httpServer.registerPathHandler(randomPath, redirectHandler); httpServer.registerPathHandler(randomPath, redirectHandler);
httpServer.registerPathHandler("/content", contentHandler); httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(4444); httpServer.start(-1);
var chan = make_channel(randomURI); var chan = make_channel(randomURI);
chan.asyncOpen(new ChannelListener(firstTimeThrough, null), null); chan.asyncOpen(new ChannelListener(firstTimeThrough, null), null);

View File

@ -5,6 +5,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserver.identity.primaryPort;
});
var httpserver = new HttpServer(); var httpserver = new HttpServer();
var testpath = "/simple"; var testpath = "/simple";
var httpbody = "<?xml version='1.0' ?><root>0123456789</root>"; var httpbody = "<?xml version='1.0' ?><root>0123456789</root>";
@ -13,7 +17,7 @@ function syncXHR()
{ {
var xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] var xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
.createInstance(Ci.nsIXMLHttpRequest); .createInstance(Ci.nsIXMLHttpRequest);
xhr.open("GET", "http://localhost:4444" + testpath, false); xhr.open("GET", URL + testpath, false);
xhr.send(null); xhr.send(null);
} }
@ -84,7 +88,7 @@ function makeChan(url) {
function next_test() function next_test()
{ {
var chan = makeChan("http://localhost:4444" + testpath); var chan = makeChan(URL + testpath);
chan.QueryInterface(Ci.nsIRequest); chan.QueryInterface(Ci.nsIRequest);
chan.asyncOpen(listener, null); chan.asyncOpen(listener, null);
} }
@ -92,7 +96,7 @@ function next_test()
function run_test() function run_test()
{ {
httpserver.registerPathHandler(testpath, serverHandler); httpserver.registerPathHandler(testpath, serverHandler);
httpserver.start(4444); httpserver.start(-1);
next_test(); next_test();

View File

@ -113,7 +113,7 @@ function test_data_channel() {
function test_http_channel() { function test_http_channel() {
test_channel(function() { test_channel(function() {
return makeChan("http://localhost:4444/"); return makeChan("http://localhost:" + httpserv.identity.primaryPort + "/");
}); });
} }
@ -138,7 +138,7 @@ function end() {
function run_test() { function run_test() {
// start server // start server
httpserv = new HttpServer(); httpserv = new HttpServer();
httpserv.start(4444); httpserv.start(-1);
run_next_test(); run_next_test();
} }

View File

@ -7,6 +7,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserver.identity.primaryPort;
});
var httpserver = null; var httpserver = null;
const NS_ERROR_ENTITY_CHANGED = 0x804b0020; const NS_ERROR_ENTITY_CHANGED = 0x804b0020;
@ -90,7 +94,7 @@ function run_test() {
dump("*** entity id = " + entityID + "\n"); dump("*** entity id = " + entityID + "\n");
// Try a non-resumable URL (responds with 200) // Try a non-resumable URL (responds with 200)
var chan = make_channel("http://localhost:4444/"); var chan = make_channel(URL);
chan.nsIResumableChannel.resumeAt(1, entityID); chan.nsIResumableChannel.resumeAt(1, entityID);
chan.asyncOpen(new ChannelListener(try_resume, null, CL_EXPECT_FAILURE), null); chan.asyncOpen(new ChannelListener(try_resume, null, CL_EXPECT_FAILURE), null);
} }
@ -100,7 +104,7 @@ function run_test() {
do_check_eq(request.status, NS_ERROR_NOT_RESUMABLE); do_check_eq(request.status, NS_ERROR_NOT_RESUMABLE);
// Try a successful resume // Try a successful resume
var chan = make_channel("http://localhost:4444/range"); var chan = make_channel(URL + "/range");
chan.nsIResumableChannel.resumeAt(1, entityID); chan.nsIResumableChannel.resumeAt(1, entityID);
chan.asyncOpen(new ChannelListener(try_resume_zero, null), null); chan.asyncOpen(new ChannelListener(try_resume_zero, null), null);
} }
@ -111,7 +115,7 @@ function run_test() {
do_check_eq(data, rangeBody.substring(1)); do_check_eq(data, rangeBody.substring(1));
// Try a server which doesn't support range requests // Try a server which doesn't support range requests
var chan = make_channel("http://localhost:4444/acceptranges"); var chan = make_channel(URL + "/acceptranges");
chan.nsIResumableChannel.resumeAt(0, entityID); chan.nsIResumableChannel.resumeAt(0, entityID);
chan.nsIHttpChannel.setRequestHeader("X-Range-Type", "none", false); chan.nsIHttpChannel.setRequestHeader("X-Range-Type", "none", false);
chan.asyncOpen(new ChannelListener(try_no_range, null, CL_EXPECT_FAILURE), null); chan.asyncOpen(new ChannelListener(try_no_range, null, CL_EXPECT_FAILURE), null);
@ -123,7 +127,7 @@ function run_test() {
do_check_eq(request.status, NS_ERROR_NOT_RESUMABLE); do_check_eq(request.status, NS_ERROR_NOT_RESUMABLE);
// Try a server which supports "bytes" range requests // Try a server which supports "bytes" range requests
var chan = make_channel("http://localhost:4444/acceptranges"); var chan = make_channel(URL + "/acceptranges");
chan.nsIResumableChannel.resumeAt(0, entityID); chan.nsIResumableChannel.resumeAt(0, entityID);
chan.nsIHttpChannel.setRequestHeader("X-Range-Type", "bytes", false); chan.nsIHttpChannel.setRequestHeader("X-Range-Type", "bytes", false);
chan.asyncOpen(new ChannelListener(try_bytes_range, null), null); chan.asyncOpen(new ChannelListener(try_bytes_range, null), null);
@ -135,7 +139,7 @@ function run_test() {
do_check_eq(data, rangeBody); do_check_eq(data, rangeBody);
// Try a server which supports "foo" and "bar" range requests // Try a server which supports "foo" and "bar" range requests
var chan = make_channel("http://localhost:4444/acceptranges"); var chan = make_channel(URL + "/acceptranges");
chan.nsIResumableChannel.resumeAt(0, entityID); chan.nsIResumableChannel.resumeAt(0, entityID);
chan.nsIHttpChannel.setRequestHeader("X-Range-Type", "foo, bar", false); chan.nsIHttpChannel.setRequestHeader("X-Range-Type", "foo, bar", false);
chan.asyncOpen(new ChannelListener(try_foo_bar_range, null, CL_EXPECT_FAILURE), null); chan.asyncOpen(new ChannelListener(try_foo_bar_range, null, CL_EXPECT_FAILURE), null);
@ -147,7 +151,7 @@ function run_test() {
do_check_eq(request.status, NS_ERROR_NOT_RESUMABLE); do_check_eq(request.status, NS_ERROR_NOT_RESUMABLE);
// Try a server which supports "foobar" range requests // Try a server which supports "foobar" range requests
var chan = make_channel("http://localhost:4444/acceptranges"); var chan = make_channel(URL + "/acceptranges");
chan.nsIResumableChannel.resumeAt(0, entityID); chan.nsIResumableChannel.resumeAt(0, entityID);
chan.nsIHttpChannel.setRequestHeader("X-Range-Type", "foobar", false); chan.nsIHttpChannel.setRequestHeader("X-Range-Type", "foobar", false);
chan.asyncOpen(new ChannelListener(try_foobar_range, null, CL_EXPECT_FAILURE), null); chan.asyncOpen(new ChannelListener(try_foobar_range, null, CL_EXPECT_FAILURE), null);
@ -159,7 +163,7 @@ function run_test() {
do_check_eq(request.status, NS_ERROR_NOT_RESUMABLE); do_check_eq(request.status, NS_ERROR_NOT_RESUMABLE);
// Try a server which supports "bytes" and "foobar" range requests // Try a server which supports "bytes" and "foobar" range requests
var chan = make_channel("http://localhost:4444/acceptranges"); var chan = make_channel(URL + "/acceptranges");
chan.nsIResumableChannel.resumeAt(0, entityID); chan.nsIResumableChannel.resumeAt(0, entityID);
chan.nsIHttpChannel.setRequestHeader("X-Range-Type", "bytes, foobar", false); chan.nsIHttpChannel.setRequestHeader("X-Range-Type", "bytes, foobar", false);
chan.asyncOpen(new ChannelListener(try_bytes_foobar_range, null), null); chan.asyncOpen(new ChannelListener(try_bytes_foobar_range, null), null);
@ -171,7 +175,7 @@ function run_test() {
do_check_eq(data, rangeBody); do_check_eq(data, rangeBody);
// Try a server which supports "bytesfoo" and "bar" range requests // Try a server which supports "bytesfoo" and "bar" range requests
var chan = make_channel("http://localhost:4444/acceptranges"); var chan = make_channel(URL + "/acceptranges");
chan.nsIResumableChannel.resumeAt(0, entityID); chan.nsIResumableChannel.resumeAt(0, entityID);
chan.nsIHttpChannel.setRequestHeader("X-Range-Type", "bytesfoo, bar", false); chan.nsIHttpChannel.setRequestHeader("X-Range-Type", "bytesfoo, bar", false);
chan.asyncOpen(new ChannelListener(try_bytesfoo_bar_range, null, CL_EXPECT_FAILURE), null); chan.asyncOpen(new ChannelListener(try_bytesfoo_bar_range, null, CL_EXPECT_FAILURE), null);
@ -183,7 +187,7 @@ function run_test() {
do_check_eq(request.status, NS_ERROR_NOT_RESUMABLE); do_check_eq(request.status, NS_ERROR_NOT_RESUMABLE);
// Try a server which doesn't send Accept-Ranges header at all // Try a server which doesn't send Accept-Ranges header at all
var chan = make_channel("http://localhost:4444/acceptranges"); var chan = make_channel(URL + "/acceptranges");
chan.nsIResumableChannel.resumeAt(0, entityID); chan.nsIResumableChannel.resumeAt(0, entityID);
chan.asyncOpen(new ChannelListener(try_no_accept_ranges, null), null); chan.asyncOpen(new ChannelListener(try_no_accept_ranges, null), null);
} }
@ -194,7 +198,7 @@ function run_test() {
do_check_eq(data, rangeBody); do_check_eq(data, rangeBody);
// Try a successful suspend/resume from 0 // Try a successful suspend/resume from 0
var chan = make_channel("http://localhost:4444/range"); var chan = make_channel(URL + "/range");
chan.nsIResumableChannel.resumeAt(0, entityID); chan.nsIResumableChannel.resumeAt(0, entityID);
chan.asyncOpen(new ChannelListener(try_suspend_resume, null, chan.asyncOpen(new ChannelListener(try_suspend_resume, null,
CL_SUSPEND | CL_EXPECT_3S_DELAY), null); CL_SUSPEND | CL_EXPECT_3S_DELAY), null);
@ -206,7 +210,7 @@ function run_test() {
do_check_eq(data, rangeBody); do_check_eq(data, rangeBody);
// Try a successful resume from 0 // Try a successful resume from 0
var chan = make_channel("http://localhost:4444/range"); var chan = make_channel(URL + "/range");
chan.nsIResumableChannel.resumeAt(0, entityID); chan.nsIResumableChannel.resumeAt(0, entityID);
chan.asyncOpen(new ChannelListener(success, null), null); chan.asyncOpen(new ChannelListener(success, null), null);
} }
@ -219,7 +223,7 @@ function run_test() {
// Authentication (no password; working resume) // Authentication (no password; working resume)
// (should not give us any data) // (should not give us any data)
var chan = make_channel("http://localhost:4444/range"); var chan = make_channel(URL + "/range");
chan.nsIResumableChannel.resumeAt(1, entityID); chan.nsIResumableChannel.resumeAt(1, entityID);
chan.nsIHttpChannel.setRequestHeader("X-Need-Auth", "true", false); chan.nsIHttpChannel.setRequestHeader("X-Need-Auth", "true", false);
chan.asyncOpen(new ChannelListener(test_auth_nopw, null, CL_EXPECT_FAILURE), null); chan.asyncOpen(new ChannelListener(test_auth_nopw, null, CL_EXPECT_FAILURE), null);
@ -231,7 +235,8 @@ function run_test() {
do_check_eq(request.status, NS_ERROR_ENTITY_CHANGED); do_check_eq(request.status, NS_ERROR_ENTITY_CHANGED);
// Authentication + not working resume // Authentication + not working resume
var chan = make_channel("http://guest:guest@localhost:4444/auth"); var chan = make_channel("http://guest:guest@localhost:" +
httpserver.identity.primaryPort + "/auth");
chan.nsIResumableChannel.resumeAt(1, entityID); chan.nsIResumableChannel.resumeAt(1, entityID);
chan.notificationCallbacks = new Requestor(); chan.notificationCallbacks = new Requestor();
chan.asyncOpen(new ChannelListener(test_auth, null, CL_EXPECT_FAILURE), null); chan.asyncOpen(new ChannelListener(test_auth, null, CL_EXPECT_FAILURE), null);
@ -242,7 +247,8 @@ function run_test() {
do_check_true(request.nsIHttpChannel.responseStatus < 300); do_check_true(request.nsIHttpChannel.responseStatus < 300);
// Authentication + working resume // Authentication + working resume
var chan = make_channel("http://guest:guest@localhost:4444/range"); var chan = make_channel("http://guest:guest@localhost:" +
httpserver.identity.primaryPort + "/range");
chan.nsIResumableChannel.resumeAt(1, entityID); chan.nsIResumableChannel.resumeAt(1, entityID);
chan.notificationCallbacks = new Requestor(); chan.notificationCallbacks = new Requestor();
chan.nsIHttpChannel.setRequestHeader("X-Need-Auth", "true", false); chan.nsIHttpChannel.setRequestHeader("X-Need-Auth", "true", false);
@ -255,7 +261,7 @@ function run_test() {
do_check_true(request.nsIHttpChannel.requestSucceeded); do_check_true(request.nsIHttpChannel.requestSucceeded);
// 404 page (same content length as real content) // 404 page (same content length as real content)
var chan = make_channel("http://localhost:4444/range"); var chan = make_channel(URL + "/range");
chan.nsIResumableChannel.resumeAt(1, entityID); chan.nsIResumableChannel.resumeAt(1, entityID);
chan.nsIHttpChannel.setRequestHeader("X-Want-404", "true", false); chan.nsIHttpChannel.setRequestHeader("X-Want-404", "true", false);
chan.asyncOpen(new ChannelListener(test_404, null, CL_EXPECT_FAILURE), null); chan.asyncOpen(new ChannelListener(test_404, null, CL_EXPECT_FAILURE), null);
@ -267,7 +273,7 @@ function run_test() {
do_check_eq(request.nsIHttpChannel.responseStatus, 404); do_check_eq(request.nsIHttpChannel.responseStatus, 404);
// 416 Requested Range Not Satisfiable // 416 Requested Range Not Satisfiable
var chan = make_channel("http://localhost:4444/range"); var chan = make_channel(URL + "/range");
chan.nsIResumableChannel.resumeAt(1000, entityID); chan.nsIResumableChannel.resumeAt(1000, entityID);
chan.asyncOpen(new ChannelListener(test_416, null, CL_EXPECT_FAILURE), null); chan.asyncOpen(new ChannelListener(test_416, null, CL_EXPECT_FAILURE), null);
} }
@ -278,8 +284,8 @@ function run_test() {
do_check_eq(request.nsIHttpChannel.responseStatus, 416); do_check_eq(request.nsIHttpChannel.responseStatus, 416);
// Redirect + successful resume // Redirect + successful resume
var chan = make_channel("http://localhost:4444/redir"); var chan = make_channel(URL + "/redir");
chan.nsIHttpChannel.setRequestHeader("X-Redir-To", "http://localhost:4444/range", false); chan.nsIHttpChannel.setRequestHeader("X-Redir-To", URL + "/range", false);
chan.nsIResumableChannel.resumeAt(1, entityID); chan.nsIResumableChannel.resumeAt(1, entityID);
chan.asyncOpen(new ChannelListener(test_redir_resume, null), null); chan.asyncOpen(new ChannelListener(test_redir_resume, null), null);
} }
@ -291,8 +297,8 @@ function run_test() {
do_check_eq(request.nsIHttpChannel.responseStatus, 206); do_check_eq(request.nsIHttpChannel.responseStatus, 206);
// Redirect + failed resume // Redirect + failed resume
var chan = make_channel("http://localhost:4444/redir"); var chan = make_channel(URL + "/redir");
chan.nsIHttpChannel.setRequestHeader("X-Redir-To", "http://localhost:4444/", false); chan.nsIHttpChannel.setRequestHeader("X-Redir-To", URL + "/", false);
chan.nsIResumableChannel.resumeAt(1, entityID); chan.nsIResumableChannel.resumeAt(1, entityID);
chan.asyncOpen(new ChannelListener(test_redir_noresume, null, CL_EXPECT_FAILURE), null); chan.asyncOpen(new ChannelListener(test_redir_noresume, null, CL_EXPECT_FAILURE), null);
} }
@ -304,8 +310,8 @@ function run_test() {
httpserver.stop(do_test_finished); httpserver.stop(do_test_finished);
} }
httpserver.start(4444); httpserver.start(-1);
var chan = make_channel("http://localhost:4444/range"); var chan = make_channel(URL + "/range");
chan.asyncOpen(new ChannelListener(get_entity_id, null), null); chan.asyncOpen(new ChannelListener(get_entity_id, null), null);
do_test_pending(); do_test_pending();
} }

View File

@ -71,21 +71,24 @@ function finish_test() {
} }
function start_cache_read() { function start_cache_read() {
var chan = make_channel("http://localhost:4444/cached/test.gz"); var chan = make_channel("http://localhost:" +
httpserver.identity.primaryPort + "/cached/test.gz");
chan.asyncOpen(new ChannelListener(finish_test, null), null); chan.asyncOpen(new ChannelListener(finish_test, null), null);
} }
function start_canceler() { function start_canceler() {
var chan = make_channel("http://localhost:4444/cached/test.gz"); var chan = make_channel("http://localhost:" +
httpserver.identity.primaryPort + "/cached/test.gz");
chan.asyncOpen(new Canceler(start_cache_read), null); chan.asyncOpen(new Canceler(start_cache_read), null);
} }
function run_test() { function run_test() {
httpserver = new HttpServer(); httpserver = new HttpServer();
httpserver.registerPathHandler("/cached/test.gz", cachedHandler); httpserver.registerPathHandler("/cached/test.gz", cachedHandler);
httpserver.start(4444); httpserver.start(-1);
var chan = make_channel("http://localhost:4444/cached/test.gz"); var chan = make_channel("http://localhost:" +
httpserver.identity.primaryPort + "/cached/test.gz");
chan.asyncOpen(new ChannelListener(start_canceler, null), null); chan.asyncOpen(new ChannelListener(start_canceler, null), null);
do_test_pending(); do_test_pending();
} }

View File

@ -26,7 +26,7 @@ function run_test() {
function setup_test() { function setup_test() {
if (dbg) { print("============== setup_test: in"); } if (dbg) { print("============== setup_test: in"); }
httpserver.registerPathHandler(testpath, serverHandler); httpserver.registerPathHandler(testpath, serverHandler);
httpserver.start(4444); httpserver.start(-1);
var channel = setupChannel(testpath); var channel = setupChannel(testpath);
// ChannelListener defined in head_channels.js // ChannelListener defined in head_channels.js
channel.asyncOpen(new ChannelListener(checkRequest, channel), null); channel.asyncOpen(new ChannelListener(checkRequest, channel), null);
@ -36,7 +36,8 @@ function setup_test() {
function setupChannel(path) { function setupChannel(path) {
var ios = Cc["@mozilla.org/network/io-service;1"]. var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService); getService(Ci.nsIIOService);
var chan = ios.newChannel("http://localhost:4444" + path, "", null); var chan = ios.newChannel("http://localhost:" +
httpserver.identity.primaryPort + path, "", null);
chan.QueryInterface(Ci.nsIHttpChannel); chan.QueryInterface(Ci.nsIHttpChannel);
chan.requestMethod = "GET"; chan.requestMethod = "GET";
return chan; return chan;

View File

@ -9,7 +9,7 @@ const ServerSocket = CC("@mozilla.org/network/server-socket;1",
var serv; var serv;
function TestServer() { function TestServer() {
this.listener = ServerSocket(4444, true, -1); this.listener = ServerSocket(-1, true, -1);
this.listener.asyncListen(this); this.listener.asyncListen(this);
} }
@ -34,7 +34,7 @@ function run_test() {
.getService(Ci.nsIIOService); .getService(Ci.nsIIOService);
serv = new TestServer(); serv = new TestServer();
URI = ios.newURI("http://localhost:4444/just/a/test", null, null); URI = ios.newURI("http://localhost:" + serv.listener.port + "/just/a/test", null, null);
ios.QueryInterface(Components.interfaces.nsISpeculativeConnect) ios.QueryInterface(Components.interfaces.nsISpeculativeConnect)
.speculativeConnect(URI, null); .speculativeConnect(URI, null);
do_test_pending(); do_test_pending();

View File

@ -10,7 +10,10 @@ const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://testing-common/httpd.js");
var httpserver = null; var httpserver = new HttpServer();
httpserver.start(-1);
const PORT = httpserver.identity.primaryPort;
var pipe = null; var pipe = null;
var streamSink = null; var streamSink = null;
@ -31,9 +34,9 @@ TracingListener.prototype = {
/* /*
do_check_eq(request.localAddress, "127.0.0.1"); do_check_eq(request.localAddress, "127.0.0.1");
do_check_eq(request.localPort > 0, true); do_check_eq(request.localPort > 0, true);
do_check_neq(request.localPort, 4444); do_check_neq(request.localPort, PORT);
do_check_eq(request.remoteAddress, "127.0.0.1"); do_check_eq(request.remoteAddress, "127.0.0.1");
do_check_eq(request.remotePort, 4444); do_check_eq(request.remotePort, PORT);
*/ */
// Make sure listener can't be replaced after OnStartRequest was called. // Make sure listener can't be replaced after OnStartRequest was called.
@ -147,11 +150,9 @@ function run_test() {
var observer = new HttpResponseExaminer(); var observer = new HttpResponseExaminer();
observer.register(); observer.register();
httpserver = new HttpServer();
httpserver.registerPathHandler("/testdir", test_handler); httpserver.registerPathHandler("/testdir", test_handler);
httpserver.start(4444);
var channel = make_channel("http://localhost:4444/testdir"); var channel = make_channel("http://localhost:" + PORT + "/testdir");
channel.asyncOpen(new ChannelListener(channel_finished), null); channel.asyncOpen(new ChannelListener(channel_finished), null);
do_test_pending(); do_test_pending();
} }

View File

@ -13,7 +13,8 @@ function createXHR(async)
{ {
var xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] var xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
.createInstance(Ci.nsIXMLHttpRequest); .createInstance(Ci.nsIXMLHttpRequest);
xhr.open("GET", "http://localhost:4444" + testpath, async); xhr.open("GET", "http://localhost:" +
httpserver.identity.primaryPort + testpath, async);
return xhr; return xhr;
} }
@ -33,7 +34,7 @@ function checkResults(xhr)
function run_test() function run_test()
{ {
httpserver.registerPathHandler(testpath, serverHandler); httpserver.registerPathHandler(testpath, serverHandler);
httpserver.start(4444); httpserver.start(-1);
// Test sync XHR sending // Test sync XHR sending
var sync = createXHR(false); var sync = createXHR(false);

View File

@ -185,7 +185,9 @@ run-if = hasNode
[test_XHR_redirects.js] [test_XHR_redirects.js]
[test_pinned_app_cache.js] [test_pinned_app_cache.js]
[test_offlinecache_custom-directory.js] [test_offlinecache_custom-directory.js]
run-sequentially = Hardcoded hash value includes port 4444.
[test_bug767025.js] [test_bug767025.js]
run-sequentially = Hardcoded hash value includes port 4444.
[test_bug826063.js] [test_bug826063.js]
[test_bug812167.js] [test_bug812167.js]
[test_tldservice_nextsubdomain.js] [test_tldservice_nextsubdomain.js]

View File

@ -2,5 +2,7 @@
// Load standard base class for network tests into child process // Load standard base class for network tests into child process
// //
Components.utils.import('resource://gre/modules/XPCOMUtils.jsm');
load("../unit/head_channels.js"); load("../unit/head_channels.js");