xpcom/tests/unit/test_hidden_files.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/tests/unit/test_hidden_files.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,37 @@
     1.4 +const Ci = Components.interfaces;
     1.5 +const Cc = Components.classes;
     1.6 +const NS_OS_TEMP_DIR = "TmpD";
     1.7 +
     1.8 +const CWD = do_get_cwd();
     1.9 +function checkOS(os) {
    1.10 +  const nsILocalFile_ = "nsILocalFile" + os;
    1.11 +  return nsILocalFile_ in Components.interfaces &&
    1.12 +         CWD instanceof Components.interfaces[nsILocalFile_];
    1.13 +}
    1.14 +
    1.15 +const isWin = checkOS("Win");
    1.16 +const isMac = checkOS("Mac");
    1.17 +const isUnix = !(isWin || isMac);
    1.18 +
    1.19 +var hiddenUnixFile;
    1.20 +function createUNIXHiddenFile() {
    1.21 +  var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
    1.22 +  var tmpDir = dirSvc.get(NS_OS_TEMP_DIR, Ci.nsIFile);
    1.23 +  hiddenUnixFile = tmpDir.clone();
    1.24 +  hiddenUnixFile.append(".foo");
    1.25 +  // we don't care if this already exists because we don't care
    1.26 +  // about the file's contents (just the name)
    1.27 +  if (!hiddenUnixFile.exists())
    1.28 +    hiddenUnixFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    1.29 +  return hiddenUnixFile.exists();
    1.30 +}
    1.31 +
    1.32 +function run_test() {
    1.33 +  // Skip this test on Windows
    1.34 +  if (isWin)
    1.35 +    return;
    1.36 +
    1.37 +  do_check_true(createUNIXHiddenFile());
    1.38 +  do_check_true(hiddenUnixFile.isHidden());
    1.39 +}
    1.40 +

mercurial