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