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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:348326f2f448
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/. */
4
5 "use strict";
6
7 Components.utils.import("resource://gre/modules/osfile.jsm");
8 Components.utils.import("resource://gre/modules/Services.jsm");
9
10 do_register_cleanup(function() {
11 Services.prefs.setBoolPref("toolkit.osfile.log", false);
12 });
13
14 function run_test() {
15 Services.prefs.setBoolPref("toolkit.osfile.log", true);
16
17 run_next_test();
18 }
19
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();
27
28 let dir = OS.Path.join(OS.Constants.Path.profileDir, "directory");
29
30 // Sanity checking for the test
31 do_check_false((yield OS.File.exists(dir)));
32
33 // Remove non-existent directory
34 yield OS.File.removeEmptyDir(dir);
35
36 // Remove non-existent directory with ignoreAbsent
37 yield OS.File.removeEmptyDir(dir, {ignoreAbsent: true});
38
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 }
46
47 do_check_true(!!exception);
48 do_check_true(exception instanceof OS.File.Error);
49 do_check_true(exception.becauseNoSuchFile);
50
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