toolkit/components/osfile/tests/xpcshell/test_compression.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 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 "use strict";
     6 Components.utils.import("resource://gre/modules/osfile.jsm");
     8 function run_test() {
     9   do_test_pending();
    10   run_next_test();
    11 }
    13 add_task(function test_compress_lz4() {
    14   let path = OS.Path.join(OS.Constants.Path.tmpDir, "compression.lz");
    15   let array = new Uint8Array(1024);
    16   for (let i = 0; i < array.byteLength; ++i) {
    17     array[i] = i;
    18   }
    20   do_print("Writing data with lz4 compression");
    21   let bytes = yield OS.File.writeAtomic(path, array, { compression: "lz4" });
    22   do_print("Compressed " + array.byteLength + " bytes into " + bytes);
    24   do_print("Reading back with lz4 decompression");
    25   let decompressed = yield OS.File.read(path, { compression: "lz4" });
    26   do_print("Decompressed into " + decompressed.byteLength + " bytes");
    27   do_check_eq(Array.prototype.join.call(array), Array.prototype.join.call(decompressed));
    28 });
    30 add_task(function test_uncompressed() {
    31   do_print("Writing data without compression");
    32   let path = OS.Path.join(OS.Constants.Path.tmpDir, "no_compression.tmp");
    33   let array = new Uint8Array(1024);
    34   for (let i = 0; i < array.byteLength; ++i) {
    35     array[i] = i;
    36   }
    37   let bytes = yield OS.File.writeAtomic(path, array); // No compression
    39   let exn;
    40   // Force decompression, reading should fail
    41   try {
    42     yield OS.File.read(path, { compression: "lz4" });
    43   } catch (ex) {
    44     exn = ex;
    45   }
    46   do_check_true(!!exn);
    47   do_check_true(exn.message.indexOf("Invalid header") != -1);
    48 });
    50 add_task(function() {
    51   do_test_finished();
    52 });

mercurial