Bug 967302 - Fix leak caused by the XUL alert shown at the end of an installation by mocking the alerts service. r=myk
authorMarco Castelluccio <mar.castelluccio@studenti.unina.it>
Sat, 12 Jul 2014 02:59:51 +0200
changeset 215635 4625ba9d9a0915bc0bbb84c8f588fb1163eb078e
parent 215634 44776990ebd01fada385c16d9944337828032f54
child 215636 42c54f0e2bf8af2029edb115dfa7c51416de4a9d
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmyk
bugs967302
milestone33.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 967302 - Fix leak caused by the XUL alert shown at the end of an installation by mocking the alerts service. r=myk
dom/tests/mochitest/webapps/head.js
dom/tests/mochitest/webapps/test_bug_771294.xul
dom/tests/mochitest/webapps/test_getNotInstalled.xul
toolkit/webapps/tests/head.js
--- a/dom/tests/mochitest/webapps/head.js
+++ b/dom/tests/mochitest/webapps/head.js
@@ -1,11 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
+const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
 function runAll(steps) {
   SimpleTest.waitForExplicitFinish();
 
   /**
    * On Mac, apps aren't considered launchable right after they've been
    * installed because the OS takes some time to detect them (so
    * nsIMacWebAppUtils::pathForAppWithIdentifier() returns null).
    * That causes methods like mgmt.getAll() to exclude the app from their
@@ -41,8 +45,49 @@ function confirmNextInstall() {
                    PopupNotifications.panel;
 
   function onPopupShown() {
     popupPanel.removeEventListener("popupshown", onPopupShown, false);
     SpecialPowers.wrap(this).childNodes[0].button.doCommand();
   }
   popupPanel.addEventListener("popupshown", onPopupShown, false);
 }
+
+// We need to mock the Alerts service, otherwise the alert that is shown
+// at the end of an installation makes the test leak the app's icon.
+
+const CID = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID();
+const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
+const ALERTS_SERVICE_CID = Components.ID(Cc[ALERTS_SERVICE_CONTRACT_ID].number);
+
+var AlertsService = {
+  classID: Components.ID(CID),
+
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory,
+                                         Ci.nsIAlertsService]),
+
+  createInstance: function(aOuter, aIID) {
+    if (aOuter) {
+      throw Cr.NS_ERROR_NO_AGGREGATION;
+    }
+
+    return this.QueryInterface(aIID);
+  },
+
+  init: function() {
+    Components.manager.nsIComponentRegistrar.registerFactory(this.classID,
+      "", ALERTS_SERVICE_CONTRACT_ID, this);
+  },
+
+  restore: function() {
+    Components.manager.nsIComponentRegistrar.registerFactory(ALERTS_SERVICE_CID,
+      "", ALERTS_SERVICE_CONTRACT_ID, null);
+  },
+
+  showAlertNotification: function() {
+  },
+};
+
+AlertsService.init();
+
+SimpleTest.registerCleanupFunction(() => {
+  AlertsService.restore();
+});
--- a/dom/tests/mochitest/webapps/test_bug_771294.xul
+++ b/dom/tests/mochitest/webapps/test_bug_771294.xul
@@ -12,19 +12,16 @@
   <script type="application/javascript" src="head.js"/>
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=771294"
      target="_blank">Mozilla Bug 771294</a>
   </body>
 
 <script>
-const Ci = Components.interfaces;
-const Cu = Components.utils;
-
 SimpleTest.waitForExplicitFinish();
 
 SpecialPowers.setAllAppsLaunchable(true);
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/PopupNotifications.jsm");
 
 let blocked = true;
--- a/dom/tests/mochitest/webapps/test_getNotInstalled.xul
+++ b/dom/tests/mochitest/webapps/test_getNotInstalled.xul
@@ -13,17 +13,16 @@
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=741549"
      target="_blank">Mozilla Bug 781379</a>
   </body>
 
 <script type="application/javascript;version=1.8">
 
-const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 Cu.import("resource://gre/modules/Webapps.jsm");
 
 // We use a different origin than other webapps test files because we compare
 // the number of apps before and after installing this one; and if a test file
 // installs our app and then doesn't uninstall it (f.e. because it isn't written
 // to clean up after itself, or because it throws an exception or times out),
 // then this test will *reinstall* the app, and the number of apps won't change,
 // which will look like a failure in this test although it's actually a failure
--- a/toolkit/webapps/tests/head.js
+++ b/toolkit/webapps/tests/head.js
@@ -1,13 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
 
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/Promise.jsm");
 Cu.import("resource://gre/modules/WebappOSUtils.jsm");
 Cu.import("resource://gre/modules/NativeApp.jsm");
 
 const LINUX = navigator.platform.startsWith("Linux");
 const MAC = navigator.platform.startsWith("Mac");
@@ -539,8 +540,49 @@ let writeToFile = Task.async(function*(a
   let file;
   try {
     file = yield OS.File.open(aPath, { truncate: true, write: true }, { unixMode: 0o777 });
     yield file.write(data);
   } finally {
     yield file.close();
   }
 });
+
+// We need to mock the Alerts service, otherwise the alert that is shown
+// at the end of an installation makes the test leak the app's icon.
+
+const CID = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID();
+const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
+const ALERTS_SERVICE_CID = Components.ID(Cc[ALERTS_SERVICE_CONTRACT_ID].number);
+
+let AlertsService = {
+  classID: Components.ID(CID),
+
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory,
+                                         Ci.nsIAlertsService]),
+
+  createInstance: function(aOuter, aIID) {
+    if (aOuter) {
+      throw Cr.NS_ERROR_NO_AGGREGATION;
+    }
+
+    return this.QueryInterface(aIID);
+  },
+
+  init: function() {
+    Components.manager.nsIComponentRegistrar.registerFactory(this.classID,
+      "", ALERTS_SERVICE_CONTRACT_ID, this);
+  },
+
+  restore: function() {
+    Components.manager.nsIComponentRegistrar.registerFactory(ALERTS_SERVICE_CID,
+      "", ALERTS_SERVICE_CONTRACT_ID, null);
+  },
+
+  showAlertNotification: function() {
+  },
+};
+
+AlertsService.init();
+
+SimpleTest.registerCleanupFunction(() => {
+  AlertsService.restore();
+});