зеркало из https://github.com/mozilla/gecko-dev.git
Bug 381598 - HTTP server tests cleanup. r=me because I don't think it's a good use of anyone's time to disentangle the tests as they were written prior to this checkin
This commit is contained in:
Родитель
4a6ba4660c
Коммит
8b5c72c8ea
|
@ -38,98 +38,19 @@
|
|||
|
||||
// basic functionality test, from the client programmer's POV
|
||||
|
||||
|
||||
var paths =
|
||||
var tests =
|
||||
[
|
||||
"http://localhost:4444/objHandler",
|
||||
"http://localhost:4444/functionHandler",
|
||||
"http://localhost:4444/non-existent-path" // intended to produce 404
|
||||
new Test("http://localhost:4444/objHandler",
|
||||
null, start_objHandler, null),
|
||||
new Test("http://localhost:4444/functionHandler",
|
||||
null, start_functionHandler, null),
|
||||
new Test("http://localhost:4444/non-existent-path",
|
||||
null, start_non_existent_path, null),
|
||||
];
|
||||
var currPathIndex = 0;
|
||||
|
||||
var listener =
|
||||
{
|
||||
// NSISTREAMLISTENER
|
||||
onDataAvailable: function(request, cx, inputStream, offset, count)
|
||||
{
|
||||
makeBIS(inputStream).readByteArray(count); // required by API
|
||||
},
|
||||
// NSIREQUESTOBSERVER
|
||||
onStartRequest: function(request, cx)
|
||||
{
|
||||
var ch = request.QueryInterface(Ci.nsIHttpChannel)
|
||||
.QueryInterface(Ci.nsIHttpChannelInternal);
|
||||
|
||||
// common properties *always* appended by server or invariants for every
|
||||
// URL in paths
|
||||
do_check_true(ch.contentLength > -1);
|
||||
do_check_eq(ch.getResponseHeader("connection"), "close");
|
||||
do_check_false(ch.isNoStoreResponse());
|
||||
|
||||
var reqMin = {}, reqMaj = {}, respMin = {}, respMaj = {};
|
||||
switch (currPathIndex)
|
||||
{
|
||||
case 0:
|
||||
do_check_eq(ch.responseStatus, 200);
|
||||
do_check_true(ch.requestSucceeded);
|
||||
do_check_eq(ch.getResponseHeader("content-type"), "text/plain");
|
||||
do_check_eq(ch.responseStatusText, "OK");
|
||||
|
||||
ch.getRequestVersion(reqMaj, reqMin);
|
||||
ch.getResponseVersion(respMaj, respMin);
|
||||
do_check_true(reqMaj.value == respMaj.value &&
|
||||
reqMin.value == respMin.value);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
do_check_eq(ch.responseStatus, 404);
|
||||
do_check_false(ch.requestSucceeded);
|
||||
do_check_eq(ch.getResponseHeader("foopy"), "quux-baz");
|
||||
do_check_eq(ch.responseStatusText, "Page Not Found");
|
||||
|
||||
ch.getResponseVersion(respMaj, respMin);
|
||||
do_check_true(respMaj.value == 1 && respMin.value == 1);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
do_check_eq(ch.responseStatus, 404);
|
||||
do_check_false(ch.requestSucceeded);
|
||||
break;
|
||||
}
|
||||
},
|
||||
onStopRequest: function(request, cx, status)
|
||||
{
|
||||
if (++currPathIndex == paths.length)
|
||||
srv.stop();
|
||||
else
|
||||
performNextTest();
|
||||
do_test_finished();
|
||||
},
|
||||
// NSISUPPORTS
|
||||
QueryInterface: function(aIID)
|
||||
{
|
||||
if (aIID.equals(Ci.nsIStreamListener) ||
|
||||
aIID.equals(Ci.nsIRequestObserver) ||
|
||||
aIID.equals(Ci.nsISupports))
|
||||
return this;
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function performNextTest()
|
||||
{
|
||||
do_test_pending();
|
||||
|
||||
var ch = makeChannel(paths[currPathIndex]);
|
||||
ch.asyncOpen(listener, null);
|
||||
}
|
||||
|
||||
var srv;
|
||||
|
||||
function run_test()
|
||||
{
|
||||
srv = createServer();
|
||||
var srv = createServer();
|
||||
|
||||
// base path
|
||||
// XXX should actually test this works with a file by comparing streams!
|
||||
|
@ -144,9 +65,59 @@ function run_test()
|
|||
|
||||
srv.start(4444);
|
||||
|
||||
performNextTest();
|
||||
runHttpTests(tests, function() { srv.stop(); });
|
||||
}
|
||||
|
||||
|
||||
// TEST DATA
|
||||
|
||||
// common properties *always* appended by server
|
||||
// or invariants for every URL in paths
|
||||
function commonCheck(ch)
|
||||
{
|
||||
do_check_true(ch.contentLength > -1);
|
||||
do_check_eq(ch.getResponseHeader("connection"), "close");
|
||||
do_check_false(ch.isNoStoreResponse());
|
||||
}
|
||||
|
||||
function start_objHandler(ch, cx)
|
||||
{
|
||||
commonCheck(ch);
|
||||
|
||||
do_check_eq(ch.responseStatus, 200);
|
||||
do_check_true(ch.requestSucceeded);
|
||||
do_check_eq(ch.getResponseHeader("content-type"), "text/plain");
|
||||
do_check_eq(ch.responseStatusText, "OK");
|
||||
|
||||
var reqMin = {}, reqMaj = {}, respMin = {}, respMaj = {};
|
||||
ch.getRequestVersion(reqMaj, reqMin);
|
||||
ch.getResponseVersion(respMaj, respMin);
|
||||
do_check_true(reqMaj.value == respMaj.value &&
|
||||
reqMin.value == respMin.value);
|
||||
}
|
||||
|
||||
function start_functionHandler(ch, cx)
|
||||
{
|
||||
commonCheck(ch);
|
||||
|
||||
do_check_eq(ch.responseStatus, 404);
|
||||
do_check_false(ch.requestSucceeded);
|
||||
do_check_eq(ch.getResponseHeader("foopy"), "quux-baz");
|
||||
do_check_eq(ch.responseStatusText, "Page Not Found");
|
||||
|
||||
ch.getResponseVersion(respMaj, respMin);
|
||||
do_check_true(respMaj.value == 1 && respMin.value == 1);
|
||||
}
|
||||
|
||||
function start_non_existent_path(ch, cx)
|
||||
{
|
||||
commonCheck(ch);
|
||||
|
||||
do_check_eq(ch.responseStatus, 404);
|
||||
do_check_false(ch.requestSucceeded);
|
||||
}
|
||||
|
||||
|
||||
// PATH HANDLERS
|
||||
|
||||
// /objHandler
|
||||
|
|
|
@ -39,60 +39,17 @@
|
|||
// in its original incarnation, the server didn't like empty response-bodies;
|
||||
// see the comment in _end for details
|
||||
|
||||
var paths =
|
||||
var tests =
|
||||
[
|
||||
"http://localhost:4444/empty-body-unwritten",
|
||||
"http://localhost:4444/empty-body-written"
|
||||
new Test("http://localhost:4444/empty-body-unwritten",
|
||||
null, ensureEmpty, null),
|
||||
new Test("http://localhost:4444/empty-body-written",
|
||||
null, ensureEmpty, null),
|
||||
];
|
||||
var currPathIndex = 0;
|
||||
|
||||
var listener =
|
||||
{
|
||||
// NSISTREAMLISTENER
|
||||
onDataAvailable: function(request, cx, inputStream, offset, count)
|
||||
{
|
||||
makeBIS(inputStream).readByteArray(count); // required by API
|
||||
},
|
||||
// NSIREQUESTOBSERVER
|
||||
onStartRequest: function(request, cx)
|
||||
{
|
||||
var ch = request.QueryInterface(Ci.nsIHttpChannel)
|
||||
.QueryInterface(Ci.nsIHttpChannelInternal);
|
||||
do_check_true(ch.contentLength == 0);
|
||||
},
|
||||
onStopRequest: function(request, cx, status)
|
||||
{
|
||||
if (++currPathIndex == paths.length)
|
||||
srv.stop();
|
||||
else
|
||||
performNextTest();
|
||||
do_test_finished();
|
||||
},
|
||||
// NSISUPPORTS
|
||||
QueryInterface: function(aIID)
|
||||
{
|
||||
if (aIID.equals(Ci.nsIStreamListener) ||
|
||||
aIID.equals(Ci.nsIRequestObserver) ||
|
||||
aIID.equals(Ci.nsISupports))
|
||||
return this;
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function performNextTest()
|
||||
{
|
||||
do_test_pending();
|
||||
|
||||
var ch = makeChannel(paths[currPathIndex]);
|
||||
ch.asyncOpen(listener, null);
|
||||
}
|
||||
|
||||
var srv;
|
||||
|
||||
function run_test()
|
||||
{
|
||||
srv = createServer();
|
||||
var srv = createServer();
|
||||
|
||||
// register a few test paths
|
||||
srv.registerPathHandler("/empty-body-unwritten", emptyBodyUnwritten);
|
||||
|
@ -100,7 +57,14 @@ function run_test()
|
|||
|
||||
srv.start(4444);
|
||||
|
||||
performNextTest();
|
||||
runHttpTests(tests, function() { srv.stop(); });
|
||||
}
|
||||
|
||||
// TEST DATA
|
||||
|
||||
function ensureEmpty(ch, cx)
|
||||
{
|
||||
do_check_true(ch.contentLength == 0);
|
||||
}
|
||||
|
||||
// PATH HANDLERS
|
||||
|
|
|
@ -39,94 +39,15 @@
|
|||
// Request handlers may throw exceptions, and those exception should be caught
|
||||
// by the server and converted into the proper error codes.
|
||||
|
||||
var paths =
|
||||
var tests =
|
||||
[
|
||||
"http://localhost:4444/throws/exception",
|
||||
"http://localhost:4444/this/file/does/not/exist/and/404s",
|
||||
"http://localhost:4444/attempts/404/fails/so/400/fails/so/500s"
|
||||
new Test("http://localhost:4444/throws/exception",
|
||||
null, start_throws_exception, succeeded),
|
||||
new Test("http://localhost:4444/this/file/does/not/exist/and/404s",
|
||||
null, start_nonexistent_404_fails_so_400, succeeded),
|
||||
new Test("http://localhost:4444/attempts/404/fails/so/400/fails/so/500s",
|
||||
register400Handler, start_multiple_exceptions_500, succeeded),
|
||||
];
|
||||
var currPathIndex = 0;
|
||||
|
||||
var listener =
|
||||
{
|
||||
// NSISTREAMLISTENER
|
||||
onDataAvailable: function(request, cx, inputStream, offset, count)
|
||||
{
|
||||
makeBIS(inputStream).readByteArray(count); // required by API
|
||||
},
|
||||
// NSIREQUESTOBSERVER
|
||||
onStartRequest: function(request, cx)
|
||||
{
|
||||
var ch = request.QueryInterface(Ci.nsIHttpChannel)
|
||||
.QueryInterface(Ci.nsIHttpChannelInternal);
|
||||
|
||||
switch (currPathIndex)
|
||||
{
|
||||
case 0:
|
||||
checkStatusLine(ch, 1, 1, 500, "Internal Server Error");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
checkStatusLine(ch, 1, 1, 400, "Bad Request");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
checkStatusLine(ch, 1, 1, 500, "Internal Server Error");
|
||||
break;
|
||||
}
|
||||
},
|
||||
onStopRequest: function(request, cx, status)
|
||||
{
|
||||
do_check_true(Components.isSuccessCode(status));
|
||||
|
||||
switch (currPathIndex)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 1:
|
||||
srv.registerErrorHandler(400, throwsException);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
break;
|
||||
}
|
||||
|
||||
if (++currPathIndex == paths.length)
|
||||
srv.stop();
|
||||
else
|
||||
performNextTest();
|
||||
do_test_finished();
|
||||
},
|
||||
// NSISUPPORTS
|
||||
QueryInterface: function(aIID)
|
||||
{
|
||||
if (aIID.equals(Ci.nsIStreamListener) ||
|
||||
aIID.equals(Ci.nsIRequestObserver) ||
|
||||
aIID.equals(Ci.nsISupports))
|
||||
return this;
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
function checkStatusLine(channel, httpMaxVer, httpMinVer, httpCode, statusText)
|
||||
{
|
||||
do_check_eq(channel.responseStatus, httpCode);
|
||||
do_check_eq(channel.responseStatusText, statusText);
|
||||
|
||||
var respMaj = {}, respMin = {};
|
||||
channel.getResponseVersion(respMaj, respMin);
|
||||
do_check_eq(respMaj.value, httpMaxVer);
|
||||
do_check_eq(respMin.value, httpMinVer);
|
||||
}
|
||||
|
||||
function performNextTest()
|
||||
{
|
||||
do_test_pending();
|
||||
|
||||
var ch = makeChannel(paths[currPathIndex]);
|
||||
ch.asyncOpen(listener, null);
|
||||
}
|
||||
|
||||
var srv;
|
||||
|
||||
|
@ -139,9 +60,49 @@ function run_test()
|
|||
|
||||
srv.start(4444);
|
||||
|
||||
performNextTest();
|
||||
runHttpTests(tests, function() { srv.stop(); });
|
||||
}
|
||||
|
||||
|
||||
// TEST DATA
|
||||
|
||||
function checkStatusLine(channel, httpMaxVer, httpMinVer, httpCode, statusText)
|
||||
{
|
||||
do_check_eq(channel.responseStatus, httpCode);
|
||||
do_check_eq(channel.responseStatusText, statusText);
|
||||
|
||||
var respMaj = {}, respMin = {};
|
||||
channel.getResponseVersion(respMaj, respMin);
|
||||
do_check_eq(respMaj.value, httpMaxVer);
|
||||
do_check_eq(respMin.value, httpMinVer);
|
||||
}
|
||||
|
||||
function start_throws_exception(ch, cx)
|
||||
{
|
||||
checkStatusLine(ch, 1, 1, 500, "Internal Server Error");
|
||||
}
|
||||
|
||||
function start_nonexistent_404_fails_so_400(ch, cx)
|
||||
{
|
||||
checkStatusLine(ch, 1, 1, 400, "Bad Request");
|
||||
}
|
||||
|
||||
function start_multiple_exceptions_500(ch, cx)
|
||||
{
|
||||
checkStatusLine(ch, 1, 1, 500, "Internal Server Error");
|
||||
}
|
||||
|
||||
function succeeded(ch, cx, status, data)
|
||||
{
|
||||
do_check_true(Components.isSuccessCode(status));
|
||||
}
|
||||
|
||||
function register400Handler(ch)
|
||||
{
|
||||
srv.registerErrorHandler(400, throwsException);
|
||||
}
|
||||
|
||||
|
||||
// PATH HANDLERS
|
||||
|
||||
// /throws/exception (and also a 404 and 400 error handler)
|
||||
|
|
|
@ -40,245 +40,275 @@
|
|||
|
||||
const BASE = "http://localhost:4444";
|
||||
|
||||
var paths =
|
||||
[
|
||||
/* 0*/ BASE + "/test_registerdirectory.js", // without a base path
|
||||
/* 1*/ BASE + "/test_registerdirectory.js", // with a base path
|
||||
/* 2*/ BASE + "/test_registerdirectory.js", // without a base path
|
||||
var tests = [];
|
||||
var test;
|
||||
|
||||
/* 3*/ BASE + "/test_registerdirectory.js", // no registered path handler
|
||||
/* 4*/ BASE + "/test_registerdirectory.js", // registered path handler
|
||||
/* 5*/ BASE + "/test_registerdirectory.js", // removed path handler
|
||||
|
||||
/* 6*/ BASE + "/test_registerdirectory.js", // with a base path
|
||||
/* 7*/ BASE + "/test_registerdirectory.js", // ...and a path handler
|
||||
/* 8*/ BASE + "/test_registerdirectory.js", // removed base handler
|
||||
/* 9*/ BASE + "/test_registerdirectory.js", // removed path handler
|
||||
|
||||
/*10*/ BASE + "/foo/test_registerdirectory.js", // mapping set up, works
|
||||
/*11*/ BASE + "/foo/test_registerdirectory.js/test_registerdirectory.js", // no mapping, fails
|
||||
/*12*/ BASE + "/foo/test_registerdirectory.js/test_registerdirectory.js", // mapping, works
|
||||
/*13*/ BASE + "/foo/test_registerdirectory.js", // two mappings set up, still works
|
||||
/*14*/ BASE + "/foo/test_registerdirectory.js", // mapping was removed
|
||||
/*15*/ BASE + "/foo/test_registerdirectory.js/test_registerdirectory.js", // mapping still present, works
|
||||
/*16*/ BASE + "/foo/test_registerdirectory.js/test_registerdirectory.js", // mapping removed
|
||||
];
|
||||
var currPathIndex = 0;
|
||||
|
||||
var listener =
|
||||
function nocache(ch)
|
||||
{
|
||||
// NSISTREAMLISTENER
|
||||
onDataAvailable: function(request, cx, inputStream, offset, count)
|
||||
{
|
||||
makeBIS(inputStream).readByteArray(count); // required by API
|
||||
},
|
||||
// NSIREQUESTOBSERVER
|
||||
onStartRequest: function(request, cx)
|
||||
{
|
||||
var ch = request.QueryInterface(Ci.nsIHttpChannel);
|
||||
|
||||
switch (currPathIndex)
|
||||
{
|
||||
case 0:
|
||||
do_check_eq(ch.responseStatus, 404);
|
||||
do_check_false(ch.requestSucceeded);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
do_check_eq(ch.responseStatus, 200);
|
||||
do_check_true(ch.requestSucceeded);
|
||||
|
||||
var actualFile = serverBasePath.clone();
|
||||
actualFile.append("test_registerdirectory.js");
|
||||
do_check_eq(ch.getResponseHeader("Content-Length"),
|
||||
actualFile.fileSize.toString());
|
||||
break;
|
||||
|
||||
case 2:
|
||||
do_check_eq(ch.responseStatus, 404);
|
||||
do_check_false(ch.requestSucceeded);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
do_check_eq(ch.responseStatus, 404);
|
||||
do_check_false(ch.requestSucceeded);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
do_check_eq(ch.responseStatus, 200);
|
||||
do_check_eq(ch.responseStatusText, "OK");
|
||||
do_check_true(ch.requestSucceeded);
|
||||
do_check_eq(ch.getResponseHeader("Override-Succeeded"), "yes");
|
||||
break;
|
||||
|
||||
case 5:
|
||||
do_check_eq(ch.responseStatus, 404);
|
||||
do_check_false(ch.requestSucceeded);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
do_check_eq(ch.responseStatus, 200);
|
||||
do_check_true(ch.requestSucceeded);
|
||||
|
||||
var actualFile = serverBasePath.clone();
|
||||
actualFile.append("test_registerdirectory.js");
|
||||
do_check_eq(ch.getResponseHeader("Content-Length"),
|
||||
actualFile.fileSize.toString());
|
||||
break;
|
||||
|
||||
case 7:
|
||||
case 8:
|
||||
do_check_eq(ch.responseStatus, 200);
|
||||
do_check_eq(ch.responseStatusText, "OK");
|
||||
do_check_true(ch.requestSucceeded);
|
||||
do_check_eq(ch.getResponseHeader("Override-Succeeded"), "yes");
|
||||
break;
|
||||
|
||||
case 9:
|
||||
do_check_eq(ch.responseStatus, 404);
|
||||
do_check_false(ch.requestSucceeded);
|
||||
break;
|
||||
|
||||
case 10:
|
||||
do_check_eq(ch.responseStatus, 200);
|
||||
do_check_eq(ch.responseStatusText, "OK");
|
||||
break;
|
||||
|
||||
case 11:
|
||||
do_check_eq(ch.responseStatus, 404);
|
||||
do_check_false(ch.requestSucceeded);
|
||||
break;
|
||||
|
||||
case 12:
|
||||
case 13:
|
||||
do_check_eq(ch.responseStatus, 200);
|
||||
do_check_eq(ch.responseStatusText, "OK");
|
||||
break;
|
||||
|
||||
case 14:
|
||||
do_check_eq(ch.responseStatus, 404);
|
||||
do_check_false(ch.requestSucceeded);
|
||||
break;
|
||||
|
||||
case 15:
|
||||
do_check_eq(ch.responseStatus, 200);
|
||||
do_check_eq(ch.responseStatusText, "OK");
|
||||
break;
|
||||
|
||||
case 16:
|
||||
do_check_eq(ch.responseStatus, 404);
|
||||
do_check_false(ch.requestSucceeded);
|
||||
break;
|
||||
ch.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE; // important!
|
||||
}
|
||||
},
|
||||
onStopRequest: function(request, cx, status)
|
||||
|
||||
function notFound(ch)
|
||||
{
|
||||
switch (currPathIndex)
|
||||
do_check_eq(ch.responseStatus, 404);
|
||||
do_check_false(ch.requestSucceeded);
|
||||
}
|
||||
|
||||
function checkOverride(ch)
|
||||
{
|
||||
case 0:
|
||||
// now set a base path
|
||||
do_check_eq(ch.responseStatus, 200);
|
||||
do_check_eq(ch.responseStatusText, "OK");
|
||||
do_check_true(ch.requestSucceeded);
|
||||
do_check_eq(ch.getResponseHeader("Override-Succeeded"), "yes");
|
||||
}
|
||||
|
||||
function check200(ch)
|
||||
{
|
||||
do_check_eq(ch.responseStatus, 200);
|
||||
do_check_eq(ch.responseStatusText, "OK");
|
||||
}
|
||||
|
||||
function checkFile(ch)
|
||||
{
|
||||
do_check_eq(ch.responseStatus, 200);
|
||||
do_check_true(ch.requestSucceeded);
|
||||
|
||||
var actualFile = serverBasePath.clone();
|
||||
actualFile.append("test_registerdirectory.js");
|
||||
do_check_eq(ch.getResponseHeader("Content-Length"),
|
||||
actualFile.fileSize.toString());
|
||||
}
|
||||
|
||||
|
||||
/***********************
|
||||
* without a base path *
|
||||
***********************/
|
||||
|
||||
test = new Test(BASE + "/test_registerdirectory.js",
|
||||
nocache, notFound, null),
|
||||
tests.push(test);
|
||||
|
||||
|
||||
/********************
|
||||
* with a base path *
|
||||
********************/
|
||||
|
||||
test = new Test(BASE + "/test_registerdirectory.js",
|
||||
function(ch)
|
||||
{
|
||||
nocache(ch);
|
||||
serverBasePath = testsDirectory.clone();
|
||||
srv.registerDirectory("/", serverBasePath);
|
||||
break;
|
||||
},
|
||||
checkFile,
|
||||
null);
|
||||
tests.push(test);
|
||||
|
||||
case 1:
|
||||
// remove base path
|
||||
|
||||
/*****************************
|
||||
* without a base path again *
|
||||
*****************************/
|
||||
|
||||
test = new Test(BASE + "/test_registerdirectory.js",
|
||||
function(ch)
|
||||
{
|
||||
nocache(ch);
|
||||
serverBasePath = null;
|
||||
srv.registerDirectory("/", serverBasePath);
|
||||
break;
|
||||
},
|
||||
notFound,
|
||||
null);
|
||||
tests.push(test);
|
||||
|
||||
case 3:
|
||||
// register overriding path
|
||||
|
||||
/***************************
|
||||
* registered path handler *
|
||||
***************************/
|
||||
|
||||
test = new Test(BASE + "/test_registerdirectory.js",
|
||||
function(ch)
|
||||
{
|
||||
nocache(ch);
|
||||
srv.registerPathHandler("/test_registerdirectory.js",
|
||||
override_test_registerdirectory);
|
||||
break;
|
||||
},
|
||||
checkOverride,
|
||||
null);
|
||||
tests.push(test);
|
||||
|
||||
case 4:
|
||||
// unregister overriding path
|
||||
|
||||
/************************
|
||||
* removed path handler *
|
||||
************************/
|
||||
|
||||
test = new Test(BASE + "/test_registerdirectory.js",
|
||||
function init_registerDirectory6(ch)
|
||||
{
|
||||
nocache(ch);
|
||||
srv.registerPathHandler("/test_registerdirectory.js", null);
|
||||
break;
|
||||
},
|
||||
notFound,
|
||||
null);
|
||||
tests.push(test);
|
||||
|
||||
|
||||
/********************
|
||||
* with a base path *
|
||||
********************/
|
||||
|
||||
test = new Test(BASE + "/test_registerdirectory.js",
|
||||
function(ch)
|
||||
{
|
||||
nocache(ch);
|
||||
|
||||
case 5:
|
||||
// set the base path again
|
||||
serverBasePath = testsDirectory.clone();
|
||||
srv.registerDirectory("/", serverBasePath);
|
||||
break;
|
||||
},
|
||||
checkFile,
|
||||
null);
|
||||
tests.push(test);
|
||||
|
||||
case 6:
|
||||
// register overriding path
|
||||
|
||||
/*************************
|
||||
* ...and a path handler *
|
||||
*************************/
|
||||
|
||||
test = new Test(BASE + "/test_registerdirectory.js",
|
||||
function(ch)
|
||||
{
|
||||
nocache(ch);
|
||||
srv.registerPathHandler("/test_registerdirectory.js",
|
||||
override_test_registerdirectory);
|
||||
break;
|
||||
},
|
||||
checkOverride,
|
||||
null);
|
||||
tests.push(test);
|
||||
|
||||
case 7:
|
||||
// remove base path
|
||||
|
||||
/************************
|
||||
* removed base handler *
|
||||
************************/
|
||||
|
||||
test = new Test(BASE + "/test_registerdirectory.js",
|
||||
function(ch)
|
||||
{
|
||||
nocache(ch);
|
||||
serverBasePath = null;
|
||||
srv.registerDirectory("/", serverBasePath);
|
||||
break;
|
||||
},
|
||||
checkOverride,
|
||||
null);
|
||||
tests.push(test);
|
||||
|
||||
case 8:
|
||||
// unregister overriding path
|
||||
|
||||
/************************
|
||||
* removed path handler *
|
||||
************************/
|
||||
|
||||
test = new Test(BASE + "/test_registerdirectory.js",
|
||||
function(ch)
|
||||
{
|
||||
nocache(ch);
|
||||
srv.registerPathHandler("/test_registerdirectory.js", null);
|
||||
break;
|
||||
},
|
||||
notFound,
|
||||
null);
|
||||
tests.push(test);
|
||||
|
||||
case 9:
|
||||
// register /foo/ as a base path
|
||||
|
||||
/*************************
|
||||
* mapping set up, works *
|
||||
*************************/
|
||||
|
||||
test = new Test(BASE + "/foo/test_registerdirectory.js",
|
||||
function(ch)
|
||||
{
|
||||
nocache(ch);
|
||||
serverBasePath = testsDirectory.clone();
|
||||
srv.registerDirectory("/foo/", serverBasePath);
|
||||
break;
|
||||
|
||||
case 10:
|
||||
// do nothing
|
||||
break;
|
||||
|
||||
case 11:
|
||||
// now register an overriding path to handle the URL that just failed
|
||||
srv.registerDirectory("/foo/test_registerdirectory.js/", serverBasePath);
|
||||
break;
|
||||
|
||||
case 12:
|
||||
// do nothing
|
||||
break;
|
||||
|
||||
case 13:
|
||||
srv.registerDirectory("/foo/", null);
|
||||
break;
|
||||
|
||||
case 14:
|
||||
// do nothing
|
||||
break;
|
||||
|
||||
case 15:
|
||||
srv.registerDirectory("/foo/test_registerdirectory.js/", null);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!paths[++currPathIndex])
|
||||
srv.stop();
|
||||
else
|
||||
performNextTest();
|
||||
|
||||
do_test_finished();
|
||||
},
|
||||
// NSISUPPORTS
|
||||
QueryInterface: function(aIID)
|
||||
{
|
||||
if (aIID.equals(Ci.nsIStreamListener) ||
|
||||
aIID.equals(Ci.nsIRequestObserver) ||
|
||||
aIID.equals(Ci.nsISupports))
|
||||
return this;
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
check200,
|
||||
null);
|
||||
tests.push(test);
|
||||
|
||||
|
||||
/*********************
|
||||
* no mapping, fails *
|
||||
*********************/
|
||||
|
||||
test = new Test(BASE + "/foo/test_registerdirectory.js/test_registerdirectory.js",
|
||||
nocache,
|
||||
notFound,
|
||||
null);
|
||||
tests.push(test);
|
||||
|
||||
|
||||
/******************
|
||||
* mapping, works *
|
||||
******************/
|
||||
|
||||
test = new Test(BASE + "/foo/test_registerdirectory.js/test_registerdirectory.js",
|
||||
function(ch)
|
||||
{
|
||||
nocache(ch);
|
||||
srv.registerDirectory("/foo/test_registerdirectory.js/",
|
||||
serverBasePath);
|
||||
},
|
||||
checkFile,
|
||||
null);
|
||||
tests.push(test);
|
||||
|
||||
|
||||
/************************************
|
||||
* two mappings set up, still works *
|
||||
************************************/
|
||||
|
||||
test = new Test(BASE + "/foo/test_registerdirectory.js",
|
||||
nocache, checkFile, null);
|
||||
tests.push(test);
|
||||
|
||||
|
||||
/**************************
|
||||
* remove topmost mapping *
|
||||
**************************/
|
||||
|
||||
test = new Test(BASE + "/foo/test_registerdirectory.js",
|
||||
function(ch)
|
||||
{
|
||||
nocache(ch);
|
||||
srv.registerDirectory("/foo/", null);
|
||||
},
|
||||
notFound,
|
||||
null);
|
||||
tests.push(test);
|
||||
|
||||
|
||||
/**************************************
|
||||
* lower mapping still present, works *
|
||||
**************************************/
|
||||
|
||||
test = new Test(BASE + "/foo/test_registerdirectory.js/test_registerdirectory.js",
|
||||
nocache, checkFile, null);
|
||||
tests.push(test);
|
||||
|
||||
|
||||
/*******************
|
||||
* mapping removed *
|
||||
*******************/
|
||||
|
||||
test = new Test(BASE + "/foo/test_registerdirectory.js/test_registerdirectory.js",
|
||||
function(ch)
|
||||
{
|
||||
nocache(ch);
|
||||
srv.registerDirectory("/foo/test_registerdirectory.js/", null);
|
||||
},
|
||||
notFound,
|
||||
null);
|
||||
tests.push(test);
|
||||
|
||||
function performNextTest()
|
||||
{
|
||||
do_test_pending();
|
||||
|
||||
var ch = makeChannel(paths[currPathIndex]);
|
||||
ch.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE; // important!
|
||||
ch.asyncOpen(listener, null);
|
||||
}
|
||||
|
||||
var srv;
|
||||
var serverBasePath;
|
||||
|
@ -291,9 +321,10 @@ function run_test()
|
|||
srv = createServer();
|
||||
srv.start(4444);
|
||||
|
||||
performNextTest();
|
||||
runHttpTests(tests, function() { srv.stop(); });
|
||||
}
|
||||
|
||||
|
||||
// PATH HANDLERS
|
||||
|
||||
// override of /test_registerdirectory.js
|
||||
|
|
|
@ -38,78 +38,40 @@
|
|||
|
||||
// make sure response.write works for strings, and coerces other args to strings
|
||||
|
||||
var paths =
|
||||
var tests =
|
||||
[
|
||||
"http://localhost:4444/writeString",
|
||||
"http://localhost:4444/writeInt"
|
||||
new Test("http://localhost:4444/writeString",
|
||||
null, check_1234, succeeded),
|
||||
new Test("http://localhost:4444/writeInt",
|
||||
null, check_1234, succeeded),
|
||||
];
|
||||
var currPathIndex = 0;
|
||||
|
||||
var listener =
|
||||
{
|
||||
// NSISTREAMLISTENER
|
||||
onDataAvailable: function(request, cx, inputStream, offset, count)
|
||||
{
|
||||
makeBIS(inputStream).readByteArray(count); // required by API
|
||||
},
|
||||
// NSIREQUESTOBSERVER
|
||||
onStartRequest: function(request, cx)
|
||||
{
|
||||
var ch = request.QueryInterface(Ci.nsIHttpChannel)
|
||||
.QueryInterface(Ci.nsIHttpChannelInternal);
|
||||
|
||||
switch (currPathIndex)
|
||||
{
|
||||
case 0:
|
||||
do_check_eq(ch.getResponseHeader("Content-Length"), "4");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
do_check_eq(ch.getResponseHeader("Content-Length"), "4");
|
||||
break;
|
||||
}
|
||||
},
|
||||
onStopRequest: function(request, cx, status)
|
||||
{
|
||||
do_check_true(Components.isSuccessCode(status));
|
||||
if (++currPathIndex == paths.length)
|
||||
srv.stop();
|
||||
else
|
||||
performNextTest();
|
||||
do_test_finished();
|
||||
},
|
||||
// NSISUPPORTS
|
||||
QueryInterface: function(aIID)
|
||||
{
|
||||
if (aIID.equals(Ci.nsIStreamListener) ||
|
||||
aIID.equals(Ci.nsIRequestObserver) ||
|
||||
aIID.equals(Ci.nsISupports))
|
||||
return this;
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
function performNextTest()
|
||||
{
|
||||
do_test_pending();
|
||||
|
||||
var ch = makeChannel(paths[currPathIndex]);
|
||||
ch.asyncOpen(listener, null);
|
||||
}
|
||||
|
||||
var srv;
|
||||
|
||||
function run_test()
|
||||
{
|
||||
srv = createServer();
|
||||
var srv = createServer();
|
||||
|
||||
srv.registerPathHandler("/writeString", writeString);
|
||||
srv.registerPathHandler("/writeInt", writeInt);
|
||||
srv.start(4444);
|
||||
|
||||
performNextTest();
|
||||
runHttpTests(tests, function() { srv.stop(); });
|
||||
}
|
||||
|
||||
|
||||
// TEST DATA
|
||||
|
||||
function succeeded(ch, cx, status)
|
||||
{
|
||||
|
||||
do_check_true(Components.isSuccessCode(status));
|
||||
}
|
||||
|
||||
function check_1234(ch, cx)
|
||||
{
|
||||
do_check_eq(ch.getResponseHeader("Content-Length"), "4");
|
||||
}
|
||||
|
||||
|
||||
// PATH HANDLERS
|
||||
|
||||
function writeString(metadata, response)
|
||||
|
|
Загрузка…
Ссылка в новой задаче