Bug 810543 - Testing the behavior of OS.Constants.Path.profileDir;r=froydnj
--- a/testing/xpcshell/head.js
+++ b/testing/xpcshell/head.js
@@ -12,16 +12,17 @@
var _quit = false;
var _passed = true;
var _tests_pending = 0;
var _passedChecks = 0, _falsePassedChecks = 0;
var _todoChecks = 0;
var _cleanupFunctions = [];
var _pendingTimers = [];
+var _profileInitialized = false;
function _dump(str) {
let start = /^TEST-/.test(str) ? "\n" : "";
if (typeof _XPCSHELL_PROCESS == "undefined") {
dump(start + str);
} else {
dump(start + _XPCSHELL_PROCESS + ": " + str);
}
@@ -723,25 +724,27 @@ function do_register_cleanup(aFunction)
/**
* Registers a directory with the profile service,
* and return the directory as an nsILocalFile.
*
* @return nsILocalFile of the profile directory.
*/
function do_get_profile() {
- // Since we have a profile, we will notify profile shutdown topics at
- // the end of the current test, to ensure correct cleanup on shutdown.
- do_register_cleanup(function() {
- let obsSvc = Components.classes["@mozilla.org/observer-service;1"].
- getService(Components.interfaces.nsIObserverService);
- obsSvc.notifyObservers(null, "profile-change-net-teardown", null);
- obsSvc.notifyObservers(null, "profile-change-teardown", null);
- obsSvc.notifyObservers(null, "profile-before-change", null);
- });
+ if (!_profileInitialized) {
+ // Since we have a profile, we will notify profile shutdown topics at
+ // the end of the current test, to ensure correct cleanup on shutdown.
+ do_register_cleanup(function() {
+ let obsSvc = Components.classes["@mozilla.org/observer-service;1"].
+ getService(Components.interfaces.nsIObserverService);
+ obsSvc.notifyObservers(null, "profile-change-net-teardown", null);
+ obsSvc.notifyObservers(null, "profile-change-teardown", null);
+ obsSvc.notifyObservers(null, "profile-before-change", null);
+ });
+ }
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);
@@ -763,22 +766,31 @@ function do_get_profile() {
return this;
}
throw Components.results.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Components.interfaces.nsIDirectoryService)
.registerProvider(provider);
- // The methods of 'provider' will entrain this scope so null out everything
+ let obsSvc = Components.classes["@mozilla.org/observer-service;1"].
+ getService(Components.interfaces.nsIObserverService);
+
+ if (!_profileInitialized) {
+ obsSvc.notifyObservers(null, "profile-do-change", "xpcshell-do-get-profile");
+ _profileInitialized = true;
+ }
+
+ // The methods of 'provider' will retain this scope so null out everything
// to avoid spurious leak reports.
env = null;
profd = null;
dirSvc = null;
provider = null;
+ obsSvc = null;
return file.clone();
}
/**
* This function loads head.js (this file) in the child process, so that all
* functions defined in this file (do_throw, etc) are available to subsequent
* sendCommand calls. It also sets various constants used by these functions.
*