modules/libmar/tests/unit/test_extract.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 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 function run_test() {
michael@0 5
michael@0 6 /**
michael@0 7 * Extracts a MAR and makes sure each file matches the reference files.
michael@0 8 *
michael@0 9 * @param marFileName The name of the MAR file to extract
michael@0 10 * @param files The files that the extracted MAR should contain
michael@0 11 */
michael@0 12 function run_one_test(marFileName, files) {
michael@0 13 // Get the MAR file that we will be extracting
michael@0 14 let mar = do_get_file("data/" + marFileName);
michael@0 15
michael@0 16 // Get the path that we will extract to
michael@0 17 let outDir = tempDir.clone();
michael@0 18 outDir.append("out");
michael@0 19 do_check_false(outDir.exists());
michael@0 20 outDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0777);
michael@0 21
michael@0 22 // Get the ref files and the files that will be extracted.
michael@0 23 let outFiles = [];
michael@0 24 let refFiles = [];
michael@0 25 for (let i = 0; i < files.length; i++) {
michael@0 26 let outFile = outDir.clone();
michael@0 27 outFile.append(files[i]);
michael@0 28 do_check_false(outFile.exists());
michael@0 29
michael@0 30 outFiles.push(outFile);
michael@0 31 refFiles.push(do_get_file("data/" + files[i]));
michael@0 32 }
michael@0 33
michael@0 34 // Extract the MAR contents into the ./out dir.
michael@0 35 extractMAR(mar, outDir);
michael@0 36
michael@0 37 // Compare to make sure the extracted files are the same.
michael@0 38 for (let i = 0; i < files.length; i++) {
michael@0 39 do_check_true(outFiles[i].exists());
michael@0 40 let refFileData = getBinaryFileData(refFiles[i]);
michael@0 41 let outFileData = getBinaryFileData(outFiles[i]);
michael@0 42 compareBinaryData(refFileData, outFileData);
michael@0 43 }
michael@0 44 }
michael@0 45
michael@0 46 // Define the unit tests to run.
michael@0 47 let tests = {
michael@0 48 // Test extracting a MAR file with a 0 byte file.
michael@0 49 test_zero_sized: function() {
michael@0 50 return run_one_test("0_sized_mar.mar", ["0_sized_file"]);
michael@0 51 },
michael@0 52 // Test extracting a MAR file with a 1 byte file.
michael@0 53 test_one_byte: function() {
michael@0 54 return run_one_test("1_byte_mar.mar", ["1_byte_file"]);
michael@0 55 },
michael@0 56 // Test extracting a MAR file with binary data.
michael@0 57 test_binary_data: function() {
michael@0 58 return run_one_test("binary_data_mar.mar", ["binary_data_file"]);
michael@0 59 },
michael@0 60 // Test extracting a MAR without a product information block (PIB) which
michael@0 61 // contains binary data.
michael@0 62 test_no_pib: function() {
michael@0 63 return run_one_test("no_pib_mar.mar", ["binary_data_file"]);
michael@0 64 },
michael@0 65 // Test extracting a MAR without a product information block (PIB) that is
michael@0 66 // signed and which contains binary data.
michael@0 67 test_no_pib_signed: function() {
michael@0 68 return run_one_test("signed_no_pib_mar.mar", ["binary_data_file"]);
michael@0 69 },
michael@0 70 // Test extracting a MAR with a product information block (PIB) that is
michael@0 71 // signed and which contains binary data.
michael@0 72 test_pib_signed: function() {
michael@0 73 return run_one_test("signed_pib_mar.mar", ["binary_data_file"]);
michael@0 74 },
michael@0 75 // Test extracting a MAR file with multiple files inside of it.
michael@0 76 test_multiple_file: function() {
michael@0 77 return run_one_test("multiple_file_mar.mar",
michael@0 78 ["0_sized_file", "1_byte_file", "binary_data_file"]);
michael@0 79 },
michael@0 80 // Between each test make sure the out directory and its subfiles do
michael@0 81 // not exist.
michael@0 82 cleanup_per_test: function() {
michael@0 83 let outDir = tempDir.clone();
michael@0 84 outDir.append("out");
michael@0 85 if (outDir.exists()) {
michael@0 86 outDir.remove(true);
michael@0 87 }
michael@0 88 }
michael@0 89 };
michael@0 90
michael@0 91 // Run all the tests
michael@0 92 do_check_eq(run_tests(tests), Object.keys(tests).length - 1);
michael@0 93 }

mercurial