toolkit/modules/tests/xpcshell/test_ZipUtils.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:b90f766a44d8
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 "use strict";
5
6 const ARCHIVE = "zips/zen.zip";
7 const SUBDIR = "zen";
8 const ENTRIES = ["beyond.txt", "waterwood.txt"];
9
10 Components.utils.import("resource://gre/modules/ZipUtils.jsm");
11 Components.utils.import("resource://gre/modules/FileUtils.jsm");
12
13
14 const archive = do_get_file(ARCHIVE, false);
15 const dir = do_get_profile().clone();
16 dir.append("test_ZipUtils");
17
18 function run_test() {
19 run_next_test();
20 }
21
22 function ensureExtracted(target) {
23 target.append(SUBDIR);
24 do_check_true(target.exists());
25
26 for (let i = 0; i < ENTRIES.length; i++) {
27 let entry = target.clone();
28 entry.append(ENTRIES[i]);
29 do_print("ENTRY " + entry.path);
30 do_check_true(entry.exists());
31 }
32 }
33
34
35 add_task(function test_extractFiles() {
36 let target = dir.clone();
37 target.append("test_extractFiles");
38
39 try {
40 ZipUtils.extractFiles(archive, target);
41 } catch(e) {
42 do_throw("Failed to extract synchronously!");
43 }
44
45 ensureExtracted(target);
46 });
47
48 add_task(function test_extractFilesAsync() {
49 let target = dir.clone();
50 target.append("test_extractFilesAsync");
51 target.create(Components.interfaces.nsIFile.DIRECTORY_TYPE,
52 FileUtils.PERMS_DIRECTORY);
53
54 yield ZipUtils.extractFilesAsync(archive, target).then(
55 function success() {
56 do_print("SUCCESS");
57 ensureExtracted(target);
58 },
59 function failure() {
60 do_print("FAILURE");
61 do_throw("Failed to extract asynchronously!");
62 }
63 );
64 });

mercurial