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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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 /**
    12  * Test to ensure that {bytes:} in options to |readTo| and |write| are correctly
    13  * preserved.
    14  */
    15 add_task(function* test_bytes() {
    16   let path = OS.Path.join(OS.Constants.Path.tmpDir,
    17                           "test_osfile_async_bytes.tmp");
    18   let file = yield OS.File.open(path, {trunc: true, read: true, write: true});
    19   try {
    20     try {
    21       // 1. Test write, by supplying {bytes:} options smaller than the actual
    22       // buffer.
    23       yield file.write(new Uint8Array(2048), {bytes: 1024});
    24       do_check_eq((yield file.stat()).size, 1024);
    26       // 2. Test same for |readTo|.
    27       yield file.setPosition(0, OS.File.POS_START);
    28       let read = yield file.readTo(new Uint8Array(1024), {bytes: 512});
    29       do_check_eq(read, 512);
    31       // 3. Test that passing nullish values for |options| still works.
    32       yield file.setPosition(0, OS.File.POS_END);
    33       yield file.write(new Uint8Array(1024), null);
    34       yield file.write(new Uint8Array(1024), undefined);
    35       do_check_eq((yield file.stat()).size, 3072);
    36     } finally {
    37       yield file.close();
    38     }
    39   } finally {
    40     yield OS.File.remove(path);
    41   }
    42 });
    44 add_task(do_test_finished);

mercurial