PageRenderTime 27ms CodeModel.GetById 15ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/zpao/v8monkey
JavaScript | 319 lines | 254 code | 14 blank | 51 comment | 3 complexity | 04c3d7b369db988f129561d640c833ab MD5 | raw file
  1/* ***** BEGIN LICENSE BLOCK *****
  2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3 *
  4 * The contents of this file are subject to the Mozilla Public License Version
  5 * 1.1 (the "License"); you may not use this file except in compliance with
  6 * the License. You may obtain a copy of the License at
  7 * http://www.mozilla.org/MPL/
  8 *
  9 * Software distributed under the License is distributed on an "AS IS" basis,
 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 11 * for the specific language governing rights and limitations under the
 12 * License.
 13 *
 14 * The Original Code is mozilla.org code.
 15 *
 16 * The Initial Developer of the Original Code is
 17 * the Mozilla Foundation.
 18 * Portions created by the Initial Developer are Copyright (C) 2008
 19 * the Initial Developer. All Rights Reserved.
 20 *
 21 * Contributor(s):
 22 *   Robert Strong <robert.bugzilla@gmail.com> (Original Author)
 23 *
 24 * Alternatively, the contents of this file may be used under the terms of
 25 * either the GNU General Public License Version 2 or later (the "GPL"), or
 26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 27 * in which case the provisions of the GPL or the LGPL are applicable instead
 28 * of those above. If you wish to allow use of your version of this file only
 29 * under the terms of either the GPL or the LGPL, and not to allow others to
 30 * use your version of this file under the terms of the MPL, indicate your
 31 * decision by deleting the provisions above and replace them with the notice
 32 * and other provisions required by the GPL or the LGPL. If you do not delete
 33 * the provisions above, a recipient may use your version of this file under
 34 * the terms of any one of the MPL, the GPL or the LGPL.
 35 *
 36 * ***** END LICENSE BLOCK *****
 37 */
 38
 39/* General Complete MAR File Patch Apply Test */
 40
 41const TEST_ID = "0110";
 42// All we care about is that the last modified time has changed so that Mac OS
 43// X Launch Services invalidates its cache so the test allows up to one minute
 44// difference in the last modified time.
 45const MAX_TIME_DIFFERENCE = 60000;
 46
 47// The files are listed in the same order as they are applied from the mar's
 48// update.manifest. Complete updates have remove file and rmdir directory
 49// operations located in the precomplete file performed first.
 50const TEST_FILES = [
 51{
 52  description      : "Should never change",
 53  fileName         : "channel-prefs.js",
 54  relPathDir       : "a/b/defaults/pref/",
 55  originalContents : "ShouldNotBeReplaced\n",
 56  compareContents  : "ShouldNotBeReplaced\n",
 57  originalFile     : null,
 58  compareFile      : null,
 59  originalPerms    : 0767,
 60  comparePerms     : 0767
 61}, {
 62  description      : "Added by update.manifest (add)",
 63  fileName         : "precomplete",
 64  relPathDir       : "",
 65  originalContents : null,
 66  compareContents  : null,
 67  originalFile     : "data/partial_precomplete",
 68  compareFile      : "data/complete_precomplete",
 69  originalPerms    : 0666,
 70  comparePerms     : 0644
 71}, {
 72  description      : "Added by update.manifest (add)",
 73  fileName         : "searchpluginstext0",
 74  relPathDir       : "a/b/searchplugins/",
 75  originalContents : "ToBeReplacedWithFromComplete\n",
 76  compareContents  : "FromComplete\n",
 77  originalFile     : null,
 78  compareFile      : null,
 79  originalPerms    : 0775,
 80  comparePerms     : 0644
 81}, {
 82  description      : "Added by update.manifest (add)",
 83  fileName         : "searchpluginspng1.png",
 84  relPathDir       : "a/b/searchplugins/",
 85  originalContents : null,
 86  compareContents  : null,
 87  originalFile     : null,
 88  compareFile      : "data/complete.png",
 89  originalPerms    : null,
 90  comparePerms     : 0644
 91}, {
 92  description      : "Added by update.manifest (add)",
 93  fileName         : "searchpluginspng0.png",
 94  relPathDir       : "a/b/searchplugins/",
 95  originalContents : null,
 96  compareContents  : null,
 97  originalFile     : "data/partial.png",
 98  compareFile      : "data/complete.png",
 99  originalPerms    : 0666,
100  comparePerms     : 0644
101}, {
102  description      : "Added by update.manifest (add)",
103  fileName         : "removed-files",
104  relPathDir       : "a/b/",
105  originalContents : null,
106  compareContents  : null,
107  originalFile     : "data/partial_removed-files",
108  compareFile      : "data/complete_removed-files",
109  originalPerms    : 0666,
110  comparePerms     : 0644
111}, {
112  description      : "Added by update.manifest if the parent directory " +
113                     "exists (add-if)",
114  fileName         : "extensions1text0",
115  relPathDir       : "a/b/extensions/extensions1/",
116  originalContents : null,
117  compareContents  : "FromComplete\n",
118  originalFile     : null,
119  compareFile      : null,
120  originalPerms    : null,
121  comparePerms     : 0644
122}, {
123  description      : "Added by update.manifest if the parent directory " +
124                     "exists (add-if)",
125  fileName         : "extensions1png1.png",
126  relPathDir       : "a/b/extensions/extensions1/",
127  originalContents : null,
128  compareContents  : null,
129  originalFile     : "data/partial.png",
130  compareFile      : "data/complete.png",
131  originalPerms    : 0666,
132  comparePerms     : 0644
133}, {
134  description      : "Added by update.manifest if the parent directory " +
135                     "exists (add-if)",
136  fileName         : "extensions1png0.png",
137  relPathDir       : "a/b/extensions/extensions1/",
138  originalContents : null,
139  compareContents  : null,
140  originalFile     : null,
141  compareFile      : "data/complete.png",
142  originalPerms    : null,
143  comparePerms     : 0644
144}, {
145  description      : "Added by update.manifest if the parent directory " +
146                     "exists (add-if)",
147  fileName         : "extensions0text0",
148  relPathDir       : "a/b/extensions/extensions0/",
149  originalContents : "ToBeReplacedWithFromComplete\n",
150  compareContents  : "FromComplete\n",
151  originalFile     : null,
152  compareFile      : null,
153  originalPerms    : null,
154  comparePerms     : 0644
155}, {
156  description      : "Added by update.manifest if the parent directory " +
157                     "exists (add-if)",
158  fileName         : "extensions0png1.png",
159  relPathDir       : "a/b/extensions/extensions0/",
160  originalContents : null,
161  compareContents  : null,
162  originalFile     : null,
163  compareFile      : "data/complete.png",
164  originalPerms    : null,
165  comparePerms     : 0644
166}, {
167  description      : "Added by update.manifest if the parent directory " +
168                     "exists (add-if)",
169  fileName         : "extensions0png0.png",
170  relPathDir       : "a/b/extensions/extensions0/",
171  originalContents : null,
172  compareContents  : null,
173  originalFile     : null,
174  compareFile      : "data/complete.png",
175  originalPerms    : null,
176  comparePerms     : 0644
177}, {
178  description      : "Added by update.manifest (add)",
179  fileName         : "exe0.exe",
180  relPathDir       : "a/b/",
181  originalContents : null,
182  compareContents  : null,
183  originalFile     : "data/partial.png",
184  compareFile      : "data/complete.png",
185  originalPerms    : 0777,
186  comparePerms     : 0755
187}, {
188  description      : "Added by update.manifest (add)",
189  fileName         : "10text0",
190  relPathDir       : "a/b/1/10/",
191  originalContents : "ToBeReplacedWithFromComplete\n",
192  compareContents  : "FromComplete\n",
193  originalFile     : null,
194  compareFile      : null,
195  originalPerms    : 0767,
196  comparePerms     : 0644
197}, {
198  description      : "Added by update.manifest (add)",
199  fileName         : "0exe0.exe",
200  relPathDir       : "a/b/0/",
201  originalContents : null,
202  compareContents  : null,
203  originalFile     : "data/partial.png",
204  compareFile      : "data/complete.png",
205  originalPerms    : 0777,
206  comparePerms     : 0755
207}, {
208  description      : "Added by update.manifest (add)",
209  fileName         : "00text1",
210  relPathDir       : "a/b/0/00/",
211  originalContents : "ToBeReplacedWithFromComplete\n",
212  compareContents  : "FromComplete\n",
213  originalFile     : null,
214  compareFile      : null,
215  originalPerms    : 0677,
216  comparePerms     : 0644
217}, {
218  description      : "Added by update.manifest (add)",
219  fileName         : "00text0",
220  relPathDir       : "a/b/0/00/",
221  originalContents : "ToBeReplacedWithFromComplete\n",
222  compareContents  : "FromComplete\n",
223  originalFile     : null,
224  compareFile      : null,
225  originalPerms    : 0775,
226  comparePerms     : 0644
227}, {
228  description      : "Added by update.manifest (add)",
229  fileName         : "00png0.png",
230  relPathDir       : "a/b/0/00/",
231  originalContents : null,
232  compareContents  : null,
233  originalFile     : null,
234  compareFile      : "data/complete.png",
235  originalPerms    : 0776,
236  comparePerms     : 0644
237}, {
238  description      : "Removed by precomplete (remove)",
239  fileName         : "20text0",
240  relPathDir       : "a/b/2/20/",
241  originalContents : "ToBeDeleted\n",
242  compareContents  : null,
243  originalFile     : null,
244  compareFile      : null,
245  originalPerms    : null,
246  comparePerms     : null
247}, {
248  description      : "Removed by precomplete (remove)",
249  fileName         : "20png0.png",
250  relPathDir       : "a/b/2/20/",
251  originalContents : "ToBeDeleted\n",
252  compareContents  : null,
253  originalFile     : null,
254  compareFile      : null,
255  originalPerms    : null,
256  comparePerms     : null
257}];
258
259ADDITIONAL_TEST_DIRS = [
260{
261  description  : "Removed by precomplete (rmdir)",
262  relPathDir   : "a/b/2/20/",
263  dirRemoved   : true
264}, {
265  description  : "Removed by precomplete (rmdir)",
266  relPathDir   : "a/b/2/",
267  dirRemoved   : true
268}];
269
270function run_test() {
271  do_test_pending();
272  do_register_cleanup(cleanupUpdaterTest);
273
274  setupUpdaterTest(MAR_COMPLETE_FILE);
275
276  let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX);
277  let applyToDir = getApplyDirFile();
278
279  // For Mac OS X set the last modified time for the root directory to a date in
280  // the past to test that the last modified time is updated on a successful
281  // update (bug 600098).
282  if (IS_MACOSX) {
283    let now = Date.now();
284    let yesterday = now - (1000 * 60 * 60 * 24);
285    applyToDir.lastModifiedTime = yesterday;
286  }
287
288  // apply the complete mar
289  let exitValue = runUpdate();
290  logTestInfo("testing updater binary process exitValue for success when " +
291              "applying a complete mar");
292  do_check_eq(exitValue, 0);
293
294  logTestInfo("testing update.status should be " + STATE_SUCCEEDED);
295  let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX);
296  do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED);
297
298  // For Mac OS X check that the last modified time for a directory has been
299  // updated after a successful update (bug 600098).
300  if (IS_MACOSX) {
301    logTestInfo("testing last modified time on the apply to directory has " +
302                "changed after a successful update (bug 600098)");
303    let now = Date.now();
304    let timeDiff = Math.abs(applyToDir.lastModifiedTime - now);
305    do_check_true(timeDiff < MAX_TIME_DIFFERENCE);
306  }
307
308  checkFilesAfterUpdateSuccess();
309  // Sorting on Linux is different so skip this check for now.
310  if (!IS_UNIX) {
311    checkUpdateLogContents(LOG_COMPLETE_SUCCESS);
312  }
313
314  logTestInfo("testing tobedeleted directory doesn't exist");
315  let toBeDeletedDir = getApplyDirFile("tobedeleted", true);
316  do_check_false(toBeDeletedDir.exists());
317
318  checkCallbackAppLog();
319}