1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/osfile/tests/xpcshell/test_removeEmptyDir.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,55 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +Components.utils.import("resource://gre/modules/osfile.jsm"); 1.11 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.12 + 1.13 +do_register_cleanup(function() { 1.14 + Services.prefs.setBoolPref("toolkit.osfile.log", false); 1.15 +}); 1.16 + 1.17 +function run_test() { 1.18 + Services.prefs.setBoolPref("toolkit.osfile.log", true); 1.19 + 1.20 + run_next_test(); 1.21 +} 1.22 + 1.23 +/** 1.24 + * Test OS.File.removeEmptyDir 1.25 + */ 1.26 +add_task(function() { 1.27 + // Set up profile. We create the directory in the profile, because the profile 1.28 + // is removed after every test run. 1.29 + do_get_profile(); 1.30 + 1.31 + let dir = OS.Path.join(OS.Constants.Path.profileDir, "directory"); 1.32 + 1.33 + // Sanity checking for the test 1.34 + do_check_false((yield OS.File.exists(dir))); 1.35 + 1.36 + // Remove non-existent directory 1.37 + yield OS.File.removeEmptyDir(dir); 1.38 + 1.39 + // Remove non-existent directory with ignoreAbsent 1.40 + yield OS.File.removeEmptyDir(dir, {ignoreAbsent: true}); 1.41 + 1.42 + // Remove non-existent directory with ignoreAbsent false 1.43 + let exception = null; 1.44 + try { 1.45 + yield OS.File.removeEmptyDir(dir, {ignoreAbsent: false}); 1.46 + } catch (ex) { 1.47 + exception = ex; 1.48 + } 1.49 + 1.50 + do_check_true(!!exception); 1.51 + do_check_true(exception instanceof OS.File.Error); 1.52 + do_check_true(exception.becauseNoSuchFile); 1.53 + 1.54 + // Remove empty directory 1.55 + yield OS.File.makeDir(dir); 1.56 + yield OS.File.removeEmptyDir(dir); 1.57 + do_check_false((yield OS.File.exists(dir))); 1.58 +});