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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 "use strict";
     3 Components.utils.import("resource://gre/modules/osfile.jsm");
     4 Components.utils.import("resource://gre/modules/Task.jsm");
     6 function run_test() {
     7   do_test_pending();
     8   run_next_test();
     9 }
    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);
    20   yield file.close();
    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);
    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);
    46 });
    48 add_task(do_test_finished);

mercurial