var httpserver = new HttpServer();
httpserver.start(-1);
// Need to randomize, because apparently no one clears our cache var suffix = Math.random(); var httpBase = "http://localhost:" + httpserver.identity.primaryPort; var shortexpPath = "/shortexp" + suffix; var longexpPath = "/longexp/" + suffix; var longexp2Path = "/longexp/2/" + suffix; var nocachePath = "/nocache" + suffix; var nostorePath = "/nostore" + suffix; var test410Path = "/test410" + suffix; var test404Path = "/test404" + suffix;
var PrivateBrowsingLoadContext = Cu.createPrivateLoadContext();
function make_channel(url, flags, usePrivateBrowsing) { var securityFlags = Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL;
var uri = Services.io.newURI(url); var principal = Services.scriptSecurityManager.createContentPrincipal(uri, {
privateBrowsingId: usePrivateBrowsing ? 1 : 0,
});
var gTests = [ new Test(
httpBase + shortexpPath,
0, true, // expect success false, // read from cache true, // hit server true
), // USE PRIVATE BROWSING, so not cached for later requests new Test(
httpBase + shortexpPath,
0, true, // expect success false, // read from cache true
), // hit server new Test(
httpBase + shortexpPath,
0, true, // expect success true, // read from cache true
), // hit server new Test(
httpBase + shortexpPath,
Ci.nsIRequest.LOAD_BYPASS_CACHE, true, // expect success false, // read from cache true
), // hit server new Test(
httpBase + shortexpPath,
Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE, false, // expect success false, // read from cache false
), // hit server new Test(
httpBase + shortexpPath,
Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE | Ci.nsIRequest.VALIDATE_NEVER, true, // expect success true, // read from cache false
), // hit server new Test(
httpBase + shortexpPath,
Ci.nsIRequest.LOAD_FROM_CACHE, true, // expect success true, // read from cache false
), // hit server
new Test(
httpBase + longexpPath,
0, true, // expect success false, // read from cache true
), // hit server new Test(
httpBase + longexpPath,
0, true, // expect success true, // read from cache false
), // hit server new Test(
httpBase + longexpPath,
Ci.nsIRequest.LOAD_BYPASS_CACHE, true, // expect success false, // read from cache true
), // hit server new Test(
httpBase + longexpPath,
Ci.nsIRequest.VALIDATE_ALWAYS, true, // expect success true, // read from cache true
), // hit server new Test(
httpBase + longexpPath,
Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE, true, // expect success true, // read from cache false
), // hit server new Test(
httpBase + longexpPath,
Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE | Ci.nsIRequest.VALIDATE_NEVER, true, // expect success true, // read from cache false
), // hit server new Test(
httpBase + longexpPath,
Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE | Ci.nsIRequest.VALIDATE_ALWAYS, false, // expect success false, // read from cache false
), // hit server new Test(
httpBase + longexpPath,
Ci.nsIRequest.LOAD_FROM_CACHE, true, // expect success true, // read from cache false
), // hit server
new Test(
httpBase + longexp2Path,
0, true, // expect success false, // read from cache true
), // hit server new Test(
httpBase + longexp2Path,
0, true, // expect success true, // read from cache false
), // hit server
new Test(
httpBase + nocachePath,
0, true, // expect success false, // read from cache true
), // hit server new Test(
httpBase + nocachePath,
0, true, // expect success true, // read from cache true
), // hit server new Test(
httpBase + nocachePath,
Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE, false, // expect success false, // read from cache false
), // hit server
// CACHE2: mayhemer - entry is doomed... I think the logic is wrong, we should not doom them // as they are not valid, but take them as they need to reval /* new Test(httpBase + nocachePath, Ci.nsIRequest.LOAD_FROM_CACHE, true, // expect success true, // read from cache false), // hit server
*/
// LOAD_ONLY_FROM_CACHE would normally fail (because no-cache forces // a validation), but VALIDATE_NEVER should override that. new Test(
httpBase + nocachePath,
Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE | Ci.nsIRequest.VALIDATE_NEVER, true, // expect success true, // read from cache false
), // hit server
// ... however, no-cache over ssl should act like no-store and force // a validation (and therefore failure) even if VALIDATE_NEVER is // set. /* XXX bug 466524: We can't currently start an ssl server in xpcshell tests, so this test is currently disabled. new Test(httpsBase + nocachePath, Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE | Ci.nsIRequest.VALIDATE_NEVER, false, // expect success false, // read from cache false) // hit server
*/
new Test(
httpBase + nostorePath,
0, true, // expect success false, // read from cache true
), // hit server new Test(
httpBase + nostorePath,
0, true, // expect success false, // read from cache true
), // hit server new Test(
httpBase + nostorePath,
Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE, false, // expect success false, // read from cache false
), // hit server new Test(
httpBase + nostorePath,
Ci.nsIRequest.LOAD_FROM_CACHE, true, // expect success true, // read from cache false
), // hit server // no-store should force the validation (and therefore failure, with // LOAD_ONLY_FROM_CACHE) even if VALIDATE_NEVER is set. new Test(
httpBase + nostorePath,
Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE | Ci.nsIRequest.VALIDATE_NEVER, false, // expect success false, // read from cache false
), // hit server
new Test(
httpBase + test410Path,
0, true, // expect success false, // read from cache true
), // hit server new Test(
httpBase + test410Path,
0, true, // expect success true, // read from cache false
), // hit server
new Test(
httpBase + test404Path,
0, true, // expect success false, // read from cache true
), // hit server new Test(
httpBase + test404Path,
0, true, // expect success false, // read from cache true
), // hit server
];
function run_next_test() { if (!gTests.length) {
httpserver.stop(do_test_finished); return;
}
var test = gTests.shift();
test.run();
}
function handler(httpStatus, metadata, response) {
gHitServer = true;
let etag; try {
etag = metadata.getHeader("If-None-Match");
} catch (ex) {
etag = "";
} if (etag == "testtag") { // Allow using the cached data
response.setStatusLine(metadata.httpVersion, 304, "Not Modified");
} else {
response.setStatusLine(metadata.httpVersion, httpStatus, "Useless Phrase");
response.setHeader("Content-Type", "text/plain", false);
response.setHeader("ETag", "testtag", false); const body = "data";
response.bodyOutputStream.write(body, body.length);
}
}
// test spaces around max-age value token function longexp2_handler(metadata, response) {
response.setHeader("Cache-Control", "max-age = 10000", false);
handler(200, metadata, response);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.