michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const { classes: Cc, interfaces: Ci, utils: Cu } = Components; michael@0: michael@0: Cu.import("resource://gre/modules/osfile.jsm"); michael@0: Cu.import("resource://gre/modules/Task.jsm"); michael@0: Cu.import("resource://gre/modules/Promise.jsm"); michael@0: michael@0: const LINUX = navigator.platform.startsWith("Linux"); michael@0: const MAC = navigator.platform.startsWith("Mac"); michael@0: const WIN = navigator.platform.startsWith("Win"); michael@0: const MAC_106 = navigator.userAgent.contains("Mac OS X 10.6"); michael@0: michael@0: function checkFiles(files) { michael@0: return Task.spawn(function*() { michael@0: for (let file of files) { michael@0: if (!(yield OS.File.exists(file))) { michael@0: info("File doesn't exist: " + file); michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: return true; michael@0: }); michael@0: } michael@0: michael@0: function checkDateHigherThan(files, date) { michael@0: return Task.spawn(function*() { michael@0: for (let file of files) { michael@0: if (!(yield OS.File.exists(file))) { michael@0: info("File doesn't exist: " + file); michael@0: return false; michael@0: } michael@0: michael@0: let stat = yield OS.File.stat(file); michael@0: if (!(stat.lastModificationDate > date)) { michael@0: info("File not newer: " + file); michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: return true; michael@0: }); michael@0: } michael@0: michael@0: function wait(time) { michael@0: let deferred = Promise.defer(); michael@0: michael@0: setTimeout(function() { michael@0: deferred.resolve(); michael@0: }, time); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: // Helper to create a nsIFile from a set of path components michael@0: function getFile() { michael@0: let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); michael@0: file.initWithPath(OS.Path.join.apply(OS.Path, arguments)); michael@0: return file; michael@0: } michael@0: michael@0: function setDryRunPref() { michael@0: let old_dry_run; michael@0: try { michael@0: old_dry_run = Services.prefs.getBoolPref("browser.mozApps.installer.dry_run"); michael@0: } catch (ex) {} michael@0: michael@0: Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", false); michael@0: michael@0: SimpleTest.registerCleanupFunction(function() { michael@0: if (old_dry_run === undefined) { michael@0: Services.prefs.clearUserPref("browser.mozApps.installer.dry_run"); michael@0: } else { michael@0: Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", old_dry_run); michael@0: } michael@0: }); michael@0: }