netwerk/test/TestCacheVisitor.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 var DEBUG = true;
     3 var clientID = "javascript";
     4 var nsICache = Components.interfaces.nsICache;
     6 function getCacheService()
     7 {
     8     var nsCacheService = Components.classes["@mozilla.org/network/cache-service;1"];
     9     var service = nsCacheService.getService(Components.interfaces.nsICacheService);
    10     return service;
    11 }
    13 function CacheVisitor()
    14 {
    15 }
    17 CacheVisitor.prototype = {
    18     QueryInterface : function(iid)
    19     {
    20         if (iid.equals(Components.interfaces.nsICacheVisitor))
    21             return this;
    22         throw Components.results.NS_NOINTERFACE;
    23     },
    25     visitDevice : function(deviceID, deviceInfo)
    26     {
    27         print("[visiting device (deviceID = " + deviceID + ", description = " + deviceInfo.description + ")]");
    28         return true;
    29     },
    31     visitEntry : function(deviceID, entryInfo)
    32     {
    33         print("[visiting entry (clientID = " + entryInfo.clientID + ", key = " + entryInfo.key + ")]");
    34         return true;
    35     }
    36 };
    38 function test()
    39 {
    40     var cacheService = getCacheService();
    41     var visitor = new CacheVisitor();
    42     cacheService.visitEntries(visitor);
    43 }
    45 // load the cache service before doing anything with Java...
    46 getCacheService();
    48 if (DEBUG) {
    49     print("cache service loaded.");
    50 } else {
    51     print("running cache visitor test.");
    52     test();
    53     print("cache visitor test complete.");
    54 }

mercurial