Backed out changeset 5e82a8ce4862 -
bug 459114 - helper function to provide a clean profile directory for xpcshell tests. r=sdwilsh - for test failures
--- a/suite/common/places/tests/autocomplete/head_000.js
+++ b/suite/common/places/tests/autocomplete/head_000.js
@@ -38,38 +38,48 @@
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;
-var profDir = do_get_profile();
-
+// If there's no location registered for the profile direcotry, register one now.
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
-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;
+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;
}
- 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);
+ };
+ 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);