toolkit/modules/tests/xpcshell/test_ZipUtils.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial