Bug 1094201 - Implement an Integration.jsm module for low-overhead registration of overrides. r=mak draft
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Mon, 18 Apr 2016 14:21:01 +0100
changeset 352703 782a2f3faceca442954c8bb6e8be3ff8f55341be
parent 352420 1f16d3da9280e40ada252acf8110b91ee1edbb08
child 518701 6b98384eb9b1f517a9d3b513e52457208cd47725
push id15748
push userpaolo.mozmail@amadzone.org
push dateMon, 18 Apr 2016 13:21:20 +0000
reviewersmak
bugs1094201
milestone48.0a1
Bug 1094201 - Implement an Integration.jsm module for low-overhead registration of overrides. r=mak MozReview-Commit-ID: NJmCSIEkAz
toolkit/components/formautofill/FormAutofill.jsm
toolkit/modules/Integration.jsm
toolkit/modules/moz.build
toolkit/modules/tests/xpcshell/TestIntegration.jsm
toolkit/modules/tests/xpcshell/test_Integration.js
toolkit/modules/tests/xpcshell/xpcshell.ini
--- a/toolkit/components/formautofill/FormAutofill.jsm
+++ b/toolkit/components/formautofill/FormAutofill.jsm
@@ -9,42 +9,24 @@
 "use strict";
 
 this.EXPORTED_SYMBOLS = [
   "FormAutofill",
 ];
 
 const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
 
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
-
-XPCOMUtils.defineLazyModuleGetter(this, "FormAutofillIntegration",
-                                  "resource://gre/modules/FormAutofillIntegration.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "Promise",
-                                  "resource://gre/modules/Promise.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "Task",
-                                  "resource://gre/modules/Task.jsm");
+Cu.import("resource://gre/modules/Integration.jsm");
+Cu.import("resource://gre/modules/Task.jsm");
 
 /**
  * Main module handling references to objects living in the main process.
  */
 this.FormAutofill = {
   /**
-   * Dynamically generated object implementing the FormAutofillIntegration
-   * methods.  Platform-specific code and add-ons can override methods of this
-   * object using the registerIntegration method.
-   */
-  get integration() {
-    // This lazy getter is only called if registerIntegration was never called.
-    this._refreshIntegrations();
-    return this.integration;
-  },
-
-  /**
    * Registers new overrides for the FormAutofillIntegration methods.  Example:
    *
    *   FormAutofill.registerIntegration(base => ({
    *     createRequestAutocompleteUI: Task.async(function* () {
    *       yield base.createRequestAutocompleteUI.apply(this, arguments);
    *     }),
    *   }));
    *
@@ -52,78 +34,52 @@ this.FormAutofill = {
    *        Function returning an object defining the methods that should be
    *        overridden.  Its only parameter is an object that contains the base
    *        implementation of all the available methods.
    *
    * @note The integration function is called every time the list of registered
    *       integration functions changes.  Thus, it should not have any side
    *       effects or do any other initialization.
    */
-  registerIntegration: function (aIntegrationFn) {
-    this._integrationFns.add(aIntegrationFn);
-    this._refreshIntegrations();
+  registerIntegration(aIntegrationFn) {
+    Integration.formAutofill.register(aIntegrationFn);
   },
 
   /**
    * Removes a previously registered FormAutofillIntegration override.
    *
    * Overrides don't usually need to be unregistered, unless they are added by a
    * restartless add-on, in which case they should be unregistered when the
    * add-on is disabled or uninstalled.
    *
    * @param aIntegrationFn
    *        This must be the same function object passed to registerIntegration.
    */
-  unregisterIntegration: function (aIntegrationFn) {
-    this._integrationFns.delete(aIntegrationFn);
-    this._refreshIntegrations();
-  },
-
-  /**
-   * Ordered list of registered functions defining integration overrides.
-   */
-  _integrationFns: new Set(),
-
-  /**
-   * Updates the "integration" getter with the object resulting from combining
-   * all the registered integration overrides with the default implementation.
-   */
-  _refreshIntegrations: function () {
-    delete this.integration;
-
-    let combined = FormAutofillIntegration;
-    for (let integrationFn of this._integrationFns) {
-      try {
-        // Obtain a new set of methods from the next integration function in the
-        // list, specifying the current combined object as the base argument.
-        let integration = integrationFn.call(null, combined);
-
-        // Retrieve a list of property descriptors from the returned object, and
-        // use them to build a new combined object whose prototype points to the
-        // previous combined object.
-        let descriptors = {};
-        for (let name of Object.getOwnPropertyNames(integration)) {
-          descriptors[name] = Object.getOwnPropertyDescriptor(integration, name);
-        }
-        combined = Object.create(combined, descriptors);
-      } catch (ex) {
-        // Any error will result in the current integration being skipped.
-        Cu.reportError(ex);
-      }
-    }
-
-    this.integration = combined;
+  unregisterIntegration(aIntegrationFn) {
+    Integration.formAutofill.unregister(aIntegrationFn);
   },
 
   /**
    * Processes a requestAutocomplete message asynchronously.
    *
    * @param aData
    *        Provided to FormAutofillIntegration.createRequestAutocompleteUI.
    *
    * @return {Promise}
    * @resolves Structured data received from the requestAutocomplete UI.
    */
   processRequestAutocomplete: Task.async(function* (aData) {
     let ui = yield FormAutofill.integration.createRequestAutocompleteUI(aData);
     return yield ui.show();
   }),
 };
+
+/**
+ * Dynamically generated object implementing the FormAutofillIntegration
+ * methods.  Platform-specific code and add-ons can override methods of this
+ * object using the registerIntegration method.
+ */
+Integration.formAutofill.defineModuleGetter(
+  this.FormAutofill,
+  "integration",
+  "resource://gre/modules/FormAutofillIntegration.jsm",
+  "FormAutofillIntegration"
+);
new file mode 100644
--- /dev/null
+++ b/toolkit/modules/Integration.jsm
@@ -0,0 +1,283 @@
+/* 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/. */
+
+/*
+ * Implements low-overhead integration between components of the application.
+ * This may have different uses depending on the component, including:
+ *
+ * - Providing product-specific implementations registered at startup.
+ * - Using alternative implementations during unit tests.
+ * - Allowing add-ons to change specific behaviors.
+ *
+ * Components may define one or more integration points, each defined by a
+ * root integration object whose properties and methods are the public interface
+ * and default implementation of the integration point. For example:
+ *
+ *   const DownloadIntegration = {
+ *     getTemporaryDirectory() {
+ *       return "/tmp/";
+ *     },
+ *
+ *     getTemporaryFile(name) {
+ *       return this.getTemporaryDirectory() + name;
+ *     },
+ *   };
+ *
+ * Other parts of the application may register overrides for some or all of the
+ * defined properties and methods. The component defining the integration point
+ * does not have to be loaded at this stage, because the name of the integration
+ * point is the only information required. For example, if the integration point
+ * is called "downloads":
+ *
+ *   Integration.downloads.register(base => ({
+ *     getTemporaryDirectory() {
+ *       return base.getTemporaryDirectory.call(this) + "subdir/";
+ *     },
+ *   }));
+ *
+ * When the component defining the integration point needs to call a method on
+ * the integration object, instead of using it directly the component would use
+ * the "getCombined" method to retrieve an object that includes all overrides.
+ * For example:
+ *
+ *   let combined = Integration.downloads.getCombined(DownloadIntegration);
+ *   Assert.is(combined.getTemporaryFile("file"), "/tmp/subdir/file");
+ *
+ * Overrides can be registered at startup or at any later time, so each call to
+ * "getCombined" may return a different object. The simplest way to create a
+ * reference to the combined object that stays updated to the latest version is
+ * to define the root object in a JSM and use the "defineModuleGetter" method.
+ *
+ * *** Registration ***
+ *
+ * Since the interface is not declared formally, the registrations can happen
+ * at startup without loading the component, so they do not affect performance.
+ *
+ * Hovever, this module does not provide a startup registry, this means that the
+ * code that registers and implements the override must be loaded at startup.
+ *
+ * If performance for the override code is a concern, you can take advantage of
+ * the fact that the function used to create the override is called lazily, and
+ * include only a stub loader for the final code in an existing startup module.
+ *
+ * The registration of overrides should be repeated for each process where the
+ * relevant integration methods will be called.
+ *
+ * *** Accessing base methods and properties ***
+ *
+ * Overrides are included in the prototype chain of the combined object in the
+ * same order they were registered, where the first is closest to the root.
+ *
+ * When defining overrides, you do not need to set the "__proto__" property of
+ * the objects you create, because their properties and methods are moved to a
+ * new object with the correct prototype. If you do, however, you can call base
+ * properties and methods using the "super" keyword. For example:
+ *
+ *   Integration.downloads.register(base => ({
+ *     __proto__: base,
+ *     getTemporaryDirectory() {
+ *       return super.getTemporaryDirectory() + "subdir/";
+ *     },
+ *   }));
+ *
+ * *** State handling ***
+ *
+ * Storing state directly on the combined integration object using the "this"
+ * reference is not recommended. When a new integration is registered, own
+ * properties stored on the old combined object are copied to the new combined
+ * object using a shallow copy, but the "this" reference for new invocations
+ * of the methods will be different.
+ *
+ * If the root object defines a property that always points to the same object,
+ * for example a "state" property, you can safely use it across registrations.
+ *
+ * Integration overrides provided by restartless add-ons should not use the
+ * "this" reference to store state, to avoid conflicts with other add-ons.
+ *
+ * *** Interaction with XPCOM ***
+ *
+ * Providing the combined object as an argument to any XPCOM method will
+ * generate a console error message, and will throw an exception where possible.
+ * For example, you cannot register observers directly on the combined object.
+ * This helps preventing mistakes due to the fact that the combined object
+ * reference changes when new integration overrides are registered.
+ */
+
+"use strict";
+
+this.EXPORTED_SYMBOLS = [
+  "Integration",
+];
+
+const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+/**
+ * Maps integration point names to IntegrationPoint objects.
+ */
+const gIntegrationPoints = new Map();
+
+/**
+ * This Proxy object creates IntegrationPoint objects using their name as key.
+ * The objects will be the same for the duration of the process. For example:
+ *
+ *   Integration.downloads.register(...);
+ *   Integration["addon-provided-integration"].register(...);
+ */
+this.Integration = new Proxy({}, {
+  get(target, name) {
+    let integrationPoint = gIntegrationPoints.get(name);
+    if (!integrationPoint) {
+      integrationPoint = new IntegrationPoint();
+      gIntegrationPoints.set(name, integrationPoint);
+    }
+    return integrationPoint;
+  },
+});
+
+/**
+ * Individual integration point for which overrides can be registered.
+ */
+this.IntegrationPoint = function () {
+  this._overrideFns = new Set();
+  this._combined = {
+    QueryInterface: function() {
+      let ex = new Components.Exception(
+                   "Integration objects should not be used with XPCOM because" +
+                   " they change when new overrides are registered.",
+                   Cr.NS_ERROR_NO_INTERFACE);
+      Cu.reportError(ex);
+      throw ex;
+    },
+  };
+}
+
+this.IntegrationPoint.prototype = {
+  /**
+   * Ordered set of registered functions defining integration overrides.
+   */
+  _overrideFns: null,
+
+  /**
+   * Combined integration object. When this reference changes, properties
+   * defined directly on this object are copied to the new object.
+   *
+   * Initially, the only property of this object is a "QueryInterface" method
+   * that throws an exception, to prevent misuse as a permanent XPCOM listener.
+   */
+  _combined: null,
+
+  /**
+   * Indicates whether the integration object is current based on the list of
+   * registered integration overrides.
+   */
+  _combinedIsCurrent: false,
+
+  /**
+   * Registers new overrides for the integration methods. For example:
+   *
+   *   Integration.nameOfIntegrationPoint.register(base => ({
+   *     asyncMethod: Task.async(function* () {
+   *       return yield base.asyncMethod.apply(this, arguments);
+   *     }),
+   *   }));
+   *
+   * @param overrideFn
+   *        Function returning an object defining the methods that should be
+   *        overridden. Its only parameter is an object that contains the base
+   *        implementation of all the available methods.
+   *
+   * @note The override function is called every time the list of registered
+   *       override functions changes. Thus, it should not have any side
+   *       effects or do any other initialization.
+   */
+  register(overrideFn) {
+    this._overrideFns.add(overrideFn);
+    this._combinedIsCurrent = false;
+  },
+
+  /**
+   * Removes a previously registered integration override.
+   *
+   * Overrides don't usually need to be unregistered, unless they are added by a
+   * restartless add-on, in which case they should be unregistered when the
+   * add-on is disabled or uninstalled.
+   *
+   * @param overrideFn
+   *        This must be the same function object passed to "register".
+   */
+  unregister(overrideFn) {
+    this._overrideFns.delete(overrideFn);
+    this._combinedIsCurrent = false;
+  },
+
+  /**
+   * Retrieves the dynamically generated object implementing the integration
+   * methods. Platform-specific code and add-ons can override methods of this
+   * object using the "register" method.
+   */
+  getCombined(root) {
+    if (this._combinedIsCurrent) {
+      return this._combined;
+    }
+
+    // In addition to enumerating all the registered integration overrides in
+    // order, we want to keep any state that was previously stored in the
+    // combined object using the "this" reference in integration methods.
+    let overrideFnArray = [...this._overrideFns, () => this._combined];
+
+    let combined = root;
+    for (let overrideFn of overrideFnArray) {
+      try {
+        // Obtain a new set of methods from the next override function in the
+        // list, specifying the current combined object as the base argument.
+        let override = overrideFn.call(null, combined);
+
+        // Retrieve a list of property descriptors from the returned object, and
+        // use them to build a new combined object whose prototype points to the
+        // previous combined object.
+        let descriptors = {};
+        for (let name of Object.getOwnPropertyNames(override)) {
+          descriptors[name] = Object.getOwnPropertyDescriptor(override, name);
+        }
+        combined = Object.create(combined, descriptors);
+      } catch (ex) {
+        // Any error will result in the current override being skipped.
+        Cu.reportError(ex);
+      }
+    }
+
+    this._combinedIsCurrent = true;
+    return this._combined = combined;
+  },
+
+  /**
+   * Defines a getter to retrieve the dynamically generated object implementing
+   * the integration methods, loading the root implementation lazily from the
+   * specified JSM module. For example:
+   *
+   *   Integration.test.defineModuleGetter(this, "TestIntegration",
+   *                    "resource://testing-common/TestIntegration.jsm");
+   *
+   * @param targetObject
+   *        The object on which the lazy getter will be defined.
+   * @param name
+   *        The name of the getter to define.
+   * @param moduleUrl
+   *        The URL used to obtain the module.
+   * @param symbol [optional]
+   *        The name of the symbol exported by the module. This can be omitted
+   *        if the name of the exported symbol is equal to the getter name.
+   */
+  defineModuleGetter(targetObject, name, moduleUrl, symbol) {
+    let moduleHolder = {};
+    XPCOMUtils.defineLazyModuleGetter(moduleHolder, name, moduleUrl, symbol);
+    Object.defineProperty(targetObject, name, {
+      get: () => this.getCombined(moduleHolder[name]),
+      configurable: true,
+      enumerable: true,
+    });
+  },
+};
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -6,16 +6,17 @@
 
 XPCSHELL_TESTS_MANIFESTS += ['tests/xpcshell/xpcshell.ini']
 BROWSER_CHROME_MANIFESTS += ['tests/browser/browser.ini']
 MOCHITEST_MANIFESTS += ['tests/mochitest/mochitest.ini']
 MOCHITEST_CHROME_MANIFESTS += ['tests/chrome/chrome.ini']
 
 TESTING_JS_MODULES += [
     'tests/PromiseTestUtils.jsm',
+    'tests/xpcshell/TestIntegration.jsm',
 ]
 
 SPHINX_TREES['toolkit_modules'] = 'docs'
 
 EXTRA_JS_MODULES += [
     'addons/MatchPattern.jsm',
     'addons/WebNavigation.jsm',
     'addons/WebNavigationContent.js',
@@ -37,16 +38,17 @@ EXTRA_JS_MODULES += [
     'FileUtils.jsm',
     'Finder.jsm',
     'Geometry.jsm',
     'GMPInstallManager.jsm',
     'GMPUtils.jsm',
     'Http.jsm',
     'InlineSpellChecker.jsm',
     'InlineSpellCheckerContent.jsm',
+    'Integration.jsm',
     'LoadContextInfo.jsm',
     'Locale.jsm',
     'Log.jsm',
     'NewTabUtils.jsm',
     'ObjectUtils.jsm',
     'PageMenu.jsm',
     'PageMetadata.jsm',
     'PermissionsUtils.jsm',
new file mode 100644
--- /dev/null
+++ b/toolkit/modules/tests/xpcshell/TestIntegration.jsm
@@ -0,0 +1,42 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/*
+ * Internal module used to test the generation of Integration.jsm getters.
+ */
+
+"use strict";
+
+this.EXPORTED_SYMBOLS = [
+  "TestIntegration",
+];
+
+const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+
+Cu.import("resource://gre/modules/Task.jsm");
+
+this.TestIntegration = {
+  value: "value",
+
+  get valueFromThis() {
+    return this.value;
+  },
+
+  get property() {
+    return this._property;
+  },
+
+  set property(value) {
+    this._property = value;
+  },
+
+  method(argument) {
+    this.methodArgument = argument;
+    return "method" + argument;
+  },
+
+  asyncMethod: Task.async(function* (argument) {
+    this.asyncMethodArgument = argument;
+    return "asyncMethod" + argument;
+  }),
+};
new file mode 100644
--- /dev/null
+++ b/toolkit/modules/tests/xpcshell/test_Integration.js
@@ -0,0 +1,238 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/*
+ * Tests the Integration.jsm module.
+ */
+
+"use strict";
+
+const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+
+Cu.import("resource://gre/modules/Integration.jsm", this);
+Cu.import("resource://gre/modules/Services.jsm", this);
+Cu.import("resource://gre/modules/Task.jsm", this);
+
+const TestIntegration = {
+  value: "value",
+
+  get valueFromThis() {
+    return this.value;
+  },
+
+  get property() {
+    return this._property;
+  },
+
+  set property(value) {
+    this._property = value;
+  },
+
+  method(argument) {
+    this.methodArgument = argument;
+    return "method" + argument;
+  },
+
+  asyncMethod: Task.async(function* (argument) {
+    this.asyncMethodArgument = argument;
+    return "asyncMethod" + argument;
+  }),
+};
+
+let overrideFn = base => ({
+  value: "overridden-value",
+
+  get property() {
+    return "overridden-" + base.__lookupGetter__("property").call(this);
+  },
+
+  set property(value) {
+    base.__lookupSetter__("property").call(this, "overridden-" + value);
+  },
+
+  method() {
+    return "overridden-" + base.method.apply(this, arguments);
+  },
+
+  asyncMethod: Task.async(function* () {
+    return "overridden-" + (yield base.asyncMethod.apply(this, arguments));
+  }),
+});
+
+let superOverrideFn = base => ({
+  __proto__: base,
+
+  value: "overridden-value",
+
+  get property() {
+    return "overridden-" + super.property;
+  },
+
+  set property(value) {
+    super.property = "overridden-" + value;
+  },
+
+  method() {
+    return "overridden-" + super.method(...arguments);
+  },
+
+  asyncMethod: Task.async(function* () {
+    // We cannot use the "super" keyword in methods defined using "Task.async".
+    return "overridden-" + (yield base.asyncMethod.apply(this, arguments));
+  }),
+});
+
+/**
+ * Fails the test if the results of method invocations on the combined object
+ * don't match the expected results based on how many overrides are registered.
+ *
+ * @param combined
+ *        The combined object based on the TestIntegration root.
+ * @param overridesCount
+ *        Zero if the root object is not overridden, or a higher value to test
+ *        the presence of one or more integration overrides.
+ */
+function* assertCombinedResults(combined, overridesCount) {
+  let expectedValue = overridesCount > 0 ? "overridden-value" : "value";
+  let prefix = "overridden-".repeat(overridesCount);
+
+  Assert.equal(combined.value, expectedValue);
+  Assert.equal(combined.valueFromThis, expectedValue);
+
+  combined.property = "property";
+  Assert.equal(combined.property, prefix.repeat(2) + "property");
+
+  combined.methodArgument = "";
+  Assert.equal(combined.method("-argument"), prefix + "method-argument");
+  Assert.equal(combined.methodArgument, "-argument");
+
+  combined.asyncMethodArgument = "";
+  Assert.equal(yield combined.asyncMethod("-argument"),
+               prefix + "asyncMethod-argument");
+  Assert.equal(combined.asyncMethodArgument, "-argument");
+}
+
+/**
+ * Fails the test if the results of method invocations on the combined object
+ * for the "testModule" integration point don't match the expected results based
+ * on how many overrides are registered.
+ *
+ * @param overridesCount
+ *        Zero if the root object is not overridden, or a higher value to test
+ *        the presence of one or more integration overrides.
+ */
+function* assertCurrentCombinedResults(overridesCount) {
+  let combined = Integration.testModule.getCombined(TestIntegration);
+  yield assertCombinedResults(combined, overridesCount);
+}
+
+/**
+ * Checks the initial state with no integration override functions registered.
+ */
+add_task(function* test_base() {
+  yield assertCurrentCombinedResults(0);
+});
+
+/**
+ * Registers and unregisters an integration override function.
+ */
+add_task(function* test_override() {
+  Integration.testModule.register(overrideFn);
+  yield assertCurrentCombinedResults(1);
+
+  // Registering the same function more than once has no effect.
+  Integration.testModule.register(overrideFn);
+  yield assertCurrentCombinedResults(1);
+
+  Integration.testModule.unregister(overrideFn);
+  yield assertCurrentCombinedResults(0);
+});
+
+/**
+ * Registers and unregisters more than one integration override function, of
+ * which one uses the prototype and the "super" keyword to access the base.
+ */
+add_task(function* test_override_super_multiple() {
+  Integration.testModule.register(overrideFn);
+  Integration.testModule.register(superOverrideFn);
+  yield assertCurrentCombinedResults(2);
+
+  Integration.testModule.unregister(overrideFn);
+  yield assertCurrentCombinedResults(1);
+
+  Integration.testModule.unregister(superOverrideFn);
+  yield assertCurrentCombinedResults(0);
+});
+
+/**
+ * Registers an integration override function that throws an exception, and
+ * ensures that this does not block other functions from being registered.
+ */
+add_task(function* test_override_error() {
+  let errorOverrideFn = base => { throw "Expected error." };
+
+  Integration.testModule.register(errorOverrideFn);
+  Integration.testModule.register(overrideFn);
+  yield assertCurrentCombinedResults(1);
+
+  Integration.testModule.unregister(errorOverrideFn);
+  Integration.testModule.unregister(overrideFn);
+  yield assertCurrentCombinedResults(0);
+});
+
+/**
+ * Checks that state saved using the "this" reference is preserved as a shallow
+ * copy when registering new integration override functions.
+ */
+add_task(function* test_state_preserved() {
+  let valueObject = { toString: () => "toString" };
+
+  let combined = Integration.testModule.getCombined(TestIntegration);
+  combined.property = valueObject;
+  Assert.ok(combined.property === valueObject);
+
+  Integration.testModule.register(overrideFn);
+  combined = Integration.testModule.getCombined(TestIntegration);
+  Assert.equal(combined.property, "overridden-toString");
+
+  Integration.testModule.unregister(overrideFn);
+  combined = Integration.testModule.getCombined(TestIntegration);
+  Assert.ok(combined.property === valueObject);
+});
+
+/**
+ * Checks that the combined integration objects cannot be used with XPCOM.
+ *
+ * This is limited by the fact that interfaces with the "[function]" annotation,
+ * for example nsIObserver, do not call the QueryInterface implementation.
+ */
+add_task(function* test_xpcom_throws() {
+  let combined = Integration.testModule.getCombined(TestIntegration);
+
+  // This calls QueryInterface because it looks for nsISupportsWeakReference.
+  Assert.throws(() => Services.obs.addObserver(combined, "test-topic", true),
+                "NS_NOINTERFACE");
+});
+
+/**
+ * Checks that getters defined by defineModuleGetter are able to retrieve the
+ * latest version of the combined integration object.
+ */
+add_task(function* test_defineModuleGetter() {
+  let objectForGetters = {};
+
+  // Test with and without the optional "symbol" parameter.
+  Integration.testModule.defineModuleGetter(objectForGetters,
+    "TestIntegration", "resource://testing-common/TestIntegration.jsm");
+  Integration.testModule.defineModuleGetter(objectForGetters,
+    "integration", "resource://testing-common/TestIntegration.jsm",
+    "TestIntegration");
+
+  Integration.testModule.register(overrideFn);
+  yield assertCombinedResults(objectForGetters.integration, 1);
+  yield assertCombinedResults(objectForGetters.TestIntegration, 1);
+
+  Integration.testModule.unregister(overrideFn);
+  yield assertCombinedResults(objectForGetters.integration, 0);
+  yield assertCombinedResults(objectForGetters.TestIntegration, 0);
+});
--- a/toolkit/modules/tests/xpcshell/xpcshell.ini
+++ b/toolkit/modules/tests/xpcshell/xpcshell.ini
@@ -16,16 +16,17 @@ skip-if = toolkit == 'android'
 [test_DeferredTask.js]
 skip-if = toolkit == 'android'
 [test_FileUtils.js]
 skip-if = toolkit == 'android'
 [test_GMPInstallManager.js]
 skip-if = toolkit == 'android'
 [test_Http.js]
 skip-if = toolkit == 'android'
+[test_Integration.js]
 [test_jsesc.js]
 skip-if = toolkit == 'android'
 [test_Log.js]
 skip-if = toolkit == 'android'
 [test_MatchPattern.js]
 skip-if = toolkit == 'android'
 [test_MatchGlobs.js]
 skip-if = toolkit == 'android'