2012-08-14 07:06:04 -07:00
|
|
|
Cu.import("resource://testing-common/httpd.js");
|
|
|
|
|
|
|
|
var httpserver = new HttpServer();
|
2009-08-24 07:32:18 -07:00
|
|
|
var index = 0;
|
|
|
|
var tests = [
|
|
|
|
{ url : "/bug510359", server : "0", expected : "0"},
|
|
|
|
{ url : "/bug510359", server : "1", expected : "1"},
|
|
|
|
];
|
|
|
|
|
|
|
|
function setupChannel(suffix, value) {
|
|
|
|
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Ci.nsIIOService);
|
2013-07-19 10:19:28 -07:00
|
|
|
var chan = ios.newChannel("http://localhost:" +
|
|
|
|
httpserver.identity.primaryPort +
|
|
|
|
suffix, "", null);
|
2009-08-24 07:32:18 -07:00
|
|
|
var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
|
|
|
|
httpChan.requestMethod = "GET";
|
|
|
|
httpChan.setRequestHeader("x-request", value, false);
|
2010-11-26 09:13:37 -08:00
|
|
|
httpChan.setRequestHeader("Cookie", "c="+value, false);
|
2009-08-24 07:32:18 -07:00
|
|
|
return httpChan;
|
|
|
|
}
|
|
|
|
|
|
|
|
function triggerNextTest() {
|
|
|
|
var channel = setupChannel(tests[index].url, tests[index].server);
|
|
|
|
channel.asyncOpen(new ChannelListener(checkValueAndTrigger, null), null);
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkValueAndTrigger(request, data, ctx) {
|
|
|
|
do_check_eq(tests[index].expected, data);
|
|
|
|
|
|
|
|
if (index < tests.length - 1) {
|
|
|
|
index++;
|
|
|
|
triggerNextTest();
|
|
|
|
} else {
|
2009-11-14 20:54:49 -08:00
|
|
|
httpserver.stop(do_test_finished);
|
2009-08-24 07:32:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
httpserver.registerPathHandler("/bug510359", handler);
|
2013-07-19 10:19:28 -07:00
|
|
|
httpserver.start(-1);
|
2009-08-24 07:32:18 -07:00
|
|
|
|
|
|
|
// clear cache
|
2012-06-12 14:23:32 -07:00
|
|
|
evict_cache_entries();
|
|
|
|
|
2009-08-24 07:32:18 -07:00
|
|
|
triggerNextTest();
|
|
|
|
|
|
|
|
do_test_pending();
|
|
|
|
}
|
|
|
|
|
|
|
|
function handler(metadata, response) {
|
|
|
|
try {
|
|
|
|
var IMS = metadata.getHeader("If-Modified-Since");
|
|
|
|
response.setStatusLine(metadata.httpVersion, 500, "Failed");
|
|
|
|
var msg = "Client should not set If-Modified-Since header";
|
|
|
|
response.bodyOutputStream.write(msg, msg.length);
|
|
|
|
} catch(ex) {
|
|
|
|
response.setStatusLine(metadata.httpVersion, 200, "Ok");
|
|
|
|
response.setHeader("Content-Type", "text/plain", false);
|
|
|
|
response.setHeader("Last-Modified", getDateString(-1), false);
|
|
|
|
response.setHeader("Vary", "Cookie", false);
|
|
|
|
var body = metadata.getHeader("x-request");
|
|
|
|
response.bodyOutputStream.write(body, body.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDateString(yearDelta) {
|
|
|
|
var months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
|
|
|
|
'Sep', 'Oct', 'Nov', 'Dec' ];
|
|
|
|
var days = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ];
|
|
|
|
|
|
|
|
var d = new Date();
|
|
|
|
return days[d.getUTCDay()] + ", " + d.getUTCDate() + " "
|
|
|
|
+ months[d.getUTCMonth()] + " " + (d.getUTCFullYear() + yearDelta)
|
|
|
|
+ " " + d.getUTCHours() + ":" + d.getUTCMinutes() + ":"
|
|
|
|
+ d.getUTCSeconds() + " UTC";
|
|
|
|
}
|