/toolkit/mozapps/update/test/sharedUpdateXML.js

http://github.com/zpao/v8monkey · JavaScript · 351 lines · 168 code · 13 blank · 170 comment · 11 complexity · 8fca2a9c8fab0f010a07da0906c49f37 MD5 · raw file

  1. /* Any copyright is dedicated to the Public Domain.
  2. * http://creativecommons.org/publicdomain/zero/1.0/
  3. */
  4. /**
  5. * Helper functions for creating xml strings used by application update tests.
  6. *
  7. * !IMPORTANT - This file contains everything needed (along with dependencies)
  8. * by the updates.sjs file used by the mochitest-chrome tests. Since xpcshell
  9. * used by the http server is launched with -v 170 this file must not use
  10. * features greater than JavaScript 1.7.
  11. */
  12. const FILE_SIMPLE_MAR = "simple.mar";
  13. const SIZE_SIMPLE_MAR = "351";
  14. const MD5_HASH_SIMPLE_MAR = "d0a7f84dacc55a252ab916668a7cb216";
  15. const SHA1_HASH_SIMPLE_MAR = "f5053f9552d087c6c6ed83f9b19405eccf1436fc";
  16. const SHA256_HASH_SIMPLE_MAR = "663c7cbd11fe45b0a71438387db924d205997ab85ccf5" +
  17. "b40aebbdaef179796ab";
  18. const SHA384_HASH_SIMPLE_MAR = "a57250554755a9f42b91932993599bb6b05e063dcbd71" +
  19. "846e350232945dbad2b0c83208a07810cf798b3d11393" +
  20. "99c453";
  21. const SHA512_HASH_SIMPLE_MAR = "55d3e2a86acaeb0abb7a444c13bba748846fcbac7ff05" +
  22. "8f8ee9c9260ba01e6aef86fa4a6c46a3016b675ef94e7" +
  23. "7e63fbe912f64d155bed9b1c341dd56e575a26";
  24. const STATE_NONE = "null";
  25. const STATE_DOWNLOADING = "downloading";
  26. const STATE_PENDING = "pending";
  27. const STATE_PENDING_SVC = "pending-service";
  28. const STATE_APPLYING = "applying";
  29. const STATE_SUCCEEDED = "succeeded";
  30. const STATE_DOWNLOAD_FAILED = "download-failed";
  31. const STATE_FAILED = "failed";
  32. /**
  33. * Constructs a string representing a remote update xml file.
  34. *
  35. * @param aUpdates
  36. * The string representing the update elements.
  37. * @return The string representing a remote update xml file.
  38. */
  39. function getRemoteUpdatesXMLString(aUpdates) {
  40. return "<?xml version=\"1.0\"?>\n" +
  41. "<updates>\n" +
  42. aUpdates +
  43. "</updates>\n";
  44. }
  45. /**
  46. * Constructs a string representing an update element for a remote update xml
  47. * file. See getUpdateString for parameter information not provided below.
  48. *
  49. * @param aPatches
  50. * String representing the application update patches.
  51. * @return The string representing an update element for an update xml file.
  52. */
  53. function getRemoteUpdateString(aPatches, aType, aName, aDisplayVersion,
  54. aAppVersion, aPlatformVersion, aBuildID,
  55. aDetailsURL, aBillboardURL, aLicenseURL,
  56. aShowPrompt, aShowNeverForVersion, aShowSurvey,
  57. aVersion, aExtensionVersion, aCustom1,
  58. aCustom2) {
  59. return getUpdateString(aType, aName, aDisplayVersion, aAppVersion,
  60. aPlatformVersion, aBuildID, aDetailsURL,
  61. aBillboardURL, aLicenseURL, aShowPrompt,
  62. aShowNeverForVersion, aShowSurvey, aVersion,
  63. aExtensionVersion, aCustom1, aCustom2) + ">\n" +
  64. aPatches +
  65. " </update>\n";
  66. }
  67. /**
  68. * Constructs a string representing a patch element for a remote update xml
  69. * file. See getPatchString for parameter information not provided below.
  70. *
  71. * @return The string representing a patch element for a remote update xml file.
  72. */
  73. function getRemotePatchString(aType, aURL, aHashFunction, aHashValue, aSize) {
  74. return getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) +
  75. "/>\n";
  76. }
  77. /**
  78. * Constructs a string representing a local update xml file.
  79. *
  80. * @param aUpdates
  81. * The string representing the update elements.
  82. * @return The string representing a local update xml file.
  83. */
  84. function getLocalUpdatesXMLString(aUpdates) {
  85. if (!aUpdates || aUpdates == "")
  86. return "<updates xmlns=\"http://www.mozilla.org/2005/app-update\"/>"
  87. return ("<updates xmlns=\"http://www.mozilla.org/2005/app-update\">" +
  88. aUpdates +
  89. "</updates>").replace(/>\s+\n*</g,'><');
  90. }
  91. /**
  92. * Constructs a string representing an update element for a local update xml
  93. * file. See getUpdateString for parameter information not provided below.
  94. *
  95. * @param aPatches
  96. * String representing the application update patches.
  97. * @param aServiceURL (optional)
  98. * The update's xml url.
  99. * If not specified it will default to 'http://test_service/'.
  100. * @param aIsCompleteUpdate (optional)
  101. * The string 'true' if this update was a complete update or the string
  102. * 'false' if this update was a partial update.
  103. * If not specified it will default to 'true'.
  104. * @param aChannel (optional)
  105. * The update channel name.
  106. * If not specified it will default to 'test_channel'.
  107. * @param aForegroundDownload (optional)
  108. * The string 'true' if this update was manually downloaded or the
  109. * string 'false' if this update was automatically downloaded.
  110. * If not specified it will default to 'true'.
  111. * @param aPreviousAppVersion (optional)
  112. * The application version prior to applying the update.
  113. * If not specified it will not be present.
  114. * @return The string representing an update element for an update xml file.
  115. */
  116. function getLocalUpdateString(aPatches, aType, aName, aDisplayVersion,
  117. aAppVersion, aPlatformVersion, aBuildID,
  118. aDetailsURL, aBillboardURL, aLicenseURL,
  119. aServiceURL, aInstallDate, aStatusText,
  120. aIsCompleteUpdate, aChannel, aForegroundDownload,
  121. aShowPrompt, aShowNeverForVersion, aShowSurvey,
  122. aVersion, aExtensionVersion, aPreviousAppVersion,
  123. aCustom1, aCustom2) {
  124. let serviceURL = aServiceURL ? aServiceURL : "http://test_service/";
  125. let installDate = aInstallDate ? aInstallDate : "1238441400314";
  126. let statusText = aStatusText ? aStatusText : "Install Pending";
  127. let isCompleteUpdate =
  128. typeof(aIsCompleteUpdate) == "string" ? aIsCompleteUpdate : "true";
  129. let channel = aChannel ? aChannel : "test_channel";
  130. let foregroundDownload =
  131. typeof(aForegroundDownload) == "string" ? aForegroundDownload : "true";
  132. let previousAppVersion = aPreviousAppVersion ? "previousAppVersion=\"" +
  133. aPreviousAppVersion + "\" "
  134. : "";
  135. return getUpdateString(aType, aName, aDisplayVersion, aAppVersion,
  136. aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL,
  137. aLicenseURL, aShowPrompt, aShowNeverForVersion,
  138. aShowSurvey, aVersion, aExtensionVersion, aCustom1,
  139. aCustom2) +
  140. " " +
  141. previousAppVersion +
  142. "serviceURL=\"" + serviceURL + "\" " +
  143. "installDate=\"" + installDate + "\" " +
  144. "statusText=\"" + statusText + "\" " +
  145. "isCompleteUpdate=\"" + isCompleteUpdate + "\" " +
  146. "channel=\"" + channel + "\" " +
  147. "foregroundDownload=\"" + foregroundDownload + "\">" +
  148. aPatches +
  149. " </update>";
  150. }
  151. /**
  152. * Constructs a string representing a patch element for a local update xml file.
  153. * See getPatchString for parameter information not provided below.
  154. *
  155. * @param aSelected (optional)
  156. * Whether this patch is selected represented or not. The string 'true'
  157. * denotes selected and the string 'false' denotes not selected.
  158. * If not specified it will default to the string 'true'.
  159. * @param aState (optional)
  160. * The patch's state.
  161. * If not specified it will default to STATE_SUCCEEDED.
  162. * @return The string representing a patch element for a local update xml file.
  163. */
  164. function getLocalPatchString(aType, aURL, aHashFunction, aHashValue, aSize,
  165. aSelected, aState) {
  166. let selected = typeof(aSelected) == "string" ? aSelected : "true";
  167. let state = aState ? aState : STATE_SUCCEEDED;
  168. return getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) + " " +
  169. "selected=\"" + selected + "\" " +
  170. "state=\"" + state + "\"/>\n";
  171. }
  172. /**
  173. * Constructs a string representing an update element for a remote update xml
  174. * file.
  175. *
  176. * @param aType (optional)
  177. * The update's type which should be major or minor. If not specified it
  178. * will default to 'major'.
  179. * @param aName (optional)
  180. * The update's name.
  181. * If not specified it will default to 'App Update Test'.
  182. * @param aDisplayVersion (optional)
  183. * The update's display version.
  184. * If not specified it will default to 'version #' where # is the value
  185. * of DEFAULT_UPDATE_VERSION.
  186. * @param aAppVersion (optional)
  187. * The update's application version.
  188. * If not specified it will default to the value of
  189. * DEFAULT_UPDATE_VERSION.
  190. * @param aPlatformVersion (optional)
  191. * The update's platform version.
  192. * If not specified it will default to the value of
  193. * DEFAULT_UPDATE_VERSION.
  194. * @param aBuildID (optional)
  195. * The update's build id.
  196. * If not specified it will default to '20080811053724'.
  197. * @param aDetailsURL (optional)
  198. * The update's details url.
  199. * If not specified it will default to 'http://test_details/' due to due
  200. * to bug 470244.
  201. * @param aBillboardURL (optional)
  202. * The update's billboard url.
  203. * If not specified it will not be present.
  204. * @param aLicenseURL (optional)
  205. * The update's license url.
  206. * If not specified it will not be present.
  207. * @param aShowPrompt (optional)
  208. * Whether to show the prompt for the update when auto update is
  209. * enabled.
  210. * If not specified it will not be present and the update service will
  211. * default to false.
  212. * @param aShowNeverForVersion (optional)
  213. * Whether to show the 'No Thanks' button in the update prompt.
  214. * If not specified it will not be present and the update service will
  215. * default to false.
  216. * @param aShowSurvey (optional)
  217. * Whether to show the 'No Thanks' button in the update prompt.
  218. * If not specified it will not be present and the update service will
  219. * default to false.
  220. * @param aVersion (optional)
  221. * The update's application version from 1.9.2.
  222. * If not specified it will not be present.
  223. * @param aExtensionVersion (optional)
  224. * The update's application version from 1.9.2.
  225. * If not specified it will not be present.
  226. * @param aCustom1 (optional)
  227. * A custom attribute name and attribute value to add to the xml.
  228. * Example: custom1_attribute="custom1 value"
  229. * If not specified it will not be present.
  230. * @param aCustom2 (optional)
  231. * A custom attribute name and attribute value to add to the xml.
  232. * Example: custom2_attribute="custom2 value"
  233. * If not specified it will not be present.
  234. * @return The string representing an update element for an update xml file.
  235. */
  236. function getUpdateString(aType, aName, aDisplayVersion, aAppVersion,
  237. aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL,
  238. aLicenseURL, aShowPrompt, aShowNeverForVersion,
  239. aShowSurvey, aVersion, aExtensionVersion, aCustom1,
  240. aCustom2) {
  241. let type = aType ? aType : "major";
  242. let name = aName ? aName : "App Update Test";
  243. let displayVersion = "";
  244. if (aDisplayVersion || !aVersion) {
  245. displayVersion = "displayVersion=\"" +
  246. (aDisplayVersion ? aDisplayVersion
  247. : "version " + DEFAULT_UPDATE_VERSION) +
  248. "\" ";
  249. }
  250. // version has been deprecated in favor of displayVersion but it still needs
  251. // to be tested for forward compatibility.
  252. let version = aVersion ? "version=\"" + aVersion + "\" " : "";
  253. let appVersion = "";
  254. if (aAppVersion || !aExtensionVersion) {
  255. appVersion = "appVersion=\"" +
  256. (aAppVersion ? aAppVersion : DEFAULT_UPDATE_VERSION) +
  257. "\" ";
  258. }
  259. // extensionVersion has been deprecated in favor of appVersion but it still
  260. // needs to be tested for forward compatibility.
  261. let extensionVersion = aExtensionVersion ? "extensionVersion=\"" +
  262. aExtensionVersion + "\" "
  263. : "";
  264. let platformVersion = "";
  265. if (aPlatformVersion) {
  266. platformVersion = "platformVersion=\"" +
  267. (aPlatformVersion ? aPlatformVersion
  268. : DEFAULT_UPDATE_VERSION) + "\" ";
  269. }
  270. let buildID = aBuildID ? aBuildID : "20080811053724";
  271. // XXXrstrong - not specifying a detailsURL will cause a leak due to bug 470244
  272. // let detailsURL = aDetailsURL ? "detailsURL=\"" + aDetailsURL + "\" " : "";
  273. let detailsURL = "detailsURL=\"" +
  274. (aDetailsURL ? aDetailsURL
  275. : "http://test_details/") + "\" ";
  276. let billboardURL = aBillboardURL ? "billboardURL=\"" +
  277. aBillboardURL + "\" "
  278. : "";
  279. let licenseURL = aLicenseURL ? "licenseURL=\"" + aLicenseURL + "\" " : "";
  280. let showPrompt = aShowPrompt ? "showPrompt=\"" + aShowPrompt + "\" " : "";
  281. let showNeverForVersion = aShowNeverForVersion ? "showNeverForVersion=\"" +
  282. aShowNeverForVersion + "\" "
  283. : "";
  284. let showSurvey = aShowSurvey ? "showSurvey=\"" + aShowSurvey + "\" " : "";
  285. let custom1 = aCustom1 ? aCustom1 + " " : "";
  286. let custom2 = aCustom2 ? aCustom2 + " " : "";
  287. return " <update type=\"" + type + "\" " +
  288. "name=\"" + name + "\" " +
  289. displayVersion +
  290. version +
  291. appVersion +
  292. extensionVersion +
  293. platformVersion +
  294. detailsURL +
  295. billboardURL +
  296. licenseURL +
  297. showPrompt +
  298. showNeverForVersion +
  299. showSurvey +
  300. custom1 +
  301. custom2 +
  302. "buildID=\"" + buildID + "\"";
  303. }
  304. /**
  305. * Constructs a string representing a patch element for an update xml file.
  306. *
  307. * @param aType (optional)
  308. * The patch's type which should be complete or partial.
  309. * If not specified it will default to 'complete'.
  310. * @param aURL (optional)
  311. * The patch's url to the mar file.
  312. * If not specified it will default to the value of:
  313. * URL_HOST + URL_PATH + "/" + FILE_SIMPLE_MAR
  314. * @param aHashFunction (optional)
  315. * The patch's hash function used to verify the mar file.
  316. * If not specified it will default to 'MD5'.
  317. * @param aHashValue (optional)
  318. * The patch's hash value used to verify the mar file.
  319. * If not specified it will default to the value of MD5_HASH_SIMPLE_MAR
  320. * which is the MD5 hash value for the file specified by FILE_SIMPLE_MAR.
  321. * @param aSize (optional)
  322. * The patch's file size for the mar file.
  323. * If not specified it will default to the file size for FILE_SIMPLE_MAR
  324. * specified by SIZE_SIMPLE_MAR.
  325. * @return The string representing a patch element for an update xml file.
  326. */
  327. function getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) {
  328. let type = aType ? aType : "complete";
  329. let url = aURL ? aURL : URL_HOST + URL_PATH + "/" + FILE_SIMPLE_MAR;
  330. let hashFunction = aHashFunction ? aHashFunction : "MD5";
  331. let hashValue = aHashValue ? aHashValue : MD5_HASH_SIMPLE_MAR;
  332. let size = aSize ? aSize : SIZE_SIMPLE_MAR;
  333. return " <patch type=\"" + type + "\" " +
  334. "URL=\"" + url + "\" " +
  335. "hashFunction=\"" + hashFunction + "\" " +
  336. "hashValue=\"" + hashValue + "\" " +
  337. "size=\"" + size + "\"";
  338. }