xpcom/tests/unit/test_home.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/tests/unit/test_home.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,24 @@
     1.4 +const Ci = Components.interfaces;
     1.5 +const Cc = Components.classes;
     1.6 +
     1.7 +const CWD = do_get_cwd();
     1.8 +function checkOS(os) {
     1.9 +  const nsILocalFile_ = "nsILocalFile" + os;
    1.10 +  return nsILocalFile_ in Components.interfaces &&
    1.11 +         CWD instanceof Components.interfaces[nsILocalFile_];
    1.12 +}
    1.13 +
    1.14 +const isWin = checkOS("Win");
    1.15 +
    1.16 +function run_test() {
    1.17 +  var envVar = isWin ? "USERPROFILE" : "HOME";
    1.18 +
    1.19 +  var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
    1.20 +  var homeDir = dirSvc.get("Home", Ci.nsIFile);
    1.21 +
    1.22 +  var env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
    1.23 +  var expected = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
    1.24 +  expected.initWithPath(env.get(envVar));
    1.25 +
    1.26 +  do_check_eq(homeDir.path, expected.path);
    1.27 +}

mercurial