1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/osfile/tests/xpcshell/test_osfile_async_bytes.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,44 @@ 1.4 +"use strict"; 1.5 + 1.6 +Components.utils.import("resource://gre/modules/osfile.jsm"); 1.7 +Components.utils.import("resource://gre/modules/Task.jsm"); 1.8 + 1.9 +function run_test() { 1.10 + do_test_pending(); 1.11 + run_next_test(); 1.12 +} 1.13 + 1.14 +/** 1.15 + * Test to ensure that {bytes:} in options to |readTo| and |write| are correctly 1.16 + * preserved. 1.17 + */ 1.18 +add_task(function* test_bytes() { 1.19 + let path = OS.Path.join(OS.Constants.Path.tmpDir, 1.20 + "test_osfile_async_bytes.tmp"); 1.21 + let file = yield OS.File.open(path, {trunc: true, read: true, write: true}); 1.22 + try { 1.23 + try { 1.24 + // 1. Test write, by supplying {bytes:} options smaller than the actual 1.25 + // buffer. 1.26 + yield file.write(new Uint8Array(2048), {bytes: 1024}); 1.27 + do_check_eq((yield file.stat()).size, 1024); 1.28 + 1.29 + // 2. Test same for |readTo|. 1.30 + yield file.setPosition(0, OS.File.POS_START); 1.31 + let read = yield file.readTo(new Uint8Array(1024), {bytes: 512}); 1.32 + do_check_eq(read, 512); 1.33 + 1.34 + // 3. Test that passing nullish values for |options| still works. 1.35 + yield file.setPosition(0, OS.File.POS_END); 1.36 + yield file.write(new Uint8Array(1024), null); 1.37 + yield file.write(new Uint8Array(1024), undefined); 1.38 + do_check_eq((yield file.stat()).size, 3072); 1.39 + } finally { 1.40 + yield file.close(); 1.41 + } 1.42 + } finally { 1.43 + yield OS.File.remove(path); 1.44 + } 1.45 +}); 1.46 + 1.47 +add_task(do_test_finished);