Bug 770772 - Implement WebappRT test framework on Linux. r=adw
authorMarco Castelluccio <mar.castelluccio@studenti.unina.it>
Sat, 14 Jul 2012 19:16:58 -0400
changeset 99330 5b5f4f615e007d9b512d235c086eabd426510743
parent 99329 70a4f4292ef4f7253b2fda776832aa87dc77f087
child 99331 ed137f37a3c26909bb2a6c5ae1cf2dcc898088c6
child 99356 648510be4091b9e31bcb95982b5fb2667517e98f
push id11940
push userryanvm@gmail.com
push dateSat, 14 Jul 2012 23:17:09 +0000
treeherdermozilla-inbound@5b5f4f615e00 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs770772
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 770772 - Implement WebappRT test framework on Linux. r=adw
testing/testsuite-targets.mk
webapprt/gtk2/webapprt.cpp
--- a/testing/testsuite-targets.mk
+++ b/testing/testsuite-targets.mk
@@ -130,16 +130,19 @@ endif
 	$(CHECK_TEST_ERROR)
 
 ifeq ($(OS_ARCH),Darwin)
 webapprt_stub_path = $(TARGET_DIST)/$(MOZ_MACBUNDLE_NAME)/Contents/MacOS/webapprt-stub$(BIN_SUFFIX)
 endif
 ifeq ($(OS_ARCH),WINNT)
 webapprt_stub_path = $(TARGET_DIST)/bin/webapprt-stub$(BIN_SUFFIX)
 endif
+ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
+webapprt_stub_path = $(TARGET_DIST)/bin/webapprt-stub$(BIN_SUFFIX)
+endif
 
 ifdef webapprt_stub_path
 webapprt-test-content:
 	$(RUN_MOCHITEST) --webapprt-content --appname $(webapprt_stub_path)
 	$(CHECK_TEST_ERROR)
 webapprt-test-chrome:
 	$(RUN_MOCHITEST) --webapprt-chrome --appname $(webapprt_stub_path) --browser-arg -test-mode
 	$(CHECK_TEST_ERROR)
--- a/webapprt/gtk2/webapprt.cpp
+++ b/webapprt/gtk2/webapprt.cpp
@@ -23,16 +23,18 @@ const char kAPP_INI[] = "application.ini
 const char kWEBAPP_INI[] = "webapp.ini";
 const char kWEBAPPRT_INI[] = "webapprt.ini";
 const char kWEBAPPRT_PATH[] = "webapprt";
 const char kAPP_ENV_VAR[] = "XUL_APP_FILE";
 const char kAPP_RT[] = "webapprt-stub";
 
 int* pargc;
 char*** pargv;
+char profile[MAXPATHLEN];
+bool isProfileOverridden = false;
 
 XRE_GetFileFromPathType XRE_GetFileFromPath;
 XRE_CreateAppDataType XRE_CreateAppData;
 XRE_FreeAppDataType XRE_FreeAppData;
 XRE_mainType XRE_main;
 
 const nsDynamicFunctionLoad kXULFuncs[] = {
   { "XRE_GetFileFromPath", (NSFuncPtr*) &XRE_GetFileFromPath },
@@ -115,36 +117,38 @@ bool CopyFile(const char* inputFile, con
 
   // Close file descriptors
   close(inputFD);
   close(outputFD);
 
   return (bytesRead >= 0);
 }
 
-bool GRELoadAndLaunch(const char* firefoxDir, const char* profile)
+bool GRELoadAndLaunch(const char* firefoxDir)
 {
   char xpcomDllPath[MAXPATHLEN];
   snprintf(xpcomDllPath, MAXPATHLEN, "%s/%s", firefoxDir, XPCOM_DLL);
 
   if (NS_FAILED(XPCOMGlueStartup(xpcomDllPath))) {
     ErrorDialog("Couldn't load the XPCOM library");
     return false;
   }
 
   if (NS_FAILED(XPCOMGlueLoadXULFunctions(kXULFuncs))) {
     ErrorDialog("Couldn't load libxul");
     return false;
   }
 
-  // Override the class name part of the WM_CLASS property, so that the
-  // DE can match our window to the correct launcher
-  char programClass[MAXPATHLEN];
-  snprintf(programClass, MAXPATHLEN, "owa-%s", profile);
-  g_set_prgname(programClass);
+  if (!isProfileOverridden) {
+    // Override the class name part of the WM_CLASS property, so that the
+    // DE can match our window to the correct launcher
+    char programClass[MAXPATHLEN];
+    snprintf(programClass, MAXPATHLEN, "owa-%s", profile);
+    g_set_prgname(programClass);
+  }
 
   // NOTE: The GRE has successfully loaded, so we can use XPCOM now
   { // Scope for any XPCOM stuff we create
     ScopedLogging log;
 
     // Get the path to the runtime
     char rtPath[MAXPATHLEN];
     snprintf(rtPath, MAXPATHLEN, "%s/%s", firefoxDir, kWEBAPPRT_PATH);
@@ -168,18 +172,20 @@ bool GRELoadAndLaunch(const char* firefo
     }
 
     nsXREAppData *webShellAppData;
     if (NS_FAILED(XRE_CreateAppData(rtINI, &webShellAppData))) {
       ErrorDialog("Couldn't read WebappRT application.ini");
       return false;
     }
 
-    SetAllocatedString(webShellAppData->profile, profile);
-    SetAllocatedString(webShellAppData->name, profile);
+    if (!isProfileOverridden) {
+      SetAllocatedString(webShellAppData->profile, profile);
+      SetAllocatedString(webShellAppData->name, profile);
+    }
 
     nsCOMPtr<nsIFile> directory;
     if (NS_FAILED(XRE_GetFileFromPath(rtPath, getter_AddRefs(directory)))) {
       ErrorDialog("Couldn't open runtime directory");
       return false;
     }
 
     nsCOMPtr<nsIFile> xreDir;
@@ -226,20 +232,39 @@ int main(int argc, char *argv[])
   pargv = &argv;
 
   // Get current executable path
   char curExePath[MAXPATHLEN];
   if (NS_FAILED(mozilla::BinaryPath::Get(argv[0], curExePath))) {
     ErrorDialog("Couldn't read current executable path");
     return 255;
   }
+  char curExeDir[MAXPATHLEN];
+  GetDirFromPath(curExeDir, curExePath);
+
+  for (int i = 1; i < argc; i++) {
+    if (!strcmp(argv[i], "-profile")) {
+      isProfileOverridden = true;
+      break;
+    }
+  }
+
+  char firefoxDir[MAXPATHLEN];
+
+  // Check if Firefox is in the ../../dist/bin directory (relative to the webapp runtime)
+  // This is the case for webapprt chrome and content tests.
+  snprintf(firefoxDir, MAXPATHLEN, "%s/../../dist/bin", curExeDir);
+  if (access(firefoxDir, F_OK) != -1) {
+    if (GRELoadAndLaunch(firefoxDir))
+      return 0;
+
+    return 255;
+  }
 
   // Set up webAppIniPath with path to webapp.ini
-  char curExeDir[MAXPATHLEN];
-  GetDirFromPath(curExeDir, curExePath);
   char webAppIniPath[MAXPATHLEN];
   snprintf(webAppIniPath, MAXPATHLEN, "%s/%s", curExeDir, kWEBAPP_INI);
 
   // Open webapp.ini as an INI file
   nsINIParser parser;
   if (NS_FAILED(parser.Init(webAppIniPath))) {
     ErrorDialog("Couldn't open webapp.ini");
     return 255;
@@ -247,24 +272,22 @@ int main(int argc, char *argv[])
 
   // Set up our environment to know where webapp.ini was loaded from
   if (setenv(kAPP_ENV_VAR, webAppIniPath, 1) == -1) {
     ErrorDialog("Couldn't set up app environment");
     return 255;
   }
 
   // Get profile dir from webapp.ini
-  char profile[MAXPATHLEN];
   if (NS_FAILED(parser.GetString("Webapp", "Profile", profile, MAXPATHLEN))) {
     ErrorDialog("Couldn't retrieve profile from web app INI file");
     return 255;
   }
 
   // Get the location of Firefox from our webapp.ini
-  char firefoxDir[MAXPATHLEN];
   if (NS_FAILED(parser.GetString("WebappRT", "InstallDir", firefoxDir, MAXPATHLEN))) {
     ErrorDialog("Couldn't find your Firefox install directory.");
     return 255;
   }
 
   // Set up appIniPath with path to application.ini.
   // This is in the Firefox installation directory.
   char appIniPath[MAXPATHLEN];
@@ -280,17 +303,17 @@ int main(int argc, char *argv[])
   char buildid[MAXPATHLEN];
   if (NS_FAILED(parser.GetString("App", "BuildID", buildid, MAXPATHLEN))) {
     ErrorDialog("Couldn't read BuildID from Firefox application.ini");
     return 255;
   }
 
   // If WebAppRT version == Firefox version, load XUL and execute the application
   if (!strcmp(buildid, NS_STRINGIFY(GRE_BUILDID))) {
-    if (GRELoadAndLaunch(firefoxDir, profile))
+    if (GRELoadAndLaunch(firefoxDir))
       return 0;
   }
   // Else, copy WebAppRT from Firefox installation and re-execute the process
   else
     CopyAndRelaunch(firefoxDir, curExePath);
 
   return 255;
 }