test_home.js 766 B

12345678910111213141516171819202122232425
  1. var Ci = Components.interfaces;
  2. var Cc = Components.classes;
  3. const CWD = do_get_cwd();
  4. function checkOS(os) {
  5. const nsILocalFile_ = "nsILocalFile" + os;
  6. return nsILocalFile_ in Components.interfaces &&
  7. CWD instanceof Components.interfaces[nsILocalFile_];
  8. }
  9. const isWin = checkOS("Win");
  10. function run_test() {
  11. var envVar = isWin ? "USERPROFILE" : "HOME";
  12. var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
  13. var homeDir = dirSvc.get("Home", Ci.nsIFile);
  14. var env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
  15. var expected = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
  16. expected.initWithPath(env.get(envVar));
  17. do_check_eq(homeDir.path, expected.path);
  18. }