[not part of build] Now tests opening output and input streams.

This commit is contained in:
beard%netscape.com 2001-02-28 23:52:20 +00:00
Родитель 6e4f158401
Коммит b1aaa0444d
1 изменённых файлов: 18 добавлений и 9 удалений

Просмотреть файл

@ -1,3 +1,5 @@
var nsICache = Components.interfaces.nsICache;
function getCacheService() function getCacheService()
{ {
var nsCacheService = Components.classes["@mozilla.org/network/cache-service;1"]; var nsCacheService = Components.classes["@mozilla.org/network/cache-service;1"];
@ -8,16 +10,14 @@ function getCacheService()
function createCacheSession(clientID, storagePolicy, streamable) function createCacheSession(clientID, storagePolicy, streamable)
{ {
var service = getCacheService(); var service = getCacheService();
var nsICache = Components.interfaces.nsICache;
var session = service.createSession(clientID, storagePolicy, streamable); var session = service.createSession(clientID, storagePolicy, streamable);
return session; return session;
} }
function openCacheEntry() function openCacheEntry(mode)
{ {
var nsICache = Components.interfaces.nsICache;
var session = createCacheSession("javascript", nsICache.STORE_ON_DISK, true); var session = createCacheSession("javascript", nsICache.STORE_ON_DISK, true);
var entry = session.openCacheEntry("theme:button", nsICache.ACCESS_READ_WRITE); var entry = session.openCacheEntry("theme:button", mode);
return entry; return entry;
} }
@ -27,12 +27,21 @@ function dumpLeaks()
leakDetector.dumpLeaks(); leakDetector.dumpLeaks();
} }
var entry = openCacheEntry(); var entry = openCacheEntry(nsICache.ACCESS_WRITE);
var transport = entry.transport; var output = entry.transport.openOutputStream(0, -1, 0);
var output = transport.openOutputStream(0, -1, 0);
if (output.write("foo", 3) == 3) if (output.write("foo", 3) == 3)
print("disk cache works!"); print("disk cache write works!");
else else
print("disk cache sucks!"); print("disk cache write broken!");
output.close();
entry.markValid(); entry.markValid();
entry.close(); entry.close();
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();