diff -r 000000000000 -r 6474c204b198 netwerk/test/TestCacheVisitor.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netwerk/test/TestCacheVisitor.js Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,54 @@ +var DEBUG = true; + +var clientID = "javascript"; +var nsICache = Components.interfaces.nsICache; + +function getCacheService() +{ + var nsCacheService = Components.classes["@mozilla.org/network/cache-service;1"]; + var service = nsCacheService.getService(Components.interfaces.nsICacheService); + return service; +} + +function CacheVisitor() +{ +} + +CacheVisitor.prototype = { + QueryInterface : function(iid) + { + if (iid.equals(Components.interfaces.nsICacheVisitor)) + return this; + throw Components.results.NS_NOINTERFACE; + }, + + visitDevice : function(deviceID, deviceInfo) + { + print("[visiting device (deviceID = " + deviceID + ", description = " + deviceInfo.description + ")]"); + return true; + }, + + visitEntry : function(deviceID, entryInfo) + { + print("[visiting entry (clientID = " + entryInfo.clientID + ", key = " + entryInfo.key + ")]"); + return true; + } +}; + +function test() +{ + var cacheService = getCacheService(); + var visitor = new CacheVisitor(); + cacheService.visitEntries(visitor); +} + +// load the cache service before doing anything with Java... +getCacheService(); + +if (DEBUG) { + print("cache service loaded."); +} else { + print("running cache visitor test."); + test(); + print("cache visitor test complete."); +}