Bug 1287007 - Make browser_ext_tabs_executeScript.js reliable
The ProxyMessenger registers a listener whenever the first addon
starts. Although the map does not have any listeners any more at
the end of the test, the listener itself is not removed because
the message-manager-close notification is not sent for them.
So do not count these persistent message managers in the test.
The actual message managers of interest are those associated with
the (closed) tab.
Note: When the test is run in isolation, it may still fail due
to bugzil.la/1293583. See bug for work-around if you want to test.
MozReview-Commit-ID: IiDHhmvQPcv
--- a/browser/components/extensions/test/browser/browser_ext_tabs_executeScript.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_executeScript.js
@@ -1,17 +1,41 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
add_task(function* testExecuteScript() {
let {MessageChannel} = Cu.import("resource://gre/modules/MessageChannel.jsm", {});
- let messageManagersSize = MessageChannel.messageManagers.size;
- let responseManagersSize = MessageChannel.responseManagers.size;
+ function countMM(messageManagerMap) {
+ let count = 0;
+ // List of permanent message managers in the main process. We should not
+ // count them in the test because MessageChannel unsubscribes when the
+ // message manager closes, which never happens to these, of course.
+ let globalMMs = [
+ Services.mm,
+ Services.ppmm,
+ Services.ppmm.getChildAt(0),
+ ];
+ for (let mm of messageManagerMap.keys()) {
+ // Sanity check: mm is a message manager.
+ try {
+ mm.QueryInterface(Ci.nsIMessageSender);
+ } catch (e) {
+ mm.QueryInterface(Ci.nsIMessageBroadcaster);
+ }
+ if (!globalMMs.includes(mm)) {
+ ++count;
+ }
+ }
+ return count;
+ }
+
+ let messageManagersSize = countMM(MessageChannel.messageManagers);
+ let responseManagersSize = countMM(MessageChannel.responseManagers);
const BASE = "http://mochi.test:8888/browser/browser/components/extensions/test/browser/";
const URL = BASE + "file_iframe_document.html";
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, URL, true);
function background() {
browser.tabs.query({active: true, currentWindow: true}).then(tabs => {
return browser.webNavigation.getAllFrames({tabId: tabs[0].id});
@@ -198,12 +222,12 @@ add_task(function* testExecuteScript() {
yield extension.awaitFinish("executeScript");
yield extension.unload();
yield 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(MessageChannel.responseManagers.size, responseManagersSize, "Response manager count");
+ is(countMM(MessageChannel.messageManagers), messageManagersSize, "Message manager count");
+ is(countMM(MessageChannel.responseManagers), responseManagersSize, "Response manager count");
is(MessageChannel.pendingResponses.size, 0, "Pending response count");
});