1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/webapps/tests/head.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +const { classes: Cc, interfaces: Ci, utils: Cu } = Components; 1.8 + 1.9 +Cu.import("resource://gre/modules/osfile.jsm"); 1.10 +Cu.import("resource://gre/modules/Task.jsm"); 1.11 +Cu.import("resource://gre/modules/Promise.jsm"); 1.12 + 1.13 +const LINUX = navigator.platform.startsWith("Linux"); 1.14 +const MAC = navigator.platform.startsWith("Mac"); 1.15 +const WIN = navigator.platform.startsWith("Win"); 1.16 +const MAC_106 = navigator.userAgent.contains("Mac OS X 10.6"); 1.17 + 1.18 +function checkFiles(files) { 1.19 + return Task.spawn(function*() { 1.20 + for (let file of files) { 1.21 + if (!(yield OS.File.exists(file))) { 1.22 + info("File doesn't exist: " + file); 1.23 + return false; 1.24 + } 1.25 + } 1.26 + 1.27 + return true; 1.28 + }); 1.29 +} 1.30 + 1.31 +function checkDateHigherThan(files, date) { 1.32 + return Task.spawn(function*() { 1.33 + for (let file of files) { 1.34 + if (!(yield OS.File.exists(file))) { 1.35 + info("File doesn't exist: " + file); 1.36 + return false; 1.37 + } 1.38 + 1.39 + let stat = yield OS.File.stat(file); 1.40 + if (!(stat.lastModificationDate > date)) { 1.41 + info("File not newer: " + file); 1.42 + return false; 1.43 + } 1.44 + } 1.45 + 1.46 + return true; 1.47 + }); 1.48 +} 1.49 + 1.50 +function wait(time) { 1.51 + let deferred = Promise.defer(); 1.52 + 1.53 + setTimeout(function() { 1.54 + deferred.resolve(); 1.55 + }, time); 1.56 + 1.57 + return deferred.promise; 1.58 +} 1.59 + 1.60 +// Helper to create a nsIFile from a set of path components 1.61 +function getFile() { 1.62 + let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); 1.63 + file.initWithPath(OS.Path.join.apply(OS.Path, arguments)); 1.64 + return file; 1.65 +} 1.66 + 1.67 +function setDryRunPref() { 1.68 + let old_dry_run; 1.69 + try { 1.70 + old_dry_run = Services.prefs.getBoolPref("browser.mozApps.installer.dry_run"); 1.71 + } catch (ex) {} 1.72 + 1.73 + Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", false); 1.74 + 1.75 + SimpleTest.registerCleanupFunction(function() { 1.76 + if (old_dry_run === undefined) { 1.77 + Services.prefs.clearUserPref("browser.mozApps.installer.dry_run"); 1.78 + } else { 1.79 + Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", old_dry_run); 1.80 + } 1.81 + }); 1.82 +}