|
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 { |
|
8 // In this test we try to open some files that aren't archives: |
|
9 // - An empty file, that is certainly not an archive. |
|
10 // - A file that couldn't be mistaken for archive, since it is too small. |
|
11 // - A file that could be mistaken for archive, if we checked only the file |
|
12 // size, but is invalid since it contains no ZIP signature. |
|
13 var invalidArchives = ["emptyfile.txt", "smallfile.txt", "test.png"]; |
|
14 |
|
15 invalidArchives.forEach(function(invalidArchive) { |
|
16 // Get a reference to the invalid file |
|
17 var invalidFile = do_get_file(DATA_DIR + invalidArchive); |
|
18 |
|
19 // Opening the invalid file should fail (but not crash) |
|
20 try { |
|
21 zipW.open(invalidFile, PR_RDWR); |
|
22 do_throw("Should have thrown NS_ERROR_FILE_CORRUPTED on " + |
|
23 invalidArchive + " !"); |
|
24 } catch (e if (e instanceof Ci.nsIException && |
|
25 e.result == Components.results.NS_ERROR_FILE_CORRUPTED)) { |
|
26 // do nothing |
|
27 } |
|
28 }); |
|
29 } |