toolkit/components/osfile/tests/xpcshell/test_removeEmptyDir.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 "use strict";
     7 Components.utils.import("resource://gre/modules/osfile.jsm");
     8 Components.utils.import("resource://gre/modules/Services.jsm");
    10 do_register_cleanup(function() {
    11   Services.prefs.setBoolPref("toolkit.osfile.log", false);
    12 });
    14 function run_test() {
    15   Services.prefs.setBoolPref("toolkit.osfile.log", true);
    17   run_next_test();
    18 }
    20 /**
    21  * Test OS.File.removeEmptyDir
    22  */
    23 add_task(function() {
    24   // Set up profile. We create the directory in the profile, because the profile
    25   // is removed after every test run.
    26   do_get_profile();
    28   let dir = OS.Path.join(OS.Constants.Path.profileDir, "directory");
    30   // Sanity checking for the test
    31   do_check_false((yield OS.File.exists(dir)));
    33   // Remove non-existent directory
    34   yield OS.File.removeEmptyDir(dir);
    36   // Remove non-existent directory with ignoreAbsent
    37   yield OS.File.removeEmptyDir(dir, {ignoreAbsent: true});
    39   // Remove non-existent directory with ignoreAbsent false
    40   let exception = null;
    41   try {
    42     yield OS.File.removeEmptyDir(dir, {ignoreAbsent: false});
    43   } catch (ex) {
    44     exception = ex;
    45   }
    47   do_check_true(!!exception);
    48   do_check_true(exception instanceof OS.File.Error);
    49   do_check_true(exception.becauseNoSuchFile);
    51   // Remove empty directory
    52   yield OS.File.makeDir(dir);
    53   yield OS.File.removeEmptyDir(dir);
    54   do_check_false((yield OS.File.exists(dir)));
    55 });

mercurial