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