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