зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 7598b4ed02f6 (bug 1395202)
This commit is contained in:
Родитель
89d9591fb8
Коммит
44b9915533
|
@ -53,7 +53,6 @@ function ChannelListener(closure, ctx, flags) {
|
|||
this._closurectx = ctx;
|
||||
this._flags = flags;
|
||||
this._isFromCache = false;
|
||||
this._cacheEntryId = undefined;
|
||||
}
|
||||
ChannelListener.prototype = {
|
||||
_closure: null,
|
||||
|
@ -80,20 +79,9 @@ ChannelListener.prototype = {
|
|||
this._lastEvent = Date.now();
|
||||
|
||||
try {
|
||||
this._isFromCache = request.QueryInterface(Ci.nsICacheInfoChannel).isFromCache();
|
||||
this._isFromCache = request.QueryInterface(Ci.nsICachingChannel).isFromCache();
|
||||
} catch (e) {}
|
||||
|
||||
var thrown = false;
|
||||
try {
|
||||
this._cacheEntryId = request.QueryInterface(Ci.nsICacheInfoChannel).getCacheEntryId();
|
||||
} catch (e) {
|
||||
thrown = true;
|
||||
}
|
||||
if (this._isFromCache && thrown)
|
||||
do_throw("Should get a CacheEntryId");
|
||||
else if (!this._isFromCache && !thrown)
|
||||
do_throw("Shouldn't get a CacheEntryId");
|
||||
|
||||
request.QueryInterface(Components.interfaces.nsIChannel);
|
||||
try {
|
||||
this._contentLen = request.contentLength;
|
||||
|
@ -183,11 +171,7 @@ ChannelListener.prototype = {
|
|||
do_throw("Error in onStopRequest: " + ex);
|
||||
}
|
||||
try {
|
||||
this._closure(request,
|
||||
this._buffer,
|
||||
this._closurectx,
|
||||
this._isFromCache,
|
||||
this._cacheEntryId);
|
||||
this._closure(request, this._buffer, this._closurectx, this._isFromCache);
|
||||
this._closurectx = null;
|
||||
} catch (ex) {
|
||||
do_throw("Error in closure function: " + ex);
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
/**
|
||||
* Test for the "CacheEntryId" under several cases.
|
||||
*/
|
||||
|
||||
Cu.import("resource://testing-common/httpd.js");
|
||||
Cu.import("resource://gre/modules/NetUtil.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "URL", function() {
|
||||
return "http://localhost:" + httpServer.identity.primaryPort + "/content";
|
||||
});
|
||||
|
||||
var httpServer = null;
|
||||
|
||||
const responseContent = "response body";
|
||||
const responseContent2 = "response body 2";
|
||||
const altContent = "!@#$%^&*()";
|
||||
const altContentType = "text/binary";
|
||||
|
||||
var handlers = [
|
||||
(m, r) => {r.bodyOutputStream.write(responseContent, responseContent.length)},
|
||||
(m, r) => {r.setStatusLine(m.httpVersion, 304, "Not Modified")},
|
||||
(m, r) => {r.setStatusLine(m.httpVersion, 304, "Not Modified")},
|
||||
(m, r) => {r.setStatusLine(m.httpVersion, 304, "Not Modified")},
|
||||
(m, r) => {r.setStatusLine(m.httpVersion, 304, "Not Modified")},
|
||||
(m, r) => {r.bodyOutputStream.write(responseContent2, responseContent2.length)},
|
||||
(m, r) => {r.setStatusLine(m.httpVersion, 304, "Not Modified")},
|
||||
];
|
||||
|
||||
function contentHandler(metadata, response)
|
||||
{
|
||||
response.setHeader("Content-Type", "text/plain");
|
||||
response.setHeader("Cache-Control", "no-cache");
|
||||
|
||||
var handler = handlers.shift();
|
||||
if (handler) {
|
||||
handler(metadata, response);
|
||||
return;
|
||||
}
|
||||
|
||||
do_check_true(false, "Should not reach here.");
|
||||
}
|
||||
|
||||
function fetch(preferredDataType = null)
|
||||
{
|
||||
return new Promise(resolve => {
|
||||
var chan = NetUtil.newChannel({uri: URL, loadUsingSystemPrincipal: true});
|
||||
|
||||
if (preferredDataType) {
|
||||
var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType(altContentType);
|
||||
}
|
||||
|
||||
chan.asyncOpen2(new ChannelListener((request,
|
||||
buffer,
|
||||
ctx,
|
||||
isFromCache,
|
||||
cacheEntryId) => {
|
||||
resolve({request, buffer, isFromCache, cacheEntryId});
|
||||
}, null));
|
||||
});
|
||||
}
|
||||
|
||||
function check(response, content, preferredDataType, isFromCache, cacheEntryIdChecker)
|
||||
{
|
||||
var cc = response.request.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
|
||||
do_check_eq(response.buffer, content);
|
||||
do_check_eq(cc.alternativeDataType, preferredDataType);
|
||||
do_check_eq(response.isFromCache, isFromCache);
|
||||
do_check_true(!cacheEntryIdChecker || cacheEntryIdChecker(response.cacheEntryId));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
function writeAltData(request)
|
||||
{
|
||||
var cc = request.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
var os = cc.openAlternativeOutputStream(altContentType);
|
||||
os.write(altContent, altContent.length);
|
||||
os.close();
|
||||
gc(); // We need to do a GC pass to ensure the cache entry has been freed.
|
||||
|
||||
return new Promise(resolve => {
|
||||
Services.cache2.QueryInterface(Ci.nsICacheTesting)
|
||||
.flush(resolve);
|
||||
});
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
do_get_profile();
|
||||
httpServer = new HttpServer();
|
||||
httpServer.registerPathHandler("/content", contentHandler);
|
||||
httpServer.start(-1);
|
||||
do_test_pending();
|
||||
|
||||
var targetCacheEntryId = null;
|
||||
|
||||
return Promise.resolve()
|
||||
// Setup testing environment: Placing alternative data into HTTP cache.
|
||||
.then(_ => fetch(altContentType))
|
||||
.then(r => check(r, responseContent, "", false,
|
||||
cacheEntryId => cacheEntryId === undefined))
|
||||
.then(r => writeAltData(r.request))
|
||||
|
||||
// Start testing.
|
||||
.then(_ => fetch(altContentType))
|
||||
.then(r => check(r, altContent, altContentType, true,
|
||||
cacheEntryId => cacheEntryId !== undefined))
|
||||
.then(r => targetCacheEntryId = r.cacheEntryId)
|
||||
|
||||
.then(_ => fetch())
|
||||
.then(r => check(r, responseContent, "", true,
|
||||
cacheEntryId => cacheEntryId === targetCacheEntryId))
|
||||
|
||||
.then(_ => fetch(altContentType))
|
||||
.then(r => check(r, altContent, altContentType, true,
|
||||
cacheEntryId => cacheEntryId === targetCacheEntryId))
|
||||
|
||||
.then(_ => fetch())
|
||||
.then(r => check(r, responseContent, "", true,
|
||||
cacheEntryId => cacheEntryId === targetCacheEntryId))
|
||||
|
||||
.then(_ => fetch()) // The response is changed here.
|
||||
.then(r => check(r, responseContent2, "", false,
|
||||
cacheEntryId => cacheEntryId === undefined))
|
||||
|
||||
.then(_ => fetch())
|
||||
.then(r => check(r, responseContent2, "", true,
|
||||
cacheEntryId => cacheEntryId !== undefined &&
|
||||
cacheEntryId !== targetCacheEntryId))
|
||||
|
||||
// Tear down.
|
||||
.catch(e => do_check_true(false, "Unexpected exception: " + e))
|
||||
.then(_ => do_check_eq(handlers.length, 0))
|
||||
.then(_ => httpServer.stop(do_test_finished));
|
||||
}
|
|
@ -180,7 +180,6 @@ skip-if = bits != 32
|
|||
[test_doomentry.js]
|
||||
[test_cacheflags.js]
|
||||
[test_cache_jar.js]
|
||||
[test_cache-entry-id.js]
|
||||
[test_channel_close.js]
|
||||
[test_compareURIs.js]
|
||||
[test_compressappend.js]
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
function run_test() {
|
||||
run_test_in_child("../unit/test_cache-entry-id.js");
|
||||
}
|
|
@ -6,7 +6,6 @@ support-files =
|
|||
!/netwerk/test/unit/test_XHR_redirects.js
|
||||
!/netwerk/test/unit/test_bug248970_cookie.js
|
||||
!/netwerk/test/unit/test_bug528292.js
|
||||
!/netwerk/test/unit/test_cache-entry-id.js
|
||||
!/netwerk/test/unit/test_cache_jar.js
|
||||
!/netwerk/test/unit/test_cacheflags.js
|
||||
!/netwerk/test/unit/test_channel_close.js
|
||||
|
@ -62,7 +61,6 @@ support-files =
|
|||
[test_bug528292_wrap.js]
|
||||
[test_bug248970_cookie_wrap.js]
|
||||
[test_cacheflags_wrap.js]
|
||||
[test_cache-entry-id_wrap.js]
|
||||
[test_cache_jar_wrap.js]
|
||||
[test_channel_close_wrap.js]
|
||||
[test_cookie_header_wrap.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче