PageRenderTime 41ms CodeModel.GetById 12ms app.highlight 21ms RepoModel.GetById 2ms app.codeStats 0ms

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