modules/libjar/zipwriter/test/unit/test_bug467740.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/modules/libjar/zipwriter/test/unit/test_bug467740.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,29 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 + */
     1.8 +
     1.9 +function run_test()
    1.10 +{
    1.11 +  // In this test we try to open some files that aren't archives:
    1.12 +  //  - An empty file, that is certainly not an archive.
    1.13 +  //  - A file that couldn't be mistaken for archive, since it is too small.
    1.14 +  //  - A file that could be mistaken for archive, if we checked only the file
    1.15 +  //     size, but is invalid since it contains no ZIP signature.
    1.16 +  var invalidArchives = ["emptyfile.txt", "smallfile.txt", "test.png"];
    1.17 +
    1.18 +  invalidArchives.forEach(function(invalidArchive) {
    1.19 +    // Get a reference to the invalid file
    1.20 +    var invalidFile = do_get_file(DATA_DIR + invalidArchive);
    1.21 +
    1.22 +    // Opening the invalid file should fail (but not crash)
    1.23 +    try {
    1.24 +      zipW.open(invalidFile, PR_RDWR);
    1.25 +      do_throw("Should have thrown NS_ERROR_FILE_CORRUPTED on " +
    1.26 +               invalidArchive + " !");
    1.27 +    } catch (e if (e instanceof Ci.nsIException &&
    1.28 +                   e.result == Components.results.NS_ERROR_FILE_CORRUPTED)) {
    1.29 +      // do nothing
    1.30 +    }
    1.31 +  });
    1.32 +}

mercurial