Bug 1314955 part A - Move the binary xpconnect testing components into libxul so that we can remove support for external binary components. Ideally we'd only compile these into the xul-gtest version, but currently we can't run xpcshell tests against that version, so I'm going to put them into the release xul, r?mrbkap draft
authorBenjamin Smedberg <benjamin@smedbergs.us>
Wed, 26 Oct 2016 11:47:52 -0400
changeset 433336 a5f8a8cf9b83f14cbdb1efbddbbfb0a6219cd7e0
parent 433335 1d532866e29090e934dccf0517635679a3bf6068
child 433337 6ec1776eba6ec1ca3e6c3e4b8bebfeddc5d84ecd
push id34547
push userbsmedberg@mozilla.com
push dateThu, 03 Nov 2016 14:53:47 +0000
reviewersmrbkap
bugs1314955
milestone52.0a1
Bug 1314955 part A - Move the binary xpconnect testing components into libxul so that we can remove support for external binary components. Ideally we'd only compile these into the xul-gtest version, but currently we can't run xpcshell tests against that version, so I'm going to put them into the release xul, r?mrbkap MozReview-Commit-ID: Lr6uKtzXdEb
js/xpconnect/src/XPCShellImpl.cpp
js/xpconnect/tests/components/native/moz.build
js/xpconnect/tests/components/native/xpctest_module.cpp
js/xpconnect/tests/components/native/xpctest_private.h
js/xpconnect/tests/unit/test_attributes.js
js/xpconnect/tests/unit/test_params.js
js/xpconnect/tests/unit/test_returncode.js
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -23,16 +23,17 @@
 #include "nscore.h"
 #include "nsArrayEnumerator.h"
 #include "nsCOMArray.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsCOMPtr.h"
 #include "nsJSPrincipals.h"
 #include "xpcpublic.h"
 #include "xpcprivate.h"
+#include "xpctest_private.h"
 #include "BackstagePass.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIPrincipal.h"
 #include "nsJSUtils.h"
 #include "gfxPrefs.h"
 #include "nsIXULRuntime.h"
 
 #include "base/histogram.h"
@@ -638,16 +639,32 @@ RegisterAppManifest(JSContext* cx, unsig
     rv = XRE_AddManifestLocation(NS_APP_LOCATION, file);
     if (NS_FAILED(rv)) {
         XPCThrower::Throw(rv, cx);
         return false;
     }
     return true;
 }
 
+static bool
+RegisterXPCTestComponents(JSContext* cx, unsigned argc, Value* vp)
+{
+    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
+    if (args.length() != 0) {
+        JS_ReportErrorASCII(cx, "Wrong number of arguments");
+        return false;
+    }
+    nsresult rv = XRE_AddStaticComponent(&kXPCTestModule);
+    if (NS_FAILED(rv)) {
+        XPCThrower::Throw(rv, cx);
+        return false;
+    }
+    return true;
+}
+
 static const JSFunctionSpec glob_functions[] = {
     JS_FS("print",           Print,          0,0),
     JS_FS("readline",        ReadLine,       1,0),
     JS_FS("load",            Load,           1,0),
     JS_FS("quit",            Quit,           0,0),
     JS_FS("version",         Version,        1,0),
     JS_FS("dumpXPC",         DumpXPC,        1,0),
     JS_FS("dump",            Dump,           1,0),
@@ -657,16 +674,17 @@ static const JSFunctionSpec glob_functio
 #endif
     JS_FS("options",         Options,        0,0),
     JS_FS("sendCommand",     SendCommand,    1,0),
     JS_FS("atob",            xpc::Atob,      1,0),
     JS_FS("btoa",            xpc::Btoa,      1,0),
     JS_FS("setInterruptCallback", SetInterruptCallback, 1,0),
     JS_FS("simulateActivityCallback", SimulateActivityCallback, 1,0),
     JS_FS("registerAppManifest", RegisterAppManifest, 1, 0),
+    JS_FS("registerXPCTestComponents", RegisterXPCTestComponents, 0, 0),
     JS_FS_END
 };
 
 static bool
 env_setProperty(JSContext* cx, HandleObject obj, HandleId id, MutableHandleValue vp,
                 ObjectOpResult& result)
 {
 /* XXX porting may be easy, but these don't seem to supply setenv by default */
--- a/js/xpconnect/tests/components/native/moz.build
+++ b/js/xpconnect/tests/components/native/moz.build
@@ -1,19 +1,22 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
-FINAL_TARGET = '_tests/xpcshell/js/xpconnect/tests/components/native/'
+EXPORTS += [
+    'xpctest_private.h',
+]
+
 EXTRA_COMPONENTS += [
     'xpctest.manifest',
 ]
 
 UNIFIED_SOURCES += [
     'xpctest_attributes.cpp',
     'xpctest_module.cpp',
     'xpctest_params.cpp',
     'xpctest_returncode.cpp',
 ]
 
-XPCOMBinaryComponent('xpctest')
+FINAL_LIBRARY = 'xul'
--- a/js/xpconnect/tests/components/native/xpctest_module.cpp
+++ b/js/xpconnect/tests/components/native/xpctest_module.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  *
  * 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/. */
 
 /* module registration and factory code. */
 
-#include "mozilla/ModuleUtils.h"
 #include "xpctest_private.h"
 
 #define NS_XPCTESTOBJECTREADONLY_CID                                          \
 { 0x492609a7, 0x2582, 0x436b,                                                 \
    { 0xb0, 0xef, 0x92, 0xe2, 0x9b, 0xb9, 0xe1, 0x43 } }
 
 #define NS_XPCTESTOBJECTREADWRITE_CID                                         \
 { 0x8f37f760, 0x3686, 0x4dbb,                                                 \
@@ -45,15 +44,13 @@ static const mozilla::Module::CIDEntry k
 static const mozilla::Module::ContractIDEntry kXPCTestContracts[] = {
     { "@mozilla.org/js/xpc/test/native/ObjectReadOnly;1", &kNS_XPCTESTOBJECTREADONLY_CID },
     { "@mozilla.org/js/xpc/test/native/ObjectReadWrite;1", &kNS_XPCTESTOBJECTREADWRITE_CID },
     { "@mozilla.org/js/xpc/test/native/Params;1", &kNS_XPCTESTPARAMS_CID },
     { "@mozilla.org/js/xpc/test/native/ReturnCodeParent;1", &kNS_XPCTESTRETURNCODEPARENT_CID },
     { nullptr }
 };
 
-static const mozilla::Module kXPCTestModule = {
+const mozilla::Module kXPCTestModule = {
     mozilla::Module::kVersion,
     kXPCTestCIDs,
     kXPCTestContracts
 };
-
-NSMODULE_DEFN(xpconnect_test) = &kXPCTestModule;
--- a/js/xpconnect/tests/components/native/xpctest_private.h
+++ b/js/xpconnect/tests/components/native/xpctest_private.h
@@ -11,16 +11,19 @@
 
 #include "nsISupports.h"
 #include "nsMemory.h"
 #include "nsStringGlue.h"
 #include "xpctest_attributes.h"
 #include "xpctest_params.h"
 #include "xpctest_returncode.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/ModuleUtils.h"
+
+extern const mozilla::Module kXPCTestModule;
 
 class xpcTestObjectReadOnly final : public nsIXPCTestObjectReadOnly {
  public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIXPCTESTOBJECTREADONLY
   xpcTestObjectReadOnly();
 
  private:
--- a/js/xpconnect/tests/unit/test_attributes.js
+++ b/js/xpconnect/tests/unit/test_attributes.js
@@ -3,17 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 function run_test() {
 
   // Load the component manifests.
-  registerAppManifest(do_get_file('../components/native/chrome.manifest'));
+  registerXPCTestComponents();
   registerAppManifest(do_get_file('../components/js/xpctest.manifest'));
 
   // Test for each component.
   test_component_readwrite("@mozilla.org/js/xpc/test/native/ObjectReadWrite;1");
   test_component_readwrite("@mozilla.org/js/xpc/test/js/ObjectReadWrite;1");
   test_component_readonly("@mozilla.org/js/xpc/test/native/ObjectReadOnly;1");
   test_component_readonly("@mozilla.org/js/xpc/test/js/ObjectReadOnly;1");
 }
--- a/js/xpconnect/tests/unit/test_params.js
+++ b/js/xpconnect/tests/unit/test_params.js
@@ -3,17 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 function run_test() {
 
   // Load the component manifests.
-  registerAppManifest(do_get_file('../components/native/chrome.manifest'));
+  registerXPCTestComponents();
   registerAppManifest(do_get_file('../components/js/xpctest.manifest'));
 
   // Test for each component.
   test_component("@mozilla.org/js/xpc/test/native/Params;1");
   test_component("@mozilla.org/js/xpc/test/js/Params;1");
 }
 
 function test_component(contractid) {
--- a/js/xpconnect/tests/unit/test_returncode.js
+++ b/js/xpconnect/tests/unit/test_returncode.js
@@ -11,17 +11,17 @@ function getConsoleMessages() {
   let messages = consoleService.getMessageArray().map((m) => m.toString());
   // reset ready for the next call.
   consoleService.reset();
   return messages;
 }
 
 function run_test() {
   // Load the component manifests.
-  registerAppManifest(do_get_file('../components/native/chrome.manifest'));
+  registerXPCTestComponents();
   registerAppManifest(do_get_file('../components/js/xpctest.manifest'));
 
   // and the tests.
   test_simple();
   test_nested();
 }
 
 function test_simple() {