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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial