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.

     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