Bug 810543 - Testing the behavior of OS.Constants.Path.profileDir;r=froydnj
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Tue, 11 Dec 2012 15:12:59 -0800
changeset 121289 c1982c49eca6d676a8a876c8e3e52b201064c09f
parent 121288 7a5e83065d9f20209a702ab857662818ae50d049
child 121290 e9d0df316d449f05d7ab04feb265e3bac711319d
push idunknown
push userunknown
push dateunknown
reviewersfroydnj
bugs810543
milestone20.0a1
Bug 810543 - Testing the behavior of OS.Constants.Path.profileDir;r=froydnj
testing/xpcshell/head.js
--- 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.
  *