michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: Components.utils.import("resource://gre/modules/osfile.jsm"); michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: do_register_cleanup(function() { michael@0: Services.prefs.setBoolPref("toolkit.osfile.log", false); michael@0: }); michael@0: michael@0: function run_test() { michael@0: Services.prefs.setBoolPref("toolkit.osfile.log", true); michael@0: michael@0: run_next_test(); michael@0: } michael@0: michael@0: /** michael@0: * Test OS.File.removeEmptyDir michael@0: */ michael@0: add_task(function() { michael@0: // Set up profile. We create the directory in the profile, because the profile michael@0: // is removed after every test run. michael@0: do_get_profile(); michael@0: michael@0: let dir = OS.Path.join(OS.Constants.Path.profileDir, "directory"); michael@0: michael@0: // Sanity checking for the test michael@0: do_check_false((yield OS.File.exists(dir))); michael@0: michael@0: // Remove non-existent directory michael@0: yield OS.File.removeEmptyDir(dir); michael@0: michael@0: // Remove non-existent directory with ignoreAbsent michael@0: yield OS.File.removeEmptyDir(dir, {ignoreAbsent: true}); michael@0: michael@0: // Remove non-existent directory with ignoreAbsent false michael@0: let exception = null; michael@0: try { michael@0: yield OS.File.removeEmptyDir(dir, {ignoreAbsent: false}); michael@0: } catch (ex) { michael@0: exception = ex; michael@0: } michael@0: michael@0: do_check_true(!!exception); michael@0: do_check_true(exception instanceof OS.File.Error); michael@0: do_check_true(exception.becauseNoSuchFile); michael@0: michael@0: // Remove empty directory michael@0: yield OS.File.makeDir(dir); michael@0: yield OS.File.removeEmptyDir(dir); michael@0: do_check_false((yield OS.File.exists(dir))); michael@0: });