Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | "use strict"; |
michael@0 | 5 | |
michael@0 | 6 | Components.utils.import("resource://gre/modules/osfile.jsm"); |
michael@0 | 7 | |
michael@0 | 8 | function run_test() { |
michael@0 | 9 | do_test_pending(); |
michael@0 | 10 | run_next_test(); |
michael@0 | 11 | } |
michael@0 | 12 | |
michael@0 | 13 | add_task(function test_compress_lz4() { |
michael@0 | 14 | let path = OS.Path.join(OS.Constants.Path.tmpDir, "compression.lz"); |
michael@0 | 15 | let array = new Uint8Array(1024); |
michael@0 | 16 | for (let i = 0; i < array.byteLength; ++i) { |
michael@0 | 17 | array[i] = i; |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | do_print("Writing data with lz4 compression"); |
michael@0 | 21 | let bytes = yield OS.File.writeAtomic(path, array, { compression: "lz4" }); |
michael@0 | 22 | do_print("Compressed " + array.byteLength + " bytes into " + bytes); |
michael@0 | 23 | |
michael@0 | 24 | do_print("Reading back with lz4 decompression"); |
michael@0 | 25 | let decompressed = yield OS.File.read(path, { compression: "lz4" }); |
michael@0 | 26 | do_print("Decompressed into " + decompressed.byteLength + " bytes"); |
michael@0 | 27 | do_check_eq(Array.prototype.join.call(array), Array.prototype.join.call(decompressed)); |
michael@0 | 28 | }); |
michael@0 | 29 | |
michael@0 | 30 | add_task(function test_uncompressed() { |
michael@0 | 31 | do_print("Writing data without compression"); |
michael@0 | 32 | let path = OS.Path.join(OS.Constants.Path.tmpDir, "no_compression.tmp"); |
michael@0 | 33 | let array = new Uint8Array(1024); |
michael@0 | 34 | for (let i = 0; i < array.byteLength; ++i) { |
michael@0 | 35 | array[i] = i; |
michael@0 | 36 | } |
michael@0 | 37 | let bytes = yield OS.File.writeAtomic(path, array); // No compression |
michael@0 | 38 | |
michael@0 | 39 | let exn; |
michael@0 | 40 | // Force decompression, reading should fail |
michael@0 | 41 | try { |
michael@0 | 42 | yield OS.File.read(path, { compression: "lz4" }); |
michael@0 | 43 | } catch (ex) { |
michael@0 | 44 | exn = ex; |
michael@0 | 45 | } |
michael@0 | 46 | do_check_true(!!exn); |
michael@0 | 47 | do_check_true(exn.message.indexOf("Invalid header") != -1); |
michael@0 | 48 | }); |
michael@0 | 49 | |
michael@0 | 50 | add_task(function() { |
michael@0 | 51 | do_test_finished(); |
michael@0 | 52 | }); |