Bug 1306327 part C - Make the IPDL unit tests use the new Bootstrap API, r?glandium draft
authorBenjamin Smedberg <benjamin@smedbergs.us>
Fri, 02 Dec 2016 13:00:17 -0500
changeset 447526 f383394b3c746a927f71f73902d026cd2db02797
parent 447525 eaa3df21340ed28f551e73f473b7b65f2c76cbff
child 447527 d32e3567f027fa27e895ed51213489df1afd9aa7
push id38072
push userbsmedberg@mozilla.com
push dateMon, 05 Dec 2016 20:09:44 +0000
reviewersglandium
bugs1306327
milestone53.0a1
Bug 1306327 part C - Make the IPDL unit tests use the new Bootstrap API, r?glandium MozReview-Commit-ID: CXpka1e61fP
ipc/ipdl/test/cxx/app/TestIPDL.cpp
toolkit/moz.configure
toolkit/xre/Bootstrap.cpp
toolkit/xre/Bootstrap.h
toolkit/xre/nsEmbedFunctions.cpp
xpcom/build/nsXULAppAPI.h
--- a/ipc/ipdl/test/cxx/app/TestIPDL.cpp
+++ b/ipc/ipdl/test/cxx/app/TestIPDL.cpp
@@ -1,20 +1,27 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "nsXULAppAPI.h"
+#include "mozilla/Bootstrap.h"
 
 #if defined(XP_WIN)
 #include <windows.h>
 #include "nsWindowsWMain.cpp"
 #endif
 
+using namespace mozilla;
+
 int
 main(int argc, char** argv)
 {
     // the first argument specifies which IPDL test case/suite to load
     if (argc < 2)
         return 1;
 
-    return XRE_RunIPDLTest(argc, argv);
+    Bootstrap::UniquePtr bootstrap;
+    XRE_GetBootstrap(bootstrap);
+    if (!bootstrap) {
+      return 2;
+    }
+    return bootstrap->RunIPDLTest(argc, argv);
 }
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -677,18 +677,22 @@ def webspeech_test_backend(value):
 
 set_config('MOZ_WEBSPEECH_TEST_BACKEND', webspeech_test_backend)
 set_define('MOZ_WEBSPEECH_TEST_BACKEND', webspeech_test_backend)
 
 # Enable IPDL's "expensive" unit tests
 # ==============================================================
 option('--enable-ipdl-tests', help='Enable expensive IPDL tests')
 
-set_config('MOZ_IPDL_TESTS',
-           depends_if('--enable-ipdl-tests')(lambda _: True))
+@depends_if('--enable-ipdl-tests')
+def enable_ipdl_tests(value):
+    return True
+
+set_config('MOZ_IPDL_TESTS', enable_ipdl_tests)
+set_define('MOZ_IPDL_TESTS', enable_ipdl_tests)
 
 include('nss.configure')
 
 # Network protocol support
 # ==============================================================
 @depends(check_build_environment, '--help')
 @imports('os')
 @imports(_from='__builtin__', _import='sorted')
--- a/toolkit/xre/Bootstrap.cpp
+++ b/toolkit/xre/Bootstrap.cpp
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Bootstrap.h"
 
 #include "BinaryPath.h"
-#include "mozilla/AppData.h"
+#include "mozilla/XREAppData.h"
 #include "mozilla/Sprintf.h"
 #include "nsAppRunner.h"
 #include "nsCOMPtr.h"
 #include "nsIFile.h"
 #include "nsString.h"
 #include "nsXULAppAPI.h"
 
 #ifdef XP_WIN
@@ -32,16 +32,23 @@
 #include "mozilla/jni/Utils.h"
 #include "chrome/common/ipc_channel.h"
 #endif
 
 #ifdef MOZ_CRASHREPORTER
 #include "nsExceptionHandler.h"
 #endif
 
+#ifdef MOZ_IPDL_TESTS
+#include "mozilla/_ipdltest/IPDLUnitTests.h"
+#include "mozilla/_ipdltest/IPDLUnitTestProcessChild.h"
+
+using mozilla::_ipdltest::IPDLUnitTestProcessChild;
+#endif
+
 #define kDesktopFolder "browser"
 
 #ifdef XP_WIN
 #define strcasecmp _stricmp
 #endif
 
 namespace mozilla {
 
@@ -131,16 +138,20 @@ public:
   virtual int ContentProcessMain(int argc, char* argv[]) override;
   virtual int XPCShellMain(int argc, char* argv[], char* envp[]) override;
 
 #ifdef MOZ_WIDGET_ANDROID
   virtual void AndroidMain(JNIEnv* jenv, int argc, char* argv[]) override;
   virtual void AndroidChildMain(int arg, char* argv[], int crashFd, int ipcFd) override;
 #endif
 
+#ifdef MOZ_IPDL_TESTS
+  virtual int RunIPDLTest(int argc, char* argv[]) override;
+#endif
+
 private:
   const StaticXREAppData* mStaticAppData;
   nsCOMPtr<nsIFile> mXREDirectory;
   XREChildData mChildData;
 #ifdef HAS_DLL_BLOCKLIST
   bool mBlocklistEnabled;
 #endif
 #if defined(XP_WIN) && defined(MOZ_SANDBOX)
@@ -374,16 +385,36 @@ BootstrapImpl::AndroidChildMain(int argc
   XRE_SetProcessType(argv[argc - 1]);
   nsresult rv = XRE_InitChildProcess(argc - 1, argv, &mChildData);
   if (NS_FAILED(rv)) {
     LOG("XRE_InitChildProcess failed: nsresult %lx", (unsigned long)rv);
   }
 }
 #endif // MOZ_WIDGET_ANDROID
 
+#ifdef MOZ_IPDL_TESTS
+int
+BootstrapImpl::RunIPDLTest(int aArgc, char* aArgv[])
+{
+    if (aArgc < 2) {
+        fprintf(stderr, "TEST-UNEXPECTED-FAIL | <---> | insufficient #args, need at least 2\n");
+        return 1;
+    }
+
+    void* data = reinterpret_cast<void*>(aArgv[aArgc-1]);
+
+    nsresult rv =
+        XRE_InitParentProcess(
+            --aArgc, aArgv, mozilla::_ipdltest::IPDLUnitTestMain, data);
+    NS_ENSURE_SUCCESS(rv, 1);
+
+    return 0;
+}
+#endif
+
 extern "C" NS_EXPORT void NS_FROZENCALL
 XRE_GetBootstrap(Bootstrap::UniquePtr& b)
 {
   static bool sBootstrapInitialized = false;
   MOZ_RELEASE_ASSERT(!sBootstrapInitialized);
 
   sBootstrapInitialized = true;
   b.reset(new BootstrapImpl());
--- a/toolkit/xre/Bootstrap.h
+++ b/toolkit/xre/Bootstrap.h
@@ -140,16 +140,20 @@ public:
 
   /**
    * @param crashFd Pass -1 when unknown
    * @param ipcFd Pass -1 when unknown
    */
   virtual void AndroidChildMain(int argc, char* argv[],
                                 int crashFd = -1, int ipcFd = -1) = 0;
 #endif
+
+#ifdef MOZ_IPDL_TESTS
+  virtual int RunIPDLTest(int argc, char* argv[]) = 0;
+#endif
 };
 
 /**
  * Creates and returns the singleton instnace of the bootstrap object.
  * @param `b` is an outparam. We use a parameter and not a return value
  *        because MSVC doesn't let us return a c++ class from a function with
  *        "C" linkage. On failure this will be null.
  * @note This function may only be called once and will crash if called again.
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -319,17 +319,17 @@ AddContentSandboxLevelAnnotation()
 
 #if defined (XP_LINUX) && defined(MOZ_GMP_SANDBOX)
 namespace {
 class LinuxSandboxStarter : public mozilla::gmp::SandboxStarter {
 public:
   LinuxSandboxStarter() { }
   static UniquePtr<LinuxSandboxStarter> Make() {
     if (mozilla::SandboxInfo::Get().CanSandboxMedia()) {
-      return new LinuxSandboxStarter();
+      return MakeUnique<LinuxSandboxStarter>();
     } else {
       // Sandboxing isn't possible, but the parent has already
       // checked that this plugin doesn't require it.  (Bug 1074561)
       return nullptr;
     }
     return nullptr;
   }
   virtual bool Start(const char *aLibPath) override {
@@ -836,39 +836,16 @@ XRE_InitParentProcess(int aArgc,
       NS_WARNING("Failed to run appshell");
       return NS_ERROR_FAILURE;
     }
   }
 
   return XRE_DeinitCommandLine();
 }
 
-#ifdef MOZ_IPDL_TESTS
-//-----------------------------------------------------------------------------
-// IPDL unit test
-
-int
-XRE_RunIPDLTest(int aArgc, char** aArgv)
-{
-    if (aArgc < 2) {
-        fprintf(stderr, "TEST-UNEXPECTED-FAIL | <---> | insufficient #args, need at least 2\n");
-        return 1;
-    }
-
-    void* data = reinterpret_cast<void*>(aArgv[aArgc-1]);
-
-    nsresult rv =
-        XRE_InitParentProcess(
-            --aArgc, aArgv, mozilla::_ipdltest::IPDLUnitTestMain, data);
-    NS_ENSURE_SUCCESS(rv, 1);
-
-    return 0;
-}
-#endif  // ifdef MOZ_IPDL_TESTS
-
 nsresult
 XRE_RunAppShell()
 {
     nsCOMPtr<nsIAppShell> appShell(do_GetService(kAppShellCID));
     NS_ENSURE_TRUE(appShell, NS_ERROR_FAILURE);
 #if defined(XP_MACOSX)
     {
       // In content processes that want XPCOM (and hence want
--- a/xpcom/build/nsXULAppAPI.h
+++ b/xpcom/build/nsXULAppAPI.h
@@ -445,20 +445,16 @@ XRE_API(bool,
 typedef void (*MainFunction)(void* aData);
 
 XRE_API(nsresult,
         XRE_InitParentProcess, (int aArgc,
                                 char* aArgv[],
                                 MainFunction aMainFunction,
                                 void* aMainFunctionExtraData))
 
-XRE_API(int,
-        XRE_RunIPDLTest, (int aArgc,
-                          char* aArgv[]))
-
 XRE_API(nsresult,
         XRE_RunAppShell, ())
 
 XRE_API(nsresult,
         XRE_InitCommandLine, (int aArgc, char* aArgv[]))
 
 XRE_API(nsresult,
         XRE_DeinitCommandLine, ())