Bug 470241 - [Firefox] test_bug248970_cache.js leaks; (Av1a) trivial cleanup; r=sdwilsh
--- a/netwerk/test/unit/test_bug248970_cache.js
+++ b/netwerk/test/unit/test_bug248970_cache.js
@@ -42,62 +42,68 @@ const Cr = Components.results;
// names for cache devices
const kDiskDevice = "disk";
const kMemoryDevice = "memory";
const kOfflineDevice = "offline";
// the name for our cache session
const kPrivateBrowsing = "PrivateBrowsing";
-var _PBSvc = null;
+var _PBSvc;
function get_privatebrowsing_service() {
if (_PBSvc)
return _PBSvc;
try {
_PBSvc = Cc["@mozilla.org/privatebrowsing;1"].
getService(Ci.nsIPrivateBrowsingService);
return _PBSvc;
} catch (e) {}
+
return null;
}
-var _CSvc = null;
+var _CSvc;
function get_cache_service() {
if (_CSvc)
return _CSvc;
return _CSvc = Cc["@mozilla.org/network/cache-service;1"].
getService(Ci.nsICacheService);
}
function setup_profile_dir() {
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
- var leafRandomName = "Cache" + Math.floor(Math.random() * 10000);
var dir = dirSvc.get("TmpD", Ci.nsILocalFile);
- dir.append(leafRandomName);
+ dir.append("Cache" + Math.floor(Math.random() * 10000));
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
+
var provider = {
getFile: function(prop, persistent) {
persistent.value = true;
+
if (prop == "ProfLD" ||
prop == "ProfD" ||
prop == "cachePDir")
return dir;
+
throw Cr.NS_ERROR_FAILURE;
},
+
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
+
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
+
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
}
function check_devices_available(devices) {
var cs = get_cache_service();
var found_devices = [];
var visitor = {
@@ -196,18 +202,19 @@ function retrieve_from_cache(aKey, aWher
var cacheEntry = session.openCacheEntry(aKey, Ci.nsICache.ACCESS_READ, true);
} catch (e) {
if (e.result == Cr.NS_ERROR_CACHE_KEY_NOT_FOUND ||
e.result == Cr.NS_ERROR_FAILURE)
// a key not found error is expected here, so we will simply return null
// to let the caller know that no data was retrieved. We also expect
// a generic failure error in case of the offline cache.
return null;
- else
- do_throw(e); // throw the textual error description
+
+ // Throw the textual error description.
+ do_throw(e);
}
var iStream = make_input_stream_scriptable(cacheEntry.openInputStream(0));
var read = iStream.read(iStream.available());
iStream.close();
cacheEntry.close();