diff --git a/netwerk/cache2/AppCacheStorage.cpp b/netwerk/cache2/AppCacheStorage.cpp index 129a63669e57..7a045175f626 100644 --- a/netwerk/cache2/AppCacheStorage.cpp +++ b/netwerk/cache2/AppCacheStorage.cpp @@ -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 diff --git a/netwerk/cache2/CacheStorage.cpp b/netwerk/cache2/CacheStorage.cpp index 88853b5d7422..33c8f9e76293 100644 --- a/netwerk/cache2/CacheStorage.cpp +++ b/netwerk/cache2/CacheStorage.cpp @@ -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, diff --git a/netwerk/cache2/CacheStorage.h b/netwerk/cache2/CacheStorage.h index b25a4b11a755..85c5bccdbb31 100644 --- a/netwerk/cache2/CacheStorage.h +++ b/netwerk/cache2/CacheStorage.h @@ -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 diff --git a/netwerk/cache2/OldWrappers.cpp b/netwerk/cache2/OldWrappers.cpp index bd083439d707..543e42bbb756 100644 --- a/netwerk/cache2/OldWrappers.cpp +++ b/netwerk/cache2/OldWrappers.cpp @@ -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, diff --git a/netwerk/cache2/nsICacheStorage.idl b/netwerk/cache2/nsICacheStorage.idl index 0a716b1e8284..8c2a10f454ac 100644 --- a/netwerk/cache2/nsICacheStorage.idl +++ b/netwerk/cache2/nsICacheStorage.idl @@ -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; - } - %} }; diff --git a/netwerk/test/unit/test_alt-data_simple.js b/netwerk/test/unit/test_alt-data_simple.js index 6b7bd93a3e5c..8d5790fc4cb2 100644 --- a/netwerk/test/unit/test_alt-data_simple.js +++ b/netwerk/test/unit/test_alt-data_simple.js @@ -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); }