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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:1103e194caf8
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 "use strict";
5
6 let {OS: {File, Path, Constants}} = Components.utils.import("resource://gre/modules/osfile.jsm", {});
7 Components.utils.import("resource://gre/modules/Task.jsm");
8
9 function run_test() {
10 run_next_test();
11 }
12
13 add_task(function* testFileError_with_writeAtomic() {
14 let DEFAULT_CONTENTS = "default contents" + Math.random();
15 let path = Path.join(Constants.Path.tmpDir,
16 "testFileError.tmp");
17 yield File.remove(path);
18 yield File.writeAtomic(path, DEFAULT_CONTENTS);
19 let exception;
20 try {
21 yield File.writeAtomic(path, DEFAULT_CONTENTS, { noOverwrite: true });
22 } catch (ex) {
23 exception = ex;
24 }
25 do_check_true(exception instanceof File.Error);
26 do_check_true(exception.path == path);
27 });
28
29 add_task(function* testFileError_with_makeDir() {
30 let path = Path.join(Constants.Path.tmpDir,
31 "directory");
32 yield File.removeDir(path);
33 yield File.makeDir(path);
34 let exception;
35 try {
36 yield File.makeDir(path, { ignoreExisting: false });
37 } catch (ex) {
38 exception = ex;
39 }
40 do_check_true(exception instanceof File.Error);
41 do_check_true(exception.path == path);
42 });
43
44 add_task(function* testFileError_with_move() {
45 let DEFAULT_CONTENTS = "default contents" + Math.random();
46 let sourcePath = Path.join(Constants.Path.tmpDir,
47 "src.tmp");
48 let destPath = Path.join(Constants.Path.tmpDir,
49 "dest.tmp");
50 yield File.remove(sourcePath);
51 yield File.remove(destPath);
52 yield File.writeAtomic(sourcePath, DEFAULT_CONTENTS);
53 yield File.writeAtomic(destPath, DEFAULT_CONTENTS);
54 let exception;
55 try {
56 yield File.move(sourcePath, destPath, { noOverwrite: true });
57 } catch (ex) {
58 exception = ex;
59 }
60 do_print(exception);
61 do_check_true(exception instanceof File.Error);
62 do_check_true(exception.path == sourcePath);
63 });

mercurial