Bug 1592776 - Fix cleanup of mock service registration. r=dom-workers-and-storage-reviewers,asuth
authorSimon Giesecke <sgiesecke@mozilla.com>
Wed, 03 Jun 2020 13:15:40 +0000
changeset 597964 001e62003bebee9a0186c03c6432383305d03a7a
parent 597963 fd4400f508cc99e96d6a1a129480d5e59b667128
child 597965 5cdf8bc8c919c522565626cca73fa0556177b929
push id13310
push userffxbld-merge
push dateMon, 29 Jun 2020 14:50:06 +0000
treeherdermozilla-beta@15a59a0afa5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdom-workers-and-storage-reviewers, asuth
bugs1592776
milestone79.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 1592776 - Fix cleanup of mock service registration. r=dom-workers-and-storage-reviewers,asuth Differential Revision: https://phabricator.services.mozilla.com/D77781
dom/notification/test/mochitest/MockServices.js
--- a/dom/notification/test/mochitest/MockServices.js
+++ b/dom/notification/test/mochitest/MockServices.js
@@ -112,16 +112,31 @@ var MockServices = (function() {
       return this.QueryInterface(aIID);
     },
   };
   mockAlertsService = SpecialPowers.wrapCallbackObject(mockAlertsService);
 
   // MockServices API
   return {
     register() {
+      try {
+        this.originalAlertsCID = registrar.contractIDToCID(
+          ALERTS_SERVICE_CONTRACT_ID
+        );
+      } catch (ex) {
+        this.originalAlertsCID = null;
+      }
+      try {
+        this.originalSystemAlertsCID = registrar.contractIDToCID(
+          SYSTEM_ALERTS_SERVICE_CONTRACT_ID
+        );
+      } catch (ex) {
+        this.originalSystemAlertsCID = null;
+      }
+
       registrar.registerFactory(
         MOCK_ALERTS_CID,
         "alerts service",
         ALERTS_SERVICE_CONTRACT_ID,
         mockAlertsService
       );
 
       registrar.registerFactory(
@@ -130,15 +145,36 @@ var MockServices = (function() {
         SYSTEM_ALERTS_SERVICE_CONTRACT_ID,
         mockAlertsService
       );
     },
 
     unregister() {
       registrar.unregisterFactory(MOCK_ALERTS_CID, mockAlertsService);
       registrar.unregisterFactory(MOCK_SYSTEM_ALERTS_CID, mockAlertsService);
+
+      // Passing `null` for the factory re-maps the contract ID to the
+      // entry for its original CID.
+
+      if (this.originalAlertsCID) {
+        registrar.registerFactory(
+          this.originalAlertsCID,
+          "alerts service",
+          ALERTS_SERVICE_CONTRACT_ID,
+          null
+        );
+      }
+
+      if (this.originalSystemAlertsCID) {
+        registrar.registerFactory(
+          this.originalSystemAlertsCID,
+          "system alerts service",
+          SYSTEM_ALERTS_SERVICE_CONTRACT_ID,
+          null
+        );
+      }
     },
 
     activeAlertNotifications,
 
     activeAppNotifications,
   };
 })();