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