1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/TestCacheVisitor.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 1.4 +var DEBUG = true; 1.5 + 1.6 +var clientID = "javascript"; 1.7 +var nsICache = Components.interfaces.nsICache; 1.8 + 1.9 +function getCacheService() 1.10 +{ 1.11 + var nsCacheService = Components.classes["@mozilla.org/network/cache-service;1"]; 1.12 + var service = nsCacheService.getService(Components.interfaces.nsICacheService); 1.13 + return service; 1.14 +} 1.15 + 1.16 +function CacheVisitor() 1.17 +{ 1.18 +} 1.19 + 1.20 +CacheVisitor.prototype = { 1.21 + QueryInterface : function(iid) 1.22 + { 1.23 + if (iid.equals(Components.interfaces.nsICacheVisitor)) 1.24 + return this; 1.25 + throw Components.results.NS_NOINTERFACE; 1.26 + }, 1.27 + 1.28 + visitDevice : function(deviceID, deviceInfo) 1.29 + { 1.30 + print("[visiting device (deviceID = " + deviceID + ", description = " + deviceInfo.description + ")]"); 1.31 + return true; 1.32 + }, 1.33 + 1.34 + visitEntry : function(deviceID, entryInfo) 1.35 + { 1.36 + print("[visiting entry (clientID = " + entryInfo.clientID + ", key = " + entryInfo.key + ")]"); 1.37 + return true; 1.38 + } 1.39 +}; 1.40 + 1.41 +function test() 1.42 +{ 1.43 + var cacheService = getCacheService(); 1.44 + var visitor = new CacheVisitor(); 1.45 + cacheService.visitEntries(visitor); 1.46 +} 1.47 + 1.48 +// load the cache service before doing anything with Java... 1.49 +getCacheService(); 1.50 + 1.51 +if (DEBUG) { 1.52 + print("cache service loaded."); 1.53 +} else { 1.54 + print("running cache visitor test."); 1.55 + test(); 1.56 + print("cache visitor test complete."); 1.57 +}