1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/update/tests/sharedUpdateXML.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,362 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +/** 1.9 + * Helper functions for creating xml strings used by application update tests. 1.10 + * 1.11 + * !IMPORTANT - This file contains everything needed (along with dependencies) 1.12 + * by the updates.sjs file used by the mochitest-chrome tests. Since xpcshell 1.13 + * used by the http server is launched with -v 170 this file must not use 1.14 + * features greater than JavaScript 1.7. 1.15 + */ 1.16 + 1.17 +const FILE_SIMPLE_MAR = "simple.mar"; 1.18 +const SIZE_SIMPLE_MAR = "1031"; 1.19 +const MD5_HASH_SIMPLE_MAR = "1f8c038577bb6845d94ccec4999113ee"; 1.20 +const SHA1_HASH_SIMPLE_MAR = "5d49a672c87f10f31d7e326349564a11272a028b"; 1.21 +const SHA256_HASH_SIMPLE_MAR = "1aabbed5b1dd6e16e139afc5b43d479e254e0c26" + 1.22 + "3c8fb9249c0a1bb93071c5fb"; 1.23 +const SHA384_HASH_SIMPLE_MAR = "26615014ea034af32ef5651492d5f493f5a7a1a48522e" + 1.24 + "d24c366442a5ec21d5ef02e23fb58d79729b8ca2f9541" + 1.25 + "99dd53"; 1.26 +const SHA512_HASH_SIMPLE_MAR = "922e5ae22081795f6e8d65a3c508715c9a314054179a8" + 1.27 + "bbfe5f50dc23919ad89888291bc0a07586ab17dd0304a" + 1.28 + "b5347473601127571c66f61f5080348e05c36b"; 1.29 + 1.30 +const STATE_NONE = "null"; 1.31 +const STATE_DOWNLOADING = "downloading"; 1.32 +const STATE_PENDING = "pending"; 1.33 +const STATE_PENDING_SVC = "pending-service"; 1.34 +const STATE_APPLYING = "applying"; 1.35 +const STATE_APPLIED = "applied"; 1.36 +const STATE_APPLIED_SVC = "applied-service"; 1.37 +const STATE_SUCCEEDED = "succeeded"; 1.38 +const STATE_DOWNLOAD_FAILED = "download-failed"; 1.39 +const STATE_FAILED = "failed"; 1.40 + 1.41 +const STATE_FAILED_READ_ERROR = STATE_FAILED + ": 6"; 1.42 +const STATE_FAILED_WRITE_ERROR = STATE_FAILED + ": 7"; 1.43 +const STATE_FAILED_CHANNEL_MISMATCH_ERROR = STATE_FAILED + ": 22"; 1.44 +const STATE_FAILED_VERSION_DOWNGRADE_ERROR = STATE_FAILED + ": 23"; 1.45 +const STATE_FAILED_UNEXPECTED_FILE_OPERATION_ERROR = STATE_FAILED + ": 42"; 1.46 + 1.47 +/** 1.48 + * Constructs a string representing a remote update xml file. 1.49 + * 1.50 + * @param aUpdates 1.51 + * The string representing the update elements. 1.52 + * @return The string representing a remote update xml file. 1.53 + */ 1.54 +function getRemoteUpdatesXMLString(aUpdates) { 1.55 + return "<?xml version=\"1.0\"?>\n" + 1.56 + "<updates>\n" + 1.57 + aUpdates + 1.58 + "</updates>\n"; 1.59 +} 1.60 + 1.61 +/** 1.62 + * Constructs a string representing an update element for a remote update xml 1.63 + * file. See getUpdateString for parameter information not provided below. 1.64 + * 1.65 + * @param aPatches 1.66 + * String representing the application update patches. 1.67 + * @return The string representing an update element for an update xml file. 1.68 + */ 1.69 +function getRemoteUpdateString(aPatches, aType, aName, aDisplayVersion, 1.70 + aAppVersion, aPlatformVersion, aBuildID, 1.71 + aDetailsURL, aBillboardURL, aLicenseURL, 1.72 + aShowPrompt, aShowNeverForVersion, aPromptWaitTime, 1.73 + aShowSurvey, aVersion, aExtensionVersion, aCustom1, 1.74 + aCustom2) { 1.75 + return getUpdateString(aType, aName, aDisplayVersion, aAppVersion, 1.76 + aPlatformVersion, aBuildID, aDetailsURL, 1.77 + aBillboardURL, aLicenseURL, aShowPrompt, 1.78 + aShowNeverForVersion, aPromptWaitTime, aShowSurvey, 1.79 + aVersion, aExtensionVersion, aCustom1, aCustom2) + ">\n" + 1.80 + aPatches + 1.81 + " </update>\n"; 1.82 +} 1.83 + 1.84 +/** 1.85 + * Constructs a string representing a patch element for a remote update xml 1.86 + * file. See getPatchString for parameter information not provided below. 1.87 + * 1.88 + * @return The string representing a patch element for a remote update xml file. 1.89 + */ 1.90 +function getRemotePatchString(aType, aURL, aHashFunction, aHashValue, aSize) { 1.91 + return getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) + 1.92 + "/>\n"; 1.93 +} 1.94 + 1.95 +/** 1.96 + * Constructs a string representing a local update xml file. 1.97 + * 1.98 + * @param aUpdates 1.99 + * The string representing the update elements. 1.100 + * @return The string representing a local update xml file. 1.101 + */ 1.102 +function getLocalUpdatesXMLString(aUpdates) { 1.103 + if (!aUpdates || aUpdates == "") 1.104 + return "<updates xmlns=\"http://www.mozilla.org/2005/app-update\"/>" 1.105 + return ("<updates xmlns=\"http://www.mozilla.org/2005/app-update\">" + 1.106 + aUpdates + 1.107 + "</updates>").replace(/>\s+\n*</g,'><'); 1.108 +} 1.109 + 1.110 +/** 1.111 + * Constructs a string representing an update element for a local update xml 1.112 + * file. See getUpdateString for parameter information not provided below. 1.113 + * 1.114 + * @param aPatches 1.115 + * String representing the application update patches. 1.116 + * @param aServiceURL (optional) 1.117 + * The update's xml url. 1.118 + * If not specified it will default to 'http://test_service/'. 1.119 + * @param aIsCompleteUpdate (optional) 1.120 + * The string 'true' if this update was a complete update or the string 1.121 + * 'false' if this update was a partial update. 1.122 + * If not specified it will default to 'true'. 1.123 + * @param aChannel (optional) 1.124 + * The update channel name. 1.125 + * If not specified it will default to the default preference value of 1.126 + * app.update.channel. 1.127 + * @param aForegroundDownload (optional) 1.128 + * The string 'true' if this update was manually downloaded or the 1.129 + * string 'false' if this update was automatically downloaded. 1.130 + * If not specified it will default to 'true'. 1.131 + * @param aPreviousAppVersion (optional) 1.132 + * The application version prior to applying the update. 1.133 + * If not specified it will not be present. 1.134 + * @return The string representing an update element for an update xml file. 1.135 + */ 1.136 +function getLocalUpdateString(aPatches, aType, aName, aDisplayVersion, 1.137 + aAppVersion, aPlatformVersion, aBuildID, 1.138 + aDetailsURL, aBillboardURL, aLicenseURL, 1.139 + aServiceURL, aInstallDate, aStatusText, 1.140 + aIsCompleteUpdate, aChannel, aForegroundDownload, 1.141 + aShowPrompt, aShowNeverForVersion, aPromptWaitTime, 1.142 + aShowSurvey, aVersion, aExtensionVersion, 1.143 + aPreviousAppVersion, aCustom1, aCustom2) { 1.144 + let serviceURL = aServiceURL ? aServiceURL : "http://test_service/"; 1.145 + let installDate = aInstallDate ? aInstallDate : "1238441400314"; 1.146 + let statusText = aStatusText ? aStatusText : "Install Pending"; 1.147 + let isCompleteUpdate = 1.148 + typeof(aIsCompleteUpdate) == "string" ? aIsCompleteUpdate : "true"; 1.149 + let channel = aChannel ? aChannel 1.150 + : gDefaultPrefBranch.getCharPref(PREF_APP_UPDATE_CHANNEL); 1.151 + let foregroundDownload = 1.152 + typeof(aForegroundDownload) == "string" ? aForegroundDownload : "true"; 1.153 + let previousAppVersion = aPreviousAppVersion ? "previousAppVersion=\"" + 1.154 + aPreviousAppVersion + "\" " 1.155 + : ""; 1.156 + return getUpdateString(aType, aName, aDisplayVersion, aAppVersion, 1.157 + aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL, 1.158 + aLicenseURL, aShowPrompt, aShowNeverForVersion, 1.159 + aPromptWaitTime, aShowSurvey, aVersion, aExtensionVersion, 1.160 + aCustom1, aCustom2) + 1.161 + " " + 1.162 + previousAppVersion + 1.163 + "serviceURL=\"" + serviceURL + "\" " + 1.164 + "installDate=\"" + installDate + "\" " + 1.165 + "statusText=\"" + statusText + "\" " + 1.166 + "isCompleteUpdate=\"" + isCompleteUpdate + "\" " + 1.167 + "channel=\"" + channel + "\" " + 1.168 + "foregroundDownload=\"" + foregroundDownload + "\">" + 1.169 + aPatches + 1.170 + " </update>"; 1.171 +} 1.172 + 1.173 +/** 1.174 + * Constructs a string representing a patch element for a local update xml file. 1.175 + * See getPatchString for parameter information not provided below. 1.176 + * 1.177 + * @param aSelected (optional) 1.178 + * Whether this patch is selected represented or not. The string 'true' 1.179 + * denotes selected and the string 'false' denotes not selected. 1.180 + * If not specified it will default to the string 'true'. 1.181 + * @param aState (optional) 1.182 + * The patch's state. 1.183 + * If not specified it will default to STATE_SUCCEEDED. 1.184 + * @return The string representing a patch element for a local update xml file. 1.185 + */ 1.186 +function getLocalPatchString(aType, aURL, aHashFunction, aHashValue, aSize, 1.187 + aSelected, aState) { 1.188 + let selected = typeof(aSelected) == "string" ? aSelected : "true"; 1.189 + let state = aState ? aState : STATE_SUCCEEDED; 1.190 + return getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) + " " + 1.191 + "selected=\"" + selected + "\" " + 1.192 + "state=\"" + state + "\"/>\n"; 1.193 +} 1.194 + 1.195 +/** 1.196 + * Constructs a string representing an update element for a remote update xml 1.197 + * file. 1.198 + * 1.199 + * @param aType (optional) 1.200 + * The update's type which should be major or minor. If not specified it 1.201 + * will default to 'major'. 1.202 + * @param aName (optional) 1.203 + * The update's name. 1.204 + * If not specified it will default to 'App Update Test'. 1.205 + * @param aDisplayVersion (optional) 1.206 + * The update's display version. 1.207 + * If not specified it will default to 'version #' where # is the value 1.208 + * of DEFAULT_UPDATE_VERSION. 1.209 + * @param aAppVersion (optional) 1.210 + * The update's application version. 1.211 + * If not specified it will default to the value of 1.212 + * DEFAULT_UPDATE_VERSION. 1.213 + * @param aPlatformVersion (optional) 1.214 + * The update's platform version. 1.215 + * If not specified it will default to the value of 1.216 + * DEFAULT_UPDATE_VERSION. 1.217 + * @param aBuildID (optional) 1.218 + * The update's build id. 1.219 + * If not specified it will default to '20080811053724'. 1.220 + * @param aDetailsURL (optional) 1.221 + * The update's details url. 1.222 + * If not specified it will default to 'http://test_details/' due to due 1.223 + * to bug 470244. 1.224 + * @param aBillboardURL (optional) 1.225 + * The update's billboard url. 1.226 + * If not specified it will not be present. 1.227 + * @param aLicenseURL (optional) 1.228 + * The update's license url. 1.229 + * If not specified it will not be present. 1.230 + * @param aShowPrompt (optional) 1.231 + * Whether to show the prompt for the update when auto update is 1.232 + * enabled. 1.233 + * If not specified it will not be present and the update service will 1.234 + * default to false. 1.235 + * @param aShowNeverForVersion (optional) 1.236 + * Whether to show the 'No Thanks' button in the update prompt. 1.237 + * If not specified it will not be present and the update service will 1.238 + * default to false. 1.239 + * @param aPromptWaitTime (optional) 1.240 + * Override for the app.update.promptWaitTime preference. 1.241 + * @param aShowSurvey (optional) 1.242 + * Whether to show the 'No Thanks' button in the update prompt. 1.243 + * If not specified it will not be present and the update service will 1.244 + * default to false. 1.245 + * @param aVersion (optional) 1.246 + * The update's application version from 1.9.2. 1.247 + * If not specified it will not be present. 1.248 + * @param aExtensionVersion (optional) 1.249 + * The update's application version from 1.9.2. 1.250 + * If not specified it will not be present. 1.251 + * @param aCustom1 (optional) 1.252 + * A custom attribute name and attribute value to add to the xml. 1.253 + * Example: custom1_attribute="custom1 value" 1.254 + * If not specified it will not be present. 1.255 + * @param aCustom2 (optional) 1.256 + * A custom attribute name and attribute value to add to the xml. 1.257 + * Example: custom2_attribute="custom2 value" 1.258 + * If not specified it will not be present. 1.259 + * @return The string representing an update element for an update xml file. 1.260 + */ 1.261 +function getUpdateString(aType, aName, aDisplayVersion, aAppVersion, 1.262 + aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL, 1.263 + aLicenseURL, aShowPrompt, aShowNeverForVersion, 1.264 + aPromptWaitTime, aShowSurvey, aVersion, aExtensionVersion, 1.265 + aCustom1, aCustom2) { 1.266 + let type = aType ? aType : "major"; 1.267 + let name = aName ? aName : "App Update Test"; 1.268 + let displayVersion = ""; 1.269 + if (aDisplayVersion || !aVersion) { 1.270 + displayVersion = "displayVersion=\"" + 1.271 + (aDisplayVersion ? aDisplayVersion 1.272 + : "version " + DEFAULT_UPDATE_VERSION) + 1.273 + "\" "; 1.274 + } 1.275 + // version has been deprecated in favor of displayVersion but it still needs 1.276 + // to be tested for forward compatibility. 1.277 + let version = aVersion ? "version=\"" + aVersion + "\" " : ""; 1.278 + let appVersion = ""; 1.279 + if (aAppVersion || !aExtensionVersion) { 1.280 + appVersion = "appVersion=\"" + 1.281 + (aAppVersion ? aAppVersion : DEFAULT_UPDATE_VERSION) + 1.282 + "\" "; 1.283 + } 1.284 + // extensionVersion has been deprecated in favor of appVersion but it still 1.285 + // needs to be tested for forward compatibility. 1.286 + let extensionVersion = aExtensionVersion ? "extensionVersion=\"" + 1.287 + aExtensionVersion + "\" " 1.288 + : ""; 1.289 + let platformVersion = ""; 1.290 + if (aPlatformVersion) { 1.291 + platformVersion = "platformVersion=\"" + 1.292 + (aPlatformVersion ? aPlatformVersion 1.293 + : DEFAULT_UPDATE_VERSION) + "\" "; 1.294 + } 1.295 + let buildID = aBuildID ? aBuildID : "20080811053724"; 1.296 + // XXXrstrong - not specifying a detailsURL will cause a leak due to bug 470244 1.297 +// let detailsURL = aDetailsURL ? "detailsURL=\"" + aDetailsURL + "\" " : ""; 1.298 + let detailsURL = "detailsURL=\"" + 1.299 + (aDetailsURL ? aDetailsURL 1.300 + : "http://test_details/") + "\" "; 1.301 + let billboardURL = aBillboardURL ? "billboardURL=\"" + aBillboardURL + "\" " 1.302 + : ""; 1.303 + let licenseURL = aLicenseURL ? "licenseURL=\"" + aLicenseURL + "\" " : ""; 1.304 + let showPrompt = aShowPrompt ? "showPrompt=\"" + aShowPrompt + "\" " : ""; 1.305 + let showNeverForVersion = aShowNeverForVersion ? "showNeverForVersion=\"" + 1.306 + aShowNeverForVersion + "\" " 1.307 + : ""; 1.308 + let promptWaitTime = aPromptWaitTime ? "promptWaitTime=\"" + aPromptWaitTime + 1.309 + "\" " 1.310 + : ""; 1.311 + let custom1 = aCustom1 ? aCustom1 + " " : ""; 1.312 + let custom2 = aCustom2 ? aCustom2 + " " : ""; 1.313 + return " <update type=\"" + type + "\" " + 1.314 + "name=\"" + name + "\" " + 1.315 + displayVersion + 1.316 + version + 1.317 + appVersion + 1.318 + extensionVersion + 1.319 + platformVersion + 1.320 + detailsURL + 1.321 + billboardURL + 1.322 + licenseURL + 1.323 + showPrompt + 1.324 + showNeverForVersion + 1.325 + promptWaitTime + 1.326 + custom1 + 1.327 + custom2 + 1.328 + "buildID=\"" + buildID + "\""; 1.329 +} 1.330 + 1.331 +/** 1.332 + * Constructs a string representing a patch element for an update xml file. 1.333 + * 1.334 + * @param aType (optional) 1.335 + * The patch's type which should be complete or partial. 1.336 + * If not specified it will default to 'complete'. 1.337 + * @param aURL (optional) 1.338 + * The patch's url to the mar file. 1.339 + * If not specified it will default to the value of: 1.340 + * gURLData + FILE_SIMPLE_MAR 1.341 + * @param aHashFunction (optional) 1.342 + * The patch's hash function used to verify the mar file. 1.343 + * If not specified it will default to 'MD5'. 1.344 + * @param aHashValue (optional) 1.345 + * The patch's hash value used to verify the mar file. 1.346 + * If not specified it will default to the value of MD5_HASH_SIMPLE_MAR 1.347 + * which is the MD5 hash value for the file specified by FILE_SIMPLE_MAR. 1.348 + * @param aSize (optional) 1.349 + * The patch's file size for the mar file. 1.350 + * If not specified it will default to the file size for FILE_SIMPLE_MAR 1.351 + * specified by SIZE_SIMPLE_MAR. 1.352 + * @return The string representing a patch element for an update xml file. 1.353 + */ 1.354 +function getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) { 1.355 + let type = aType ? aType : "complete"; 1.356 + let url = aURL ? aURL : gURLData + FILE_SIMPLE_MAR; 1.357 + let hashFunction = aHashFunction ? aHashFunction : "MD5"; 1.358 + let hashValue = aHashValue ? aHashValue : MD5_HASH_SIMPLE_MAR; 1.359 + let size = aSize ? aSize : SIZE_SIMPLE_MAR; 1.360 + return " <patch type=\"" + type + "\" " + 1.361 + "URL=\"" + url + "\" " + 1.362 + "hashFunction=\"" + hashFunction + "\" " + 1.363 + "hashValue=\"" + hashValue + "\" " + 1.364 + "size=\"" + size + "\""; 1.365 +}