modules/libmar/tests/unit/test_create.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 * Creates MAR from the passed files, compares it to the reference MAR.
michael@0 8 *
michael@0 9 * @param refMARFileName The name of the MAR file that should match
michael@0 10 * @param files The files that should go in the created MAR
michael@0 11 * @param checkNoMAR If true return an error if a file already exists
michael@0 12 */
michael@0 13 function run_one_test(refMARFileName, files, checkNoMAR) {
michael@0 14 if (checkNoMAR === undefined) {
michael@0 15 checkNoMAR = true;
michael@0 16 }
michael@0 17
michael@0 18 // Ensure the MAR we will create doesn't already exist.
michael@0 19 let outMAR = tempDir.clone();
michael@0 20 outMAR.append("out.mar");
michael@0 21 if (checkNoMAR) {
michael@0 22 do_check_false(outMAR.exists());
michael@0 23 }
michael@0 24
michael@0 25 // Create the actual MAR file.
michael@0 26 createMAR(outMAR, do_get_file("data"), files);
michael@0 27
michael@0 28 // Get the reference MAR data.
michael@0 29 let refMAR = do_get_file("data/" + refMARFileName);
michael@0 30 let refMARData = getBinaryFileData(refMAR);
michael@0 31
michael@0 32 // Verify the data of the MAR is what it should be.
michael@0 33 let outMARData = getBinaryFileData(outMAR);
michael@0 34 compareBinaryData(outMARData, refMARData);
michael@0 35 }
michael@0 36
michael@0 37 // Define the unit tests to run.
michael@0 38 let tests = {
michael@0 39 // Test creating a MAR file with a 0 byte file.
michael@0 40 test_zero_sized: function() {
michael@0 41 return run_one_test(refMARPrefix + "0_sized_mar.mar", ["0_sized_file"]);
michael@0 42 },
michael@0 43 // Test creating a MAR file with a 1 byte file.
michael@0 44 test_one_byte: function() {
michael@0 45 return run_one_test(refMARPrefix + "1_byte_mar.mar", ["1_byte_file"]);
michael@0 46 },
michael@0 47 // Test creating a MAR file with binary data.
michael@0 48 test_binary_data: function() {
michael@0 49 return run_one_test(refMARPrefix + "binary_data_mar.mar",
michael@0 50 ["binary_data_file"]);
michael@0 51 },
michael@0 52 // Test creating a MAR file with multiple files inside of it.
michael@0 53 test_multiple_file: function() {
michael@0 54 return run_one_test(refMARPrefix + "multiple_file_mar.mar",
michael@0 55 ["0_sized_file", "1_byte_file", "binary_data_file"]);
michael@0 56 },
michael@0 57 // Test creating a MAR file on top of a different one that already exists
michael@0 58 // at the location the new one will be created at.
michael@0 59 test_overwrite_already_exists: function() {
michael@0 60 let differentFile = do_get_file("data/1_byte_mar.mar");
michael@0 61 let outMARDir = tempDir.clone();
michael@0 62 differentFile.copyTo(outMARDir, "out.mar");
michael@0 63 return run_one_test(refMARPrefix + "binary_data_mar.mar",
michael@0 64 ["binary_data_file"], false);
michael@0 65 },
michael@0 66 // Between each test make sure the out MAR does not exist.
michael@0 67 cleanup_per_test: function() {
michael@0 68 let outMAR = tempDir.clone();
michael@0 69 outMAR.append("out.mar");
michael@0 70 if (outMAR.exists()) {
michael@0 71 outMAR.remove(false);
michael@0 72 }
michael@0 73 }
michael@0 74 };
michael@0 75
michael@0 76 // Run all the tests
michael@0 77 do_check_eq(run_tests(tests), Object.keys(tests).length - 1);
michael@0 78 }

mercurial