Mac v2 signing - Bug 1077268 - Make app update tests use the GreBinD dir service key implemented in bug 1077099. r=spohl
authorRobert Strong <robert.bugzilla@gmail.com>
Thu, 02 Oct 2014 23:55:58 -0700
changeset 491310 2469404b228dd5a60c40dd1bc8208e2eecc97192
parent 491309 bb4b10aa46eae51974e7e5cb861189ad3533ce9f
child 491311 3df4eb39cf4a509bc86d92c150acbe53ce449d87
push id47343
push userbmo:dothayer@mozilla.com
push dateWed, 01 Mar 2017 22:58:58 +0000
reviewersspohl
bugs1077268, 1077099
milestone35.0a1
Mac v2 signing - Bug 1077268 - Make app update tests use the GreBinD dir service key implemented in bug 1077099. r=spohl
toolkit/mozapps/update/tests/shared.js
toolkit/mozapps/update/tests/unit_aus_update/head_update.js
--- a/toolkit/mozapps/update/tests/shared.js
+++ b/toolkit/mozapps/update/tests/shared.js
@@ -46,34 +46,38 @@ const PREF_DISTRIBUTION_ID              
 const PREF_DISTRIBUTION_VERSION           = "distribution.version";
 
 const PREF_EXTENSIONS_UPDATE_URL          = "extensions.update.url";
 const PREF_EXTENSIONS_STRICT_COMPAT       = "extensions.strictCompatibility";
 
 const NS_APP_PROFILE_DIR_STARTUP   = "ProfDS";
 const NS_APP_USER_PROFILE_50_DIR   = "ProfD";
 const NS_GRE_DIR                   = "GreD";
+const NS_GRE_BIN_DIR               = "GreBinD";
 const NS_XPCOM_CURRENT_PROCESS_DIR = "XCurProcD";
 const XRE_EXECUTABLE_FILE          = "XREExeF";
 const XRE_UPDATE_ROOT_DIR          = "UpdRootD";
 
 const CRC_ERROR   = 4;
 const WRITE_ERROR = 7;
 
-const DIR_PATCH        = "0";
-const DIR_TOBEDELETED  = "tobedeleted";
-const DIR_UPDATES      = "updates";
+const DIR_PATCH            = "0";
+const DIR_TOBEDELETED      = "tobedeleted";
+const DIR_UPDATES          = "updates";
 #ifdef XP_MACOSX
-const DIR_BIN_REL_PATH = "Contents/MacOS/";
-const DIR_UPDATED      = "Updated.app";
+const DIR_BIN_REL_PATH     = "Contents/MacOS/";
+const DIR_GRE_BIN_REL_PATH = "Contents/MacOS/";
+const DIR_UPDATED          = "Updated.app";
 #else
-const DIR_BIN_REL_PATH = "";
-const DIR_UPDATED      = "updated";
+const DIR_BIN_REL_PATH     = "";
+const DIR_GRE_BIN_REL_PATH = "";
+const DIR_UPDATED          = "updated";
 #endif
 
+const FILE_APPLICATION_INI           = "application.ini";
 const FILE_BACKUP_LOG                = "backup-update.log";
 const FILE_LAST_LOG                  = "last-update.log";
 const FILE_UPDATER_INI               = "updater.ini";
 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_SETTINGS_INI       = "update-settings.ini";
@@ -566,28 +570,40 @@ function getCurrentProcessDir() {
  *
  * @return  nsIFile object for the application base directory.
  */
 function getAppBaseDir() {
   return Services.dirsvc.get(XRE_EXECUTABLE_FILE, AUS_Ci.nsIFile).parent;
 }
 
 /**
- * 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.
+ * Returns the Gecko Runtime Engine directory where files other than executable
+ * binaries are located. On Mac OS X this will be <bundle>/Contents/Resources/
+ * and the installation directory on all other platforms.
  *
  * @return nsIFile for the Gecko Runtime Engine directory.
  */
 function getGREDir() {
   return Services.dirsvc.get(NS_GRE_DIR, AUS_Ci.nsIFile);
 }
 
 /**
+ * Returns the Gecko Runtime Engine Binary directory where the executable
+ * binaries are located such as the updater binary (Windows and Linux) or
+ * updater package (Mac OS X). On Mac OS X this will be
+ * <bundle>/Contents/MacOS/ and the installation directory on all other
+ * platforms.
+ *
+ * @return nsIFile for the Gecko Runtime Engine Binary directory.
+ */
+function getGREBinDir() {
+  return Services.dirsvc.get(NS_GRE_BIN_DIR, AUS_Ci.nsIFile);
+}
+
+/**
  * Logs TEST-INFO messages.
  *
  * @param  aText
  *         The text to log.
  * @param  aCaller (optional)
  *         An optional Components.stack.caller. If not specified
  *         Components.stack.caller will be used.
  */
--- a/toolkit/mozapps/update/tests/unit_aus_update/head_update.js
+++ b/toolkit/mozapps/update/tests/unit_aus_update/head_update.js
@@ -170,16 +170,17 @@ var gStatusCode;
 var gStatusText;
 var gStatusResult;
 
 var gProcess;
 var gAppTimer;
 var gHandle;
 
 var gGREDirOrig;
+var gGREBinDirOrig;
 var gAppDirOrig;
 
 var gServiceLaunchedCallbackLog = null;
 var gServiceLaunchedCallbackArgs = null;
 
 // Variables are used instead of contants so tests can override these values if
 // necessary.
 var gCallbackBinFile = "callback_app" + BIN_SUFFIX;
@@ -829,16 +830,17 @@ function setupTestCommon() {
       dump = dumpOverride;
     }
   }
 
   // Don't attempt to show a prompt when an update finishes.
   Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, true);
 
   gGREDirOrig = getGREDir();
+  gGREBinDirOrig = getGREBinDir();
   gAppDirOrig = getAppBaseDir();
 
   let applyDir = getApplyDirFile(null, true).parent;
 
   // Try to remove the directory used to apply updates and the updates directory
   // on platforms other than Windows. Since the test hasn't ran yet and the
   // directory shouldn't exist finished this is non-fatal for the test.
   if (applyDir.exists()) {
@@ -1123,20 +1125,20 @@ function pathHandler(aMetadata, aRespons
  * application.ini file.
  *
  * @return  The version string from the application.ini file.
  * @throws  If the application.ini file is not found.
  */
 function getAppVersion() {
   // Read the application.ini and use its application version.
   let iniFile = gGREDirOrig.clone();
-  iniFile.append("application.ini");
+  iniFile.append(FILE_APPLICATION_INI);
   if (!iniFile.exists()) {
-    iniFile = gAppDirOrig.clone();
-    iniFile.append("application.ini");
+    iniFile = gGREBinDirOrig.clone();
+    iniFile.append(FILE_APPLICATION_INI);
   }
   if (!iniFile.exists()) {
     do_throw("Unable to find application.ini!");
   }
   let iniParser = AUS_Cc["@mozilla.org/xpcom/ini-parser-factory;1"].
                   getService(AUS_Ci.nsIINIParserFactory).
                   createINIParser(iniFile);
   return iniParser.getString("App", "Version");
@@ -1468,17 +1470,17 @@ if (IS_WIN) {
  * @param   aCallback (optional)
  *          A callback function that will be called when this function finishes.
  *          If null no function will be called when this function finishes.
  *          If not specified the checkUpdateApplied function will be called when
  *          this function finishes.
  */
 function runUpdate(aExpectedExitValue, aExpectedStatus, aCallback) {
   // Copy the updater binary to the updates directory.
-  let binDir = gAppDirOrig.clone();
+  let binDir = gGREBinDirOrig.clone();
   let updater = binDir.clone();
   updater.append("updater.app");
   if (!updater.exists()) {
     updater = binDir.clone();
     updater.append(FILE_UPDATER_BIN);
     if (!updater.exists()) {
       do_throw("Unable to find updater binary!");
     }
@@ -1739,103 +1741,112 @@ function setupAppFiles() {
       logTestInfo("unable to create directory, Path: " + destDir.path +
                   ", Exception: " + e);
       do_throw(e);
     }
   }
 
   // Required files for the application or the test that aren't listed in the
   // dependentlibs.list file.
-  let fileRelPaths = [ { src: FILE_APP_BIN },
-                       { src: FILE_UPDATER_BIN} ];
-  if (IS_MACOSX) {
-    fileRelPaths.push( { src: "../Resources/application.ini", dst: "../Resources/application.ini" } );
-    fileRelPaths.push( { src: "../Resources/dependentlibs.list", dst: "../Resources/dependentlibs.list" } );
-  } else {
-    fileRelPaths.push( { src: "application.ini" } );
-    fileRelPaths.push( { src: "dependentlibs.list" } );
-  }
+  let fileRelPaths = [ { file     : FILE_APP_BIN,
+                         inGreDir : false },
+                       { file     : FILE_UPDATER_BIN,
+                         inGreDir : false },
+                       { file     : FILE_APPLICATION_INI,
+                         inGreDir : true },
+                       { file      : "dependentlibs.list",
+                         inGreDir : true } ];
 
   // On Linux the updater.png must also be copied
   if (IS_UNIX && !IS_MACOSX) {
-    fileRelPaths.push( { src: "icons/updater.png" } );
+    fileRelPaths.push( { file     : "icons/updater.png",
+                         inGreDir : true } );
   }
 
   // Read the dependent libs file leafnames from the dependentlibs.list file
   // into the array.
   let deplibsFile = srcDir.clone();
   deplibsFile.append("dependentlibs.list");
   let istream = AUS_Cc["@mozilla.org/network/file-input-stream;1"].
                 createInstance(AUS_Ci.nsIFileInputStream);
   istream.init(deplibsFile, 0x01, 0o444, 0);
   istream.QueryInterface(AUS_Ci.nsILineInputStream);
 
   let hasMore;
   let line = {};
   do {
     hasMore = istream.readLine(line);
-    fileRelPaths.push( { src: line.value } );
+    fileRelPaths.push( { file     : line.value,
+                         inGreDir : false } );
   } while(hasMore);
 
   istream.close();
 
   fileRelPaths.forEach(function CMAF_FLN_FE(aFileRelPath) {
-    copyFileToTestAppDir(aFileRelPath.src, aFileRelPath.dst ? aFileRelPath.dst
-                                                            : null);
+    copyFileToTestAppDir(aFileRelPath.file, aFileRelPath.inGreDir);
   });
 
   logTestInfo("finish - copying or creating symlinks to application files " +
               "for the test");
 }
 
 /**
  * Copies the specified files from the dist/bin directory into the test's
  * application directory.
  *
  * @param  aFileRelPath
  *         The relative path of the file to copy.
- * @param  aDestFileRelPath (optional)
- *         The relative path of the destination file.
+ * @param  aInGreDir
+ *         Whether the file is located in the GRE directory which is
+ *         <bundle>/Contents/Resources on Mac OS X and is the installation
+ *         directory on all other platforms. If false the file must be in the
+ *         GRE Binary directory which is <bundle>/Contents/MacOS on Mac OS X and
+ *         is the installation directory on on all other platforms.
  */
-function copyFileToTestAppDir(aFileRelPath, aDestFileRelPath) {
+function copyFileToTestAppDir(aFileRelPath, aInGreDir) {
+  // gGREDirOrig and gGREBinDirOrig must always be cloned when changing its
+  // properties
+  let srcFile = aInGreDir ? gGREDirOrig.clone() : gGREBinDirOrig.clone();
+  let destFile = aInGreDir ? getGREDir() : getGREBinDir();
   let fileRelPath = aFileRelPath;
-  let srcFile = gAppDirOrig.clone();
   let pathParts = fileRelPath.split("/");
   for (let i = 0; i < pathParts.length; i++) {
     if (pathParts[i]) {
       srcFile.append(pathParts[i]);
+      destFile.append(pathParts[i]);
     }
   }
 
   if (IS_MACOSX && !srcFile.exists()) {
     logTestInfo("unable to copy file since it doesn't exist! Checking if " +
                  fileRelPath + ".app exists. Path: " +
                  srcFile.path);
-    srcFile = gAppDirOrig.clone();
+    // gGREDirOrig and gGREBinDirOrig must always be cloned when changing its
+    // properties
+    srcFile = aInGreDir ? gGREDirOrig.clone() : gGREBinDirOrig.clone();
+    destFile = aInGreDir ? getGREDir() : getGREBinDir();
     for (let i = 0; i < pathParts.length; i++) {
       if (pathParts[i]) {
         srcFile.append(pathParts[i] + (pathParts.length - 1 == i ? ".app" : ""));
+        destFile.append(pathParts[i] + (pathParts.length - 1 == i ? ".app" : ""));
       }
     }
     fileRelPath = fileRelPath + ".app";
   }
 
   if (!srcFile.exists()) {
     do_throw("Unable to copy file since it doesn't exist! Path: " +
              srcFile.path);
   }
 
   // Symlink libraries. Note that the XUL library on Mac OS X doesn't have a
-  // file extension and this will always be false on Windows.
+  // file extension and shouldSymlink will always be false on Windows.
   let shouldSymlink = (pathParts[pathParts.length - 1] == "XUL" ||
                        fileRelPath.substr(fileRelPath.length - 3) == ".so" ||
                        fileRelPath.substr(fileRelPath.length - 6) == ".dylib");
-  let destFile = getApplyDirFile(DIR_BIN_REL_PATH +
-                                 (aDestFileRelPath ? aDestFileRelPath
-                                                   : fileRelPath), true);
   if (!shouldSymlink) {
     if (!destFile.exists()) {
       try {
         srcFile.copyToFollowingLinks(destFile.parent, destFile.leafName);
       } catch (e) {
         // Just in case it is partially copied
         if (destFile.exists()) {
           try {
@@ -3389,16 +3400,21 @@ function adjustGeneralPaths() {
     getFile: function AGP_DP_getFile(aProp, aPersistent) {
       aPersistent.value = true;
       switch (aProp) {
         case NS_GRE_DIR:
           if (gUseTestAppDir) {
             return getApplyDirFile(DIR_BIN_REL_PATH, true);
           }
           break;
+        case NS_GRE_BIN_DIR:
+          if (gUseTestAppDir) {
+            return getApplyDirFile(DIR_GRE_BIN_REL_PATH, true);
+          }
+          break;
         case XRE_EXECUTABLE_FILE:
           if (gUseTestAppDir) {
             return getApplyDirFile(DIR_BIN_REL_PATH + FILE_APP_BIN, true);
           }
           break;
         case XRE_UPDATE_ROOT_DIR:
           return getMockUpdRootD();
       }
@@ -3408,16 +3424,17 @@ function adjustGeneralPaths() {
       if (aIID.equals(AUS_Ci.nsIDirectoryServiceProvider) ||
           aIID.equals(AUS_Ci.nsISupports))
         return this;
       throw AUS_Cr.NS_ERROR_NO_INTERFACE;
     }
   };
   let ds = Services.dirsvc.QueryInterface(AUS_Ci.nsIDirectoryService);
   ds.QueryInterface(AUS_Ci.nsIProperties).undefine(NS_GRE_DIR);
+  ds.QueryInterface(AUS_Ci.nsIProperties).undefine(NS_GRE_BIN_DIR);
   ds.QueryInterface(AUS_Ci.nsIProperties).undefine(XRE_EXECUTABLE_FILE);
   ds.registerProvider(dirProvider);
   do_register_cleanup(function AGP_cleanup() {
     logTestInfo("start - unregistering directory provider");
 
     if (gAppTimer) {
       logTestInfo("start - cancel app timer");
       gAppTimer.cancel();