1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/modules/tests/xpcshell/test_ZipUtils.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +"use strict"; 1.8 + 1.9 +const ARCHIVE = "zips/zen.zip"; 1.10 +const SUBDIR = "zen"; 1.11 +const ENTRIES = ["beyond.txt", "waterwood.txt"]; 1.12 + 1.13 +Components.utils.import("resource://gre/modules/ZipUtils.jsm"); 1.14 +Components.utils.import("resource://gre/modules/FileUtils.jsm"); 1.15 + 1.16 + 1.17 +const archive = do_get_file(ARCHIVE, false); 1.18 +const dir = do_get_profile().clone(); 1.19 +dir.append("test_ZipUtils"); 1.20 + 1.21 +function run_test() { 1.22 + run_next_test(); 1.23 +} 1.24 + 1.25 +function ensureExtracted(target) { 1.26 + target.append(SUBDIR); 1.27 + do_check_true(target.exists()); 1.28 + 1.29 + for (let i = 0; i < ENTRIES.length; i++) { 1.30 + let entry = target.clone(); 1.31 + entry.append(ENTRIES[i]); 1.32 + do_print("ENTRY " + entry.path); 1.33 + do_check_true(entry.exists()); 1.34 + } 1.35 +} 1.36 + 1.37 + 1.38 +add_task(function test_extractFiles() { 1.39 + let target = dir.clone(); 1.40 + target.append("test_extractFiles"); 1.41 + 1.42 + try { 1.43 + ZipUtils.extractFiles(archive, target); 1.44 + } catch(e) { 1.45 + do_throw("Failed to extract synchronously!"); 1.46 + } 1.47 + 1.48 + ensureExtracted(target); 1.49 +}); 1.50 + 1.51 +add_task(function test_extractFilesAsync() { 1.52 + let target = dir.clone(); 1.53 + target.append("test_extractFilesAsync"); 1.54 + target.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 1.55 + FileUtils.PERMS_DIRECTORY); 1.56 + 1.57 + yield ZipUtils.extractFilesAsync(archive, target).then( 1.58 + function success() { 1.59 + do_print("SUCCESS"); 1.60 + ensureExtracted(target); 1.61 + }, 1.62 + function failure() { 1.63 + do_print("FAILURE"); 1.64 + do_throw("Failed to extract asynchronously!"); 1.65 + } 1.66 + ); 1.67 +});