зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1360163 - Add test for altData of cache index, r=michal
--HG-- extra : rebase_source : fcd588c232364fa7fc4cbd4e133bd32557231b3c
This commit is contained in:
Родитель
1eae0fcd88
Коммит
6f2d5288c1
|
@ -171,5 +171,13 @@ NS_IMETHODIMP AppCacheStorage::AsyncVisitStorage(nsICacheStorageVisitor* aVisito
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP AppCacheStorage::GetCacheIndexEntryAttrs(nsIURI *aURI,
|
||||
const nsACString &aIdExtension,
|
||||
bool *aHasAltData,
|
||||
uint32_t *aSizeInKB)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -171,7 +171,7 @@ NS_IMETHODIMP CacheStorage::Exists(nsIURI *aURI, const nsACString & aIdExtension
|
|||
this, asciiSpec, aIdExtension, aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_IMETHODIMP
|
||||
CacheStorage::GetCacheIndexEntryAttrs(nsIURI *aURI,
|
||||
const nsACString &aIdExtension,
|
||||
bool *aHasAltData,
|
||||
|
|
|
@ -73,9 +73,6 @@ public:
|
|||
bool LookupAppCache() const { return mLookupAppCache; }
|
||||
bool SkipSizeCheck() const { return mSkipSizeCheck; }
|
||||
bool Pinning() const { return mPinning; }
|
||||
virtual nsresult GetCacheIndexEntryAttrs(
|
||||
nsIURI *aURI, const nsACString &aIdExtension,
|
||||
bool *aHasAltData, uint32_t *aSizeInKB) override;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
|
|
|
@ -1076,6 +1076,14 @@ NS_IMETHODIMP _OldStorage::AsyncVisitStorage(nsICacheStorageVisitor* aVisitor,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP _OldStorage::GetCacheIndexEntryAttrs(nsIURI *aURI,
|
||||
const nsACString &aIdExtension,
|
||||
bool *aHasAltData,
|
||||
uint32_t *aSizeInKB)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// Internal
|
||||
|
||||
nsresult _OldStorage::AssembleCacheKey(nsIURI *aURI,
|
||||
|
|
|
@ -113,6 +113,16 @@ interface nsICacheStorage : nsISupports
|
|||
*/
|
||||
boolean exists(in nsIURI aURI, in ACString aIdExtension);
|
||||
|
||||
/**
|
||||
* Synchronously check on existance of alternative data and size of the
|
||||
* content. When the index data are not up to date or index is still building,
|
||||
* NS_ERROR_NOT_AVAILABLE is thrown. The same error may throw any storage
|
||||
* implementation that cannot determine entry state without blocking the caller.
|
||||
*/
|
||||
void getCacheIndexEntryAttrs(in nsIURI aURI,
|
||||
in ACString aIdExtension,
|
||||
out bool aHasAltData,
|
||||
out uint32_t aSizeInKB);
|
||||
/**
|
||||
* Asynchronously removes an entry belonging to the URI from the cache.
|
||||
*/
|
||||
|
@ -132,11 +142,4 @@ interface nsICacheStorage : nsISupports
|
|||
void asyncVisitStorage(in nsICacheStorageVisitor aVisitor,
|
||||
in boolean aVisitEntries);
|
||||
|
||||
%{C++
|
||||
virtual nsresult GetCacheIndexEntryAttrs(
|
||||
nsIURI *aURI, const nsACString &aIdExtension,
|
||||
bool *aHasAltData, uint32_t *aSizeInKB) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
%}
|
||||
};
|
||||
|
|
|
@ -23,6 +23,12 @@ function make_channel(url, callback, ctx) {
|
|||
return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true});
|
||||
}
|
||||
|
||||
function inChildProcess() {
|
||||
return Cc["@mozilla.org/xre/app-info;1"]
|
||||
.getService(Ci.nsIXULRuntime)
|
||||
.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||
}
|
||||
|
||||
const responseContent = "response body";
|
||||
const responseContent2 = "response body 2";
|
||||
const altContent = "!@#$%^&*()";
|
||||
|
@ -31,6 +37,8 @@ const altContentType = "text/binary";
|
|||
var servedNotModified = false;
|
||||
var shouldPassRevalidation = true;
|
||||
|
||||
var cache_storage = null;
|
||||
|
||||
function contentHandler(metadata, response)
|
||||
{
|
||||
response.setHeader("Content-Type", "text/plain");
|
||||
|
@ -52,20 +60,40 @@ function contentHandler(metadata, response)
|
|||
}
|
||||
}
|
||||
|
||||
function check_has_alt_data_in_index(aHasAltData)
|
||||
{
|
||||
if (inChildProcess()) {
|
||||
return;
|
||||
}
|
||||
var hasAltData = {};
|
||||
cache_storage.getCacheIndexEntryAttrs(createURI(URL), "", hasAltData, {});
|
||||
do_check_eq(hasAltData.value, aHasAltData);
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
do_get_profile();
|
||||
httpServer = new HttpServer();
|
||||
httpServer.registerPathHandler("/content", contentHandler);
|
||||
httpServer.start(-1);
|
||||
do_test_pending();
|
||||
|
||||
if (!inChildProcess()) {
|
||||
cache_storage = getCacheStorage("disk") ;
|
||||
wait_for_cache_index(asyncOpen);
|
||||
} else {
|
||||
asyncOpen();
|
||||
}
|
||||
}
|
||||
|
||||
function asyncOpen()
|
||||
{
|
||||
var chan = make_channel(URL);
|
||||
|
||||
var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType(altContentType);
|
||||
|
||||
chan.asyncOpen2(new ChannelListener(readServerContent, null));
|
||||
do_test_pending();
|
||||
}
|
||||
|
||||
function readServerContent(request, buffer)
|
||||
|
@ -74,6 +102,7 @@ function readServerContent(request, buffer)
|
|||
|
||||
do_check_eq(buffer, responseContent);
|
||||
do_check_eq(cc.alternativeDataType, "");
|
||||
check_has_alt_data_in_index(false);
|
||||
|
||||
do_execute_soon(() => {
|
||||
var os = cc.openAlternativeOutputStream(altContentType);
|
||||
|
@ -109,6 +138,7 @@ function readAltContent(request, buffer)
|
|||
do_check_eq(servedNotModified, true);
|
||||
do_check_eq(cc.alternativeDataType, altContentType);
|
||||
do_check_eq(buffer, altContent);
|
||||
check_has_alt_data_in_index(true);
|
||||
|
||||
requestAgain();
|
||||
}
|
||||
|
@ -129,6 +159,7 @@ function readEmptyAltContent(request, buffer)
|
|||
// the cache is overwrite and the alt-data is reset
|
||||
do_check_eq(cc.alternativeDataType, "");
|
||||
do_check_eq(buffer, responseContent2);
|
||||
check_has_alt_data_in_index(false);
|
||||
|
||||
httpServer.stop(do_test_finished);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче