From 8b26cd73bb8a7802e3e9d18acbf3738da8e42aef Mon Sep 17 00:00:00 2001 From: Kashav Madan Date: Tue, 1 Jun 2021 20:06:48 +0000 Subject: [PATCH] Bug 1706445 - Fix test helpers that use "SessionStore:update", r=nika,perftest-reviewers,sparky Also skips a frame script OOM test for Fission. Differential Revision: https://phabricator.services.mozilla.com/D115930 --- .../components/sessionstore/test/browser.ini | 5 +- .../BrowserTestUtils/BrowserTestUtils.jsm | 56 +++++++++---------- .../talos/tests/cpstartup/extension/api.js | 21 +++---- testing/talos/talos/tests/tabpaint/api.js | 22 ++++---- 4 files changed, 48 insertions(+), 56 deletions(-) diff --git a/browser/components/sessionstore/test/browser.ini b/browser/components/sessionstore/test/browser.ini index e603006f77e9..b9ebba3f5a4a 100644 --- a/browser/components/sessionstore/test/browser.ini +++ b/browser/components/sessionstore/test/browser.ini @@ -289,6 +289,7 @@ skip-if = verify && debug run-if = e10s tags = openUILinkIn [browser_send_async_message_oom.js] +skip-if = fission # Tests that the frame script OOMs, which is unused in Fission. [browser_sessionStoreContainer.js] [browser_windowStateContainer.js] [browser_1234021.js] @@ -328,7 +329,7 @@ skip-if = true #Bug 1455602 [browser_reopen_all_windows.js] [browser_ignore_updates_crashed_tabs.js] run-if = e10s && crashreporter -skip-if = +skip-if = asan apple_silicon # crash - (os == "win" && fission && verify) # bug 1709907 \ No newline at end of file + (os == "win" && fission && verify) # bug 1709907 diff --git a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm index c3f4b6183ffa..680080b5338c 100644 --- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm +++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm @@ -1119,6 +1119,7 @@ var BrowserTestUtils = { let domWinClosedPromise = BrowserTestUtils.domWindowClosed(win); let promises = [domWinClosedPromise]; let winType = win.document.documentElement.getAttribute("windowtype"); + let flushTopic = "sessionstore-browser-shutdown-flush"; if (winType == "navigator:browser") { let finalMsgsPromise = new Promise(resolve => { @@ -1128,24 +1129,21 @@ var BrowserTestUtils = { browserSet.forEach(browser => { win.gBrowser._insertBrowser(win.gBrowser.getTabForBrowser(browser)); }); - let mm = win.getGroupMessageManager("browsers"); - mm.addMessageListener( - "SessionStore:update", - function onMessage(msg) { - if (browserSet.has(msg.target) && msg.data.isFinal) { - browserSet.delete(msg.target); - if (!browserSet.size) { - mm.removeMessageListener("SessionStore:update", onMessage); - // Give the TabStateFlusher a chance to react to this final - // update and for the TabStateFlusher.flushWindow promise - // to resolve before we resolve. - TestUtils.executeSoon(resolve); - } - } - }, - true - ); + let observer = (subject, topic, data) => { + if (browserSet.has(subject)) { + browserSet.delete(subject); + } + if (!browserSet.size) { + Services.obs.removeObserver(observer, flushTopic); + // Give the TabStateFlusher a chance to react to this final + // update and for the TabStateFlusher.flushWindow promise + // to resolve before we resolve. + TestUtils.executeSoon(resolve); + } + }; + + Services.obs.addObserver(observer, flushTopic); }); promises.push(finalMsgsPromise); @@ -1165,19 +1163,17 @@ var BrowserTestUtils = { */ waitForSessionStoreUpdate(tab) { return new Promise(resolve => { - let { messageManager: mm, frameLoader } = tab.linkedBrowser; - mm.addMessageListener( - "SessionStore:update", - function onMessage(msg) { - if (msg.targetFrameLoader == frameLoader && msg.data.isFinal) { - mm.removeMessageListener("SessionStore:update", onMessage); - // Wait for the next event tick to make sure other listeners are - // called. - TestUtils.executeSoon(() => resolve()); - } - }, - true - ); + let browser = tab.linkedBrowser; + let flushTopic = "sessionstore-browser-shutdown-flush"; + let observer = (subject, topic, data) => { + if (subject === browser) { + Services.obs.removeObserver(observer, flushTopic); + // Wait for the next event tick to make sure other listeners are + // called. + TestUtils.executeSoon(() => resolve()); + } + }; + Services.obs.addObserver(observer, flushTopic); }); }, diff --git a/testing/talos/talos/tests/cpstartup/extension/api.js b/testing/talos/talos/tests/cpstartup/extension/api.js index ec3ce9994f28..816d8144a29c 100644 --- a/testing/talos/talos/tests/cpstartup/extension/api.js +++ b/testing/talos/talos/tests/cpstartup/extension/api.js @@ -23,6 +23,7 @@ ChromeUtils.defineModuleGetter( const PREALLOCATED_PREF = "dom.ipc.processPrelaunch.enabled"; const MESSAGES = ["CPStartup:Go", "CPStartup:BrowserChildReady"]; +const BROWSER_FLUSH_TOPIC = "sessionstore-browser-shutdown-flush"; let domainID = 1; /* global ExtensionAPI */ @@ -117,18 +118,14 @@ this.cpstartup = class extends ExtensionAPI { removeTab(tab) { return new Promise(resolve => { - let { messageManager: mm, frameLoader } = tab.linkedBrowser; - mm.addMessageListener( - "SessionStore:update", - function onMessage(msg) { - if (msg.targetFrameLoader == frameLoader && msg.data.isFinal) { - mm.removeMessageListener("SessionStore:update", onMessage); - resolve(); - } - }, - true - ); - + let browser = tab.linkedBrowser; + let observer = (subject, topic, data) => { + if (subject === browser) { + Services.obs.removeObserver(observer, BROWSER_FLUSH_TOPIC); + resolve(); + } + }; + Services.obs.addObserver(observer, BROWSER_FLUSH_TOPIC); tab.ownerGlobal.gBrowser.removeTab(tab); }); } diff --git a/testing/talos/talos/tests/tabpaint/api.js b/testing/talos/talos/tests/tabpaint/api.js index 72d32989a1ad..ce9e7c0b4988 100644 --- a/testing/talos/talos/tests/tabpaint/api.js +++ b/testing/talos/talos/tests/tabpaint/api.js @@ -36,6 +36,8 @@ const MULTI_OPT_OUT_PREF = "dom.ipc.multiOptOut"; const MESSAGES = ["TabPaint:Go", "TabPaint:Painted"]; +const BROWSER_FLUSH_TOPIC = "sessionstore-browser-shutdown-flush"; + /* globals ExtensionAPI */ this.tabpaint = class extends ExtensionAPI { onStartup() { @@ -201,18 +203,14 @@ this.tabpaint = class extends ExtensionAPI { removeTab(tab) { TalosParentProfiler.mark("Tabpaint: Remove Tab"); return new Promise(resolve => { - let { messageManager: mm, frameLoader } = tab.linkedBrowser; - mm.addMessageListener( - "SessionStore:update", - function onMessage(msg) { - if (msg.targetFrameLoader == frameLoader && msg.data.isFinal) { - mm.removeMessageListener("SessionStore:update", onMessage); - resolve(); - } - }, - true - ); - + let browser = tab.linkedBrowser; + let observer = (subject, topic, data) => { + if (subject === browser) { + Services.obs.removeObserver(observer, BROWSER_FLUSH_TOPIC); + resolve(); + } + }; + Services.obs.addObserver(observer, BROWSER_FLUSH_TOPIC); tab.ownerGlobal.gBrowser.removeTab(tab); }); }