2001-03-01 02:52:20 +03:00
|
|
|
var nsICache = Components.interfaces.nsICache;
|
|
|
|
|
2001-02-28 08:06:25 +03:00
|
|
|
function getCacheService()
|
|
|
|
{
|
|
|
|
var nsCacheService = Components.classes["@mozilla.org/network/cache-service;1"];
|
|
|
|
var service = nsCacheService.getService(Components.interfaces.nsICacheService);
|
|
|
|
return service;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createCacheSession(clientID, storagePolicy, streamable)
|
|
|
|
{
|
|
|
|
var service = getCacheService();
|
|
|
|
var session = service.createSession(clientID, storagePolicy, streamable);
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
2001-03-01 02:52:20 +03:00
|
|
|
function openCacheEntry(mode)
|
2001-02-28 08:06:25 +03:00
|
|
|
{
|
|
|
|
var session = createCacheSession("javascript", nsICache.STORE_ON_DISK, true);
|
2001-03-01 02:52:20 +03:00
|
|
|
var entry = session.openCacheEntry("theme:button", mode);
|
2001-02-28 08:06:25 +03:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
function dumpLeaks()
|
|
|
|
{
|
|
|
|
var leakDetector = Components.classes["@mozilla.org/xpcom/leakdetector;1"].getService(Components.interfaces.nsILeakDetector);
|
|
|
|
leakDetector.dumpLeaks();
|
|
|
|
}
|
|
|
|
|
2001-03-01 02:52:20 +03:00
|
|
|
var entry = openCacheEntry(nsICache.ACCESS_WRITE);
|
|
|
|
var output = entry.transport.openOutputStream(0, -1, 0);
|
2001-02-28 08:06:25 +03:00
|
|
|
if (output.write("foo", 3) == 3)
|
2001-03-01 02:52:20 +03:00
|
|
|
print("disk cache write works!");
|
2001-02-28 08:06:25 +03:00
|
|
|
else
|
2001-03-01 02:52:20 +03:00
|
|
|
print("disk cache write broken!");
|
|
|
|
output.close();
|
2001-02-28 08:06:25 +03:00
|
|
|
entry.markValid();
|
|
|
|
entry.close();
|
2001-03-01 02:52:20 +03:00
|
|
|
|
|
|
|
var newEntry = openCacheEntry(nsICache.ACCESS_READ);
|
|
|
|
var input = newEntry.transport.openInputStream(0, -1, 0);
|
|
|
|
if (input.available() == 3)
|
|
|
|
print("disk cache read works!");
|
|
|
|
else
|
|
|
|
print("disk cache read broken!");
|
|
|
|
input.close();
|
|
|
|
newEntry.close();
|