toolkit/mozapps/update/tests/sharedUpdateXML.js

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

mercurial