3 This test exercises the CacheFileContextEvictor::WasEvicted API and code using it.
5 - We store 10+10 (pinned and non-pinned) entries to the cache, wait for them being written.
6 - Then we purge the memory pools.
7 - Now the IO thread is suspended on the EVICT (7) level to prevent actual deletion of the files.
9 - We do clear() of the cache, this creates the "ce_*" file and posts to the EVICT level
10 the eviction loop mechanics.
11 - We open again those 10+10 entries previously stored.
13 - We expect to get all the pinned and
14 loose all the non-pinned (common) entries.
20 const kENTRYCOUNT = 10;
24 dump(">>>>>>>>>>>>> " + msg + "\n");
31 var lci = Services.loadContextInfo.default;
32 var testingInterface = Services.cache2.QueryInterface(Ci.nsICacheTesting);
33 Assert.ok(testingInterface);
35 var mc = new MultipleCallbacks(
40 mc = new MultipleCallbacks(1, finish_cache2_test);
41 // Release all references to cache entries so that they can be purged
42 // Calling gc() four times is needed to force it to actually release
43 // entries that are obviously unreferenced. Yeah, I know, this is wacky...
51 // Invokes cacheservice:purge-memory-pools when done.
52 Services.cache2.purgeFromMemory(
53 Ci.nsICacheStorageService.PURGE_EVERYTHING
62 log_("first set of opens");
64 for (i = 0; i < kENTRYCOUNT; ++i) {
68 "http://pinned" + i + "/",
70 Ci.nsICacheStorage.OPEN_TRUNCATE,
72 new OpenCallback(NEW | WAITFORWRITE, "m" + i, "p" + i, function (entry) {
79 "http://common" + i + "/",
81 Ci.nsICacheStorage.OPEN_TRUNCATE,
83 new OpenCallback(NEW | WAITFORWRITE, "m" + i, "d" + i, function (entry) {
89 mc.fired(); // Goes to (2)
91 Services.obs.addObserver(
93 observe(subject, topic, data) {
97 // Prevent the I/O thread from evicting physically the data. We first want to re-open the entries.
98 // This deterministically emulates a slow hard drive.
99 testingInterface.suspendCacheIOThread(7);
102 // Now clear everything except pinned. Stores the "ce_*" file and schedules background eviction.
103 Services.cache2.clear();
106 log_("second set of opens");
107 // Now open again. Pinned entries should be there, disk entries should be the renewed entries.
109 for (i = 0; i < kENTRYCOUNT; ++i) {
112 "http://pinned" + i + "/",
114 Ci.nsICacheStorage.OPEN_NORMALLY,
116 new OpenCallback(NORMAL, "m" + i, "p" + i, function (entry) {
123 "http://common" + i + "/",
125 Ci.nsICacheStorage.OPEN_NORMALLY,
127 new OpenCallback(NEW, "m2" + i, "d2" + i, function (entry) {
133 // Resume IO, this will just pop-off the CacheFileContextEvictor::EvictEntries() because of
134 // an early check on CacheIOThread::YieldAndRerun() in that method.
135 // CacheFileIOManager::OpenFileInternal should now run and CacheFileContextEvictor::WasEvicted
136 // should be checked on.
138 testingInterface.resumeCacheIOThread();
141 mc.fired(); // Finishes this test
144 "cacheservice:purge-memory-pools"