tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug467740.js (1222B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 */
      5 
      6 function run_test() {
      7  // In this test we try to open some files that aren't archives:
      8  //  - An empty file, that is certainly not an archive.
      9  //  - A file that couldn't be mistaken for archive, since it is too small.
     10  //  - A file that could be mistaken for archive, if we checked only the file
     11  //     size, but is invalid since it contains no ZIP signature.
     12  var invalidArchives = ["emptyfile.txt", "smallfile.txt", "test.png"];
     13 
     14  invalidArchives.forEach(function (invalidArchive) {
     15    // Get a reference to the invalid file
     16    var invalidFile = do_get_file(DATA_DIR + invalidArchive);
     17 
     18    // Opening the invalid file should fail (but not crash)
     19    try {
     20      zipW.open(invalidFile, PR_RDWR);
     21      do_throw(
     22        "Should have thrown NS_ERROR_FILE_CORRUPTED on " + invalidArchive + " !"
     23      );
     24    } catch (e) {
     25      if (
     26        !(
     27          e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_FILE_CORRUPTED
     28        )
     29      ) {
     30        throw e;
     31      }
     32      // do nothing
     33    }
     34  });
     35 }