Bug 459114 - helper function to provide a clean profile directory for xpcshell tests; merged patch and 2 bustage fixes
authorTed Mielczarek <ted.mielczarek@gmail.com>
Tue, 22 Sep 2009 02:05:28 +0200
changeset 26406 b8f01b7aadc32183ca3920f2d52fa553a7b79027
parent 26405 d3b1d076e611b796ca4125da20df930ef89ac0a3
child 26407 6b19fc023243dc81d3bf7d7cc19ea17d557a0b59
push id2000
push usersgautherie.bz@free.fr
push dateTue, 22 Sep 2009 00:06:01 +0000
bugs459114
milestone1.9.1.4pre
Bug 459114 - helper function to provide a clean profile directory for xpcshell tests; merged patch and 2 bustage fixes r=sdwilsh
browser/components/places/tests/unit/head_bookmarks.js
extensions/cookie/test/unit/test_permmanager_removeall.js
js/src/Makefile.in
modules/plugin/test/unit/head_plugins.js
modules/plugin/test/unit/test_bug455213.js
netwerk/test/unit/test_bug248970_cache.js
testing/xpcshell/example/unit/test_get_file.js
testing/xpcshell/example/unit/test_profile.js
testing/xpcshell/head.js
testing/xpcshell/runxpcshelltests.py
toolkit/components/downloads/test/schema_migration/head_migration.js
toolkit/components/downloads/test/unit/head_download_manager.js
toolkit/components/downloads/test/unit/test_bug_382825.js
toolkit/components/downloads/test/unit/test_bug_395092.js
toolkit/components/downloads/test/unit/test_bug_401430.js
toolkit/components/downloads/test/unit/test_bug_401582.js
toolkit/components/downloads/test/unit/test_bug_409179.js
toolkit/components/downloads/test/unit/test_bug_420230.js
toolkit/components/downloads/test/unit/test_download_manager.js
toolkit/components/downloads/test/unit/test_privatebrowsing.js
toolkit/components/passwordmgr/test/unit/head_storage_legacy_1.js
toolkit/components/places/tests/autocomplete/head_000.js
toolkit/components/places/tests/bookmarks/head_bookmarks.js
toolkit/components/places/tests/queries/head_queries.js
toolkit/components/places/tests/unit/head_bookmarks.js
toolkit/components/satchel/test/unit/head_satchel.js
toolkit/components/url-classifier/tests/unit/head_urlclassifier.js
toolkit/mozapps/extensions/test/unit/head_extensionmanager.js
toolkit/mozapps/extensions/test/unit/tail_extensionmanager.js
--- a/browser/components/places/tests/unit/head_bookmarks.js
+++ b/browser/components/places/tests/unit/head_bookmarks.js
@@ -49,36 +49,24 @@ var Cr = Components.results;
 
 function LOG(aMsg) {
   aMsg = ("*** PLACES TESTS: " + aMsg);
   Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).
                                       logStringMessage(aMsg);
   print(aMsg);
 }
 
+var gProfD = do_get_profile();
 var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
              getService(Ci.nsIProperties);
-// Remove '/unit/*.js'.
-var gTestRoot = __LOCATION__.parent.parent;
-gTestRoot.normalize();
-
-// Need to create and register a profile folder.
-var gProfD = gTestRoot.clone();
-gProfD.append("profile");
-if (gProfD.exists())
-  gProfD.remove(true);
-gProfD.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
 
 var dirProvider = {
   getFile: function(prop, persistent) {
     persistent.value = true;
-    if (prop == NS_APP_USER_PROFILE_50_DIR ||
-        prop == NS_APP_PROFILE_DIR_STARTUP)
-      return gProfD.clone();
-    else if (prop == NS_APP_BOOKMARKS_50_FILE) {
+    if (prop == NS_APP_BOOKMARKS_50_FILE) {
       var bmarks = gProfD.clone();
       bmarks.append("bookmarks.html");
       return bmarks;
     }
     return null;
   },
   QueryInterface: function(iid) {
     if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
--- a/extensions/cookie/test/unit/test_permmanager_removeall.js
+++ b/extensions/cookie/test/unit/test_permmanager_removeall.js
@@ -1,37 +1,14 @@
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 function run_test() {
   // setup a profile directory
-  var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
-               getService(Ci.nsIProperties);
-  var leafRandomName = "PermMgr" + Math.floor(Math.random() * 10000);
-  var dir = dirSvc.get("TmpD", Ci.nsILocalFile);
-  dir.append(leafRandomName);
-  dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
-  var provider = {
-    getFile: function(prop, persistent) {
-      persistent.value = true;
-      if (prop == "ProfLD" ||
-          prop == "ProfD")
-        return dir.clone();
-      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);
+  var dir = do_get_profile();
 
   // initialize the permission manager service
   var pm = Cc["@mozilla.org/permissionmanager;1"].
            getService(Ci.nsIPermissionManager);
 
   // get the db file
   var file = dir.clone();
   file.append("permissions.sqlite");
@@ -51,13 +28,9 @@ function run_test() {
   // prepare an empty hostperm.1 file so that it can be used for importing
   var hostperm = dir.clone();
   hostperm.append("hostperm.1");
   ostream.init(hostperm, 0x02 | 0x08, 0666, 0);
   ostream.close();
 
   // remove all should not throw
   pm.removeAll();
-
-  // cleanup
-  dirSvc.unregisterProvider(provider);
 }
-
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -38,16 +38,17 @@
 # ***** END LICENSE BLOCK *****
 
 DEPTH		= .
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 
 DIRS		= config
 
+run_for_side_effects := $(shell echo "MAKE: $(MAKE)")
 include $(DEPTH)/config/autoconf.mk
 
 MODULE		= js
 LIBRARY_NAME	= mozjs
 GRE_MODULE	= 1
 
 PROGRAM         = js$(BIN_SUFFIX)
 # The shell uses some 'HIDDEN' symbols to produce statistics, so we
new file mode 100644
--- /dev/null
+++ b/modules/plugin/test/unit/head_plugins.js
@@ -0,0 +1,66 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ *      Dave Townsend <dtownsend@oxymoronical.com>.
+ *
+ * Portions created by the Initial Developer are Copyright (C) 2007
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK *****
+ */
+
+// Finds the test plugin library
+function get_test_plugin() {
+  var plugins = gDirSvc.get("CurProcD", Ci.nsILocalFile);
+  plugins.append("plugins");
+  do_check_true(plugins.exists());
+  var plugin = plugins.clone();
+  // OSX plugin
+  plugin.append("Test.plugin");
+  if (plugin.exists()) {
+    plugin.normalize();
+    return plugin;
+  }
+  plugin = plugins.clone();
+  // *nix plugin
+  plugin.append("libnptest.so");
+  if (plugin.exists()) {
+    plugin.normalize();
+    return plugin;
+  }
+  // Windows plugin
+  plugin = plugins.clone();
+  plugin.append("nptest.dll");
+  if (plugin.exists()) {
+    plugin.normalize();
+    return plugin;
+  }
+  return null;
+}
--- a/modules/plugin/test/unit/test_bug455213.js
+++ b/modules/plugin/test/unit/test_bug455213.js
@@ -34,126 +34,62 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK *****
  */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
-const NS_APP_USER_PROFILE_50_DIR      = "ProfD";
-const NS_APP_PROFILE_DIR_STARTUP      = "ProfDS";
-
 // Plugin registry uses different field delimeters on different platforms
 var DELIM = ":";
 if ("@mozilla.org/windows-registry-key;1" in Components.classes)
   DELIM = "|";
 
-var gProfD;
+var gProfD = do_get_profile();
 var gDirSvc = Cc["@mozilla.org/file/directory_service;1"].
              getService(Ci.nsIProperties);
 
-// Creates a fake profile folder that the pluginhost will read our crafted
-// pluginreg.dat from
-function createProfileFolder() {
-  // Remove '/unit/*.js'.
-  gProfD = do_get_cwd();
-  gProfD.append("profile");
-  
-  if (gProfD.exists())
-    gProfD.remove(true);
-  gProfD.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
-  
-  var dirProvider = {
-    getFile: function(prop, persistent) {
-      persistent.value = true;
-      if (prop == NS_APP_USER_PROFILE_50_DIR ||
-          prop == NS_APP_PROFILE_DIR_STARTUP)
-        return gProfD.clone();
-      return null;
-    },
-    QueryInterface: function(iid) {
-      if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
-          iid.equals(Ci.nsISupports)) {
-        return this;
-      }
-      throw Components.results.NS_ERROR_NO_INTERFACE;
-    }
-  };
-  gDirSvc.QueryInterface(Ci.nsIDirectoryService)
-         .registerProvider(dirProvider);
-}
-
 // Writes out some plugin registry to the profile
 function write_registry(version, info) {
   var header = "Generated File. Do not edit.\n\n";
   header += "[HEADER]\n";
   header += "Version" + DELIM + version + DELIM + "$\n\n";
   header += "[PLUGINS]\n";
 
   var registry = gProfD.clone();
   registry.append("pluginreg.dat");
   var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
                            .createInstance(Components.interfaces.nsIFileOutputStream);
   // write, create, truncate
-  foStream.init(registry, 0x02 | 0x08 | 0x20, 0666, 0); 
+  foStream.init(registry, 0x02 | 0x08 | 0x20, 0666, 0);
 
   var charset = "UTF-8"; // Can be any character encoding name that Mozilla supports
   var os = Cc["@mozilla.org/intl/converter-output-stream;1"].
            createInstance(Ci.nsIConverterOutputStream);
   os.init(foStream, charset, 0, 0x0000);
-  
+
   os.writeString(header);
   os.writeString(info);
   os.close();
 }
 
-// Finds the test plugin library
-function get_test_plugin() {
-  var plugins = gDirSvc.get("CurProcD", Ci.nsILocalFile);
-  plugins.append("plugins");
-  do_check_true(plugins.exists());
-  var plugin = plugins.clone();
-  // OSX plugin
-  plugin.append("Test.plugin");
-  if (plugin.exists()) {
-    plugin.normalize();
-    return plugin;
-  }
-  plugin = plugins.clone();
-  // *nix plugin
-  plugin.append("libnptest.so");
-  if (plugin.exists()) {
-    plugin.normalize();
-    return plugin;
-  }
-  // Windows plugin
-  plugin = plugins.clone();
-  plugin.append("nptest.dll");
-  if (plugin.exists()) {
-    plugin.normalize();
-    return plugin;
-  }
-  return null;
-}
-
 // Finds the test nsIPluginTag
 function get_test_plugintag() {
   var host = Cc["@mozilla.org/plugin/host;1"].
              getService(Ci.nsIPluginHost);
   var tags = host.getPluginTags({});
   for (var i = 0; i < tags.length; i++) {
     if (tags[i].name == "Test Plug-in")
       return tags[i];
   }
   return null;
 }
 
 function run_test() {
-  createProfileFolder();
   var file = get_test_plugin();
   if (!file)
     do_throw("Plugin library not found");
 
   // Write out a 0.9 version registry that marks the test plugin as disabled
   var registry = "";
   registry += file.leafName + DELIM + "$\n";
   registry += file.path + DELIM + "$\n";
@@ -170,16 +106,9 @@ function run_test() {
     do_throw("Plugin tag not found");
 
   // If the plugin was not rescanned then this version will not be correct
   do_check_eq(plugin.version, "1.0.0.0");
   do_check_eq(plugin.description, "Plug-in for testing purposes.");
   // If the plugin registry was not read then the plugin will not be disabled
   do_check_true(plugin.disabled);
   do_check_false(plugin.blocklisted);
-
-  try {
-    gProfD.remove(true);
-  }
-  catch (e) {
-    // Failure to remove temp dir shouldn't be a test failure
-  }
 }
--- a/netwerk/test/unit/test_bug248970_cache.js
+++ b/netwerk/test/unit/test_bug248970_cache.js
@@ -65,47 +65,21 @@ 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 dir = dirSvc.get("TmpD", Ci.nsILocalFile);
-  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 = {
     visitDevice: function (deviceID, deviceInfo) {
       found_devices.push(deviceID);
@@ -229,17 +203,17 @@ function run_test() {
     prefBranch.setBoolPref("browser.privatebrowsing.keep_current_session", true);
 
     const kCacheA = "cache-A",
           kCacheB = "cache-B",
           kCacheC = "cache-C",
           kTestContent = "test content";
 
     // Simulate a profile dir for xpcshell
-    setup_profile_dir();
+    do_get_profile();
 
     var cs = get_cache_service();
 
     // Start off with an empty cache
     cs.evictEntries(Ci.nsICache.STORE_ANYWHERE);
 
     // Store cache-A, cache-B and cache-C
     store_in_cache(kCacheA, kTestContent, kMemoryDevice);
--- a/testing/xpcshell/example/unit/test_get_file.js
+++ b/testing/xpcshell/example/unit/test_get_file.js
@@ -1,9 +1,8 @@
-/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et: */
 /* ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
new file mode 100644
--- /dev/null
+++ b/testing/xpcshell/example/unit/test_profile.js
@@ -0,0 +1,52 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * The Mozilla Foundation
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *  Ted Mielczarek <ted.mielczarek@gmail.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+function run_test()
+{
+  let profd = do_get_profile();
+  do_check_true(profd.exists());
+  do_check_true(profd.isDirectory());
+  let dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
+                         .getService(Components.interfaces.nsIProperties);
+  let profd2 = dirSvc.get("ProfD", Components.interfaces.nsILocalFile);
+  do_check_true(profd2.exists());
+  do_check_true(profd2.isDirectory());
+  // make sure we got the same thing back...
+  do_check_true(profd.equals(profd2));
+}
--- a/testing/xpcshell/head.js
+++ b/testing/xpcshell/head.js
@@ -1,9 +1,8 @@
-/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et: */
 /* ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
@@ -310,8 +309,46 @@ function do_parse_document(aPath, aType)
   var parser = Components.classes[parserClass]
                          .createInstance(C_i.nsIDOMParser);
   var doc = parser.parseFromStream(stream, null, lf.fileSize, aType);
   parser = null;
   stream = null;
   lf = null;
   return doc;
 }
+
+/**
+ * Registers a directory with the profile service,
+ * and return the directory as an nsILocalFile.
+ *
+ * @return nsILocalFile of the profile directory.
+ */
+function do_get_profile() {
+  let env = Components.classes["@mozilla.org/process/environment;1"]
+                      .getService(Components.interfaces.nsIEnvironment);
+  // the python harness sets this in the environment for us
+  let profd = env.get("XPCSHELL_TEST_PROFILE_DIR");
+  let file = Components.classes["@mozilla.org/file/local;1"]
+                       .createInstance(Components.interfaces.nsILocalFile);
+  file.initWithPath(profd);
+
+  let dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
+                         .getService(Components.interfaces.nsIProperties);
+  let provider = {
+    getFile: function(prop, persistent) {
+      persistent.value = true;
+      if (prop == "ProfD" || prop == "ProfLD" || prop == "ProfDS") {
+        return file.clone();
+      }
+      throw Components.results.NS_ERROR_FAILURE;
+    },
+    QueryInterface: function(iid) {
+      if (iid.equals(Components.interfaces.nsIDirectoryProvider) ||
+          iid.equals(Components.interfaces.nsISupports)) {
+        return this;
+      }
+      throw Components.results.NS_ERROR_NO_INTERFACE;
+    }
+  };
+  dirSvc.QueryInterface(Components.interfaces.nsIDirectoryService)
+        .registerProvider(provider);
+  return file.clone();
+}
--- a/testing/xpcshell/runxpcshelltests.py
+++ b/testing/xpcshell/runxpcshelltests.py
@@ -32,21 +32,22 @@
 # use your version of this file under the terms of the MPL, indicate your
 # decision by deleting the provisions above and replace them with the notice
 # and other provisions required by the GPL or the LGPL. If you do not delete
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK ***** */
 
-import re, sys, os, os.path, logging
+import re, sys, os, os.path, logging, shutil
 import tempfile
 from glob import glob
 from optparse import OptionParser
 from subprocess import Popen, PIPE, STDOUT
+from tempfile import mkdtemp
 
 from automationutils import addCommonOptions, checkForCrashes, dumpLeakLog
 
 # Init logging
 log = logging.getLogger()
 handler = logging.StreamHandler(sys.stdout)
 log.setLevel(logging.INFO)
 log.addHandler(handler)
@@ -200,21 +201,27 @@ def runTests(xpcshell, testdirs=[], xreP
            ['-e', 'const _HEAD_FILES = [%s];' % cmdH] + \
            ['-e', 'const _TAIL_FILES = [%s];' % cmdT]
 
     # Now execute each test individually.
     for test in testfiles:
       # The test file will have to be loaded after the head files.
       cmdT = ['-e', 'const _TEST_FILE = ["%s"];' %
                       os.path.join(testdir, test).replace('\\', '/')]
+      # create a temp dir that the JS harness can stick a profile in
+      profd = mkdtemp()
+      env["XPCSHELL_TEST_PROFILE_DIR"] = profd
+
       proc = Popen(cmdH + cmdT + xpcsRunArgs,
                    stdout=pStdout, stderr=pStderr, env=env, cwd=testdir)
       # |stderr == None| as |pStderr| was either |None| or redirected to |stdout|.
       stdout, stderr = proc.communicate()
 
+      shutil.rmtree(profd, True)
+
       if interactive:
         # not sure what else to do here...
         return True
 
       if proc.returncode != 0 or (stdout is not None and re.search("^TEST-UNEXPECTED-FAIL", stdout, re.MULTILINE)):
         print """TEST-UNEXPECTED-FAIL | %s | test failed (with xpcshell return code: %d), see following log:
   >>>>>>>
   %s
--- a/toolkit/components/downloads/test/schema_migration/head_migration.js
+++ b/toolkit/components/downloads/test/schema_migration/head_migration.js
@@ -33,48 +33,20 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 
+do_get_profile();
+
 var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
              getService(Ci.nsIProperties);
-var profileDir = null;
-try {
-  profileDir = dirSvc.get("ProfD", Ci.nsIFile);
-} catch (e) { }
-if (!profileDir) {
-  // Register our own provider for the profile directory.
-  // It will simply return the current directory.
-  var provider = {
-    getFile: function(prop, persistent) {
-      persistent.value = true;
-      if (prop == "ProfD") {
-        return dirSvc.get("CurProcD", Ci.nsILocalFile);
-      } else if (prop == "DLoads") {
-        var file = dirSvc.get("CurProcD", Ci.nsILocalFile);
-        file.append("downloads.rdf");
-        return file;
-      }
-      print("*** Throwing trying to get " + prop);
-      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 importDatabaseFile(aFName)
 {
   var file = do_get_file(aFName);
   var newFile = dirSvc.get("ProfD", Ci.nsIFile);
   file.copyTo(newFile, "downloads.sqlite");
 }
 
--- a/toolkit/components/downloads/test/unit/head_download_manager.js
+++ b/toolkit/components/downloads/test/unit/head_download_manager.js
@@ -33,58 +33,49 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 // This file tests the download manager backend
 
 do_load_httpd_js();
+do_get_profile();
 
 function createURI(aObj)
 {
   var ios = Cc["@mozilla.org/network/io-service;1"].
             getService(Ci.nsIIOService);
   return (aObj instanceof Ci.nsIFile) ? ios.newFileURI(aObj) :
                                         ios.newURI(aObj, null, null);
 }
 
 var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
              getService(Ci.nsIProperties);
-var profileDir = null;
-try {
-  profileDir = dirSvc.get("ProfD", Ci.nsIFile);
-} catch (e) { }
-if (!profileDir) {
-  // Register our own provider for the profile directory.
-  // It will simply return the current directory.
-  var provider = {
-    getFile: function(prop, persistent) {
-      persistent.value = true;
-      if (prop == "ProfD") {
-        return dirSvc.get("CurProcD", Ci.nsILocalFile);
-      } else if (prop == "DLoads") {
-        var file = dirSvc.get("CurProcD", Ci.nsILocalFile);
-        file.append("downloads.rdf");
-        return file;
-      }
-      print("*** Throwing trying to get " + prop);
-      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;
+
+var provider = {
+  getFile: function(prop, persistent) {
+    persistent.value = true;
+    if (prop == "DLoads") {
+      var file = dirSvc.get("ProfD", Ci.nsILocalFile);
+      file.append("downloads.rdf");
+      return file;
+     }
+    print("*** Throwing trying to get " + prop);
+    throw Cr.NS_ERROR_FAILURE;
+  },
+  QueryInterface: function(iid) {
+    if (iid.equals(Ci.nsIDirectoryProvider) ||
+        iid.equals(Ci.nsISupports)) {
+      return this;
     }
-  };
-  dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
-}
-
+    throw Cr.NS_ERROR_NO_INTERFACE;
+  }
+};
+dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
 
 /**
  * Imports a download test file to use.  Works with rdf and sqlite files.
  *
  * @param aFName
  *        The name of the file to import.  This file should be located in the
  *        same directory as this file.
  */
@@ -95,41 +86,16 @@ function importDownloadsFile(aFName)
   if (/\.rdf$/i.test(aFName))
     file.copyTo(newFile, "downloads.rdf");
   else if (/\.sqlite$/i.test(aFName))
     file.copyTo(newFile, "downloads.sqlite");
   else
     do_throw("Unexpected filename!");
 }
 
-function cleanup()
-{
-  // removing rdf
-  var rdfFile = dirSvc.get("DLoads", Ci.nsIFile);
-  if (rdfFile.exists()) rdfFile.remove(true);
-
-  // removing database
-  var dbFile = dirSvc.get("ProfD", Ci.nsIFile);
-  dbFile.append("downloads.sqlite");
-  if (dbFile.exists())
-    try { dbFile.remove(true); } catch(e) { /* stupid windows box */ }
-
-  // remove places.sqlite since expiration won't work properly if we do not have
-  // a clean database file.
-  dbFile = dirSvc.get("ProfD", Ci.nsIFile);
-  dbFile.append("places.sqlite");
-  if (dbFile.exists())
-    try { dbFile.remove(true); } catch(e) { /* stupid windows box */ }
-
-  // removing downloaded file
-  var destFile = dirSvc.get("ProfD", Ci.nsIFile);
-  destFile.append("download.result");
-  if (destFile.exists()) destFile.remove(true);
-}
-
 var gDownloadCount = 0;
 /**
  * Adds a download to the DM, and starts it.
  * @param aParams (optional): an optional object which contains the function
  *                            parameters:
  *                              resultFileName: leaf node for the target file
  *                              targetFile: nsIFile for the target (overrides resultFileName)
  *                              sourceURI: the download source URI
@@ -142,17 +108,17 @@ function addDownload(aParams)
     aParams = {};
   if (!("resultFileName" in aParams))
     aParams.resultFileName = "download.result";
   if (!("targetFile" in aParams)) {
     aParams.targetFile = dirSvc.get("ProfD", Ci.nsIFile);
     aParams.targetFile.append(aParams.resultFileName);
   }
   if (!("sourceURI" in aParams))
-    aParams.sourceURI = "http://localhost:4444/res/language.properties";
+    aParams.sourceURI = "http://localhost:4444/head_download_manager.js";
   if (!("downloadName" in aParams))
     aParams.downloadName = null;
   if (!("runBeforeStart" in aParams))
     aParams.runBeforeStart = function () {};
 
   const nsIWBP = Ci.nsIWebBrowserPersist;
   var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
                 .createInstance(Ci.nsIWebBrowserPersist);
@@ -205,11 +171,8 @@ function getDownloadListener()
     onProgressChange: function(a, b, c, d, e, f, g) { },
     onSecurityChange: function(a, b, c, d) { }
   };
 }
 
 // Disable alert service notifications
 let ps = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch);
 ps.setBoolPref("browser.download.manager.showAlertOnComplete", false);
-
-cleanup();
-
--- a/toolkit/components/downloads/test/unit/test_bug_382825.js
+++ b/toolkit/components/downloads/test/unit/test_bug_382825.js
@@ -68,18 +68,16 @@ function test_retry_bad()
 }
 
 var tests = [test_retry_canceled, test_retry_bad];
 
 var httpserv = null;
 function run_test()
 {
   httpserv = new nsHttpServer();
-  httpserv.registerDirectory("/", dirSvc.get("ProfD", Ci.nsILocalFile));
+  httpserv.registerDirectory("/", do_get_cwd());
   httpserv.start(4444);
-  
+
   dm.addListener(getDownloadListener());
-  
+
   for (var i = 0; i < tests.length; i++)
     tests[i]();
-  
-  cleanup();
 }
--- a/toolkit/components/downloads/test/unit/test_bug_395092.js
+++ b/toolkit/components/downloads/test/unit/test_bug_395092.js
@@ -59,17 +59,17 @@ var observer = {
   }
 };
 
 var httpserv = null;
 var timer = null;
 function run_test()
 {
   httpserv = new nsHttpServer();
-  httpserv.registerDirectory("/", dirSvc.get("ProfD", Ci.nsILocalFile));
+  httpserv.registerDirectory("/", do_get_cwd());
   httpserv.start(4444);
 
   // our download listener
   var listener = {
     onDownloadStateChange: function(aOldState, aDownload)
     {
       if (Ci.nsIDownloadManager.DOWNLOAD_PAUSED == aDownload.state) {
         // This is so hacky, but it let's the nsWebBrowserPersist catch up with
--- a/toolkit/components/downloads/test/unit/test_bug_401430.js
+++ b/toolkit/components/downloads/test/unit/test_bug_401430.js
@@ -41,18 +41,17 @@ const nsIDownloadManager = Ci.nsIDownloa
 const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager);
 
 const resultFileName = "test" + Date.now() + ".doc";
 
 function checkResult() {
   do_check_true(checkRecentDocsFor(resultFileName));
 
   // delete the saved file
-  var resultFile = dirSvc.get("ProfD", Ci.nsIFile);
-  resultFile.append(resultFileName);
+  var resultFile = do_get_file(resultFileName);
   resultFile.remove(false);
 
   do_test_finished();
 }
 
 function checkRecentDocsFor(aFileName) {
   var recentDocsKey = Cc["@mozilla.org/windows-registry-key;1"].
                         createInstance(Ci.nsIWindowsRegKey);
@@ -87,17 +86,17 @@ function run_test()
                getService(Ci.nsIHttpProtocolHandler);
   if (httpPH.platform != "Windows")
     return;
 
   // Don't finish until the download is finished
   do_test_pending();
 
   httpserv = new nsHttpServer();
-  httpserv.registerDirectory("/", dirSvc.get("ProfD", Ci.nsILocalFile));
+  httpserv.registerDirectory("/", do_get_cwd());
   httpserv.start(4444);
 
   var listener = {
     onDownloadStateChange: function test_401430_odsc(aState, aDownload) {
       if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_FINISHED) {
         // Need to run this from a timeout, because the SHAddToRecentDocs call
         // doesn't update the registry immediately.
         do_timeout(1000, "checkResult();");
@@ -106,12 +105,14 @@ function run_test()
     onStateChange: function(a, b, c, d, e) { },
     onProgressChange: function(a, b, c, d, e, f, g) { },
     onSecurityChange: function(a, b, c, d) { }
   };
 
   dm.addListener(listener);
   dm.addListener(getDownloadListener());
 
-  var dl = addDownload({resultFileName: resultFileName});
-
-  cleanup();
+  // need to save the file to the CWD, because the profile dir is in $TEMP,
+  // and Windows apparently doesn't like putting things from $TEMP into
+  // the recent files list.
+  var dl = addDownload({resultFileName: resultFileName,
+                        targetFile: do_get_file(resultFileName, true)});
 }
--- a/toolkit/components/downloads/test/unit/test_bug_401582.js
+++ b/toolkit/components/downloads/test/unit/test_bug_401582.js
@@ -33,18 +33,16 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 // This tests that downloads in the scanning state are set to a completed state
 // upon service initialization.
 
-cleanup();
-
 importDownloadsFile("bug_401582_downloads.sqlite");
 
 const nsIDownloadManager = Ci.nsIDownloadManager;
 const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager);
 
 function test_noScanningDownloads()
 {
   var stmt = dm.DBConnection.createStatement(
@@ -59,11 +57,9 @@ function test_noScanningDownloads()
 }
 
 var tests = [test_noScanningDownloads];
 
 function run_test()
 {
   for (var i = 0; i < tests.length; i++)
     tests[i]();
-  
-  cleanup();
 }
--- a/toolkit/components/downloads/test/unit/test_bug_409179.js
+++ b/toolkit/components/downloads/test/unit/test_bug_409179.js
@@ -33,25 +33,21 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 // This file ensures that the download manager service can be instantiated with
 // a certain downloads.sqlite file that had incorrect data.
 
-cleanup();
-
 importDownloadsFile("bug_409179_downloads.sqlite");
 
 function run_test()
 {
   var caughtException = false;
   try {
     var dm = Cc["@mozilla.org/download-manager;1"].
              getService(Ci.nsIDownloadManager);
   } catch (e) {
     caughtException = true;
   }
   do_check_false(caughtException);
-  
-  cleanup();
 }
--- a/toolkit/components/downloads/test/unit/test_bug_420230.js
+++ b/toolkit/components/downloads/test/unit/test_bug_420230.js
@@ -42,69 +42,67 @@ const nsIDownloadManager = Ci.nsIDownloa
 const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager);
 
 function run_test()
 {
   // Don't finish until the download is finished
   do_test_pending();
 
   function addDownload() {
-    const nsIWBP = Ci.nsIWebBrowserPersist; 
-    var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"] 
-                  .createInstance(Ci.nsIWebBrowserPersist); 
-    persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES | 
-                           nsIWBP.PERSIST_FLAGS_BYPASS_CACHE | 
+    const nsIWBP = Ci.nsIWebBrowserPersist;
+    var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
+                  .createInstance(Ci.nsIWebBrowserPersist);
+    persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
+                           nsIWBP.PERSIST_FLAGS_BYPASS_CACHE |
                            nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
- 
+
     // Download to a temp local file
     let file = dirSvc.get("ProfD", Ci.nsIFile);
     file.append("policychecktest.png");
     if (file.exists())
       file.remove(false);
     file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
 
     gDownloadCount++;
 
-    var dl = dm.addDownload(Ci.nsIDownloadManager.DOWNLOAD_TYPE_DOWNLOAD, 
-                            createURI("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACGFjVEwAAAAEAAAAAHzNZtAAAAAaZmNUTAAAAAAAAAAQAAAAEAAAAAAAAAAAAPoD6AEBim0EngAAAfVJREFUOI2tke9LEwEYx/0vwwgpRKLoTRC+iAhXSFJYYEERbZjd1N1+5I+dW+laeh1rmkKzbbftpuvWvN020aSs5t0+vVgO5hy98QvfNw/P9/N94OnpOUvp1UO8sSrCSpmX0RL+mMHCeoUP6V0S29/JlX6g6vt0BQTiVRLf6qimTdq0SZdtFiIKzukgvvlFBHGWKWm1E3Cy2bVU5Pmbr4iSwtjrT8jqDr+A1S0TlxiiVqvx3+ZU2WbcM8dUvERuD5ImpHYhlDAIhRfbARPvd1BNm0yladW0SRoWLsHHhgnZGpQPoPoT0nvgFPztAOdSkYxpoZoWXwyLzZJFomQxLnhYzu5hHsJvCw5siCQN3O7JdsCzcIFMpRmKbdWRtTqK9gePL4gwG0XVKxwBa7kST168wjCMdsDjeY1Nw0LJH7GSa9o7JyOKPgZvDuH1z+CenMI14WFsWu78wsOAymrBaoVFKY5e0Bm4eh1Zs5A1i8ujEeR8g77hcCdgxJNEyTcXRX8IfVvn4sA13qUOkTUbWbPpv7+InG/Q65A6AXeFz63Fj8tLDDpGcc6s/Zs1Ws2TcoX+e6dccGt8vQU4Dpx0r0PigiOIkih2AoYm1gms7Z8alPON7s3H2sia3HiqcOVRlI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0+WWuOCOoqR32gH9vlUmVw7OLMrFemfzyaxtWNx4onBlOEXvgySXBt/QPRDn/B2Jc7cjnc0ul+sPqZsqAeXgvCsAAAAASUVORK5CYII="), 
-                            createURI(file), null, null, 
-                            Math.round(Date.now() * 1000), null, persist); 
- 
-    persist.progressListener = dl.QueryInterface(Ci.nsIWebProgressListener); 
-    persist.saveURI(dl.source, null, null, null, null, dl.targetFile); 
- 
-    return dl; 
-  } 
+    var dl = dm.addDownload(Ci.nsIDownloadManager.DOWNLOAD_TYPE_DOWNLOAD,
+                            createURI("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACGFjVEwAAAAEAAAAAHzNZtAAAAAaZmNUTAAAAAAAAAAQAAAAEAAAAAAAAAAAAPoD6AEBim0EngAAAfVJREFUOI2tke9LEwEYx/0vwwgpRKLoTRC+iAhXSFJYYEERbZjd1N1+5I+dW+laeh1rmkKzbbftpuvWvN020aSs5t0+vVgO5hy98QvfNw/P9/N94OnpOUvp1UO8sSrCSpmX0RL+mMHCeoUP6V0S29/JlX6g6vt0BQTiVRLf6qimTdq0SZdtFiIKzukgvvlFBHGWKWm1E3Cy2bVU5Pmbr4iSwtjrT8jqDr+A1S0TlxiiVqvx3+ZU2WbcM8dUvERuD5ImpHYhlDAIhRfbARPvd1BNm0yladW0SRoWLsHHhgnZGpQPoPoT0nvgFPztAOdSkYxpoZoWXwyLzZJFomQxLnhYzu5hHsJvCw5siCQN3O7JdsCzcIFMpRmKbdWRtTqK9gePL4gwG0XVKxwBa7kST168wjCMdsDjeY1Nw0LJH7GSa9o7JyOKPgZvDuH1z+CenMI14WFsWu78wsOAymrBaoVFKY5e0Bm4eh1Zs5A1i8ujEeR8g77hcCdgxJNEyTcXRX8IfVvn4sA13qUOkTUbWbPpv7+InG/Q65A6AXeFz63Fj8tLDDpGcc6s/Zs1Ws2TcoX+e6dccGt8vQU4Dpx0r0PigiOIkih2AoYm1gms7Z8alPON7s3H2sia3Hi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W0CTgqn0+WWuOCOoqR32gH9vlUmVw7OLMrFemfzyaxtWNx4onBlOEXvgySXBt/QPRDn/B2Jc7cjnc0ul+sPqZsqAeXgvCsAAAAASUVORK5CYII="),
+                            createURI(file), null, null,
+                            Math.round(Date.now() * 1000), null, persist);
+
+    persist.progressListener = dl.QueryInterface(Ci.nsIWebProgressListener);
+    persist.saveURI(dl.source, null, null, null, null, dl.targetFile);
+
+    return dl;
+  }
 
   let listener = {
     onDownloadStateChange: function(aState, aDownload)
     {
       switch (aDownload.state) {
         case dm.DOWNLOAD_FAILED:
         case dm.DOWNLOAD_CANCELED:
         case dm.DOWNLOAD_DIRTY:
         case dm.DOWNLOAD_BLOCKED_POLICY:
           // Fail!
           if (aDownload.targetFile.exists())
             aDownload.targetFile.remove(false);
           dm.removeListener(this);
           do_throw("data: uri failed to download successfully");
           do_test_finished();
           break;
-          
+
         case dm.DOWNLOAD_FINISHED:
           do_check_true(aDownload.targetFile.exists());
           aDownload.targetFile.remove(false);
           dm.removeListener(this);
           do_test_finished();
           break;
       }
     },
     onStateChange: function(a, b, c, d, e) { }
   };
 
   dm.addListener(listener);
   dm.addListener(getDownloadListener());
-  
+
   addDownload();
-
-  cleanup();
 }
--- a/toolkit/components/downloads/test/unit/test_download_manager.js
+++ b/toolkit/components/downloads/test/unit/test_download_manager.js
@@ -107,35 +107,35 @@ function test_addDownload_cancel()
   print("*** DOWNLOAD MANAGER TEST - Testing download cancel");
   var dl = addDownload();
 
   dm.cancelDownload(dl.id);
 
   do_check_eq(nsIDownloadManager.DOWNLOAD_CANCELED, dl.state);
 }
 
-// This test is actually ran by the observer 
+// This test is actually ran by the observer
 function test_dm_getDownload(aDl)
 {
   // this will get it from the database
   var dl = dm.getDownload(aDl.id);
-  
+
   do_check_eq(aDl.displayName, dl.displayName);
 }
 
 var tests = [test_get_download_empty_queue, test_connection,
              test_count_empty_queue, test_canCleanUp_empty_queue,
              test_pauseDownload_empty_queue, test_resumeDownload_empty_queue,
              test_addDownload_normal, test_addDownload_cancel];
 
 var httpserv = null;
 function run_test()
 {
   httpserv = new nsHttpServer();
-  httpserv.registerDirectory("/", dirSvc.get("ProfD", Ci.nsILocalFile));
+  httpserv.registerDirectory("/", do_get_cwd());
   httpserv.start(4444);
 
   // our download listener
   var listener = {
     // this listener checks to ensure activeDownloadCount is correct.
     onDownloadStateChange: function(aState, aDownload)
     {
       do_check_eq(gDownloadCount, dm.activeDownloadCount);
@@ -156,11 +156,9 @@ function run_test()
     }
   };
   var os = Cc["@mozilla.org/observer-service;1"]
            .getService(Ci.nsIObserverService);
   os.addObserver(observer, "dl-cancel", false);
 
   for (var i = 0; i < tests.length; i++)
     tests[i]();
-
-  cleanup();
 }
--- a/toolkit/components/downloads/test/unit/test_privatebrowsing.js
+++ b/toolkit/components/downloads/test/unit/test_privatebrowsing.js
@@ -48,17 +48,17 @@
     * Check that Download-B is retrievable.
     * Exit private browsing mode.
     * Check that Download-A is retrievable.
     * Check that Download-B is not accessible.
     * Create a new download (Download-C) with specific details.
       Start it and enter private browsing mode immediately after.
     * Check that Download-C has been paused.
     * Exit the private browsing mode.
-    * Verify that Download-C resumes and finishes correctly now. 
+    * Verify that Download-C resumes and finishes correctly now.
 **/
 
 this.__defineGetter__("pb", function () {
   delete this.pb;
   try {
     return this.pb = Cc["@mozilla.org/privatebrowsing;1"].
                      getService(Ci.nsIPrivateBrowsingService);
   } catch (e) {}
@@ -110,17 +110,17 @@ function run_test() {
     return;
 
   let prefBranch = Cc["@mozilla.org/preferences-service;1"].
                    getService(Ci.nsIPrefBranch);
   prefBranch.setBoolPref("browser.privatebrowsing.keep_current_session", true);
 
   do_test_pending();
   let httpserv = new nsHttpServer();
-  httpserv.registerDirectory("/", dirSvc.get("ProfD", Ci.nsILocalFile));
+  httpserv.registerDirectory("/", do_get_cwd());
 
   let tmpDir = Cc["@mozilla.org/file/directory_service;1"].
                getService(Ci.nsIProperties).
                get("TmpD", Ci.nsIFile);
   const nsIWBP = Ci.nsIWebBrowserPersist;
 
   // make sure we're starting with an empty DB
   do_check_eq(dm.activeDownloadCount, 0);
@@ -303,17 +303,17 @@ function run_test() {
   // properties of Download-B
   let downloadB = -1;
   const downloadBSource = "data:application/octet-stream;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9gKHhQaLFEVkXsAAAAIdEVYdENvbW1lbnQA9syWvwAABXZJREFUaN7VmnuIVUUcxz/3uma5ZJJmrZGVuZWupGSZsVNwTRYJYk8vRzd6o0kglgpm9q/ZEhlBUEssUpTtqMixl6LlURtDwyzCWmLxkZZL6qZRi/nc/tjf2Ybjufd6797HOrDM7NzfmfP9zfzm9zxwkbdEIRYxyhsCTAYmAWOBkcAwYBBwFugEDgN7gd3AdmCTtn5HWRkwynsamA7U5bnEBqBFW395SRkwylsIzAWqnOnvgTVAG3AIOA4cAwYAlwFDgZuAUcB4YApQIc+2A29p6zcWlQGjvEeBJUC1TO0BmoAPtfXbc1yrH/AwMB+YKNNtwGJt/VUFZ8Ao713gOfn3O2CBtv7mAt2hUcAi4BmZatLWn10QBozyRgArgFoRixe09d8vhkYxypsKfAwMBrYBDdr6B/JmwChvNLBWRCYA6rX1/y6mWjTKqwQ+BVIiUvXa+q3p6JNZdj4E3wJMKTZ4AG39TuA+oFnevVaw5MaAiE01sEJbf4a2/rlSGSdt/S5gJrAqxJATA3Jha4GdwFPlsLDChBZbUSuYst8BUZUr5cKOyVU9FuFODAZagWuAaVEVG3cCS6SfWW7wchLHgcci2OIZEAtbDWzR1l/dVxw2bf1N4X0QjD2tIkI7V/oF7qQyqa40a58Rd6EVWA+8Z3VwNI4wwxqIs/e7OHnNVgdbY2gWAQ8JxsbzTkAcsyog0NbfeYGbUwFcBdwLvAq0KpNK5bHJlcDNwBPAFmVS7yiTSkZOYQ+wGqgSrOeJ0HTpmzO9yeogEf6JozZOrC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+KOb9iAAAAABJRU5ErkJggg==";
   const downloadBDest = "download-file-B";
   const downloadBName = "download-B";
 
   // properties of Download-C
   let downloadC = -1;
-  const downloadCSource = "http://localhost:4444/res/language.properties";
+  const downloadCSource = "http://localhost:4444/head_download_manager.js";
   const downloadCDest = "download-file-C";
   const downloadCName = "download-C";
 
   // Create all target files
   let fileA = tmpDir.clone();
   fileA.append(downloadADest);
   fileA.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   let fileB = tmpDir.clone();
--- a/toolkit/components/passwordmgr/test/unit/head_storage_legacy_1.js
+++ b/toolkit/components/passwordmgr/test/unit/head_storage_legacy_1.js
@@ -1,50 +1,19 @@
 // Copied from components/places/tests/unit/head_bookmarks.js
 
 const NS_APP_USER_PROFILE_50_DIR = "ProfD";
 const Ci = Components.interfaces;
 const Cc = Components.classes;
 const Cr = Components.results;
 
-
-
 // Various functions common to the tests.
 const LoginTest = {
 
   /*
-   * makeDirectoryService
-   *
-   */
-  makeDirectoryService : function () {
-    // Register our own provider for the profile directory.
-    // It will simply return the current directory.
-    const provider = {
-        getFile : function(prop, persistent) {
-            persistent.value = true;
-            if (prop == NS_APP_USER_PROFILE_50_DIR) {
-                return dirSvc.get("CurProcD", Ci.nsIFile);
-            }
-            throw Cr.NS_ERROR_FAILURE;
-        },
-
-        QueryInterface : function(iid) {
-            if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
-                iid.equals(Ci.nsISupports)) {
-                return this;
-            }
-            throw Cr.NS_ERROR_NO_INTERFACE;
-        }
-    };
-
-    dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
-  },
-
-
-  /*
    * initStorage
    *
    */
   initStorage : function (aInputPathName,  aInputFileName,
                           aOutputPathName, aOutputFileName, aExpectedError) {
     var err = null;
 
     var newStorage = this.newStorage();
@@ -202,29 +171,29 @@ const LoginTest = {
     var inputStream = Cc["@mozilla.org/network/file-input-stream;1"].
                       createInstance(Ci.nsIFileInputStream);
     // init the stream as RD_ONLY, -1 == default permissions.
     inputStream.init(inputFile, 0x01, -1, null);
     var lineStream = inputStream.QueryInterface(Ci.nsILineInputStream);
 
     var line = { value : null };
     var lineCount = 1; // Empty files were dealt with above.
-    while (lineStream.readLine(line)) 
+    while (lineStream.readLine(line))
         lineCount++;
 
     return lineCount;
   },
 
   newStorage : function () {
     var ID;
 
     if (STORAGE_TYPE == "legacy")
-        ID = "@mozilla.org/login-manager/storage/legacy;1"; 
+        ID = "@mozilla.org/login-manager/storage/legacy;1";
     else if (STORAGE_TYPE == "mozStorage")
-        ID = "@mozilla.org/login-manager/storage/mozStorage;1"; 
+        ID = "@mozilla.org/login-manager/storage/mozStorage;1";
     else
         throw "Unknown STORAGE_TYPE";
 
     var storage = Cc[ID].
                   createInstance(Ci.nsILoginManagerStorage);
     if (!storage)
       throw "Couldn't create storage instance.";
     return storage;
@@ -266,32 +235,18 @@ const LoginTest = {
 
     if (profileFile.exists())
         profileFile.remove(false);
 
     file.copyTo(PROFDIR, filename);
   }
 };
 
-
-// If there's no location registered for the profile direcotry, register one
-var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
-             getService(Ci.nsIProperties);
-try {
-    var profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
-} catch (e) { }
-
-if (!profileDir) {
-    LoginTest.makeDirectoryService();
-    profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
-}
-
-
 // nsIFiles...
-var PROFDIR = profileDir;
+var PROFDIR = do_get_profile();
 var DATADIR = do_get_file("data/");
 // string versions...
 var OUTDIR = PROFDIR.path;
 var INDIR = DATADIR.path;
 
 // Copy key3.db into the profile used for the unit tests. Need this so we can
 // decrypt the encrypted logins stored in the various tests inputs.
 LoginTest.copyFile("key3.db");
--- a/toolkit/components/places/tests/autocomplete/head_000.js
+++ b/toolkit/components/places/tests/autocomplete/head_000.js
@@ -38,48 +38,38 @@
 
 const NS_APP_USER_PROFILE_50_DIR = "ProfD";
 const NS_APP_HISTORY_50_FILE = "UHist";
 
 const Ci = Components.interfaces;
 const Cc = Components.classes;
 const Cr = Components.results;
 
-// If there's no location registered for the profile direcotry, register one now.
+var profDir = do_get_profile();
+
 let dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
-let profileDir = null;
-try {
-  profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
-} catch (e) {}
-if (!profileDir) {
-  // Register our own provider for the profile directory.
-  // It will simply return the current directory.
-  let provider = {
-    getFile: function(prop, persistent) {
-      persistent.value = true;
-      if (prop == NS_APP_USER_PROFILE_50_DIR) {
-        return dirSvc.get("CurProcD", Ci.nsIFile);
-      }
-      if (prop == NS_APP_HISTORY_50_FILE) {
-        let histFile = dirSvc.get("CurProcD", Ci.nsIFile);
-        histFile.append("history.dat");
-        return histFile;
-      }
-      throw Cr.NS_ERROR_FAILURE;
-    },
-    QueryInterface: function(iid) {
-      if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
-          iid.equals(Ci.nsISupports)) {
-        return this;
-      }
-      throw Cr.NS_ERROR_NO_INTERFACE;
+let provider = {
+  getFile: function(prop, persistent) {
+    persistent.value = true;
+    if (prop == NS_APP_HISTORY_50_FILE) {
+      let histFile = profDir.clone();
+      histFile.append("history.dat");
+      return histFile;
     }
-  };
-  dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
-}
+    throw Cr.NS_ERROR_FAILURE;
+  },
+  QueryInterface: function(iid) {
+    if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
+        iid.equals(Ci.nsISupports)) {
+      return this;
+    }
+    throw Cr.NS_ERROR_NO_INTERFACE;
+  }
+};
+dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
 
 // Delete a previously created sqlite file
 function clearDB() {
   try {
     let file = dirSvc.get('ProfD', Ci.nsIFile);
     file.append("places.sqlite");
     if (file.exists())
       file.remove(false);
--- a/toolkit/components/places/tests/bookmarks/head_bookmarks.js
+++ b/toolkit/components/places/tests/bookmarks/head_bookmarks.js
@@ -44,44 +44,19 @@ const Cr = Components.results;
 
 function LOG(aMsg) {
   aMsg = ("*** PLACES TESTS: " + aMsg);
   Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).
                                       logStringMessage(aMsg);
   print(aMsg);
 }
 
-// If there's no location registered for the profile direcotry, register one now.
+do_get_profile();
+
 var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
-var profileDir = null;
-try {
-  profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
-} catch (e) {}
-if (!profileDir) {
-  // Register our own provider for the profile directory.
-  // It will simply return the current directory.
-  var provider = {
-    getFile: function(prop, persistent) {
-      persistent.value = true;
-      if (prop == NS_APP_USER_PROFILE_50_DIR) {
-        return dirSvc.get("CurProcD", Ci.nsIFile);
-      }
-      throw Cr.NS_ERROR_FAILURE;
-    },
-    QueryInterface: function(iid) {
-      if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
-          iid.equals(Ci.nsISupports)) {
-        return this;
-      }
-      throw Cr.NS_ERROR_NO_INTERFACE;
-    }
-  };
-  dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
-}
-
 var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
 
 function uri(spec) {
   return iosvc.newURI(spec, null, null);
 }
 
 // Delete a previously created sqlite file
 function clearDB() {
--- a/toolkit/components/places/tests/queries/head_queries.js
+++ b/toolkit/components/places/tests/queries/head_queries.js
@@ -54,46 +54,37 @@ const futureday = today + (DAY_MICROSEC 
 
 function LOG(aMsg) {
  aMsg = ("*** PLACES TESTS: " + aMsg);
  print(aMsg);
 }
 
 // If there's no location registered for the profile directory, register one now.
 var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
-var profileDir = null;
-try {
- profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
-} catch (e) {}
-if (!profileDir) {
- // Register our own provider for the profile directory.
- // It will simply return the current directory.
- var provider = {
-   getFile: function(prop, persistent) {
-     persistent.value = true;
-     if (prop == NS_APP_USER_PROFILE_50_DIR) {
-       return dirSvc.get("CurProcD", Ci.nsIFile);
-     }
-     if (prop == NS_APP_HISTORY_50_FILE) {
-       var histFile = dirSvc.get("CurProcD", Ci.nsIFile);
-       histFile.append("history.dat");
-       return histFile;
-     }
-     throw Cr.NS_ERROR_FAILURE;
-   },
-   QueryInterface: function(iid) {
-     if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
-         iid.equals(Ci.nsISupports)) {
-       return this;
-     }
-     throw Cr.NS_ERROR_NO_INTERFACE;
-   }
- };
- dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
-}
+var profileDir = do_get_profile();
+
+var provider = {
+  getFile: function(prop, persistent) {
+    persistent.value = true;
+    if (prop == NS_APP_HISTORY_50_FILE) {
+      var histFile = profileDir.clone();
+      histFile.append("history.dat");
+      return histFile;
+    }
+    throw Cr.NS_ERROR_FAILURE;
+  },
+  QueryInterface: function(iid) {
+    if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
+        iid.equals(Ci.nsISupports)) {
+      return this;
+    }
+    throw Cr.NS_ERROR_NO_INTERFACE;
+  }
+};
+dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
 
 var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
 
 function uri(spec) {
  return iosvc.newURI(spec, null, null);
 }
 
 // Delete a previously created sqlite file
--- a/toolkit/components/places/tests/unit/head_bookmarks.js
+++ b/toolkit/components/places/tests/unit/head_bookmarks.js
@@ -46,48 +46,38 @@ const Cr = Components.results;
 
 function LOG(aMsg) {
   aMsg = ("*** PLACES TESTS: " + aMsg);
   Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).
                                       logStringMessage(aMsg);
   print(aMsg);
 }
 
-// If there's no location registered for the profile direcotry, register one now.
+do_get_profile();
+
 var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
-var profileDir = null;
-try {
-  profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
-} catch (e) {}
-if (!profileDir) {
-  // Register our own provider for the profile directory.
-  // It will simply return the current directory.
-  var provider = {
-    getFile: function(prop, persistent) {
-      persistent.value = true;
-      if (prop == NS_APP_USER_PROFILE_50_DIR) {
-        return dirSvc.get("CurProcD", Ci.nsIFile);
-      }
-      if (prop == NS_APP_HISTORY_50_FILE) {
-        var histFile = dirSvc.get("CurProcD", Ci.nsIFile);
-        histFile.append("history.dat");
-        return histFile;
-      }
-      throw Cr.NS_ERROR_FAILURE;
-    },
-    QueryInterface: function(iid) {
-      if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
-          iid.equals(Ci.nsISupports)) {
-        return this;
-      }
-      throw Cr.NS_ERROR_NO_INTERFACE;
+var provider = {
+  getFile: function(prop, persistent) {
+    persistent.value = true;
+    if (prop == NS_APP_HISTORY_50_FILE) {
+      var histFile = dirSvc.get("ProfD", Ci.nsIFile);
+      histFile.append("history.dat");
+      return histFile;
     }
-  };
-  dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
-}
+    throw Cr.NS_ERROR_FAILURE;
+  },
+  QueryInterface: function(iid) {
+    if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
+        iid.equals(Ci.nsISupports)) {
+      return this;
+    }
+    throw Cr.NS_ERROR_NO_INTERFACE;
+  }
+};
+dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
 
 var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
 
 function uri(spec) {
   return iosvc.newURI(spec, null, null);
 }
 
 // Delete a previously created sqlite file
--- a/toolkit/components/satchel/test/unit/head_satchel.js
+++ b/toolkit/components/satchel/test/unit/head_satchel.js
@@ -29,55 +29,27 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
- 
+
 const Ci = Components.interfaces;
 const Cc = Components.classes;
 
 const CURRENT_SCHEMA = 2;
 const PR_HOURS = 60 * 60 * 1000000;
 
-
-var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
-             getService(Ci.nsIProperties);
+do_get_profile();
 
 var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
              getService(Ci.nsIProperties);
-var profileDir = null;
-try {
-  profileDir = dirSvc.get("ProfD", Ci.nsIFile);
-} catch (e) { }
-if (!profileDir) {
-  // Register our own provider for the profile directory.
-  // It will simply return the current directory.
-  var provider = {
-    getFile: function(prop, persistent) {
-      persistent.value = true;
-      if (prop == "ProfD") {
-        return dirSvc.get("CurProcD", Ci.nsILocalFile);
-      }
-      print("*** Throwing trying to get " + prop);
-      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 getDBVersion(dbfile) {
     var ss = Cc["@mozilla.org/storage/service;1"].
              getService(Ci.mozIStorageService);
     var dbConnection = ss.openDatabase(dbfile);
     var version = dbConnection.schemaVersion;
     dbConnection.close();
 
--- a/toolkit/components/url-classifier/tests/unit/head_urlclassifier.js
+++ b/toolkit/components/url-classifier/tests/unit/head_urlclassifier.js
@@ -3,46 +3,19 @@ function dumpn(s) {
 }
 
 const NS_APP_USER_PROFILE_50_DIR = "ProfD";
 const NS_APP_USER_PROFILE_LOCAL_50_DIR = "ProfLD";
 const Ci = Components.interfaces;
 const Cc = Components.classes;
 const Cr = Components.results;
 
-// If there's no location registered for the profile direcotry, register one now.
-var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
-var profileDir = null;
-try {
-  profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
-} catch (e) {}
+do_get_profile();
 
-if (!profileDir) {
-  // Register our own provider for the profile directory.
-  // It will simply return the current directory.
-  var provider = {
-    getFile: function(prop, persistent) {
-      dump("getting file " + prop + "\n");
-      persistent.value = true;
-      if (prop == NS_APP_USER_PROFILE_50_DIR ||
-          prop == NS_APP_USER_PROFILE_LOCAL_50_DIR) {
-        return dirSvc.get("CurProcD", Ci.nsIFile);
-      }
-      throw Cr.NS_ERROR_FAILURE;
-    },
-    QueryInterface: function(iid) {
-      if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
-          iid.equals(Ci.nsISupports)) {
-        return this;
-      }
-      throw Cr.NS_ERROR_NO_INTERFACE;
-    }
-  };
-  dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
-}
+var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
 
 var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
 
 // Disable hashcompleter noise for tests
 var prefBranch = Cc["@mozilla.org/preferences-service;1"].
                  getService(Ci.nsIPrefBranch);
 prefBranch.setIntPref("urlclassifier.gethashnoise", 0);
 
@@ -267,17 +240,17 @@ function checkAssertions(assertions, don
   checkAssertion();
 }
 
 function updateError(arg)
 {
   do_throw(arg);
 }
 
-// Runs a set of updates, and then checks a set of assertions.  
+// Runs a set of updates, and then checks a set of assertions.
 function doUpdateTest(updates, assertions, successCallback, errorCallback, clientKey) {
   var errorUpdate = function() {
     checkAssertions(assertions, errorCallback);
   }
 
   var runUpdate = function() {
     if (updates.length > 0) {
       var update = updates.shift();
--- a/toolkit/mozapps/extensions/test/unit/head_extensionmanager.js
+++ b/toolkit/mozapps/extensions/test/unit/head_extensionmanager.js
@@ -40,20 +40,16 @@
  * These are intended to be a set of base functions enabling unit testing
  * for the Extension Manager component.
  */
 
 const PREFIX_NS_EM                    = "http://www.mozilla.org/2004/em-rdf#";
 const PREFIX_NS_CHROME                = "http://www.mozilla.org/rdf/chrome#";
 const PREFIX_ITEM_URI                 = "urn:mozilla:item:";
 
-const NS_APP_USER_PROFILE_50_DIR      = "ProfD";
-const NS_APP_PROFILE_DIR_STARTUP      = "ProfDS";
-const NS_OS_TEMP_DIR                  = "TmpD";
-
 const NS_INSTALL_LOCATION_APPPROFILE = "app-profile";
 
 const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
 const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}");
 
 var gEM = null;
 var gRDF = Components.classes["@mozilla.org/rdf/rdf-service;1"]
                      .getService(Components.interfaces.nsIRDFService);
@@ -110,19 +106,19 @@ function intData(literal) {
   if (literal instanceof Components.interfaces.nsIRDFInt)
     return literal.Value;
   return undefined;
 }
 
 /**
  * Gets a RDF Resource for item with the given ID
  * @param   id
- *          The GUID of the item to construct a RDF resource to the 
+ *          The GUID of the item to construct a RDF resource to the
  *          active item for
- * @returns The RDF Resource to the Active item. 
+ * @returns The RDF Resource to the Active item.
  */
 function getResourceForID(id) {
   return gRDF.GetResource(PREFIX_ITEM_URI + id);
 }
 
 /**
  * Extract a string property for an add-on
  * @param   id
@@ -167,27 +163,27 @@ function createAppInfo(id, name, version
     version: version,
     appBuildID: "2007010101",
     platformVersion: platformVersion,
     platformBuildID: "2007010101",
     inSafeMode: false,
     logConsoleErrors: true,
     OS: "XPCShell",
     XPCOMABI: "noarch-spidermonkey",
-    
+
     QueryInterface: function QueryInterface(iid) {
       if (iid.equals(Components.interfaces.nsIXULAppInfo)
        || iid.equals(Components.interfaces.nsIXULRuntime)
        || iid.equals(Components.interfaces.nsISupports))
         return this;
-    
+
       throw Components.results.NS_ERROR_NO_INTERFACE;
     }
   };
-  
+
   var XULAppInfoFactory = {
     createInstance: function (outer, iid) {
       if (outer != null)
         throw Components.results.NS_ERROR_NO_AGGREGATION;
       return XULAppInfo.QueryInterface(iid);
     }
   };
   var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
@@ -199,20 +195,20 @@ function createAppInfo(id, name, version
  * This simulates an application startup. Since we will be starting from an
  * empty profile we follow that path.
  */
 function startupEM()
 {
   // Make sure the update service is initialised.
   var updateSvc = Components.classes["@mozilla.org/updates/update-service;1"]
                             .getService(Components.interfaces.nsISupports);
-  
+
   gEM = Components.classes["@mozilla.org/extensions/manager;1"]
                   .getService(Components.interfaces.nsIExtensionManager);
-  
+
   gEM.QueryInterface(Components.interfaces.nsIObserver);
   gEM.observe(null, "profile-after-change", "startup");
 
   // First run is a new profile which nsAppRunner would consider as an update
   // (no existing compatibility.ini)
   var upgraded = true;
   var needsRestart = false;
   try {
@@ -230,17 +226,16 @@ function startupEM()
 
 /**
  * Simple function to simulate the termination of an app to the EM.
  * This harness does not support creating a new EM after calling this.
  */
 function shutdownEM()
 {
   // xpcshell calls xpcom-shutdown so we don't actually do anything here.
-  gDirSvc.unregisterProvider(dirProvider);
   gEM = null;
 }
 
 /**
  * Many operations require restarts to take effect. This function should
  * perform all that is necessary for this to happen.
  */
 function restartEM()
@@ -249,37 +244,14 @@ function restartEM()
   if (needsRestart)
     gEM.start(null);
 }
 
 var gDirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
                         .getService(Components.interfaces.nsIProperties);
 
 // Need to create and register a profile folder.
-var gProfD = do_get_cwd();
-gProfD.append("profile");
-if (gProfD.exists())
-  gProfD.remove(true);
-gProfD.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
-
-var dirProvider = {
-  getFile: function(prop, persistent) {
-    persistent.value = true;
-    if (prop == NS_APP_USER_PROFILE_50_DIR ||
-        prop == NS_APP_PROFILE_DIR_STARTUP)
-      return gProfD.clone();
-    return null;
-  },
-  QueryInterface: function(iid) {
-    if (iid.equals(Components.interfaces.nsIDirectoryServiceProvider) ||
-        iid.equals(Components.interfaces.nsISupports)) {
-      return this;
-    }
-    throw Components.results.NS_ERROR_NO_INTERFACE;
-  }
-};
-gDirSvc.QueryInterface(Components.interfaces.nsIDirectoryService)
-       .registerProvider(dirProvider);
+var gProfD = do_get_profile();
 
 var gPrefs = Components.classes["@mozilla.org/preferences;1"]
                    .getService(Components.interfaces.nsIPrefBranch);
 // Enable more extensive EM logging
 gPrefs.setBoolPref("extensions.logging.enabled", true);
--- a/toolkit/mozapps/extensions/test/unit/tail_extensionmanager.js
+++ b/toolkit/mozapps/extensions/test/unit/tail_extensionmanager.js
@@ -34,18 +34,8 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK *****
  */
 
 // Close down any remaining EM
 if (gEM)
   shutdownEM();
-
-// Clean up the temporary profile dir.
-try {
-  if (gProfD.exists())
-    gProfD.remove(true);
-}
-catch (e) {
-  // There are many valid reasons for being unable to remove the temporary
-  // profile dir so not much point in failing on it.
-}