michael@0: /* Any copyright is dedicated to the Public Domain.
michael@0: * http://creativecommons.org/publicdomain/zero/1.0/
michael@0: */
michael@0:
michael@0: /**
michael@0: * Helper functions for creating xml strings used by application update tests.
michael@0: *
michael@0: * !IMPORTANT - This file contains everything needed (along with dependencies)
michael@0: * by the updates.sjs file used by the mochitest-chrome tests. Since xpcshell
michael@0: * used by the http server is launched with -v 170 this file must not use
michael@0: * features greater than JavaScript 1.7.
michael@0: */
michael@0:
michael@0: const FILE_SIMPLE_MAR = "simple.mar";
michael@0: const SIZE_SIMPLE_MAR = "1031";
michael@0: const MD5_HASH_SIMPLE_MAR = "1f8c038577bb6845d94ccec4999113ee";
michael@0: const SHA1_HASH_SIMPLE_MAR = "5d49a672c87f10f31d7e326349564a11272a028b";
michael@0: const SHA256_HASH_SIMPLE_MAR = "1aabbed5b1dd6e16e139afc5b43d479e254e0c26" +
michael@0: "3c8fb9249c0a1bb93071c5fb";
michael@0: const SHA384_HASH_SIMPLE_MAR = "26615014ea034af32ef5651492d5f493f5a7a1a48522e" +
michael@0: "d24c366442a5ec21d5ef02e23fb58d79729b8ca2f9541" +
michael@0: "99dd53";
michael@0: const SHA512_HASH_SIMPLE_MAR = "922e5ae22081795f6e8d65a3c508715c9a314054179a8" +
michael@0: "bbfe5f50dc23919ad89888291bc0a07586ab17dd0304a" +
michael@0: "b5347473601127571c66f61f5080348e05c36b";
michael@0:
michael@0: const STATE_NONE = "null";
michael@0: const STATE_DOWNLOADING = "downloading";
michael@0: const STATE_PENDING = "pending";
michael@0: const STATE_PENDING_SVC = "pending-service";
michael@0: const STATE_APPLYING = "applying";
michael@0: const STATE_APPLIED = "applied";
michael@0: const STATE_APPLIED_SVC = "applied-service";
michael@0: const STATE_SUCCEEDED = "succeeded";
michael@0: const STATE_DOWNLOAD_FAILED = "download-failed";
michael@0: const STATE_FAILED = "failed";
michael@0:
michael@0: const STATE_FAILED_READ_ERROR = STATE_FAILED + ": 6";
michael@0: const STATE_FAILED_WRITE_ERROR = STATE_FAILED + ": 7";
michael@0: const STATE_FAILED_CHANNEL_MISMATCH_ERROR = STATE_FAILED + ": 22";
michael@0: const STATE_FAILED_VERSION_DOWNGRADE_ERROR = STATE_FAILED + ": 23";
michael@0: const STATE_FAILED_UNEXPECTED_FILE_OPERATION_ERROR = STATE_FAILED + ": 42";
michael@0:
michael@0: /**
michael@0: * Constructs a string representing a remote update xml file.
michael@0: *
michael@0: * @param aUpdates
michael@0: * The string representing the update elements.
michael@0: * @return The string representing a remote update xml file.
michael@0: */
michael@0: function getRemoteUpdatesXMLString(aUpdates) {
michael@0: return "\n" +
michael@0: "\n" +
michael@0: aUpdates +
michael@0: "\n";
michael@0: }
michael@0:
michael@0: /**
michael@0: * Constructs a string representing an update element for a remote update xml
michael@0: * file. See getUpdateString for parameter information not provided below.
michael@0: *
michael@0: * @param aPatches
michael@0: * String representing the application update patches.
michael@0: * @return The string representing an update element for an update xml file.
michael@0: */
michael@0: function getRemoteUpdateString(aPatches, aType, aName, aDisplayVersion,
michael@0: aAppVersion, aPlatformVersion, aBuildID,
michael@0: aDetailsURL, aBillboardURL, aLicenseURL,
michael@0: aShowPrompt, aShowNeverForVersion, aPromptWaitTime,
michael@0: aShowSurvey, aVersion, aExtensionVersion, aCustom1,
michael@0: aCustom2) {
michael@0: return getUpdateString(aType, aName, aDisplayVersion, aAppVersion,
michael@0: aPlatformVersion, aBuildID, aDetailsURL,
michael@0: aBillboardURL, aLicenseURL, aShowPrompt,
michael@0: aShowNeverForVersion, aPromptWaitTime, aShowSurvey,
michael@0: aVersion, aExtensionVersion, aCustom1, aCustom2) + ">\n" +
michael@0: aPatches +
michael@0: " \n";
michael@0: }
michael@0:
michael@0: /**
michael@0: * Constructs a string representing a patch element for a remote update xml
michael@0: * file. See getPatchString for parameter information not provided below.
michael@0: *
michael@0: * @return The string representing a patch element for a remote update xml file.
michael@0: */
michael@0: function getRemotePatchString(aType, aURL, aHashFunction, aHashValue, aSize) {
michael@0: return getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) +
michael@0: "/>\n";
michael@0: }
michael@0:
michael@0: /**
michael@0: * Constructs a string representing a local update xml file.
michael@0: *
michael@0: * @param aUpdates
michael@0: * The string representing the update elements.
michael@0: * @return The string representing a local update xml file.
michael@0: */
michael@0: function getLocalUpdatesXMLString(aUpdates) {
michael@0: if (!aUpdates || aUpdates == "")
michael@0: return ""
michael@0: return ("" +
michael@0: aUpdates +
michael@0: "").replace(/>\s+\n*<');
michael@0: }
michael@0:
michael@0: /**
michael@0: * Constructs a string representing an update element for a local update xml
michael@0: * file. See getUpdateString for parameter information not provided below.
michael@0: *
michael@0: * @param aPatches
michael@0: * String representing the application update patches.
michael@0: * @param aServiceURL (optional)
michael@0: * The update's xml url.
michael@0: * If not specified it will default to 'http://test_service/'.
michael@0: * @param aIsCompleteUpdate (optional)
michael@0: * The string 'true' if this update was a complete update or the string
michael@0: * 'false' if this update was a partial update.
michael@0: * If not specified it will default to 'true'.
michael@0: * @param aChannel (optional)
michael@0: * The update channel name.
michael@0: * If not specified it will default to the default preference value of
michael@0: * app.update.channel.
michael@0: * @param aForegroundDownload (optional)
michael@0: * The string 'true' if this update was manually downloaded or the
michael@0: * string 'false' if this update was automatically downloaded.
michael@0: * If not specified it will default to 'true'.
michael@0: * @param aPreviousAppVersion (optional)
michael@0: * The application version prior to applying the update.
michael@0: * If not specified it will not be present.
michael@0: * @return The string representing an update element for an update xml file.
michael@0: */
michael@0: function getLocalUpdateString(aPatches, aType, aName, aDisplayVersion,
michael@0: aAppVersion, aPlatformVersion, aBuildID,
michael@0: aDetailsURL, aBillboardURL, aLicenseURL,
michael@0: aServiceURL, aInstallDate, aStatusText,
michael@0: aIsCompleteUpdate, aChannel, aForegroundDownload,
michael@0: aShowPrompt, aShowNeverForVersion, aPromptWaitTime,
michael@0: aShowSurvey, aVersion, aExtensionVersion,
michael@0: aPreviousAppVersion, aCustom1, aCustom2) {
michael@0: let serviceURL = aServiceURL ? aServiceURL : "http://test_service/";
michael@0: let installDate = aInstallDate ? aInstallDate : "1238441400314";
michael@0: let statusText = aStatusText ? aStatusText : "Install Pending";
michael@0: let isCompleteUpdate =
michael@0: typeof(aIsCompleteUpdate) == "string" ? aIsCompleteUpdate : "true";
michael@0: let channel = aChannel ? aChannel
michael@0: : gDefaultPrefBranch.getCharPref(PREF_APP_UPDATE_CHANNEL);
michael@0: let foregroundDownload =
michael@0: typeof(aForegroundDownload) == "string" ? aForegroundDownload : "true";
michael@0: let previousAppVersion = aPreviousAppVersion ? "previousAppVersion=\"" +
michael@0: aPreviousAppVersion + "\" "
michael@0: : "";
michael@0: return getUpdateString(aType, aName, aDisplayVersion, aAppVersion,
michael@0: aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL,
michael@0: aLicenseURL, aShowPrompt, aShowNeverForVersion,
michael@0: aPromptWaitTime, aShowSurvey, aVersion, aExtensionVersion,
michael@0: aCustom1, aCustom2) +
michael@0: " " +
michael@0: previousAppVersion +
michael@0: "serviceURL=\"" + serviceURL + "\" " +
michael@0: "installDate=\"" + installDate + "\" " +
michael@0: "statusText=\"" + statusText + "\" " +
michael@0: "isCompleteUpdate=\"" + isCompleteUpdate + "\" " +
michael@0: "channel=\"" + channel + "\" " +
michael@0: "foregroundDownload=\"" + foregroundDownload + "\">" +
michael@0: aPatches +
michael@0: " ";
michael@0: }
michael@0:
michael@0: /**
michael@0: * Constructs a string representing a patch element for a local update xml file.
michael@0: * See getPatchString for parameter information not provided below.
michael@0: *
michael@0: * @param aSelected (optional)
michael@0: * Whether this patch is selected represented or not. The string 'true'
michael@0: * denotes selected and the string 'false' denotes not selected.
michael@0: * If not specified it will default to the string 'true'.
michael@0: * @param aState (optional)
michael@0: * The patch's state.
michael@0: * If not specified it will default to STATE_SUCCEEDED.
michael@0: * @return The string representing a patch element for a local update xml file.
michael@0: */
michael@0: function getLocalPatchString(aType, aURL, aHashFunction, aHashValue, aSize,
michael@0: aSelected, aState) {
michael@0: let selected = typeof(aSelected) == "string" ? aSelected : "true";
michael@0: let state = aState ? aState : STATE_SUCCEEDED;
michael@0: return getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) + " " +
michael@0: "selected=\"" + selected + "\" " +
michael@0: "state=\"" + state + "\"/>\n";
michael@0: }
michael@0:
michael@0: /**
michael@0: * Constructs a string representing an update element for a remote update xml
michael@0: * file.
michael@0: *
michael@0: * @param aType (optional)
michael@0: * The update's type which should be major or minor. If not specified it
michael@0: * will default to 'major'.
michael@0: * @param aName (optional)
michael@0: * The update's name.
michael@0: * If not specified it will default to 'App Update Test'.
michael@0: * @param aDisplayVersion (optional)
michael@0: * The update's display version.
michael@0: * If not specified it will default to 'version #' where # is the value
michael@0: * of DEFAULT_UPDATE_VERSION.
michael@0: * @param aAppVersion (optional)
michael@0: * The update's application version.
michael@0: * If not specified it will default to the value of
michael@0: * DEFAULT_UPDATE_VERSION.
michael@0: * @param aPlatformVersion (optional)
michael@0: * The update's platform version.
michael@0: * If not specified it will default to the value of
michael@0: * DEFAULT_UPDATE_VERSION.
michael@0: * @param aBuildID (optional)
michael@0: * The update's build id.
michael@0: * If not specified it will default to '20080811053724'.
michael@0: * @param aDetailsURL (optional)
michael@0: * The update's details url.
michael@0: * If not specified it will default to 'http://test_details/' due to due
michael@0: * to bug 470244.
michael@0: * @param aBillboardURL (optional)
michael@0: * The update's billboard url.
michael@0: * If not specified it will not be present.
michael@0: * @param aLicenseURL (optional)
michael@0: * The update's license url.
michael@0: * If not specified it will not be present.
michael@0: * @param aShowPrompt (optional)
michael@0: * Whether to show the prompt for the update when auto update is
michael@0: * enabled.
michael@0: * If not specified it will not be present and the update service will
michael@0: * default to false.
michael@0: * @param aShowNeverForVersion (optional)
michael@0: * Whether to show the 'No Thanks' button in the update prompt.
michael@0: * If not specified it will not be present and the update service will
michael@0: * default to false.
michael@0: * @param aPromptWaitTime (optional)
michael@0: * Override for the app.update.promptWaitTime preference.
michael@0: * @param aShowSurvey (optional)
michael@0: * Whether to show the 'No Thanks' button in the update prompt.
michael@0: * If not specified it will not be present and the update service will
michael@0: * default to false.
michael@0: * @param aVersion (optional)
michael@0: * The update's application version from 1.9.2.
michael@0: * If not specified it will not be present.
michael@0: * @param aExtensionVersion (optional)
michael@0: * The update's application version from 1.9.2.
michael@0: * If not specified it will not be present.
michael@0: * @param aCustom1 (optional)
michael@0: * A custom attribute name and attribute value to add to the xml.
michael@0: * Example: custom1_attribute="custom1 value"
michael@0: * If not specified it will not be present.
michael@0: * @param aCustom2 (optional)
michael@0: * A custom attribute name and attribute value to add to the xml.
michael@0: * Example: custom2_attribute="custom2 value"
michael@0: * If not specified it will not be present.
michael@0: * @return The string representing an update element for an update xml file.
michael@0: */
michael@0: function getUpdateString(aType, aName, aDisplayVersion, aAppVersion,
michael@0: aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL,
michael@0: aLicenseURL, aShowPrompt, aShowNeverForVersion,
michael@0: aPromptWaitTime, aShowSurvey, aVersion, aExtensionVersion,
michael@0: aCustom1, aCustom2) {
michael@0: let type = aType ? aType : "major";
michael@0: let name = aName ? aName : "App Update Test";
michael@0: let displayVersion = "";
michael@0: if (aDisplayVersion || !aVersion) {
michael@0: displayVersion = "displayVersion=\"" +
michael@0: (aDisplayVersion ? aDisplayVersion
michael@0: : "version " + DEFAULT_UPDATE_VERSION) +
michael@0: "\" ";
michael@0: }
michael@0: // version has been deprecated in favor of displayVersion but it still needs
michael@0: // to be tested for forward compatibility.
michael@0: let version = aVersion ? "version=\"" + aVersion + "\" " : "";
michael@0: let appVersion = "";
michael@0: if (aAppVersion || !aExtensionVersion) {
michael@0: appVersion = "appVersion=\"" +
michael@0: (aAppVersion ? aAppVersion : DEFAULT_UPDATE_VERSION) +
michael@0: "\" ";
michael@0: }
michael@0: // extensionVersion has been deprecated in favor of appVersion but it still
michael@0: // needs to be tested for forward compatibility.
michael@0: let extensionVersion = aExtensionVersion ? "extensionVersion=\"" +
michael@0: aExtensionVersion + "\" "
michael@0: : "";
michael@0: let platformVersion = "";
michael@0: if (aPlatformVersion) {
michael@0: platformVersion = "platformVersion=\"" +
michael@0: (aPlatformVersion ? aPlatformVersion
michael@0: : DEFAULT_UPDATE_VERSION) + "\" ";
michael@0: }
michael@0: let buildID = aBuildID ? aBuildID : "20080811053724";
michael@0: // XXXrstrong - not specifying a detailsURL will cause a leak due to bug 470244
michael@0: // let detailsURL = aDetailsURL ? "detailsURL=\"" + aDetailsURL + "\" " : "";
michael@0: let detailsURL = "detailsURL=\"" +
michael@0: (aDetailsURL ? aDetailsURL
michael@0: : "http://test_details/") + "\" ";
michael@0: let billboardURL = aBillboardURL ? "billboardURL=\"" + aBillboardURL + "\" "
michael@0: : "";
michael@0: let licenseURL = aLicenseURL ? "licenseURL=\"" + aLicenseURL + "\" " : "";
michael@0: let showPrompt = aShowPrompt ? "showPrompt=\"" + aShowPrompt + "\" " : "";
michael@0: let showNeverForVersion = aShowNeverForVersion ? "showNeverForVersion=\"" +
michael@0: aShowNeverForVersion + "\" "
michael@0: : "";
michael@0: let promptWaitTime = aPromptWaitTime ? "promptWaitTime=\"" + aPromptWaitTime +
michael@0: "\" "
michael@0: : "";
michael@0: let custom1 = aCustom1 ? aCustom1 + " " : "";
michael@0: let custom2 = aCustom2 ? aCustom2 + " " : "";
michael@0: return "