Bug 470241 - [Firefox] test_bug248970_cache.js leaks; (Av1a) trivial cleanup; r=sdwilsh
authorSerge Gautherie <sgautherie.bz@free.fr>
Tue, 02 Jun 2009 16:39:49 +0200
changeset 25848 24f007882aff83e04924b66f11df82fae8fc92ca
parent 25847 2c9e498c400cc06bdecbf69ba80656c70e742b30
child 25849 51450142f83bd24a0bc9c88343f4e9f2e8eb612e
push id1634
push usersgautherie.bz@free.fr
push dateTue, 02 Jun 2009 14:40:25 +0000
reviewerssdwilsh
bugs470241
milestone1.9.1pre
Bug 470241 - [Firefox] test_bug248970_cache.js leaks; (Av1a) trivial cleanup; r=sdwilsh
netwerk/test/unit/test_bug248970_cache.js
--- 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();