|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 const { classes: Cc, interfaces: Ci, utils: Cu } = Components; |
|
5 |
|
6 Cu.import("resource://gre/modules/osfile.jsm"); |
|
7 Cu.import("resource://gre/modules/Task.jsm"); |
|
8 Cu.import("resource://gre/modules/Promise.jsm"); |
|
9 |
|
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"); |
|
14 |
|
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 } |
|
23 |
|
24 return true; |
|
25 }); |
|
26 } |
|
27 |
|
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 } |
|
35 |
|
36 let stat = yield OS.File.stat(file); |
|
37 if (!(stat.lastModificationDate > date)) { |
|
38 info("File not newer: " + file); |
|
39 return false; |
|
40 } |
|
41 } |
|
42 |
|
43 return true; |
|
44 }); |
|
45 } |
|
46 |
|
47 function wait(time) { |
|
48 let deferred = Promise.defer(); |
|
49 |
|
50 setTimeout(function() { |
|
51 deferred.resolve(); |
|
52 }, time); |
|
53 |
|
54 return deferred.promise; |
|
55 } |
|
56 |
|
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 } |
|
63 |
|
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) {} |
|
69 |
|
70 Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", false); |
|
71 |
|
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 } |