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