summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_cache2-02b-open-non-existing-and-doom.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /netwerk/test/unit/test_cache2-02b-open-non-existing-and-doom.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_cache2-02b-open-non-existing-and-doom.js')
-rw-r--r--netwerk/test/unit/test_cache2-02b-open-non-existing-and-doom.js180
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..c4b2a679f2
--- /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();
+});