PageRenderTime 67ms CodeModel.GetById 22ms app.highlight 36ms RepoModel.GetById 4ms app.codeStats 0ms

/toolkit/mozapps/update/test/unit/test_0160_appInUse_xp_unix_complete.js

http://github.com/zpao/v8monkey
JavaScript | 295 lines | 261 code | 17 blank | 17 comment | 2 complexity | eb7b32fced78cffcf480ddcf96b66eb1 MD5 | raw file
  1/* Any copyright is dedicated to the Public Domain.
  2 * http://creativecommons.org/publicdomain/zero/1.0/
  3 */
  4
  5/* Application in use complete MAR file patch apply success test */
  6
  7const TEST_ID = "0160";
  8// All we care about is that the last modified time has changed so that Mac OS
  9// X Launch Services invalidates its cache so the test allows up to one minute
 10// difference in the last modified time.
 11const MAX_TIME_DIFFERENCE = 60000;
 12
 13// The files are listed in the same order as they are applied from the mar's
 14// update.manifest. Complete updates have remove file and rmdir directory
 15// operations located in the precomplete file performed first.
 16const TEST_FILES = [
 17{
 18  description      : "Should never change",
 19  fileName         : "channel-prefs.js",
 20  relPathDir       : "a/b/defaults/pref/",
 21  originalContents : "ShouldNotBeReplaced\n",
 22  compareContents  : "ShouldNotBeReplaced\n",
 23  originalFile     : null,
 24  compareFile      : null,
 25  originalPerms    : 0767,
 26  comparePerms     : 0767
 27}, {
 28  description      : "Added by update.manifest (add)",
 29  fileName         : "precomplete",
 30  relPathDir       : "",
 31  originalContents : null,
 32  compareContents  : null,
 33  originalFile     : "data/partial_precomplete",
 34  compareFile      : "data/complete_precomplete",
 35  originalPerms    : 0666,
 36  comparePerms     : 0644
 37}, {
 38  description      : "Added by update.manifest (add)",
 39  fileName         : "searchpluginstext0",
 40  relPathDir       : "a/b/searchplugins/",
 41  originalContents : "ToBeReplacedWithFromComplete\n",
 42  compareContents  : "FromComplete\n",
 43  originalFile     : null,
 44  compareFile      : null,
 45  originalPerms    : 0775,
 46  comparePerms     : 0644
 47}, {
 48  description      : "Added by update.manifest (add)",
 49  fileName         : "searchpluginspng1.png",
 50  relPathDir       : "a/b/searchplugins/",
 51  originalContents : null,
 52  compareContents  : null,
 53  originalFile     : null,
 54  compareFile      : "data/complete.png",
 55  originalPerms    : null,
 56  comparePerms     : 0644
 57}, {
 58  description      : "Added by update.manifest (add)",
 59  fileName         : "searchpluginspng0.png",
 60  relPathDir       : "a/b/searchplugins/",
 61  originalContents : null,
 62  compareContents  : null,
 63  originalFile     : "data/partial.png",
 64  compareFile      : "data/complete.png",
 65  originalPerms    : 0666,
 66  comparePerms     : 0644
 67}, {
 68  description      : "Added by update.manifest (add)",
 69  fileName         : "removed-files",
 70  relPathDir       : "a/b/",
 71  originalContents : null,
 72  compareContents  : null,
 73  originalFile     : "data/partial_removed-files",
 74  compareFile      : "data/complete_removed-files",
 75  originalPerms    : 0666,
 76  comparePerms     : 0644
 77}, {
 78  description      : "Added by update.manifest if the parent directory " +
 79                     "exists (add-if)",
 80  fileName         : "extensions1text0",
 81  relPathDir       : "a/b/extensions/extensions1/",
 82  originalContents : null,
 83  compareContents  : "FromComplete\n",
 84  originalFile     : null,
 85  compareFile      : null,
 86  originalPerms    : null,
 87  comparePerms     : 0644
 88}, {
 89  description      : "Added by update.manifest if the parent directory " +
 90                     "exists (add-if)",
 91  fileName         : "extensions1png1.png",
 92  relPathDir       : "a/b/extensions/extensions1/",
 93  originalContents : null,
 94  compareContents  : null,
 95  originalFile     : "data/partial.png",
 96  compareFile      : "data/complete.png",
 97  originalPerms    : 0666,
 98  comparePerms     : 0644
 99}, {
100  description      : "Added by update.manifest if the parent directory " +
101                     "exists (add-if)",
102  fileName         : "extensions1png0.png",
103  relPathDir       : "a/b/extensions/extensions1/",
104  originalContents : null,
105  compareContents  : null,
106  originalFile     : null,
107  compareFile      : "data/complete.png",
108  originalPerms    : null,
109  comparePerms     : 0644
110}, {
111  description      : "Added by update.manifest if the parent directory " +
112                     "exists (add-if)",
113  fileName         : "extensions0text0",
114  relPathDir       : "a/b/extensions/extensions0/",
115  originalContents : "ToBeReplacedWithFromComplete\n",
116  compareContents  : "FromComplete\n",
117  originalFile     : null,
118  compareFile      : null,
119  originalPerms    : null,
120  comparePerms     : 0644
121}, {
122  description      : "Added by update.manifest if the parent directory " +
123                     "exists (add-if)",
124  fileName         : "extensions0png1.png",
125  relPathDir       : "a/b/extensions/extensions0/",
126  originalContents : null,
127  compareContents  : null,
128  originalFile     : null,
129  compareFile      : "data/complete.png",
130  originalPerms    : null,
131  comparePerms     : 0644
132}, {
133  description      : "Added by update.manifest if the parent directory " +
134                     "exists (add-if)",
135  fileName         : "extensions0png0.png",
136  relPathDir       : "a/b/extensions/extensions0/",
137  originalContents : null,
138  compareContents  : null,
139  originalFile     : null,
140  compareFile      : "data/complete.png",
141  originalPerms    : null,
142  comparePerms     : 0644
143}, {
144  description      : "Added by update.manifest (add)",
145  fileName         : "exe0.exe",
146  relPathDir       : "a/b/",
147  originalContents : null,
148  compareContents  : null,
149  originalFile     : "data/partial.png",
150  compareFile      : "data/complete.png",
151  originalPerms    : 0777,
152  comparePerms     : 0755
153}, {
154  description      : "Added by update.manifest (add)",
155  fileName         : "10text0",
156  relPathDir       : "a/b/1/10/",
157  originalContents : "ToBeReplacedWithFromComplete\n",
158  compareContents  : "FromComplete\n",
159  originalFile     : null,
160  compareFile      : null,
161  originalPerms    : 0767,
162  comparePerms     : 0644
163}, {
164  description      : "Added by update.manifest (add)",
165  fileName         : "0exe0.exe",
166  relPathDir       : "a/b/0/",
167  originalContents : null,
168  compareContents  : null,
169  originalFile     : "data/partial.png",
170  compareFile      : "data/complete.png",
171  originalPerms    : 0777,
172  comparePerms     : 0755
173}, {
174  description      : "Added by update.manifest (add)",
175  fileName         : "00text1",
176  relPathDir       : "a/b/0/00/",
177  originalContents : "ToBeReplacedWithFromComplete\n",
178  compareContents  : "FromComplete\n",
179  originalFile     : null,
180  compareFile      : null,
181  originalPerms    : 0677,
182  comparePerms     : 0644
183}, {
184  description      : "Added by update.manifest (add)",
185  fileName         : "00text0",
186  relPathDir       : "a/b/0/00/",
187  originalContents : "ToBeReplacedWithFromComplete\n",
188  compareContents  : "FromComplete\n",
189  originalFile     : null,
190  compareFile      : null,
191  originalPerms    : 0775,
192  comparePerms     : 0644
193}, {
194  description      : "Added by update.manifest (add)",
195  fileName         : "00png0.png",
196  relPathDir       : "a/b/0/00/",
197  originalContents : null,
198  compareContents  : null,
199  originalFile     : null,
200  compareFile      : "data/complete.png",
201  originalPerms    : 0776,
202  comparePerms     : 0644
203}, {
204  description      : "Removed by precomplete (remove)",
205  fileName         : "20text0",
206  relPathDir       : "a/b/2/20/",
207  originalContents : "ToBeDeleted\n",
208  compareContents  : null,
209  originalFile     : null,
210  compareFile      : null,
211  originalPerms    : null,
212  comparePerms     : null
213}, {
214  description      : "Removed by precomplete (remove)",
215  fileName         : "20png0.png",
216  relPathDir       : "a/b/2/20/",
217  originalContents : "ToBeDeleted\n",
218  compareContents  : null,
219  originalFile     : null,
220  compareFile      : null,
221  originalPerms    : null,
222  comparePerms     : null
223}];
224
225ADDITIONAL_TEST_DIRS = [
226{
227  description  : "Removed by precomplete (rmdir)",
228  relPathDir   : "a/b/2/20/",
229  dirRemoved   : true
230}, {
231  description  : "Removed by precomplete (rmdir)",
232  relPathDir   : "a/b/2/",
233  dirRemoved   : true
234}];
235
236function run_test() {
237  do_test_pending();
238  do_register_cleanup(cleanupUpdaterTest);
239
240  setupUpdaterTest(MAR_COMPLETE_FILE);
241
242  // Launch the callback helper application so it is in use during the update
243  let callbackApp = getApplyDirFile("a/b/" + gCallbackBinFile);
244  callbackApp.permissions = PERMS_DIRECTORY;
245  let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "20"];
246  let callbackAppProcess = AUS_Cc["@mozilla.org/process/util;1"].
247                           createInstance(AUS_Ci.nsIProcess);
248  callbackAppProcess.init(callbackApp);
249  callbackAppProcess.run(false, args, args.length);
250
251  do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep);
252}
253
254function doUpdate() {
255  let applyToDir = getApplyDirFile();
256
257  // For Mac OS X set the last modified time for the root directory to a date in
258  // the past to test that the last modified time is updated on a successful
259  // update (bug 600098).
260  if (IS_MACOSX) {
261    let now = Date.now();
262    let yesterday = now - (1000 * 60 * 60 * 24);
263    applyToDir.lastModifiedTime = yesterday;
264  }
265
266  // apply the complete mar
267  let exitValue = runUpdate();
268  logTestInfo("testing updater binary process exitValue for success when " +
269              "applying a complete mar");
270  do_check_eq(exitValue, 0);
271
272  setupHelperFinish();
273}
274
275
276function checkUpdate() {
277  logTestInfo("testing update.status should be " + STATE_SUCCEEDED);
278  let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX);
279  do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED);
280
281  // For Mac OS X check that the last modified time for a directory has been
282  // updated after a successful update (bug 600098).
283  if (IS_MACOSX) {
284    logTestInfo("testing last modified time on the apply to directory has " +
285                "changed after a successful update (bug 600098)");
286    let now = Date.now();
287    let applyToDir = getApplyDirFile();
288    let timeDiff = Math.abs(applyToDir.lastModifiedTime - now);
289    do_check_true(timeDiff < MAX_TIME_DIFFERENCE);
290  }
291
292  checkFilesAfterUpdateSuccess();
293
294  checkCallbackAppLog();
295}