|
1 "use strict"; |
|
2 |
|
3 Components.utils.import("resource://gre/modules/osfile.jsm"); |
|
4 Components.utils.import("resource://gre/modules/Task.jsm"); |
|
5 |
|
6 function run_test() { |
|
7 do_test_pending(); |
|
8 run_next_test(); |
|
9 } |
|
10 |
|
11 add_task(function test_closed() { |
|
12 OS.Shared.DEBUG = true; |
|
13 let currentDir = yield OS.File.getCurrentDirectory(); |
|
14 do_print("Open a file, ensure that we can call stat()"); |
|
15 let path = OS.Path.join(currentDir, "test_osfile_closed.js"); |
|
16 let file = yield OS.File.open(path); |
|
17 yield file.stat(); |
|
18 do_check_true(true); |
|
19 |
|
20 yield file.close(); |
|
21 |
|
22 do_print("Ensure that we cannot stat() on closed file"); |
|
23 let exn; |
|
24 try { |
|
25 yield file.stat(); |
|
26 } catch (ex) { |
|
27 exn = ex; |
|
28 } |
|
29 do_print("Ensure that this raises the correct error"); |
|
30 do_check_true(!!exn); |
|
31 do_check_true(exn instanceof OS.File.Error); |
|
32 do_check_true(exn.becauseClosed); |
|
33 |
|
34 do_print("Ensure that we cannot read() on closed file"); |
|
35 exn = null; |
|
36 try { |
|
37 yield file.read(); |
|
38 } catch (ex) { |
|
39 exn = ex; |
|
40 } |
|
41 do_print("Ensure that this raises the correct error"); |
|
42 do_check_true(!!exn); |
|
43 do_check_true(exn instanceof OS.File.Error); |
|
44 do_check_true(exn.becauseClosed); |
|
45 |
|
46 }); |
|
47 |
|
48 add_task(do_test_finished); |