3 var clientID = "javascript";
4 var key = "theme:button";
5 var nsICache = Components.interfaces.nsICache;
7 function getCacheService()
9 var nsCacheService = Components.classes["@mozilla.org/network/cache-service;1"];
10 var service = nsCacheService.getService(Components.interfaces.nsICacheService);
14 function createCacheSession(clientID, storagePolicy, streamable)
16 var service = getCacheService();
17 var session = service.createSession(clientID, storagePolicy, streamable);
21 function openCacheEntry(mode)
23 var session = createCacheSession(clientID, nsICache.STORE_ON_DISK, true);
24 var entry = session.openCacheEntry(key, mode);
30 var leakDetector = Components.classes["@mozilla.org/xpcom/leakdetector;1"].getService(Components.interfaces.nsILeakDetector);
31 leakDetector.dumpLeaks();
34 function wrapInputStream(input)
36 var nsIScriptableInputStream = Components.interfaces.nsIScriptableInputStream;
37 var factory = Components.classes["@mozilla.org/scriptableinputstream;1"];
38 var wrapper = factory.createInstance(nsIScriptableInputStream);
45 var outputEntry = openCacheEntry(nsICache.ACCESS_WRITE);
46 var output = outputEntry.transport.openOutputStream(0, -1, 0);
47 if (output.write("foo", 3) == 3)
48 print("disk cache write works!");
50 print("disk cache write broken!");
52 // store some metadata.
53 outputEntry.setMetaDataElement("size", "3");
56 outputEntry.markValid();
59 var inputEntry = openCacheEntry(nsICache.ACCESS_READ);
60 var input = wrapInputStream(inputEntry.transport.openInputStream(0, -1, 0));
62 if (input.read(input.available()) == "foo")
63 print("disk cache read works!");
65 print("disk cache read broken!");
67 if (inputEntry.getMetaDataElement("size") == "3")
68 print("disk cache metadata works!");
70 print("disk cache metadata broken!");
78 var doomedEntry = openCacheEntry(nsICache.ACCESS_READ_WRITE);
85 print("cache service loaded.");
87 print("running disk cache test.");
89 print("disk cache test complete.");