From d96e43a73642409007c43c3cab0cd9747a60ef56 Mon Sep 17 00:00:00 2001 From: Robert Strong Date: Wed, 3 Mar 2010 10:56:47 -0800 Subject: [PATCH] 2. updated xpcshell tests - Bug 530872. r=dolske --- toolkit/mozapps/update/test/shared.js | 694 ++++++++++++++++++ .../update/test/unit/head_update.js.in | 563 +------------- .../update/test/unit/test_0010_general.js | 2 +- .../update/test/unit/test_0020_general.js | 261 ++++--- .../update/test/unit/test_0030_general.js | 9 +- .../update/test/unit/test_0040_general.js | 67 +- .../update/test/unit/test_0050_general.js | 7 +- .../update/test/unit/test_0060_manager.js | 179 ++++- .../update/test/unit/test_0061_manager.js | 17 +- .../update/test/unit/test_0062_manager.js | 21 +- .../update/test/unit/test_0063_manager.js | 30 +- .../update/test/unit/test_0064_manager.js | 19 +- .../test/unit/test_0070_update_dir_cleanup.js | 6 +- .../test/unit/test_0071_update_dir_cleanup.js | 6 +- .../update/test/unit/test_0110_general.js | 4 +- .../update/test/unit/test_0111_general.js | 4 +- .../update/test/unit/test_0112_general.js | 4 +- .../update/test/unit/test_bug497578.js | 20 +- 18 files changed, 1127 insertions(+), 786 deletions(-) create mode 100644 toolkit/mozapps/update/test/shared.js diff --git a/toolkit/mozapps/update/test/shared.js b/toolkit/mozapps/update/test/shared.js new file mode 100644 index 000000000000..9d12f4671fb6 --- /dev/null +++ b/toolkit/mozapps/update/test/shared.js @@ -0,0 +1,694 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * the Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Robert Strong (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +/* Shared code for xpcshell and mochitests-chrome */ + +// const Cc, Ci, and Cr are defined in netwerk/test/httpserver/httpd.js so we +// need to define unique ones. +const AUS_Cc = Components.classes; +const AUS_Ci = Components.interfaces; +const AUS_Cr = Components.results; + +const PREF_APP_UPDATE_CHANNEL = "app.update.channel"; +const PREF_APP_UPDATE_ENABLED = "app.update.enabled"; +const PREF_APP_UPDATE_LOG = "app.update.log"; +const PREF_APP_UPDATE_SHOW_INSTALLED_UI = "app.update.showInstalledUI"; +const PREF_APP_UPDATE_URL_DETAILS = "app.update.url.details"; +const PREF_APP_UPDATE_URL_OVERRIDE = "app.update.url.override"; + +const PREF_APP_UPDATE_NEVER_BRANCH = "app.update.never."; + +const PREF_APP_PARTNER_BRANCH = "app.partner."; +const PREF_DISTRIBUTION_ID = "distribution.id"; +const PREF_DISTRIBUTION_VERSION = "distribution.version"; + +const NS_APP_PROFILE_DIR_STARTUP = "ProfDS"; +const NS_APP_USER_PROFILE_50_DIR = "ProfD"; +const NS_GRE_DIR = "GreD"; +const NS_XPCOM_CURRENT_PROCESS_DIR = "XCurProcD"; +const XRE_UPDATE_ROOT_DIR = "UpdRootD"; + +const STATE_NONE = "null"; +const STATE_DOWNLOADING = "downloading"; +const STATE_PENDING = "pending"; +const STATE_APPLYING = "applying"; +const STATE_SUCCEEDED = "succeeded"; +const STATE_DOWNLOAD_FAILED = "download-failed"; +const STATE_FAILED = "failed"; + +const FILE_BACKUP_LOG = "backup-update.log"; +const FILE_LAST_LOG = "last-update.log"; +const FILE_UPDATES_DB = "updates.xml"; +const FILE_UPDATE_ACTIVE = "active-update.xml"; +const FILE_UPDATE_ARCHIVE = "update.mar"; +const FILE_UPDATE_LOG = "update.log"; +const FILE_UPDATE_STATUS = "update.status"; + +const MODE_RDONLY = 0x01; +const MODE_WRONLY = 0x02; +const MODE_CREATE = 0x08; +const MODE_APPEND = 0x10; +const MODE_TRUNCATE = 0x20; + +const PERMS_FILE = 0644; +const PERMS_DIRECTORY = 0755; + +const URI_UPDATES_PROPERTIES = "chrome://mozapps/locale/update/updates.properties"; +const gUpdateBundle = AUS_Cc["@mozilla.org/intl/stringbundle;1"]. + getService(AUS_Ci.nsIStringBundleService). + createBundle(URI_UPDATES_PROPERTIES); + +var gDirSvc = AUS_Cc["@mozilla.org/file/directory_service;1"]. + getService(AUS_Ci.nsIProperties); + +__defineGetter__("gAUS", function() { + delete this.gAUS; + return this.gAUS = AUS_Cc["@mozilla.org/updates/update-service;1"]. + getService(AUS_Ci.nsIApplicationUpdateService). + QueryInterface(AUS_Ci.nsIObserver); +}); + +__defineGetter__("gUpdateManager", function() { + delete this.gUpdateManager; + return this.gUpdateManager = AUS_Cc["@mozilla.org/updates/update-manager;1"]. + getService(AUS_Ci.nsIUpdateManager); +}); + +__defineGetter__("gUpdateChecker", function() { + delete this.gUpdateChecker; + return this.gUpdateChecker = AUS_Cc["@mozilla.org/updates/update-checker;1"]. + createInstance(AUS_Ci.nsIUpdateChecker); +}); + +__defineGetter__("gUP", function() { + delete this.gUP; + return this.gUP = AUS_Cc["@mozilla.org/updates/update-prompt;1"]. + createInstance(AUS_Ci.nsIUpdatePrompt); +}); + +__defineGetter__("gPref", function() { + delete this.gPref; + return this.gPref = AUS_Cc["@mozilla.org/preferences-service;1"]. + getService(AUS_Ci.nsIPrefBranch2). + QueryInterface(AUS_Ci.nsIPrefService); +}); + + +/* Initializes the update service stub */ +function initUpdateServiceStub() { + AUS_Cc["@mozilla.org/updates/update-service-stub;1"]. + createInstance(AUS_Ci.nsISupports); +} + +/* Reloads the update metadata from disk */ +function reloadUpdateManagerData() { + gUpdateManager.QueryInterface(AUS_Ci.nsIObserver). + observe(null, "um-reload-update-data", ""); +} + +function getDefaultPrefBranch() { + return gPref.QueryInterface(AUS_Ci.nsIPrefService).getDefaultBranch(null); +} + +/** + * Sets the app.update.channel preference. + * @param aChannel + * The update channel. If not specified 'test_channel' will be used. + */ +function setUpdateChannel(aChannel) { + getDefaultPrefBranch().setCharPref(PREF_APP_UPDATE_CHANNEL, + aChannel ? aChannel : "test_channel"); +} + +/** + * Sets the app.update.url.override preference. + * @param aURL + * The update url. If not specified 'URL_HOST + "update.xml"' will be + * used. + */ +function setUpdateURLOverride(aURL) { + gPref.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, + aURL ? aURL : URL_HOST + "update.xml"); +} + +/** + * Constructs a string representing a remote update xml file. + * @param aUpdates + * The string representing the update elements. + * @returns The string representing a remote update xml file. + */ +function getRemoteUpdatesXMLString(aUpdates) { + return "\n" + + "\n" + + aUpdates + + "\n"; +} + +/** + * Constructs a string representing an update element for a remote update xml + * file. + * See getUpdateString + * @returns The string representing an update element for an update xml file. + */ +function getRemoteUpdateString(aPatches, aType, aName, aDisplayVersion, + aAppVersion, aPlatformVersion, aBuildID, + aDetailsURL, aBillboardURL, aLicenseURL, + aShowPrompt, aShowNeverForVersion, aShowSurvey, + aExtra1, aVersion, aExtensionVersion) { + return getUpdateString(aType, aName, aDisplayVersion, aAppVersion, + aPlatformVersion, aBuildID, aDetailsURL, + aBillboardURL, aLicenseURL, aShowPrompt, + aShowNeverForVersion, aShowSurvey, aExtra1, aVersion, + aExtensionVersion) + ">\n" + + aPatches + + " \n"; +} + +/** + * Constructs a string representing a patch element for a remote update xml + * file + * See getPatchString + * @returns The string representing a patch element for a remote update xml + * file. + */ +function getRemotePatchString(aType, aURL, aHashFunction, aHashValue, aSize) { + return getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) + + "/>\n"; +} + +/** + * Constructs a string representing a local update xml file. + * @param aUpdates + * The string representing the update elements. + * @returns The string representing a local update xml file. + */ +function getLocalUpdatesXMLString(aUpdates) { + if (!aUpdates || aUpdates == "") + return "" + return ("" + + aUpdates + + "").replace(/>\s+\n*<'); +} + +/** + * Constructs a string representing an update element for a local update xml + * file. + * See getUpdateString + * @param aServiceURL + * The update's xml url. + * If null will default to 'http://test_service/'. + * @param aIsCompleteUpdate + * The string 'true' if this update was a complete update or the string + * 'false' if this update was a partial update. + * If null will default to 'true'. + * @param aChannel + * The update channel name. + * If null will default to 'test_channel'. + * @param aForegroundDownload + * The string 'true' if this update was manually downloaded or the + * string 'false' if this update was automatically downloaded. + * If null will default to 'true'. + * @param aPreviousAppVersion + * The application version prior to applying the update. + * If null will not be present. + * @returns The string representing an update element for an update xml file. + */ +function getLocalUpdateString(aPatches, aType, aName, aDisplayVersion, + aAppVersion, aPlatformVersion, aBuildID, + aDetailsURL, aBillboardURL, aLicenseURL, + aServiceURL, aInstallDate, aStatusText, + aIsCompleteUpdate, aChannel, aForegroundDownload, + aShowPrompt, aShowNeverForVersion, aShowSurvey, + aExtra1, aVersion, aExtensionVersion, + aPreviousAppVersion) { + var serviceURL = aServiceURL ? aServiceURL : "http://test_service/"; + var installDate = aInstallDate ? aInstallDate : "1238441400314"; + var statusText = aStatusText ? aStatusText : "Install Pending"; + var isCompleteUpdate = typeof(aIsCompleteUpdate) == "string" ? aIsCompleteUpdate : "true"; + var channel = aChannel ? aChannel : "test_channel"; + var foregroundDownload = + typeof(aForegroundDownload) == "string" ? aForegroundDownload : "true"; + var previousAppVersion = aPreviousAppVersion ? "previousAppVersion=\"" + aPreviousAppVersion + "\" " : ""; + return getUpdateString(aType, aName, aDisplayVersion, aAppVersion, + aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL, + aLicenseURL, aShowPrompt, aShowNeverForVersion, + aShowSurvey, aExtra1, aVersion, aExtensionVersion) + + " " + + previousAppVersion + + "serviceURL=\"" + serviceURL + "\" " + + "installDate=\"" + installDate + "\" " + + "statusText=\"" + statusText + "\" " + + "isCompleteUpdate=\"" + isCompleteUpdate + "\" " + + "channel=\"" + channel + "\" " + + "foregroundDownload=\"" + foregroundDownload + "\">" + + aPatches + + " "; +} + +/** + * Constructs a string representing a patch element for a local update xml file. + * See getPatchString + * @param aSelected + * Whether this patch is selected represented or not. The string 'true' + * denotes selected and the string 'false' denotes not selected. + * If null will default to the string 'true'. + * @param aState + * The patch's state. + * If null will default to STATE_SUCCEEDED (e.g. 'succeeded'). + * @returns The string representing a patch element for a local update xml file. + */ +function getLocalPatchString(aType, aURL, aHashFunction, aHashValue, aSize, + aSelected, aState) { + var selected = typeof(aSelected) == "string" ? aSelected : "true"; + var state = aState ? aState : STATE_SUCCEEDED; + return getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) + " " + + "selected=\"" + selected + "\" " + + "state=\"" + state + "\"/>\n"; +} + +/** + * Constructs a string representing an update element for a remote update xml + * file. + * @param aType + * The update's type which should be major or minor. + * If null will default to 'major'. + * @param aName + * The update's name. + * If null will default to 'App Update Test'. + * @param aDisplayVersion + * The update's display version. + * If null will default to 'version 99.0'. + * @param aAppVersion + * The update's application version. + * If null will default to '99.0'. + * @param aPlatformVersion + * The update's platform version. + * If null will default to '99.0'. + * @param aBuildID + * The update's build id. + * If null will default to '20080811053724'. + * @param aDetailsURL + * The update's details url. + * If null will default to 'http://test_details/' due to due to + * bug 470244. + * @param aBillboardURL + * The update's billboard url. + * If null it will not be added. + * @param aLicenseURL + * The update's license url. + * If null will not be added. + * @param aShowPrompt + * Whether to show the prompt for the update when auto update is + * enabled. + * If null will not be added and the backend will default to false. + * @param aShowNeverForVersion + * Whether to show the 'No Thanks' button in the update prompt. + * If null will not be added and the backend will default to false. + * @param aShowSurvey + * Whether to show the 'No Thanks' button in the update prompt. + * If null will not be added and the backend will default to false. + * @param aExtra1 + * A custom string provided by the update xml for use by the + * application. + * If null will not be added. + * @param aVersion + * The update's application version from 1.9.2. + * If null will not be present. + * @param aExtensionVersion + * The update's application version from 1.9.2. + * If null will not be present. + * @returns The string representing an update element for an update xml file. + */ +function getUpdateString(aType, aName, aDisplayVersion, aAppVersion, + aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL, + aLicenseURL, aShowPrompt, aShowNeverForVersion, + aShowSurvey, aExtra1, aVersion, aExtensionVersion) { + var type = aType ? aType : "major"; + var name = aName ? aName : "App Update Test"; + var displayVersion = ""; + if (aDisplayVersion || !aVersion) { + displayVersion = "displayVersion=\"" + + (aDisplayVersion ? aDisplayVersion + : "version 99.0") + "\" "; + } + // version has been deprecated in favor of displayVersion but it still needs + // to be tested for forward compatibility. + var version = aVersion ? "version=\"" + aVersion + "\" " : ""; + var appVersion = ""; + if (aAppVersion || !aExtensionVersion) { + appVersion = "appVersion=\"" + (aAppVersion ? aAppVersion : "99.0") + "\" "; + } + // extensionVersion has been deprecated in favor of appVersion but it still + // needs to be tested for forward compatibility. + var extensionVersion = aExtensionVersion ? "extensionVersion=\"" + aExtensionVersion + "\" " : ""; + var platformVersion = ""; + if (aPlatformVersion) { + platformVersion = "platformVersion=\"" + (aPlatformVersion ? aPlatformVersion : "99.0") + "\" "; + } + var buildID = aBuildID ? aBuildID : "20080811053724"; + // XXXrstrong - not specifying a detailsURL will cause a leak due to bug 470244 +// var detailsURL = aDetailsURL ? "detailsURL=\"" + aDetailsURL + "\" " : ""; + var detailsURL = "detailsURL=\"" + (aDetailsURL ? aDetailsURL : "http://test_details/") + "\" "; + var billboardURL = aBillboardURL ? "billboardURL=\"" + aBillboardURL + "\" " : ""; + var licenseURL = aLicenseURL ? "licenseURL=\"" + aLicenseURL + "\" " : ""; + var showPrompt = aShowPrompt ? "showPrompt=\"" + aShowPrompt + "\" " : ""; + var showNeverForVersion = aShowNeverForVersion ? "showNeverForVersion=\"" + aShowNeverForVersion + "\" " : ""; + var showSurvey = aShowSurvey ? "showSurvey=\"" + aShowSurvey + "\" " : ""; + var extra1 = aExtra1 ? "extra1=\"" + aExtra1 + "\" " : ""; + return " 0) { + var bytes = bis.readByteArray(Math.min(65535, count)); + data.push(String.fromCharCode.apply(null, bytes)); + count -= bytes.length; + if (bytes.length == 0) + do_throw("Nothing read from input stream!"); + } + data.join(''); + fis.close(); + return data.toString(); +} + +/* Returns human readable status text from the updates.properties bundle */ +function getStatusText(aErrCode) { + return getString("check_error-" + aErrCode); +} + +/* Returns a string from the updates.properties bundle */ +function getString(aName) { + try { + return gUpdateBundle.GetStringFromName(aName); + } + catch (e) { + } + return null; +} + +/** + * Removes the updates.xml file, active-update.xml file, and all files and + * sub-directories in the updates directory except for the "0" sub-directory. + * This prevents some tests from failing due to files being left behind when the + * tests are interrupted. + */ +function removeUpdateDirsAndFiles() { + var appDir = getCurrentProcessDir(); + var file = appDir.clone(); + file.append(FILE_UPDATE_ACTIVE); + try { + if (file.exists()) + file.remove(false); + } + catch (e) { + dump("Unable to remove file\npath: " + file.path + + "\nException: " + e + "\n"); + } + + file = appDir.clone(); + file.append(FILE_UPDATES_DB); + try { + if (file.exists()) + file.remove(false); + } + catch (e) { + dump("Unable to remove file\npath: " + file.path + + "\nException: " + e + "\n"); + } + + // This fails sporadically on Mac OS X so wrap it in a try catch + var updatesDir = appDir.clone(); + updatesDir.append("updates"); + try { + cleanUpdatesDir(updatesDir); + } + catch (e) { + dump("Unable to remove files / directories from directory\npath: " + + updatesDir.path + "\nException: " + e + "\n"); + } +} + +/** + * Removes all files and sub-directories in the updates directory except for + * the "0" sub-directory. + * @param dir + * A nsIFile for the directory to be deleted + */ +function cleanUpdatesDir(aDir) { + if (!aDir.exists()) + return; + + var dirEntries = aDir.directoryEntries; + while (dirEntries.hasMoreElements()) { + var entry = dirEntries.getNext().QueryInterface(AUS_Ci.nsIFile); + + if (entry.isDirectory()) { + if (entry.leafName == "0" && entry.parent.leafName == "updates") { + cleanUpdatesDir(entry); + entry.permissions = PERMS_DIRECTORY; + } + else { + try { + entry.remove(true); + return; + } + catch (e) { + } + cleanUpdatesDir(entry); + entry.permissions = PERMS_DIRECTORY; + entry.remove(true); + } + } + else { + entry.permissions = PERMS_FILE; + entry.remove(false); + } + } +} + +/** + * Deletes a directory and its children. First it tries nsIFile::Remove(true). + * If that fails it will fall back to recursing, setting the appropriate + * permissions, and deleting the current entry. + * @param dir + * A nsIFile for the directory to be deleted + */ +function removeDirRecursive(aDir) { + if (!aDir.exists()) + return; + try { + aDir.remove(true); + return; + } + catch (e) { + } + + var dirEntries = aDir.directoryEntries; + while (dirEntries.hasMoreElements()) { + var entry = dirEntries.getNext().QueryInterface(AUS_Ci.nsIFile); + + if (entry.isDirectory()) { + removeDirRecursive(entry); + } + else { + entry.permissions = PERMS_FILE; + entry.remove(false); + } + } + aDir.permissions = PERMS_DIRECTORY; + aDir.remove(true); +} + +/** + * Returns the directory for the currently running process. This is used to + * clean up after the tests and to locate the active-update.xml and updates.xml + * files. + */ +function getCurrentProcessDir() { + return gDirSvc.get(NS_XPCOM_CURRENT_PROCESS_DIR, AUS_Ci.nsIFile); +} + +/** + * Returns the Gecko Runtime Engine directory. This is used to locate the the + * updater binary (Windows and Linux) or updater package (Mac OS X). For + * XULRunner applications this is different than the currently running process + * directory. + */ +function getGREDir() { + return gDirSvc.get(NS_GRE_DIR, AUS_Ci.nsIFile); +} diff --git a/toolkit/mozapps/update/test/unit/head_update.js.in b/toolkit/mozapps/update/test/unit/head_update.js.in index 4e08c9478ae6..b87346d9fa0a 100644 --- a/toolkit/mozapps/update/test/unit/head_update.js.in +++ b/toolkit/mozapps/update/test/unit/head_update.js.in @@ -11,15 +11,15 @@ * for the specific language governing rights and limitations under the * License. * - * The Original Code is the Application Update Service. + * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is - * Robert Strong . - * - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Mozilla Foundation . All Rights Reserved. + * the Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Robert Strong (Original Author) * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -33,61 +33,10 @@ * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * - * ***** END LICENSE BLOCK ***** - */ - -// const Cc, Ci, and Cr are defined in netwerk/test/httpserver/httpd.js so we -// need to define unique ones. -const AUS_Cc = Components.classes; -const AUS_Ci = Components.interfaces; -const AUS_Cr = Components.results; - -const NS_APP_PROFILE_DIR_STARTUP = "ProfDS"; -const NS_APP_USER_PROFILE_50_DIR = "ProfD"; -const NS_GRE_DIR = "GreD"; -const NS_XPCOM_CURRENT_PROCESS_DIR = "XCurProcD"; -const XRE_UPDATE_ROOT_DIR = "UpdRootD"; - -const PREF_APP_UPDATE_URL_OVERRIDE = "app.update.url.override"; -const PREF_APP_UPDATE_SHOW_INSTALLED_UI = "app.update.showInstalledUI"; - -const URI_UPDATES_PROPERTIES = "chrome://mozapps/locale/update/updates.properties"; -const gUpdateBundle = AUS_Cc["@mozilla.org/intl/stringbundle;1"]. - getService(AUS_Ci.nsIStringBundleService). - createBundle(URI_UPDATES_PROPERTIES); - -const STATE_NONE = "null"; -const STATE_DOWNLOADING = "downloading"; -const STATE_PENDING = "pending"; -const STATE_APPLYING = "applying"; -const STATE_SUCCEEDED = "succeeded"; -const STATE_DOWNLOAD_FAILED = "download-failed"; -const STATE_FAILED = "failed"; - -const FILE_UPDATES_DB = "updates.xml"; -const FILE_UPDATE_ACTIVE = "active-update.xml"; -const FILE_UPDATE_LOG = "update.log"; -const FILE_LAST_LOG = "last-update.log"; -const FILE_BACKUP_LOG = "backup-update.log"; - -const MODE_RDONLY = 0x01; -const MODE_WRONLY = 0x02; -const MODE_CREATE = 0x08; -const MODE_APPEND = 0x10; -const MODE_TRUNCATE = 0x20; - -const PERMS_FILE = 0644; -const PERMS_DIRECTORY = 0755; + * ***** END LICENSE BLOCK ***** */ const URL_HOST = "http://localhost:4444/"; -const DIR_DATA = "data"; - -var gDirSvc = AUS_Cc["@mozilla.org/file/directory_service;1"]. - getService(AUS_Ci.nsIProperties); - -var gAUS; -var gUpdateChecker; -var gUpdateManager; +const URL_PATH = "data"; var gTestserver; @@ -103,27 +52,25 @@ var gUpdates; var gStatusCode; var gStatusText; - -function getPrefBranch() { - return AUS_Cc["@mozilla.org/preferences;1"].getService(AUS_Ci.nsIPrefBranch); -} +#include ../shared.js /** * Nulls out the most commonly used global vars used by tests as appropriate. - * This was moved here from the tail file due to check-interactive executing - * the tail file prior to _execute_test(); (bug 384339). It hasn't been moved - * back since it is easier to comment out the call to cleanUp when needed. */ function cleanUp() { - // Always call app update's observe method passing xpcom-shutdown to test that - // the shutdown of app update runs without throwing or leaking. The observer + removeUpdateDirsAndFiles(); + + // Force the update manager to reload the update data to prevent it from + // writing the old data to the files that have just been removed. + reloadUpdateManagerData(); + + // Call app update's observe method passing xpcom-shutdown to test that the + // shutdown of app update runs without throwing or leaking. The observer // method is used directly instead of calling notifyObservers so components // outside of the scope of this test don't assert and thereby cause app update // tests to fail. - if (gAUS) - gAUS.observe(null, "xpcom-shutdown", ""); + gAUS.observe(null, "xpcom-shutdown", ""); - removeUpdateDirsAndFiles(); gDirSvc.unregisterProvider(gDirProvider); if (gXHR) { @@ -138,9 +85,6 @@ function cleanUp() { gXHR = null; } - gUpdateManager = null; - gUpdateChecker = null; - gAUS = null; gTestserver = null; } @@ -148,351 +92,22 @@ function cleanUp() { * Sets the most commonly used preferences used by tests */ function setDefaultPrefs() { - var pb = getPrefBranch(); // Don't display UI for a successful installation. Some apps may not set this // pref to false like Firefox does. - pb.setBoolPref(PREF_APP_UPDATE_SHOW_INSTALLED_UI, false); + gPref.setBoolPref(PREF_APP_UPDATE_SHOW_INSTALLED_UI, false); // Enable Update logging - pb.setBoolPref("app.update.log", true); + gPref.setBoolPref(PREF_APP_UPDATE_LOG, true); } /** - * Initializes nsIApplicationUpdateService and the most commonly used global - * vars used by tests. + * Initializes the most commonly used settings and creates an instance of the + * update service stub. */ -function startAUS() { +function standardInit() { createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1.0", "2.0"); setDefaultPrefs(); // Initialize the update service stub component - AUS_Cc["@mozilla.org/updates/update-service-stub;1"]. - createInstance(AUS_Ci.nsISupports); - gAUS = AUS_Cc["@mozilla.org/updates/update-service;1"]. - getService(AUS_Ci.nsIApplicationUpdateService). - QueryInterface(AUS_Ci.nsIObserver); -} - -/* Initializes nsIUpdateChecker */ -function startUpdateChecker() { - gUpdateChecker = AUS_Cc["@mozilla.org/updates/update-checker;1"]. - createInstance(AUS_Ci.nsIUpdateChecker); -} - -/* Initializes nsIUpdateManager */ -function startUpdateManager() { - gUpdateManager = AUS_Cc["@mozilla.org/updates/update-manager;1"]. - getService(AUS_Ci.nsIUpdateManager); -} - -/** - * Constructs a string representing a remote update xml file. - * @param aUpdates - * The string representing the update elements. - * @returns The string representing a remote update xml file. - */ -function getRemoteUpdatesXMLString(aUpdates) { - return "\n" + - "\n" + - aUpdates + - "\n"; -} - -/** - * Constructs a string representing an update element for a remote update xml - * file. - * See getUpdateString - * @returns The string representing an update element for an update xml file. - */ -function getRemoteUpdateString(aPatches, aName, aType, aVersion, - aPlatformVersion, aExtensionVersion, aBuildID, - aLicenseURL, aDetailsURL) { - return getUpdateString(aName, aType, aVersion, aPlatformVersion, - aExtensionVersion, aBuildID, aLicenseURL, - aDetailsURL) + ">\n" + - aPatches + - " \n"; -} - -/** - * Constructs a string representing a patch element for a remote update xml - * file - * See getPatchString - * @returns The string representing a patch element for a remote update xml - * file. - */ -function getRemotePatchString(aType, aURL, aHashFunction, aHashValue, aSize) { - return getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) + - "/>\n"; -} - -/** - * Constructs a string representing a local update xml file. - * @param aUpdates - * The string representing the update elements. - * @returns The string representing a local update xml file. - */ -function getLocalUpdatesXMLString(aUpdates) { - if (!aUpdates || aUpdates == "") - return "" - return ("" + - aUpdates + - "").replace(/>\s+\n*<'); -} - -/** - * Constructs a string representing an update element for a local update xml - * file. - * See getUpdateString - * @param aServiceURL - * The update's xml url. - * If null this will default to 'http://dummyservice/'. - * @param aIsCompleteUpdate - * The string 'true' if this update was a complete update or the string - * 'false' if this update was a partial update. - * If null this will default to 'true'. - * @param aChannel - * The update channel name. - * If null this will default to 'bogus_channel'. - * @param aForegroundDownload - * The string 'true' if this update was manually downloaded or the - * string 'false' if this update was automatically downloaded. - * If null this will default to 'true'. - * @returns The string representing an update element for an update xml file. - */ -function getLocalUpdateString(aPatches, aName, aType, aVersion, aPlatformVersion, - aExtensionVersion, aBuildID, aLicenseURL, - aDetailsURL, aServiceURL, aInstallDate, aStatusText, - aIsCompleteUpdate, aChannel, aForegroundDownload) { - var serviceURL = aServiceURL ? aServiceURL : "http://dummyservice/"; - var installDate = aInstallDate ? aInstallDate : "1238441400314"; - var statusText = aStatusText ? aStatusText : "Install Pending"; - var isCompleteUpdate = - typeof(aIsCompleteUpdate) == "string" ? aIsCompleteUpdate : "true"; - var channel = aChannel ? aChannel : "bogus_channel"; - var foregroundDownload = - typeof(aForegroundDownload) == "string" ? aForegroundDownload : "true"; - return getUpdateString(aName, aType, aVersion, aPlatformVersion, - aExtensionVersion, aBuildID, aLicenseURL, - aDetailsURL) + " " + - "serviceURL=\"" + serviceURL + "\" " + - "installDate=\"" + installDate + "\" " + - "statusText=\"" + statusText + "\" " + - "isCompleteUpdate=\"" + isCompleteUpdate + "\" " + - "channel=\"" + channel + "\" " + - "foregroundDownload=\"" + foregroundDownload + "\">" + - aPatches + - " "; -} - -/** - * Constructs a string representing a patch element for a local update xml file. - * See getPatchString - * @param aSelected - * Whether this patch is selected represented or not. The string 'true' - * denotes selected and the string 'false' denotes not selected. - * If null this will default to the string 'true'. - * @param aState - * The patch's state. - * If null this will default to STATE_SUCCEEDED (e.g. 'succeeded'). - * @returns The string representing a patch element for a local update xml file. - */ -function getLocalPatchString(aType, aURL, aHashFunction, aHashValue, aSize, - aSelected, aState) { - var selected = typeof(aSelected) == "string" ? aSelected : "true"; - var state = aState ? aState : STATE_SUCCEEDED; - return getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) + " " + - "selected=\"" + selected + "\" " + - "state=\"" + state + "\"/>\n"; -} - -/** - * Constructs a string representing an update element for a remote update xml - * file. - * @param aPatches - * The string representing the update's patches. - * @param aName - * The update's name. - * If null this will default to 'XPCShell App Update Test'. - * @param aType - * The update's type which should be major or minor. - * If null this will default to 'major'. - * @param aVersion - * The update's app version. - * If null this will default to '4.0'. - * @param aPlatformVersion - * The update's platform version. - * If null this will default to '4.0'. - * @param aExtensionVersion - * The update's extension version. - * If null this will default to '4.0'. - * @param aBuildID - * The update's build id. - * If null this will default to '20080811053724'. - * @param aLicenseURL - * The update's license url. - * If null this will default to 'http://dummylicense/'. - * @param aDetailsURL - * The update's details url. - * If null this will default to 'http://dummydetails/'. - * @returns The string representing an update element for an update xml file. - */ -function getUpdateString(aName, aType, aVersion, aPlatformVersion, - aExtensionVersion, aBuildID, aLicenseURL, aDetailsURL) { - var name = aName ? aName : "XPCShell App Update Test"; - var type = aType ? aType : "major"; - var version = aVersion ? aVersion : "4.0"; - var platformVersion = aPlatformVersion ? aPlatformVersion : "4.0"; - var extensionVersion = aExtensionVersion ? aExtensionVersion : "4.0"; - var buildID = aBuildID ? aBuildID : "20080811053724"; - var licenseURL = aLicenseURL ? aLicenseURL : "http://dummylicense/"; - var detailsURL = aDetailsURL ? aDetailsURL : "http://dummydetails/"; - return " 0) { - var bytes = bis.readByteArray(Math.min(65535, count)); - data.push(String.fromCharCode.apply(null, bytes)); - count -= bytes.length; - if (bytes.length == 0) - do_throw("Nothing read from input stream!"); - } - data.join(''); - fis.close(); - return data.toString(); + initUpdateServiceStub(); } /* Custom path handler for the http server */ @@ -502,21 +117,6 @@ function pathHandler(metadata, response) { response.bodyOutputStream.write(gResponseBody, gResponseBody.length); } -/* Returns human readable status text from the updates.properties bundle */ -function getStatusText(aErrCode) { - return getString("check_error-" + aErrCode); -} - -/* Returns a string from the updates.properties bundle */ -function getString(aName) { - try { - return gUpdateBundle.GetStringFromName(aName); - } - catch (e) { - } - return null; -} - /** * Launches the updater binary to apply a mar file using the current working * directory for the location to apply the mar. @@ -678,104 +278,6 @@ const updateCheckListener = { } }; -/** - * Removes the updates directory, updates.xml file, and active-update.xml file - * if they exist. This prevents some tests from failing due to files being left - * behind when the tests are interrupted. - */ -function removeUpdateDirsAndFiles() { - var appDir = getCurrentProcessDir(); - var file = appDir.clone(); - file.append("active-update.xml"); - try { - if (file.exists()) - file.remove(false); - } - catch (e) { - dump("Unable to remove file\npath: " + file.path + - "\nException: " + e + "\n"); - } - - file = appDir.clone(); - file.append("updates.xml"); - try { - if (file.exists()) - file.remove(false); - } - catch (e) { - dump("Unable to remove file\npath: " + file.path + - "\nException: " + e + "\n"); - } - - file = appDir.clone(); - file.append("updates"); - file.append(FILE_LAST_LOG); - try { - if (file.exists()) - file.remove(false); - } - catch (e) { - dump("Unable to remove file\npath: " + file.path + - "\nException: " + e + "\n"); - } - - file = appDir.clone(); - file.append("updates"); - file.append(FILE_BACKUP_LOG); - try { - if (file.exists()) - file.remove(false); - } - catch (e) { - dump("Unable to remove file\npath: " + file.path + - "\nException: " + e + "\n"); - } - - // This fails sporadically on Mac OS X so wrap it in a try catch - var updatesDir = appDir.clone(); - updatesDir.append("updates"); - try { - removeDirRecursive(updatesDir); - } - catch (e) { - dump("Unable to remove directory\npath: " + updatesDir.path + - "\nException: " + e + "\n"); - } -} - -/** - * Deletes a directory and its children. First it tries nsIFile::Remove(true). - * If that fails it will fall back to recursing, setting the appropriate - * permissions, and deleting the current entry. - * @param dir - * A nsIFile for the directory to be deleted - */ -function removeDirRecursive(aDir) { - if (!aDir.exists()) - return; - try { - aDir.remove(true); - return; - } - catch (e) { - } - - var dirEntries = aDir.directoryEntries; - while (dirEntries.hasMoreElements()) { - var entry = dirEntries.getNext().QueryInterface(AUS_Ci.nsIFile); - - if (entry.isDirectory()) { - removeDirRecursive(entry); - } - else { - entry.permissions = PERMS_FILE; - entry.remove(false); - } - } - aDir.permissions = PERMS_DIRECTORY; - aDir.remove(true); -} - /** * Helper for starting the http server used by the tests * @param aRelativeDirName @@ -853,25 +355,6 @@ function createAppInfo(id, name, version, platformVersion) { XULAPPINFO_CONTRACTID, XULAppInfoFactory); } -/** - * Returns the Gecko Runtime Engine directory. This is used to locate the the - * updater binary (Windows and Linux) or updater package (Mac OS X). For - * XULRunner applications this is different than the currently running process - * directory. - */ -function getGREDir() { - return gDirSvc.get(NS_GRE_DIR, AUS_Ci.nsIFile); -} - -/** - * Returns the directory for the currently running process. This is used to - * clean up after the tests and to locate the active-update.xml and updates.xml - * files. - */ -function getCurrentProcessDir() { - return gDirSvc.get(NS_XPCOM_CURRENT_PROCESS_DIR, AUS_Ci.nsIFile); -} - // On Vista XRE_UPDATE_ROOT_DIR can be a directory other than the one in the // application directory. This will reroute it back to the one in the // application directory. diff --git a/toolkit/mozapps/update/test/unit/test_0010_general.js b/toolkit/mozapps/update/test/unit/test_0010_general.js index be82adba7ecc..d5d1d4f29528 100644 --- a/toolkit/mozapps/update/test/unit/test_0010_general.js +++ b/toolkit/mozapps/update/test/unit/test_0010_general.js @@ -49,7 +49,7 @@ function run_test() { testFile.remove(false); do_check_false(testFile.exists()); - startAUS(); + standardInit(); // Check if available updates can be checked for dump("Testing: nsIApplicationUpdateService:canCheckForUpdates\n"); diff --git a/toolkit/mozapps/update/test/unit/test_0020_general.js b/toolkit/mozapps/update/test/unit/test_0020_general.js index cc8fee30a56e..3258e00dfea8 100644 --- a/toolkit/mozapps/update/test/unit/test_0020_general.js +++ b/toolkit/mozapps/update/test/unit/test_0020_general.js @@ -44,15 +44,12 @@ var gExpectedCount; function run_test() { do_test_pending(); removeUpdateDirsAndFiles(); - var pb = getPrefBranch(); - pb.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, URL_HOST + "update.xml"); - var defaults = pb.QueryInterface(AUS_Ci.nsIPrefService).getDefaultBranch(null); - defaults.setCharPref("app.update.channel", "bogus_channel"); + setUpdateURLOverride(); + setUpdateChannel(); // The mock XMLHttpRequest is MUCH faster overrideXHR(callHandleEvent); - startAUS(); - startUpdateChecker(); - do_timeout(0, run_test_pt1); + standardInit(); + do_timeout(0, run_test_pt01); } function end_test() { @@ -94,49 +91,73 @@ function callHandleEvent() { } // update xml not found -function run_test_pt1() { - run_test_helper_pt1("run_test_pt1 - update xml not available", - null, run_test_pt2); +function run_test_pt01() { + run_test_helper_pt1("run_test_pt01 - update xml not available", + null, run_test_pt02); } // one update available and the update's property values -function run_test_pt2() { - dump("Testing: run_test_pt2 - one update available and the update's " + +function run_test_pt02() { + dump("Testing: run_test_pt02 - one update available and the update's " + "property values\n"); gUpdates = null; gUpdateCount = null; - gCheckFunc = check_test_pt2; + gCheckFunc = check_test_pt02; var patches = getRemotePatchString("complete", "http://complete/", "SHA1", "98db9dad8e1d80eda7e1170d0187d6f53e477059", "9856459"); patches += getRemotePatchString("partial", "http://partial/", "SHA1", "e6678ca40ae7582316acdeddf3c133c9c8577de4", "1316138"); - var updates = getRemoteUpdateString(patches, "XPCShell App Update Test", - "minor", "1.1a1pre", "2.1a1pre", + var updates = getRemoteUpdateString(patches, "minor", "Minor Test", + "version 2.1a1pre", "2.1a1pre", "3.1a1pre", "20080811053724", - "http://dummylicense/index.html", - "http://dummydetails/index.html"); + "http://details/", + "http://billboard/", + "http://license/", "true", + "true", "true", "test extra1", + "4.1a1pre", "5.1a1pre"); gResponseBody = getRemoteUpdatesXMLString(updates); gUpdateChecker.checkForUpdates(updateCheckListener, true); } -function check_test_pt2() { +function check_test_pt02() { + // XXXrstrong - not specifying a detailsURL will cause a leak due to bug 470244 + // and until this is fixed this will not test the value for detailsURL when it + // isn't specified in the update xml. +// var defaultDetailsURL; +// try { + // Try using a default details URL supplied by the distribution + // if the update XML does not supply one. +// var formatter = AUS_Cc["@mozilla.org/toolkit/URLFormatterService;1"]. +// getService(AUS_Ci.nsIURLFormatter); +// defaultDetailsURL = formatter.formatURLPref(PREF_APP_UPDATE_URL_DETAILS); +// } +// catch (e) { +// defaultDetailsURL = ""; +// } + do_check_eq(gUpdateCount, 1); var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount); do_check_eq(bestUpdate.type, "minor"); - do_check_eq(bestUpdate.name, "XPCShell App Update Test"); - do_check_eq(bestUpdate.version, "1.1a1pre"); - do_check_eq(bestUpdate.platformVersion, "2.1a1pre"); - do_check_eq(bestUpdate.extensionVersion, "3.1a1pre"); + do_check_eq(bestUpdate.name, "Minor Test"); + do_check_eq(bestUpdate.displayVersion, "version 2.1a1pre"); + do_check_eq(bestUpdate.appVersion, "2.1a1pre"); + do_check_eq(bestUpdate.platformVersion, "3.1a1pre"); do_check_eq(bestUpdate.buildID, "20080811053724"); - do_check_eq(bestUpdate.licenseURL, "http://dummylicense/index.html"); - do_check_eq(bestUpdate.detailsURL, "http://dummydetails/index.html"); + do_check_eq(bestUpdate.detailsURL, "http://details/"); + do_check_eq(bestUpdate.billboardURL, "http://billboard/"); + do_check_eq(bestUpdate.licenseURL, "http://license/"); + do_check_true(bestUpdate.showPrompt); + do_check_true(bestUpdate.showNeverForVersion); + do_check_true(bestUpdate.showSurvey); + do_check_eq(bestUpdate.extra1, "test extra1"); do_check_eq(bestUpdate.serviceURL, URL_HOST + "update.xml?force=1"); - do_check_eq(bestUpdate.channel, "bogus_channel"); + do_check_eq(bestUpdate.channel, "test_channel"); do_check_false(bestUpdate.isCompleteUpdate); do_check_false(bestUpdate.isSecurityUpdate); - do_check_eq(bestUpdate.installDate, 0); + // Check the date is approximately equal + do_check_neq(bestUpdate.installDate, 0); do_check_eq(bestUpdate.statusText, null); // nsIUpdate:state returns an empty string when no action has been performed // on an available update @@ -145,26 +166,24 @@ function check_test_pt2() { do_check_eq(bestUpdate.patchCount, 2); //XXX TODO - test nsIUpdate:serialize - var type = "complete"; var patch = bestUpdate.getPatchAt(0); - do_check_eq(patch.type, type); - do_check_eq(patch.URL, "http://" + type + "/"); + do_check_eq(patch.type, "complete"); + do_check_eq(patch.URL, "http://complete/"); do_check_eq(patch.hashFunction, "SHA1"); do_check_eq(patch.hashValue, "98db9dad8e1d80eda7e1170d0187d6f53e477059"); do_check_eq(patch.size, 9856459); // The value for patch.state can be the string 'null' as a valid value. This // is confusing if it returns null which is an invalid value since the test // failure output will show a failure for null == null. To lessen the - // confusion first check that the typeof for patch.value is a string. + // confusion first check that the typeof for patch.state is string. do_check_eq(typeof(patch.state), "string"); do_check_eq(patch.state, STATE_NONE); do_check_false(patch.selected); //XXX TODO - test nsIUpdatePatch:serialize - type = "partial"; patch = bestUpdate.getPatchAt(1); - do_check_eq(patch.type, type); - do_check_eq(patch.URL, "http://" + type + "/"); + do_check_eq(patch.type, "partial"); + do_check_eq(patch.URL, "http://partial/"); do_check_eq(patch.hashFunction, "SHA1"); do_check_eq(patch.hashValue, "e6678ca40ae7582316acdeddf3c133c9c8577de4"); do_check_eq(patch.size, 1316138); @@ -172,124 +191,174 @@ function check_test_pt2() { do_check_false(patch.selected); //XXX TODO - test nsIUpdatePatch:serialize - run_test_pt3(); + run_test_pt03(); +} + +// one update available and the update's property default values +function run_test_pt03() { + dump("Testing: run_test_pt03 - one update available and the update's " + + "property default values\n"); + gUpdates = null; + gUpdateCount = null; + gCheckFunc = check_test_pt03; + var patches = getRemotePatchString("complete", "http://complete/", "SHA1", + "98db9dad8e1d80eda7e1170d0187d6f53e477059", + "9856459"); + var updates = getRemoteUpdateString(patches, "major", "Major Test", + null, null, + "5.1a1pre", "20080811053724", + "http://details/", + null, + null, null, + null, null, null, + "version 4.1a1pre", "4.1a1pre"); + gResponseBody = getRemoteUpdatesXMLString(updates); + gUpdateChecker.checkForUpdates(updateCheckListener, true); +} + +function check_test_pt03() { + do_check_eq(gUpdateCount, 1); + var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount); + do_check_eq(bestUpdate.type, "major"); + do_check_eq(bestUpdate.name, "Major Test"); + do_check_eq(bestUpdate.displayVersion, "version 4.1a1pre"); + do_check_eq(bestUpdate.appVersion, "4.1a1pre"); + do_check_eq(bestUpdate.platformVersion, "5.1a1pre"); + do_check_eq(bestUpdate.buildID, "20080811053724"); + do_check_eq(bestUpdate.detailsURL, "http://details/"); + do_check_eq(bestUpdate.billboardURL, null); + do_check_eq(bestUpdate.licenseURL, null); + do_check_false(bestUpdate.showPrompt); + do_check_false(bestUpdate.showNeverForVersion); + do_check_false(bestUpdate.showSurvey); + do_check_eq(bestUpdate.extra1, null); + do_check_eq(bestUpdate.serviceURL, URL_HOST + "update.xml?force=1"); + do_check_eq(bestUpdate.channel, "test_channel"); + do_check_false(bestUpdate.isCompleteUpdate); + do_check_false(bestUpdate.isSecurityUpdate); + // Check the date is approximately equal + do_check_neq(bestUpdate.installDate, 0); + do_check_eq(bestUpdate.statusText, null); + // nsIUpdate:state returns an empty string when no action has been performed + // on an available update + do_check_eq(bestUpdate.state, ""); + do_check_eq(bestUpdate.errorCode, 0); + do_check_eq(bestUpdate.patchCount, 1); + //XXX TODO - test nsIUpdate:serialize + + var patch = bestUpdate.getPatchAt(0); + do_check_eq(patch.type, "complete"); + do_check_eq(patch.URL, "http://complete/"); + do_check_eq(patch.hashFunction, "SHA1"); + do_check_eq(patch.hashValue, "98db9dad8e1d80eda7e1170d0187d6f53e477059"); + do_check_eq(patch.size, 9856459); + // The value for patch.state can be the string 'null' as a valid value. This + // is confusing if it returns null which is an invalid value since the test + // failure output will show a failure for null == null. To lessen the + // confusion first check that the typeof for patch.state is string. + do_check_eq(typeof(patch.state), "string"); + do_check_eq(patch.state, STATE_NONE); + do_check_false(patch.selected); + //XXX TODO - test nsIUpdatePatch:serialize + + run_test_pt04(); } // Empty update xml -function run_test_pt3() { +function run_test_pt04() { gResponseBody = "\n"; - run_test_helper_pt1("run_test_pt3 - empty update xml", - null, run_test_pt4); + run_test_helper_pt1("run_test_pt04 - empty update xml", + null, run_test_pt05); } // no updates available -function run_test_pt4() { +function run_test_pt05() { gResponseBody = getRemoteUpdatesXMLString(""); - run_test_helper_pt1("run_test_pt4 - no updates available", - 0, run_test_pt5); + run_test_helper_pt1("run_test_pt05 - no updates available", + 0, run_test_pt06); } // one update available with two patches -function run_test_pt5() { +function run_test_pt06() { var patches = getRemotePatchString("complete"); patches += getRemotePatchString("partial"); var updates = getRemoteUpdateString(patches); gResponseBody = getRemoteUpdatesXMLString(updates); - run_test_helper_pt1("run_test_pt5 - one update available", - 1, run_test_pt6); + run_test_helper_pt1("run_test_pt06 - one update available", + 1, run_test_pt07); } // three updates available each with two patches -function run_test_pt6() { +function run_test_pt07() { var patches = getRemotePatchString("complete"); patches += getRemotePatchString("partial"); var updates = getRemoteUpdateString(patches); updates += getRemoteUpdateString(patches); updates += getRemoteUpdateString(patches); gResponseBody = getRemoteUpdatesXMLString(updates); - run_test_helper_pt1("run_test_pt6 - three updates available", - 3, run_test_pt7); + run_test_helper_pt1("run_test_pt07 - three updates available", + 3, run_test_pt08); } // one update with complete and partial patches with size 0 specified in the // update xml -function run_test_pt7() { +function run_test_pt08() { var patches = getRemotePatchString("complete", null, null, null, "0"); patches += getRemotePatchString("partial", null, null, null, "0"); var updates = getRemoteUpdateString(patches); gResponseBody = getRemoteUpdatesXMLString(updates); - run_test_helper_pt1("run_test_pt7 - one update with complete and partial " + - "patches with size 0", 0, run_test_pt8); + run_test_helper_pt1("run_test_pt08 - one update with complete and partial " + + "patches with size 0", 0, run_test_pt09); } // one update with complete patch with size 0 specified in the update xml -function run_test_pt8() { +function run_test_pt09() { var patches = getRemotePatchString("complete", null, null, null, "0"); var updates = getRemoteUpdateString(patches); gResponseBody = getRemoteUpdatesXMLString(updates); run_test_helper_pt1("one update with complete patch with size 0", - 0, run_test_pt9); + 0, run_test_pt10); } // one update with partial patch with size 0 specified in the update xml -function run_test_pt9() { +function run_test_pt10() { var patches = getRemotePatchString("partial", null, null, null, "0"); var updates = getRemoteUpdateString(patches); gResponseBody = getRemoteUpdatesXMLString(updates); run_test_helper_pt1("one update with partial patch with size 0", - 0, run_test_pt10); + 0, run_test_pt11); } // check that updates for older versions of the application aren't selected -function run_test_pt10() { - var patches = getRemotePatchString("complete", "http://complete/", "SHA1", - "98db9dad8e1d80eda7e1170d0187d6f53e477059", - "9856459"); - patches += getRemotePatchString("partial", "http://partial/", "SHA1", - "e6678ca40ae7582316acdeddf3c133c9c8577de4", - "1316138"); - var updates = getRemoteUpdateString(patches, "XPCShell App Update Test", - "minor", "version 1.0pre", "2.0", - "1.0pre", "20080811053724", - "http://dummylicense/index.html", - "http://dummydetails/index.html"); - updates += getRemoteUpdateString(patches, "XPCShell App Update Test", - "minor", "version 1.0a", "3.0", - "1.0a", "20080811053724", - "http://dummylicense/index.html", - "http://dummydetails/index.html"); +function run_test_pt11() { + var patches = getRemotePatchString("complete"); + patches += getRemotePatchString("partial"); + var updates = getRemoteUpdateString(patches, "minor", null, null, "1.0pre"); + updates += getRemoteUpdateString(patches, "minor", null, null, "1.0a"); gResponseBody = getRemoteUpdatesXMLString(updates); run_test_helper_pt1("two updates older than the current version", - 2, check_test_pt10); -} - -function check_test_pt10() { - var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount); - do_check_eq(bestUpdate, null); - run_test_pt11(); -} - -// check that updates for the current version of the application are selected -function run_test_pt11() { - var patches = getRemotePatchString("complete", "http://complete/", "SHA1", - "98db9dad8e1d80eda7e1170d0187d6f53e477059", - "9856459"); - patches += getRemotePatchString("partial", "http://partial/", "SHA1", - "e6678ca40ae7582316acdeddf3c133c9c8577de4", - "1316138"); - var updates = getRemoteUpdateString(patches, "XPCShell App Update Test", - "minor", "version 1.0", "3.0", - "1.0", "20080811053724", - "http://dummylicense/index.html", - "http://dummydetails/index.html"); - gResponseBody = getRemoteUpdatesXMLString(updates); - run_test_helper_pt1("one updates equal to the current version", - 1, check_test_pt11); + 2, check_test_pt11); } function check_test_pt11() { + var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount); + do_check_eq(bestUpdate, null); + run_test_pt12(); +} + +// check that updates for the current version of the application are selected +function run_test_pt12() { + var patches = getRemotePatchString("complete"); + patches += getRemotePatchString("partial"); + var updates = getRemoteUpdateString(patches, "minor", null, "version 1.0"); + gResponseBody = getRemoteUpdatesXMLString(updates); + run_test_helper_pt1("one update equal to the current version", + 1, check_test_pt12); +} + +function check_test_pt12() { var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount); do_check_neq(bestUpdate, null); - do_check_eq(bestUpdate.version, "version 1.0"); + do_check_eq(bestUpdate.displayVersion, "version 1.0"); end_test(); } diff --git a/toolkit/mozapps/update/test/unit/test_0030_general.js b/toolkit/mozapps/update/test/unit/test_0030_general.js index ebd2ee309897..aa00b89d74b9 100644 --- a/toolkit/mozapps/update/test/unit/test_0030_general.js +++ b/toolkit/mozapps/update/test/unit/test_0030_general.js @@ -45,13 +45,12 @@ var gExpectedStatusResult; function run_test() { do_test_pending(); removeUpdateDirsAndFiles(); + setUpdateURLOverride(); // The mock XMLHttpRequest is MUCH faster - getPrefBranch().setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, URL_HOST + "update.xml"); overrideXHR(callHandleEvent); - startAUS(); - startUpdateChecker(); + standardInit(); // The HTTP server is only used for the mar file downloads which is slow - start_httpserver(DIR_DATA); + start_httpserver(URL_PATH); do_timeout(0, run_test_pt1); } @@ -197,7 +196,7 @@ function run_test_pt10() { // mar download with the mar not found function run_test_pt11() { - var patches = getRemotePatchString(null, URL_HOST + DIR_DATA + "/bogus.mar"); + var patches = getRemotePatchString(null, URL_HOST + URL_PATH + "/missing.mar"); var updates = getRemoteUpdateString(patches); gResponseBody = getRemoteUpdatesXMLString(updates); run_test_helper_pt1("run_test_pt11 - mar download with the mar not found", diff --git a/toolkit/mozapps/update/test/unit/test_0040_general.js b/toolkit/mozapps/update/test/unit/test_0040_general.js index 7d3f9fa1676b..2dab2ae1f702 100644 --- a/toolkit/mozapps/update/test/unit/test_0040_general.js +++ b/toolkit/mozapps/update/test/unit/test_0040_general.js @@ -38,12 +38,7 @@ /* General URL Construction Tests */ -const URL_PREFIX = URL_HOST + DIR_DATA + "/"; - -const PREF_APP_UPDATE_CHANNEL = "app.update.channel"; -const PREF_PARTNER_BRANCH = "app.partner."; -const PREF_APP_DISTRIBUTION = "distribution.id"; -const PREF_APP_DISTRIBUTION_VERSION = "distribution.version"; +const URL_PREFIX = URL_HOST + URL_PATH + "/"; var gAppInfo; @@ -52,8 +47,7 @@ function run_test() { removeUpdateDirsAndFiles(); // The mock XMLHttpRequest is MUCH faster overrideXHR(callHandleEvent); - startAUS(); - startUpdateChecker(); + standardInit(); gAppInfo = AUS_Cc["@mozilla.org/xre/app-info;1"]. getService(AUS_Ci.nsIXULAppInfo). QueryInterface(AUS_Ci.nsIXULRuntime); @@ -82,7 +76,7 @@ function run_test_pt1() { gCheckFunc = check_test_pt1; var url = URL_PREFIX + "%PRODUCT%/"; dump("Testing: url constructed with %PRODUCT% - " + url + "\n"); - getPrefBranch().setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url); + setUpdateURLOverride(url); gUpdateChecker.checkForUpdates(updateCheckListener, true); } @@ -96,7 +90,7 @@ function run_test_pt2() { gCheckFunc = check_test_pt2; var url = URL_PREFIX + "%VERSION%/"; dump("Testing: url constructed with %VERSION% - " + url + "\n"); - getPrefBranch().setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url); + setUpdateURLOverride(url); gUpdateChecker.checkForUpdates(updateCheckListener, true); } @@ -110,7 +104,7 @@ function run_test_pt3() { gCheckFunc = check_test_pt3; var url = URL_PREFIX + "%BUILD_ID%/"; dump("Testing: url constructed with %BUILD_ID% - " + url + "\n"); - getPrefBranch().setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url); + setUpdateURLOverride(url); gUpdateChecker.checkForUpdates(updateCheckListener, true); } @@ -125,7 +119,7 @@ function run_test_pt4() { gCheckFunc = check_test_pt4; var url = URL_PREFIX + "%BUILD_TARGET%/"; dump("Testing: url constructed with %BUILD_TARGET% - " + url + "\n"); - getPrefBranch().setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url); + setUpdateURLOverride(url); gUpdateChecker.checkForUpdates(updateCheckListener, true); } @@ -159,7 +153,7 @@ function run_test_pt5() { gCheckFunc = check_test_pt5; var url = URL_PREFIX + "%LOCALE%/"; dump("Testing: url constructed with %LOCALE% - " + url + "\n"); - getPrefBranch().setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url); + setUpdateURLOverride(url); try { gUpdateChecker.checkForUpdates(updateCheckListener, true); } @@ -180,15 +174,13 @@ function run_test_pt6() { gCheckFunc = check_test_pt6; var url = URL_PREFIX + "%CHANNEL%/"; dump("Testing: url constructed with %CHANNEL% - " + url + "\n"); - var pb = getPrefBranch(); - pb.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url); - var defaults = pb.QueryInterface(AUS_Ci.nsIPrefService).getDefaultBranch(null); - defaults.setCharPref(PREF_APP_UPDATE_CHANNEL, "bogus_channel"); + setUpdateURLOverride(url); + setUpdateChannel(); gUpdateChecker.checkForUpdates(updateCheckListener, true); } function check_test_pt6() { - do_check_eq(getResult(gRequestURL), "bogus_channel"); + do_check_eq(getResult(gRequestURL), "test_channel"); run_test_pt7(); } @@ -197,16 +189,15 @@ function run_test_pt7() { gCheckFunc = check_test_pt7; var url = URL_PREFIX + "%CHANNEL%/"; dump("Testing: url constructed with %CHANNEL% - " + url + "\n"); - var pb = getPrefBranch(); - pb.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url); - var defaults = pb.QueryInterface(AUS_Ci.nsIPrefService).getDefaultBranch(null); - defaults.setCharPref(PREF_PARTNER_BRANCH + "bogus_partner1", "bogus_partner1"); - defaults.setCharPref(PREF_PARTNER_BRANCH + "bogus_partner2", "bogus_partner2"); + setUpdateURLOverride(url); + var defaults = getDefaultPrefBranch(); + defaults.setCharPref(PREF_APP_PARTNER_BRANCH + "test_partner1", "test_partner1"); + defaults.setCharPref(PREF_APP_PARTNER_BRANCH + "test_partner2", "test_partner2"); gUpdateChecker.checkForUpdates(updateCheckListener, true); } function check_test_pt7() { - do_check_eq(getResult(gRequestURL), "bogus_channel-cck-bogus_partner1-bogus_partner2"); + do_check_eq(getResult(gRequestURL), "test_channel-cck-test_partner1-test_partner2"); run_test_pt8(); } @@ -215,7 +206,7 @@ function run_test_pt8() { gCheckFunc = check_test_pt8; var url = URL_PREFIX + "%PLATFORM_VERSION%/"; dump("Testing: url constructed with %PLATFORM_VERSION% - " + url + "\n"); - getPrefBranch().setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url); + setUpdateURLOverride(url); gUpdateChecker.checkForUpdates(updateCheckListener, true); } @@ -229,7 +220,7 @@ function run_test_pt9() { gCheckFunc = check_test_pt9; var url = URL_PREFIX + "%OS_VERSION%/"; dump("Testing: url constructed with %OS_VERSION% - " + url + "\n"); - getPrefBranch().setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url); + setUpdateURLOverride(url); gUpdateChecker.checkForUpdates(updateCheckListener, true); } @@ -259,15 +250,13 @@ function run_test_pt10() { gCheckFunc = check_test_pt10; var url = URL_PREFIX + "%DISTRIBUTION%/"; dump("Testing: url constructed with %DISTRIBUTION% - " + url + "\n"); - var pb = getPrefBranch(); - pb.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url); - var defaults = pb.QueryInterface(AUS_Ci.nsIPrefService).getDefaultBranch(null); - defaults.setCharPref(PREF_APP_DISTRIBUTION, "bogus_distro"); + setUpdateURLOverride(url); + getDefaultPrefBranch().setCharPref(PREF_DISTRIBUTION_ID, "test_distro"); gUpdateChecker.checkForUpdates(updateCheckListener, true); } function check_test_pt10() { - do_check_eq(getResult(gRequestURL), "bogus_distro"); + do_check_eq(getResult(gRequestURL), "test_distro"); run_test_pt11(); } @@ -276,15 +265,13 @@ function run_test_pt11() { gCheckFunc = check_test_pt11; var url = URL_PREFIX + "%DISTRIBUTION_VERSION%/"; dump("Testing: url constructed with %DISTRIBUTION_VERSION% - " + url + "\n"); - var pb = getPrefBranch(); - pb.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url); - var defaults = pb.QueryInterface(AUS_Ci.nsIPrefService).getDefaultBranch(null); - defaults.setCharPref(PREF_APP_DISTRIBUTION_VERSION, "bogus_distro_version"); + setUpdateURLOverride(url); + getDefaultPrefBranch().setCharPref(PREF_DISTRIBUTION_VERSION, "test_distro_version"); gUpdateChecker.checkForUpdates(updateCheckListener, true); } function check_test_pt11() { - do_check_eq(getResult(gRequestURL), "bogus_distro_version"); + do_check_eq(getResult(gRequestURL), "test_distro_version"); run_test_pt12(); } @@ -293,7 +280,7 @@ function run_test_pt12() { gCheckFunc = check_test_pt12; var url = URL_PREFIX; dump("Testing: url constructed that doesn't have a parameter - " + url + "\n"); - getPrefBranch().setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url); + setUpdateURLOverride(url); gUpdateChecker.checkForUpdates(updateCheckListener, true); } @@ -305,13 +292,13 @@ function check_test_pt12() { // url constructed that has a parameter - bug 454357 function run_test_pt13() { gCheckFunc = check_test_pt13; - var url = URL_PREFIX + "?bogus=param"; + var url = URL_PREFIX + "?extra=param"; dump("Testing: url constructed that has a parameter - " + url + "\n"); - getPrefBranch().setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url); + setUpdateURLOverride(url); gUpdateChecker.checkForUpdates(updateCheckListener, true); } function check_test_pt13() { - do_check_eq(getResult(gRequestURL), "?bogus=param&force=1"); + do_check_eq(getResult(gRequestURL), "?extra=param&force=1"); end_test(); } diff --git a/toolkit/mozapps/update/test/unit/test_0050_general.js b/toolkit/mozapps/update/test/unit/test_0050_general.js index 491fa6b4c257..97ac6b006dbd 100644 --- a/toolkit/mozapps/update/test/unit/test_0050_general.js +++ b/toolkit/mozapps/update/test/unit/test_0050_general.js @@ -51,10 +51,9 @@ var gExpectedStatusText; function run_test() { do_test_pending(); removeUpdateDirsAndFiles(); - startAUS(); - startUpdateChecker(); - getPrefBranch().setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, - URL_HOST + "update.xml"); + setUpdateURLOverride(); + standardInit(); + // The mock XMLHttpRequest is MUCH faster overrideXHR(callHandleEvent); do_timeout(0, run_test_pt1); } diff --git a/toolkit/mozapps/update/test/unit/test_0060_manager.js b/toolkit/mozapps/update/test/unit/test_0060_manager.js index 30208c3519b5..5021466cbcbd 100644 --- a/toolkit/mozapps/update/test/unit/test_0060_manager.js +++ b/toolkit/mozapps/update/test/unit/test_0060_manager.js @@ -42,46 +42,161 @@ function run_test() { dump("Testing: addition of a successful update to " + FILE_UPDATES_DB + " and verification of update properties\n"); removeUpdateDirsAndFiles(); - var defaults = getPrefBranch().QueryInterface(AUS_Ci.nsIPrefService). - getDefaultBranch(null); - defaults.setCharPref("app.update.channel", "bogus_channel"); + setUpdateChannel("test_channel"); - var patches = getLocalPatchString(null, null, null, null, null, null, - STATE_FAILED); - var updates = getLocalUpdateString(patches, "Existing", null, "3.0", "3.0", - "3.0", null, null, null, null, null, - getString("patchApplyFailure")); - writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), false); + var patch, patches, update, updates; + // XXXrstrong - not specifying a detailsURL will cause a leak due to bug 470244 + // and until bug 470244 is fixed this will not test the value for detailsURL + // when it isn't specified in the update xml. + patches = getLocalPatchString("partial", "http://partial/", "SHA256", "cd43", + "86", "true", STATE_PENDING); + updates = getLocalUpdateString(patches, "major", "New", "version 4", "4.0", + "4.0", "20070811053724", "http://details1/", + "http://billboard1/", "http://license1/", + "http://service1/", "1238441300314", + "test status text", "false", "test_channel", + "true", "true", "true", "true", "test extra1", + "test version", "3.0", "3.0"); - patches = getLocalPatchString(null, null, null, null, null, null, - STATE_PENDING); - updates = getLocalUpdateString(patches, "New"); writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); writeStatusFile(STATE_SUCCEEDED); - startAUS(); - startUpdateManager(); + patches = getLocalPatchString("complete", "http://complete/", "SHA1", "6232", + "75", "true", STATE_FAILED); + updates = getLocalUpdateString(patches, "major", "Existing", null, null, + "3.0", null, "http://details2/", null, null, + "http://service2/", null, + getString("patchApplyFailure"), "true", + "test_channel", "false", null, null, null, + null, "version 3", "3.0", null); + writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), false); + + standardInit(); do_check_eq(gUpdateManager.activeUpdate, null); do_check_eq(gUpdateManager.updateCount, 2); - var update = gUpdateManager.getUpdateAt(0); + update = gUpdateManager.getUpdateAt(0); do_check_eq(update.state, STATE_SUCCEEDED); - do_check_eq(update.name, "New"); do_check_eq(update.type, "major"); - do_check_eq(update.version, "4.0"); + do_check_eq(update.name, "New"); + do_check_eq(update.displayVersion, "version 4"); + do_check_eq(update.appVersion, "4.0"); do_check_eq(update.platformVersion, "4.0"); - do_check_eq(update.extensionVersion, "4.0"); - do_check_eq(update.detailsURL, "http://dummydetails/"); - do_check_eq(update.licenseURL, "http://dummylicense/"); - do_check_eq(update.serviceURL, "http://dummyservice/"); + do_check_eq(update.buildID, "20070811053724"); + do_check_eq(update.detailsURL, "http://details1/"); + do_check_eq(update.billboardURL, "http://billboard1/"); + do_check_eq(update.licenseURL, "http://license1/"); + do_check_eq(update.serviceURL, "http://service1/"); + do_check_eq(update.installDate, "1238441300314"); + // statusText is updated + do_check_eq(update.statusText, getString("installSuccess")); + do_check_false(update.isCompleteUpdate); + do_check_eq(update.channel, "test_channel"); + do_check_true(update.showPrompt); + do_check_true(update.showNeverForVersion); + do_check_true(update.showSurvey); + do_check_eq(update.extra1, "test extra1"); + do_check_eq(update.previousAppVersion, "3.0"); + + patch = update.selectedPatch; + do_check_eq(patch.type, "partial"); + do_check_eq(patch.URL, "http://partial/"); + do_check_eq(patch.hashFunction, "SHA256"); + do_check_eq(patch.hashValue, "cd43"); + do_check_eq(patch.size, "86"); + do_check_true(patch.selected); + do_check_eq(patch.state, STATE_SUCCEEDED); + + update = gUpdateManager.getUpdateAt(1); + do_check_eq(update.state, STATE_FAILED); + do_check_eq(update.name, "Existing"); + do_check_eq(update.type, "major"); + do_check_eq(update.displayVersion, "version 3"); + do_check_eq(update.appVersion, "3.0"); + do_check_eq(update.platformVersion, "3.0"); + do_check_eq(update.detailsURL, "http://details2/"); + do_check_eq(update.billboardURL, null); + do_check_eq(update.licenseURL, null); + do_check_false(update.showPrompt); + do_check_false(update.showNeverForVersion); + do_check_false(update.showSurvey); + do_check_eq(update.serviceURL, "http://service2/"); + do_check_eq(update.installDate, "1238441400314"); + do_check_eq(update.statusText, getString("patchApplyFailure")); + do_check_eq(update.buildID, "20080811053724"); + do_check_true(update.isCompleteUpdate); + do_check_eq(update.channel, "test_channel"); + do_check_false(update.showPrompt); + do_check_false(update.showNeverForVersion); + do_check_false(update.showSurvey); + do_check_eq(update.extra1, null); + do_check_eq(update.previousAppVersion, null); + + patch = update.selectedPatch; + do_check_eq(patch.type, "complete"); + do_check_eq(patch.URL, "http://complete/"); + do_check_eq(patch.hashFunction, "SHA1"); + do_check_eq(patch.hashValue, "6232"); + do_check_eq(patch.size, "75"); + do_check_true(patch.selected); + do_check_eq(patch.state, STATE_FAILED); + + removeUpdateDirsAndFiles(); + + // XXXrstrong - not specifying a detailsURL will cause a leak due to bug 470244 + // and until this is fixed this will not test the value for detailsURL when it + // isn't specified in the update xml. + patches = getLocalPatchString(null, null, null, null, null, null, + STATE_PENDING); + updates = getLocalUpdateString(patches, "major", "New", null, null, "4.0", + null, "http://details/", "http://billboard/", + "http://license/", "http://service/", + "1238441400314", "test status text", null, + "test_channel", "true", "true", "true", "true", + "test extra1", "version 4.0", "4.0", "3.0"); + + writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); + writeStatusFile(STATE_SUCCEEDED); + + patches = getLocalPatchString(null, null, null, null, null, null, + STATE_FAILED); + updates = getLocalUpdateString(patches, "major", "Existing", "version 3.0", + "3.0", "3.0", null, "http://details/", null, + null, "http://service/", null, + getString("patchApplyFailure"), null, + "test_channel", "false", null, null, null, + null, "version 3", null, null); + writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), false); + + reloadUpdateManagerData(); + initUpdateServiceStub(); + + do_check_eq(gUpdateManager.activeUpdate, null); + do_check_eq(gUpdateManager.updateCount, 2); + + update = gUpdateManager.getUpdateAt(0); + do_check_eq(update.state, STATE_SUCCEEDED); + do_check_eq(update.type, "major"); + do_check_eq(update.name, "New"); + do_check_eq(update.displayVersion, "version 4.0"); + do_check_eq(update.appVersion, "4.0"); + do_check_eq(update.platformVersion, "4.0"); + do_check_eq(update.detailsURL, "http://details/"); + do_check_eq(update.billboardURL, "http://billboard/"); + do_check_eq(update.licenseURL, "http://license/"); + do_check_true(update.showPrompt); + do_check_true(update.showNeverForVersion); + do_check_true(update.showSurvey); + do_check_eq(update.serviceURL, "http://service/"); do_check_eq(update.installDate, "1238441400314"); do_check_eq(update.statusText, getString("installSuccess")); do_check_eq(update.buildID, "20080811053724"); do_check_true(update.isCompleteUpdate); - do_check_eq(update.channel, "bogus_channel"); + do_check_eq(update.channel, "test_channel"); + do_check_eq(update.previousAppVersion, "3.0"); - var patch = update.selectedPatch; + patch = update.selectedPatch; do_check_eq(patch.type, "complete"); do_check_eq(patch.URL, "http://localhost:4444/data/empty.mar"); do_check_eq(patch.hashFunction, "MD5"); @@ -94,17 +209,22 @@ function run_test() { do_check_eq(update.state, STATE_FAILED); do_check_eq(update.name, "Existing"); do_check_eq(update.type, "major"); - do_check_eq(update.version, "3.0"); + do_check_eq(update.displayVersion, "version 3.0"); + do_check_eq(update.appVersion, "3.0"); do_check_eq(update.platformVersion, "3.0"); - do_check_eq(update.extensionVersion, "3.0"); - do_check_eq(update.detailsURL, "http://dummydetails/"); - do_check_eq(update.licenseURL, "http://dummylicense/"); - do_check_eq(update.serviceURL, "http://dummyservice/"); + do_check_eq(update.detailsURL, "http://details/"); + do_check_eq(update.billboardURL, null); + do_check_eq(update.licenseURL, null); + do_check_false(update.showPrompt); + do_check_false(update.showNeverForVersion); + do_check_false(update.showSurvey); + do_check_eq(update.serviceURL, "http://service/"); do_check_eq(update.installDate, "1238441400314"); do_check_eq(update.statusText, getString("patchApplyFailure")); do_check_eq(update.buildID, "20080811053724"); do_check_true(update.isCompleteUpdate); - do_check_eq(update.channel, "bogus_channel"); + do_check_eq(update.channel, "test_channel"); + do_check_eq(update.previousAppVersion, null); patch = update.selectedPatch; do_check_eq(patch.type, "complete"); @@ -114,5 +234,6 @@ function run_test() { do_check_eq(patch.size, "775"); do_check_true(patch.selected); do_check_eq(patch.state, STATE_FAILED); + cleanUp(); } diff --git a/toolkit/mozapps/update/test/unit/test_0061_manager.js b/toolkit/mozapps/update/test/unit/test_0061_manager.js index 88042b55db40..eddbfc374d16 100644 --- a/toolkit/mozapps/update/test/unit/test_0061_manager.js +++ b/toolkit/mozapps/update/test/unit/test_0061_manager.js @@ -42,20 +42,19 @@ function run_test() { dump("Testing: removal of an update download in progress for an older " + "version of the application on startup - bug 485624\n"); removeUpdateDirsAndFiles(); - var defaults = getPrefBranch().QueryInterface(AUS_Ci.nsIPrefService). - getDefaultBranch(null); - defaults.setCharPref("app.update.channel", "bogus_channel"); + setUpdateChannel(); - writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false); + var patches, updates; - var patches = getLocalPatchString(null, null, null, null, null, null, - STATE_DOWNLOADING); - var updates = getLocalUpdateString(patches, null, null, "0.9", null, "0.9"); + patches = getLocalPatchString(null, null, null, null, null, null, + STATE_DOWNLOADING); + updates = getLocalUpdateString(patches, null, null, "version 0.9", "0.9"); writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); writeStatusFile(STATE_DOWNLOADING); - startAUS(); - startUpdateManager(); + writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false); + + standardInit(); do_check_eq(gUpdateManager.activeUpdate, null); do_check_eq(gUpdateManager.updateCount, 0); diff --git a/toolkit/mozapps/update/test/unit/test_0062_manager.js b/toolkit/mozapps/update/test/unit/test_0062_manager.js index 69ac545ac7ed..dbb913d950de 100644 --- a/toolkit/mozapps/update/test/unit/test_0062_manager.js +++ b/toolkit/mozapps/update/test/unit/test_0062_manager.js @@ -42,22 +42,21 @@ function run_test() { dump("Testing: resuming an update download in progress for the same " + "version of the application on startup - bug 485624\n"); removeUpdateDirsAndFiles(); - var defaults = getPrefBranch().QueryInterface(AUS_Ci.nsIPrefService). - getDefaultBranch(null); - defaults.setCharPref("app.update.channel", "bogus_channel"); + setUpdateChannel(); - writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false); + var patches, updates; - var patches = getLocalPatchString(null, null, null, null, null, null, - STATE_DOWNLOADING); - var updates = getLocalUpdateString(patches, null, null, "1.0", null, "1.0", - null, null, null, - URL_HOST + DIR_DATA + "/empty.mar"); + patches = getLocalPatchString(null, null, null, null, null, null, + STATE_DOWNLOADING); + updates = getLocalUpdateString(patches, null, null, "1.0", "1.0", null, + null, null, null, + URL_HOST + URL_PATH + "/empty.mar"); writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); writeStatusFile(STATE_DOWNLOADING); - startAUS(); - startUpdateManager(); + writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false); + + standardInit(); do_check_eq(gUpdateManager.updateCount, 1); do_check_eq(gUpdateManager.activeUpdate.state, STATE_DOWNLOADING); diff --git a/toolkit/mozapps/update/test/unit/test_0063_manager.js b/toolkit/mozapps/update/test/unit/test_0063_manager.js index 5e81aa3e2ce8..c0ca3d99fa2b 100644 --- a/toolkit/mozapps/update/test/unit/test_0063_manager.js +++ b/toolkit/mozapps/update/test/unit/test_0063_manager.js @@ -42,35 +42,35 @@ function run_test() { dump("Testing: removing an active update for a channel that is not valid " + "due to switching channels - bug 486275\n"); removeUpdateDirsAndFiles(); - var defaults = getPrefBranch().QueryInterface(AUS_Ci.nsIPrefService). - getDefaultBranch(null); - defaults.setCharPref("app.update.channel", "original_channel"); + setUpdateChannel("original_channel"); - var patches = getLocalPatchString(null, null, null, null, null, null, - STATE_FAILED); - var updates = getLocalUpdateString(patches, "Existing", null, "3.0", "3.0", - "3.0", null, null, null, null, null, - getString("patchApplyFailure")); - writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), false); + var patches, update, update; patches = getLocalPatchString(null, null, null, null, null, null, STATE_DOWNLOADING); - updates = getLocalUpdateString(patches, null, null, "1.0", null, "1.0", null, - null, null, URL_HOST + DIR_DATA + "/empty.mar"); + updates = getLocalUpdateString(patches, null, null, "version 1.0", "1.0", null, + null, null, null, + URL_HOST + URL_PATH + "/empty.mar"); writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); writeStatusFile(STATE_DOWNLOADING); - startAUS(); - startUpdateManager(); + patches = getLocalPatchString(null, null, null, null, null, null, + STATE_FAILED); + updates = getLocalUpdateString(patches, null, "Existing", "version 3.0", + "3.0", "3.0", null, null, null, null, null, + getString("patchApplyFailure")); + writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), false); + + standardInit(); do_check_eq(gUpdateManager.updateCount, 1); - var update = gUpdateManager.getUpdateAt(0); + update = gUpdateManager.getUpdateAt(0); do_check_eq(update.name, "Existing"); do_check_eq(gUpdateManager.activeUpdate, null); // Verify that the active-update.xml file has had the update from the old // channel removed. - var file = getCurrentProcessDir(); + file = getCurrentProcessDir(); file.append(FILE_UPDATE_ACTIVE); dump("Testing: verifying contents of " + FILE_UPDATE_ACTIVE + "\n"); do_check_eq(readFile(file), getLocalUpdatesXMLString("")); diff --git a/toolkit/mozapps/update/test/unit/test_0064_manager.js b/toolkit/mozapps/update/test/unit/test_0064_manager.js index c2624b8d32e5..a18f39f8e2bb 100644 --- a/toolkit/mozapps/update/test/unit/test_0064_manager.js +++ b/toolkit/mozapps/update/test/unit/test_0064_manager.js @@ -43,21 +43,20 @@ function run_test() { "version of the application with the same application build id on " + "startup - bug 536547\n"); removeUpdateDirsAndFiles(); - var defaults = getPrefBranch().QueryInterface(AUS_Ci.nsIPrefService). - getDefaultBranch(null); - defaults.setCharPref("app.update.channel", "bogus_channel"); + setUpdateChannel(); - writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false); + var patches, updates; - var patches = getLocalPatchString(null, null, null, null, null, null, - STATE_DOWNLOADING); - var updates = getLocalUpdateString(patches, null, null, "1.0", null, "1.0", - "2007010101"); + patches = getLocalPatchString(null, null, null, null, null, null, + STATE_DOWNLOADING); + updates = getLocalUpdateString(patches, null, null, "version 1.0", "1.0", null, + "2007010101"); writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); writeStatusFile(STATE_DOWNLOADING); - startAUS(); - startUpdateManager(); + writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false); + + standardInit(); do_check_eq(gUpdateManager.activeUpdate, null); do_check_eq(gUpdateManager.updateCount, 0); diff --git a/toolkit/mozapps/update/test/unit/test_0070_update_dir_cleanup.js b/toolkit/mozapps/update/test/unit/test_0070_update_dir_cleanup.js index 621534833261..150ae9f1127b 100644 --- a/toolkit/mozapps/update/test/unit/test_0070_update_dir_cleanup.js +++ b/toolkit/mozapps/update/test/unit/test_0070_update_dir_cleanup.js @@ -40,9 +40,7 @@ function run_test() { removeUpdateDirsAndFiles(); - var defaults = getPrefBranch().QueryInterface(AUS_Ci.nsIPrefService). - getDefaultBranch(null); - defaults.setCharPref("app.update.channel", "bogus_channel"); + setUpdateChannel(); writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false); var patches = getLocalPatchString(null, null, null, null, null, null, @@ -57,7 +55,7 @@ function run_test() { log.append(FILE_UPDATE_LOG); writeFile(log, "Last Update Log"); - startAUS(); + standardInit(); dump("Testing: " + FILE_UPDATE_LOG + " doesn't exist\n"); do_check_false(log.exists()); diff --git a/toolkit/mozapps/update/test/unit/test_0071_update_dir_cleanup.js b/toolkit/mozapps/update/test/unit/test_0071_update_dir_cleanup.js index 7ba21251b102..bda53270f578 100644 --- a/toolkit/mozapps/update/test/unit/test_0071_update_dir_cleanup.js +++ b/toolkit/mozapps/update/test/unit/test_0071_update_dir_cleanup.js @@ -40,9 +40,7 @@ function run_test() { removeUpdateDirsAndFiles(); - var defaults = getPrefBranch().QueryInterface(AUS_Ci.nsIPrefService). - getDefaultBranch(null); - defaults.setCharPref("app.update.channel", "bogus_channel"); + setUpdateChannel(); writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false); var patches = getLocalPatchString(null, null, null, null, null, null, @@ -65,7 +63,7 @@ function run_test() { log.append(FILE_UPDATE_LOG); writeFile(log, "Last Update Log"); - startAUS(); + standardInit(); dump("Testing: " + FILE_UPDATE_LOG + " doesn't exist\n"); do_check_false(log.exists()); diff --git a/toolkit/mozapps/update/test/unit/test_0110_general.js b/toolkit/mozapps/update/test/unit/test_0110_general.js index 0fb9dee63162..d14e2dd9a72b 100644 --- a/toolkit/mozapps/update/test/unit/test_0110_general.js +++ b/toolkit/mozapps/update/test/unit/test_0110_general.js @@ -163,7 +163,7 @@ function run_test() { } var mar = do_get_file("data/aus-0110_general.mar"); - mar.copyTo(updatesDir, "update.mar"); + mar.copyTo(updatesDir, FILE_UPDATE_ARCHIVE); // apply the complete mar and check the innards of the files var exitValue = runUpdate(updatesDir, updater); @@ -173,7 +173,7 @@ function run_test() { dump("Testing: update.status should be set to STATE_SUCCEEDED\n"); testFile = updatesDir.clone(); - testFile.append("update.status"); + testFile.append(FILE_UPDATE_STATUS); do_check_eq(readFile(testFile).split("\n")[0], STATE_SUCCEEDED); dump("Testing: contents of files added by a complete mar\n"); diff --git a/toolkit/mozapps/update/test/unit/test_0111_general.js b/toolkit/mozapps/update/test/unit/test_0111_general.js index 007ff1aad197..ee532736eea0 100644 --- a/toolkit/mozapps/update/test/unit/test_0111_general.js +++ b/toolkit/mozapps/update/test/unit/test_0111_general.js @@ -183,7 +183,7 @@ function run_test() { updatesDir.create(AUS_Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY); var mar = do_get_file("data/aus-0111_general.mar"); - mar.copyTo(updatesDir, "update.mar"); + mar.copyTo(updatesDir, FILE_UPDATE_ARCHIVE); // apply the partial mar and check the innards of the files var exitValue = runUpdate(updatesDir, updater); @@ -193,7 +193,7 @@ function run_test() { dump("Testing: update.status should be set to STATE_SUCCEEDED\n"); testFile = updatesDir.clone(); - testFile.append("update.status"); + testFile.append(FILE_UPDATE_STATUS); do_check_eq(readFile(testFile).split("\n")[0], STATE_SUCCEEDED); dump("Testing: removal of files and contents of added / modified files by " + diff --git a/toolkit/mozapps/update/test/unit/test_0112_general.js b/toolkit/mozapps/update/test/unit/test_0112_general.js index 16e139f0813a..b8433893d69f 100644 --- a/toolkit/mozapps/update/test/unit/test_0112_general.js +++ b/toolkit/mozapps/update/test/unit/test_0112_general.js @@ -165,7 +165,7 @@ function run_test() { updatesDir.create(AUS_Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY); var mar = do_get_file("data/aus-0111_general.mar"); - mar.copyTo(updatesDir, "update.mar"); + mar.copyTo(updatesDir, FILE_UPDATE_ARCHIVE); // apply the partial mar and check the innards of the files var exitValue = runUpdate(updatesDir, updater); @@ -175,7 +175,7 @@ function run_test() { dump("Testing: update.status should be set to STATE_FAILED\n"); testFile = updatesDir.clone(); - testFile.append("update.status"); + testFile.append(FILE_UPDATE_STATUS); // The update status format for a failure is failed: # where # is the error // code for the failure. do_check_eq(readFile(testFile).split(": ")[0], STATE_FAILED); diff --git a/toolkit/mozapps/update/test/unit/test_bug497578.js b/toolkit/mozapps/update/test/unit/test_bug497578.js index ac0a5651c513..ca69e44d1241 100644 --- a/toolkit/mozapps/update/test/unit/test_bug497578.js +++ b/toolkit/mozapps/update/test/unit/test_bug497578.js @@ -54,6 +54,7 @@ function run_test() { "browser.privatebrowsing.autostart set to true\n"); removeUpdateDirsAndFiles(); + setUpdateChannel(); var registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar); registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), @@ -61,14 +62,10 @@ function run_test() { "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); - var pb = getPrefBranch(); // Enable automatic app update so that after the failed partial is found the // complete update will start to download automatically. - pb.setBoolPref("app.update.enabled", true); - pb.setBoolPref("browser.privatebrowsing.autostart", true); - - var defaults = pb.QueryInterface(AUS_Ci.nsIPrefService).getDefaultBranch(null); - defaults.setCharPref("app.update.channel", "bogus_channel"); + gPref.setBoolPref(PREF_APP_UPDATE_ENABLED, true); + gPref.setBoolPref("browser.privatebrowsing.autostart", true); createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1.0", "2.0"); setDefaultPrefs(); @@ -82,19 +79,18 @@ function end_test() { function run_test_pt1() { writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false); - var url = URL_HOST + DIR_DATA + "/partial.mar"; + var url = URL_HOST + URL_PATH + "/partial.mar"; var patches = getLocalPatchString("partial", url, null, null, null, null, STATE_FAILED) + getLocalPatchString(null, null, null, null, null, null, STATE_NONE); - var updates = getLocalUpdateString(patches, false, null, "1.0", null, "1.0", - null, null, null, - URL_HOST + DIR_DATA + "/partial.mar"); + var updates = getLocalUpdateString(patches, null, null, "version 1.0", "1.0", + null, null, null, null, url); writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); writeStatusFile(STATE_FAILED); - startAUS(); - startUpdateManager(); + standardInit(); + dump("Testing: activeUpdate.state should equal STATE_DOWNLOADING prior to " + "entering private browsing\n"); do_check_eq(gUpdateManager.activeUpdate.state, STATE_DOWNLOADING);