commit c770e703ca451728087be228f9deee2bb346c335
parent 5a9bb43f63a583676b21122b1d96bd837a568542
Author: Tooru Fujisawa <arai_a@mac.com>
Date: Mon, 10 Nov 2025 08:30:05 +0000
Bug 1998926 - Part 2: Remove IsFromCache requirements from GetCacheEntryId. r=valentin,necko-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D271872
Diffstat:
4 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/netwerk/protocol/http/HttpChannelChild.cpp b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -2789,9 +2789,7 @@ HttpChannelChild::HasCacheEntry(bool* value) {
NS_IMETHODIMP
HttpChannelChild::GetCacheEntryId(uint64_t* aCacheEntryId) {
- bool fromCache = false;
- if (NS_FAILED(IsFromCache(&fromCache)) || !fromCache ||
- !mCacheEntryAvailable) {
+ if (!mCacheEntryAvailable) {
return NS_ERROR_NOT_AVAILABLE;
}
diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -10575,9 +10575,7 @@ nsHttpChannel::HasCacheEntry(bool* value) {
NS_IMETHODIMP
nsHttpChannel::GetCacheEntryId(uint64_t* aCacheEntryId) {
- bool fromCache = false;
- if (NS_FAILED(IsFromCache(&fromCache)) || !fromCache || !mCacheEntry ||
- NS_FAILED(mCacheEntry->GetCacheEntryId(aCacheEntryId))) {
+ if (!mCacheEntry || NS_FAILED(mCacheEntry->GetCacheEntryId(aCacheEntryId))) {
return NS_ERROR_NOT_AVAILABLE;
}
diff --git a/netwerk/test/unit/head_channels.js b/netwerk/test/unit/head_channels.js
@@ -60,6 +60,7 @@ function ChannelListener(closure, ctx, flags) {
this._closurectx = ctx;
this._flags = flags;
this._isFromCache = false;
+ this._hasCacheEntry = false;
this._cacheEntryId = undefined;
}
ChannelListener.prototype = {
@@ -90,6 +91,12 @@ ChannelListener.prototype = {
.isFromCache();
} catch (e) {}
+ try {
+ this._hasCacheEntry = request
+ .QueryInterface(Ci.nsICacheInfoChannel)
+ .hasCacheEntry();
+ } catch (e) {}
+
var thrown = false;
try {
this._cacheEntryId = request
@@ -98,9 +105,9 @@ ChannelListener.prototype = {
} catch (e) {
thrown = true;
}
- if (this._isFromCache && thrown) {
+ if (this._hasCacheEntry && thrown) {
do_throw("Should get a CacheEntryId");
- } else if (!this._isFromCache && !thrown) {
+ } else if (!this._hasCacheEntry && !thrown) {
do_throw("Shouldn't get a CacheEntryId");
}
diff --git a/netwerk/test/unit/test_cache-entry-id.js b/netwerk/test/unit/test_cache-entry-id.js
@@ -127,6 +127,7 @@ function run_test() {
do_test_pending();
var targetCacheEntryId = null;
+ var secondCacheEntryId = null;
return (
Promise.resolve()
@@ -138,10 +139,13 @@ function run_test() {
responseContent,
"",
false,
- cacheEntryId => cacheEntryId === undefined
+ cacheEntryId => cacheEntryId !== undefined
)
)
- .then(r => writeAltData(r.request))
+ .then(r => {
+ targetCacheEntryId = r.cacheEntryId;
+ writeAltData(r.request);
+ })
// Start testing.
.then(_ => fetch(altContentType))
@@ -154,7 +158,6 @@ function run_test() {
cacheEntryId => cacheEntryId !== undefined
)
)
- .then(r => (targetCacheEntryId = r.cacheEntryId))
.then(_ => fetch())
.then(r =>
@@ -196,9 +199,13 @@ function run_test() {
responseContent2,
"",
false,
- cacheEntryId => cacheEntryId === undefined
+ cacheEntryId =>
+ cacheEntryId !== undefined && cacheEntryId !== targetCacheEntryId
)
)
+ .then(r => {
+ secondCacheEntryId = r.cacheEntryId;
+ })
.then(_ => fetch())
.then(r =>
@@ -207,8 +214,7 @@ function run_test() {
responseContent2,
"",
true,
- cacheEntryId =>
- cacheEntryId !== undefined && cacheEntryId !== targetCacheEntryId
+ cacheEntryId => cacheEntryId === secondCacheEntryId
)
)