diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /netwerk/test/unit/test_cache2-02b-open-non-existing-and-doom.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | netwerk/test/unit/test_cache2-02b-open-non-existing-and-doom.js | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_cache2-02b-open-non-existing-and-doom.js b/netwerk/test/unit/test_cache2-02b-open-non-existing-and-doom.js new file mode 100644 index 0000000000..c7387b42cb --- /dev/null +++ b/netwerk/test/unit/test_cache2-02b-open-non-existing-and-doom.js @@ -0,0 +1,180 @@ +"use strict"; + +add_task(async function test() { + do_get_profile(); + do_test_pending(); + + await new Promise(resolve => { + // Open non-existing for read, should fail + asyncOpenCacheEntry( + "http://b/", + "disk", + Ci.nsICacheStorage.OPEN_READONLY, + null, + new OpenCallback(NOTFOUND, null, null, function(entry) { + resolve(entry); + }) + ); + }); + + await new Promise(resolve => { + // Open the same non-existing for read again, should fail second time + asyncOpenCacheEntry( + "http://b/", + "disk", + Ci.nsICacheStorage.OPEN_READONLY, + null, + new OpenCallback(NOTFOUND, null, null, function(entry) { + resolve(entry); + }) + ); + }); + + await new Promise(resolve => { + // Try it again normally, should go + asyncOpenCacheEntry( + "http://b/", + "disk", + Ci.nsICacheStorage.OPEN_NORMALLY, + null, + new OpenCallback(NEW, "b1m", "b1d", function(entry) { + resolve(entry); + }) + ); + }); + + await new Promise(resolve => { + // ...and check + asyncOpenCacheEntry( + "http://b/", + "disk", + Ci.nsICacheStorage.OPEN_NORMALLY, + null, + new OpenCallback(NORMAL, "b1m", "b1d", function(entry) { + resolve(entry); + }) + ); + }); + + Services.prefs.setBoolPref("network.cache.bug1708673", true); + registerCleanupFunction(() => { + Services.prefs.clearUserPref("network.cache.bug1708673"); + }); + + let asyncDoomVisitor = new Promise(resolve => { + let doomTasks = []; + let visitor = { + onCacheStorageInfo() {}, + async onCacheEntryInfo( + aURI, + aIdEnhance, + aDataSize, + aAltDataSize, + aFetchCount, + aLastModifiedTime, + aExpirationTime, + aPinned, + aInfo + ) { + doomTasks.push( + new Promise(resolve => { + Services.cache2 + .diskCacheStorage(aInfo, false) + .asyncDoomURI(aURI, aIdEnhance, { + onCacheEntryDoomed() { + info("doomed"); + resolve(); + }, + }); + }) + ); + }, + onCacheEntryVisitCompleted() { + Promise.allSettled(doomTasks).then(resolve); + }, + QueryInterface: ChromeUtils.generateQI(["nsICacheStorageVisitor"]), + }; + Services.cache2.asyncVisitAllStorages(visitor, true); + }); + + let asyncOpenVisitor = new Promise(resolve => { + let openTasks = []; + let visitor = { + onCacheStorageInfo() {}, + async onCacheEntryInfo( + aURI, + aIdEnhance, + aDataSize, + aAltDataSize, + aFetchCount, + aLastModifiedTime, + aExpirationTime, + aPinned, + aInfo + ) { + info(`found ${aURI.spec}`); + openTasks.push( + new Promise(r2 => { + Services.cache2 + .diskCacheStorage(aInfo, false) + .asyncOpenURI( + aURI, + "", + Ci.nsICacheStorage.OPEN_READONLY | + Ci.nsICacheStorage.OPEN_SECRETLY, + { + onCacheEntryCheck() { + return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED; + }, + onCacheEntryAvailable(entry, isnew, status) { + info("opened"); + r2(); + }, + QueryInterface: ChromeUtils.generateQI([ + "nsICacheEntryOpenCallback", + ]), + } + ); + }) + ); + }, + onCacheEntryVisitCompleted() { + Promise.all(openTasks).then(resolve); + }, + QueryInterface: ChromeUtils.generateQI(["nsICacheStorageVisitor"]), + }; + Services.cache2.asyncVisitAllStorages(visitor, true); + }); + + await Promise.all([asyncDoomVisitor, asyncOpenVisitor]); + + info("finished visiting"); + + await new Promise(resolve => { + let entryCount = 0; + let visitor = { + onCacheStorageInfo() {}, + async onCacheEntryInfo( + aURI, + aIdEnhance, + aDataSize, + aAltDataSize, + aFetchCount, + aLastModifiedTime, + aExpirationTime, + aPinned, + aInfo + ) { + entryCount++; + }, + onCacheEntryVisitCompleted() { + Assert.equal(entryCount, 0); + resolve(); + }, + QueryInterface: ChromeUtils.generateQI(["nsICacheStorageVisitor"]), + }; + Services.cache2.asyncVisitAllStorages(visitor, true); + }); + + finish_cache2_test(); +}); |