Bug 1420485 - Fix 'message manager count' failure when browser_ext_tabs_insertCSS.js is executed first. r=mixedpuppy, a=RyanVM
authorLuca Greco <lgreco@mozilla.com>
Mon, 29 Jan 2018 17:24:57 +0100
changeset 454717 05fd88206d24afef45187cf35c6f8b04d496fc9b
parent 454716 a20b24dc938970597c9268b11e4cbc4f8ae3bcb2
child 454718 16970266565679053bf6a9c63ad6084c14422d0b
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, RyanVM
bugs1420485
milestone59.0
Bug 1420485 - Fix 'message manager count' failure when browser_ext_tabs_insertCSS.js is executed first. r=mixedpuppy, a=RyanVM MozReview-Commit-ID: HEWS8Lxldbi
browser/components/extensions/test/browser/browser_ext_tabs_insertCSS.js
--- a/browser/components/extensions/test/browser/browser_ext_tabs_insertCSS.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_insertCSS.js
@@ -1,16 +1,26 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 add_task(async function testExecuteScript() {
   let {MessageChannel} = Cu.import("resource://gre/modules/MessageChannel.jsm", {});
 
-  let messageManagersSize = MessageChannel.messageManagers.size;
+  // When the first extension is started, ProxyMessenger.init adds MessageChannel
+  // listeners for Services.mm and Services.ppmm, and they are never unsubscribed.
+  // We have to exclude them after the extension has been unloaded to get an accurate
+  // test.
+  function getMessageManagersSize(messageManagers) {
+    return Array.from(messageManagers).filter(([mm]) => {
+      return !([Services.mm, Services.ppmm].includes(mm));
+    }).length;
+  }
+
+  let messageManagersSize = getMessageManagersSize(MessageChannel.messageManagers);
   let responseManagersSize = MessageChannel.responseManagers.size;
 
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://mochi.test:8888/", true);
 
   async function background() {
     let tasks = [
       {
         background: "rgba(0, 0, 0, 0)",
@@ -102,17 +112,18 @@ add_task(async function testExecuteScrip
   await extension.awaitFinish("insertCSS");
 
   await extension.unload();
 
   await BrowserTestUtils.removeTab(tab);
 
   // Make sure that we're not holding on to references to closed message
   // managers.
-  is(MessageChannel.messageManagers.size, messageManagersSize, "Message manager count");
+  is(getMessageManagersSize(MessageChannel.messageManagers), messageManagersSize,
+     "Message manager count");
   is(MessageChannel.responseManagers.size, responseManagersSize, "Response manager count");
   is(MessageChannel.pendingResponses.size, 0, "Pending response count");
 });
 
 add_task(async function testInsertCSS_cleanup() {
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://mochi.test:8888/", true);
 
   async function background() {