# HG changeset patch # User Luca Greco # Date 1517243097 -3600 # Node ID c79f381e64d6984622694df8b8b9d71d546cf73d # Parent 2f4c36b5cbba613f6bb89c31912745b30a4b1645 Bug 1420485 - Fix 'message manager count' failure when browser_ext_tabs_insertCSS.js is executed first. r=mixedpuppy MozReview-Commit-ID: HEWS8Lxldbi diff --git a/browser/components/extensions/test/browser/browser_ext_tabs_insertCSS.js b/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} = ChromeUtils.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() {