3 var { XPCOMUtils } = ChromeUtils.importESModule(
4 "resource://gre/modules/XPCOMUtils.sys.mjs"
7 function evict_cache_entries(where) {
8 var clearDisk = !where || where == "disk" || where == "all";
9 var clearMem = !where || where == "memory" || where == "all";
14 storage = Services.cache2.memoryCacheStorage(
15 Services.loadContextInfo.default
17 storage.asyncEvictStorage(null);
21 storage = Services.cache2.diskCacheStorage(
22 Services.loadContextInfo.default
24 storage.asyncEvictStorage(null);
28 function createURI(urispec) {
29 return Services.io.newURI(urispec);
32 function getCacheStorage(where, lci) {
34 lci = Services.loadContextInfo.default;
38 return Services.cache2.diskCacheStorage(lci);
40 return Services.cache2.memoryCacheStorage(lci);
42 return Services.cache2.pinningCacheStorage(lci);
47 function asyncOpenCacheEntry(key, where, flags, lci, callback) {
50 function CacheListener() {}
51 CacheListener.prototype = {
52 QueryInterface: ChromeUtils.generateQI(["nsICacheEntryOpenCallback"]),
54 onCacheEntryCheck(entry) {
55 if (typeof callback === "object") {
56 return callback.onCacheEntryCheck(entry);
58 return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED;
61 onCacheEntryAvailable(entry, isnew, status) {
62 if (typeof callback === "object") {
63 // Root us at the callback
64 callback.__cache_listener_root = this;
65 callback.onCacheEntryAvailable(entry, isnew, status);
67 callback(status, entry);
72 var storage = getCacheStorage(where, lci);
73 storage.asyncOpenURI(key, "", flags, this);
77 new CacheListener().run();
80 function syncWithCacheIOThread(callback, force) {
83 "http://nonexistententry/",
85 Ci.nsICacheStorage.OPEN_READONLY,
88 Assert.equal(status, Cr.NS_ERROR_CACHE_KEY_NOT_FOUND);
97 function get_device_entry_count(where, lci, continuation) {
98 var storage = getCacheStorage(where, lci);
105 onCacheStorageInfo(entryCount, consumption) {
106 executeSoon(function () {
107 continuation(entryCount, consumption);
112 // get the device entry count
113 storage.asyncVisitStorage(visitor, false);
116 function asyncCheckCacheEntryPresence(key, where, shouldExist, continuation) {
120 Ci.nsICacheStorage.OPEN_READONLY,
122 function (status, entry) {
124 dump("TEST-INFO | checking cache key " + key + " exists @ " + where);
125 Assert.equal(status, Cr.NS_OK);
129 "TEST-INFO | checking cache key " + key + " doesn't exist @ " + where
131 Assert.equal(status, Cr.NS_ERROR_CACHE_KEY_NOT_FOUND);
132 Assert.equal(null, entry);