Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
6 Cu.import("resource://gre/modules/osfile.jsm");
7 Cu.import("resource://gre/modules/Task.jsm");
8 Cu.import("resource://gre/modules/Promise.jsm");
10 const LINUX = navigator.platform.startsWith("Linux");
11 const MAC = navigator.platform.startsWith("Mac");
12 const WIN = navigator.platform.startsWith("Win");
13 const MAC_106 = navigator.userAgent.contains("Mac OS X 10.6");
15 function checkFiles(files) {
16 return Task.spawn(function*() {
17 for (let file of files) {
18 if (!(yield OS.File.exists(file))) {
19 info("File doesn't exist: " + file);
20 return false;
21 }
22 }
24 return true;
25 });
26 }
28 function checkDateHigherThan(files, date) {
29 return Task.spawn(function*() {
30 for (let file of files) {
31 if (!(yield OS.File.exists(file))) {
32 info("File doesn't exist: " + file);
33 return false;
34 }
36 let stat = yield OS.File.stat(file);
37 if (!(stat.lastModificationDate > date)) {
38 info("File not newer: " + file);
39 return false;
40 }
41 }
43 return true;
44 });
45 }
47 function wait(time) {
48 let deferred = Promise.defer();
50 setTimeout(function() {
51 deferred.resolve();
52 }, time);
54 return deferred.promise;
55 }
57 // Helper to create a nsIFile from a set of path components
58 function getFile() {
59 let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
60 file.initWithPath(OS.Path.join.apply(OS.Path, arguments));
61 return file;
62 }
64 function setDryRunPref() {
65 let old_dry_run;
66 try {
67 old_dry_run = Services.prefs.getBoolPref("browser.mozApps.installer.dry_run");
68 } catch (ex) {}
70 Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", false);
72 SimpleTest.registerCleanupFunction(function() {
73 if (old_dry_run === undefined) {
74 Services.prefs.clearUserPref("browser.mozApps.installer.dry_run");
75 } else {
76 Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", old_dry_run);
77 }
78 });
79 }