PageRenderTime 24ms CodeModel.GetById 12ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/zpao/v8monkey
JavaScript | 237 lines | 210 code | 14 blank | 13 comment | 0 complexity | c1ee771b9ec56559acb96863a72f6f34 MD5 | raw file
  1/* Any copyright is dedicated to the Public Domain.
  2 * http://creativecommons.org/publicdomain/zero/1.0/
  3 */
  4
  5/* File locked partial MAR file patch apply failure test */
  6
  7const TEST_ID = "0171";
  8
  9// The files are listed in the same order as they are applied from the mar's
 10// update.manifest. Complete updates have remove file and rmdir directory
 11// operations located in the precomplete file performed first.
 12const TEST_FILES = [
 13{
 14  description      : "Should never change",
 15  fileName         : "channel-prefs.js",
 16  relPathDir       : "a/b/defaults/pref/",
 17  originalContents : "ShouldNotBeReplaced\n",
 18  compareContents  : "ShouldNotBeReplaced\n",
 19  originalFile     : null,
 20  compareFile      : null
 21}, {
 22  description      : "Not added for failed update (add)",
 23  fileName         : "precomplete",
 24  relPathDir       : "",
 25  originalContents : null,
 26  compareContents  : null,
 27  originalFile     : "data/complete_precomplete",
 28  compareFile      : "data/complete_precomplete"
 29}, {
 30  description      : "Not added for failed update (add)",
 31  fileName         : "searchpluginstext0",
 32  relPathDir       : "a/b/searchplugins/",
 33  originalContents : "ShouldNotBeReplaced\n",
 34  compareContents  : "ShouldNotBeReplaced\n",
 35  originalFile     : null,
 36  compareFile      : null
 37}, {
 38  description      : "Not patched for failed update (patch-if)",
 39  fileName         : "searchpluginspng1.png",
 40  relPathDir       : "a/b/searchplugins/",
 41  originalContents : null,
 42  compareContents  : null,
 43  originalFile     : "data/complete.png",
 44  compareFile      : "data/complete.png"
 45}, {
 46  description      : "Not patched for failed update (patch-if)",
 47  fileName         : "searchpluginspng0.png",
 48  relPathDir       : "a/b/searchplugins/",
 49  originalContents : null,
 50  compareContents  : null,
 51  originalFile     : "data/complete.png",
 52  compareFile      : "data/complete.png"
 53}, {
 54  description      : "Not added for failed update (add-if)",
 55  fileName         : "extensions1text0",
 56  relPathDir       : "a/b/extensions/extensions1/",
 57  originalContents : null,
 58  compareContents  : null,
 59  originalFile     : null,
 60  compareFile      : null
 61}, {
 62  description      : "Not patched for failed update (patch-if)",
 63  fileName         : "extensions1png1.png",
 64  relPathDir       : "a/b/extensions/extensions1/",
 65  originalContents : null,
 66  compareContents  : null,
 67  originalFile     : "data/complete.png",
 68  compareFile      : "data/complete.png"
 69}, {
 70  description      : "Not patched for failed update (patch-if)",
 71  fileName         : "extensions1png0.png",
 72  relPathDir       : "a/b/extensions/extensions1/",
 73  originalContents : null,
 74  compareContents  : null,
 75  originalFile     : "data/complete.png",
 76  compareFile      : "data/complete.png"
 77}, {
 78  description      : "Not added for failed update (add-if)",
 79  fileName         : "extensions0text0",
 80  relPathDir       : "a/b/extensions/extensions0/",
 81  originalContents : "ShouldNotBeReplaced\n",
 82  compareContents  : "ShouldNotBeReplaced\n",
 83  originalFile     : null,
 84  compareFile      : null
 85}, {
 86  description      : "Not patched for failed update (patch-if)",
 87  fileName         : "extensions0png1.png",
 88  relPathDir       : "a/b/extensions/extensions0/",
 89  originalContents : null,
 90  compareContents  : null,
 91  originalFile     : "data/complete.png",
 92  compareFile      : "data/complete.png"
 93}, {
 94  description      : "Not patched for failed update (patch-if)",
 95  fileName         : "extensions0png0.png",
 96  relPathDir       : "a/b/extensions/extensions0/",
 97  originalContents : null,
 98  compareContents  : null,
 99  originalFile     : "data/complete.png",
100  compareFile      : "data/complete.png"
101}, {
102  description      : "Not patched for failed update (patch)",
103  fileName         : "exe0.exe",
104  relPathDir       : "a/b/",
105  originalContents : null,
106  compareContents  : null,
107  originalFile     : "data/complete.png",
108  compareFile      : "data/complete.png"
109}, {
110  description      : "Not patched for failed update (patch) and causes " +
111                     "LoadSourceFile failed",
112  fileName         : "0exe0.exe",
113  relPathDir       : "a/b/0/",
114  originalContents : null,
115  compareContents  : null,
116  originalFile     : "data/partial.png",
117  compareFile      : "data/partial.png"
118}, {
119  description      : "Not added for failed update (add)",
120  fileName         : "00text0",
121  relPathDir       : "a/b/0/00/",
122  originalContents : "ShouldNotBeReplaced\n",
123  compareContents  : "ShouldNotBeReplaced\n",
124  originalFile     : null,
125  compareFile      : null
126}, {
127  description      : "Not patched for failed update (patch)",
128  fileName         : "00png0.png",
129  relPathDir       : "a/b/0/00/",
130  originalContents : null,
131  compareContents  : null,
132  originalFile     : "data/complete.png",
133  compareFile      : "data/complete.png"
134}, {
135  description      : "Not added for failed update (add)",
136  fileName         : "20text0",
137  relPathDir       : "a/b/2/20/",
138  originalContents : null,
139  compareContents  : null,
140  originalFile     : null,
141  compareFile      : null
142}, {
143  description      : "Not added for failed update (add)",
144  fileName         : "20png0.png",
145  relPathDir       : "a/b/2/20/",
146  originalContents : null,
147  compareContents  : null,
148  originalFile     : null,
149  compareFile      : null
150}, {
151  description      : "Not added for failed update (add)",
152  fileName         : "00text2",
153  relPathDir       : "a/b/0/00/",
154  originalContents : null,
155  compareContents  : null,
156  originalFile     : null,
157  compareFile      : null
158}, {
159  description      : "Not removed for failed update (remove)",
160  fileName         : "10text0",
161  relPathDir       : "a/b/1/10/",
162  originalContents : "ShouldNotBeDeleted\n",
163  compareContents  : "ShouldNotBeDeleted\n",
164  originalFile     : null,
165  compareFile      : null
166}, {
167  description      : "Not removed for failed update (remove)",
168  fileName         : "00text1",
169  relPathDir       : "a/b/0/00/",
170  originalContents : "ShouldNotBeDeleted\n",
171  compareContents  : "ShouldNotBeDeleted\n",
172  originalFile     : null,
173  compareFile      : null
174}];
175
176ADDITIONAL_TEST_DIRS = [
177{
178  description  : "Not removed for failed update (rmdir)",
179  relPathDir   : "a/b/1/10/",
180  dirRemoved   : false
181}, {
182  description  : "Not removed for failed update (rmdir)",
183  relPathDir   : "a/b/1/",
184  dirRemoved   : false
185}];
186
187function run_test() {
188  do_test_pending();
189  do_register_cleanup(cleanupUpdaterTest);
190
191  setupUpdaterTest(MAR_PARTIAL_FILE);
192
193  // Exclusively lock an existing file so it is in use during the update
194  let helperBin = do_get_file(HELPER_BIN_FILE);
195  let helperDestDir = getApplyDirFile("a/b/");
196  helperBin.copyTo(helperDestDir, HELPER_BIN_FILE);
197  helperBin = getApplyDirFile("a/b/" + HELPER_BIN_FILE);
198  // Strip off the first two directories so the path has to be from the helper's
199  // working directory.
200  let lockFileRelPath = TEST_FILES[3].relPathDir.split("/");
201  lockFileRelPath = lockFileRelPath.slice(2);
202  lockFileRelPath = lockFileRelPath.join("/") + "/" + TEST_FILES[3].fileName;
203  let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "20", lockFileRelPath];
204  let lockFileProcess = AUS_Cc["@mozilla.org/process/util;1"].
205                     createInstance(AUS_Ci.nsIProcess);
206  lockFileProcess.init(helperBin);
207  lockFileProcess.run(false, args, args.length);
208
209  do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep);
210}
211
212function doUpdate() {
213  // apply the complete mar
214  let exitValue = runUpdate();
215  logTestInfo("testing updater binary process exitValue for success when " +
216              "applying a partial mar");
217  do_check_eq(exitValue, 0);
218
219  setupHelperFinish();
220}
221
222function checkUpdate() {
223  logTestInfo("testing update.status should be " + STATE_FAILED);
224  let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX);
225  // The update status format for a failure is failed: # where # is the error
226  // code for the failure.
227  do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED);
228
229  checkFilesAfterUpdateFailure();
230  checkUpdateLogContains(ERR_UNABLE_OPEN_DEST);
231
232  logTestInfo("testing tobedeleted directory doesn't exist");
233  let toBeDeletedDir = getApplyDirFile("tobedeleted", true);
234  do_check_false(toBeDeletedDir.exists());
235
236  checkCallbackAppLog();
237}