From 2d0b0bc8931b638b38c61b7be813777db780e483 Mon Sep 17 00:00:00 2001 From: Yura Zenevich Date: Mon, 11 May 2020 17:45:54 +0000 Subject: [PATCH] Bug 1636490 - rely on garbage collection rather than disabling via UI when testing accessibility panel. r=mtigley Differential Revision: https://phabricator.services.mozilla.com/D74411 --- ...ser_accessibility_fission_switch_target.js | 2 +- ...browser_accessibility_panel_highlighter.js | 4 + ...cessibility_panel_highlighter_multi_tab.js | 22 ++++-- .../client/accessibility/test/browser/head.js | 77 +++++++++++-------- 4 files changed, 67 insertions(+), 38 deletions(-) diff --git a/devtools/client/accessibility/test/browser/browser_accessibility_fission_switch_target.js b/devtools/client/accessibility/test/browser/browser_accessibility_fission_switch_target.js index 21e93992286f..6cbc285739ec 100644 --- a/devtools/client/accessibility/test/browser/browser_accessibility_fission_switch_target.js +++ b/devtools/client/accessibility/test/browser/browser_accessibility_fission_switch_target.js @@ -56,5 +56,5 @@ add_task(async () => { await navigateTo(CONTENT_PROCESS_URL); await runA11yPanelTests(CONTENT_PROCESS_EXPECTED, env); - await disableAccessibilityInspector(env); + await closeTabToolboxAccessibility(env.tab); }); diff --git a/devtools/client/accessibility/test/browser/browser_accessibility_panel_highlighter.js b/devtools/client/accessibility/test/browser/browser_accessibility_panel_highlighter.js index 9f463b11a077..3a9ee5ba7858 100644 --- a/devtools/client/accessibility/test/browser/browser_accessibility_panel_highlighter.js +++ b/devtools/client/accessibility/test/browser/browser_accessibility_panel_highlighter.js @@ -6,6 +6,7 @@ const TEST_URI = '

header

paragraph

'; add_task(async function tabNotHighlighted() { + Services.prefs.setBoolPref("devtools.accessibility.auto-init.enabled", false); await addTab(buildURL(TEST_URI)); const { toolbox } = await openInspector(); const isHighlighted = await toolbox.isToolHighlighted("accessibility"); @@ -17,9 +18,11 @@ add_task(async function tabNotHighlighted() { ); gBrowser.removeCurrentTab(); + Services.prefs.clearUserPref("devtools.accessibility.auto-init.enabled"); }); add_task(async function tabHighlighted() { + Services.prefs.setBoolPref("devtools.accessibility.auto-init.enabled", false); let a11yService = await initA11y(); ok(a11yService, "Accessibility service was started"); await addTab(buildURL(TEST_URI)); @@ -28,4 +31,5 @@ add_task(async function tabHighlighted() { a11yService = null; gBrowser.removeCurrentTab(); + Services.prefs.clearUserPref("devtools.accessibility.auto-init.enabled"); }); diff --git a/devtools/client/accessibility/test/browser/browser_accessibility_panel_highlighter_multi_tab.js b/devtools/client/accessibility/test/browser/browser_accessibility_panel_highlighter_multi_tab.js index 6a0704d8ac9d..4eac38e4bedf 100644 --- a/devtools/client/accessibility/test/browser/browser_accessibility_panel_highlighter_multi_tab.js +++ b/devtools/client/accessibility/test/browser/browser_accessibility_panel_highlighter_multi_tab.js @@ -6,6 +6,8 @@ const TEST_URI = '

header

paragraph

'; add_task(async function() { + Services.prefs.setBoolPref("devtools.accessibility.auto-init.enabled", false); + const { toolbox: toolbox1 } = await addTestTab(buildURL(TEST_URI)); const { toolbox: toolbox2 } = await addTestTab(buildURL(TEST_URI)); const options = await openOptions(toolbox2); @@ -33,15 +35,23 @@ add_task(async function() { await toggleAccessibility(options); await toggleAccessibility(options); - const panel = await toolbox2.selectTool("accessibility"); - await disableAccessibilityInspector({ - panel, - win: panel.panelWin, - doc: panel.panelWin.document, - }); + const { accessibilityProxy, panelWin } = await toolbox2.selectTool( + "accessibility" + ); + // Disable accessibility service through the panel and wait for the shutdown + // event. + const shutdown = accessibilityProxy.accessibilityFront.once("shutdown"); + const disableButton = await BrowserTestUtils.waitForCondition( + () => panelWin.document.getElementById("accessibility-disable-button"), + "Wait for the disable button." + ); + EventUtils.sendMouseEvent({ type: "click" }, disableButton, panelWin); + await shutdown; await checkHighlighted(toolbox1, false); await checkHighlighted(toolbox2, false); + + Services.prefs.clearUserPref("devtools.accessibility.auto-init.enabled"); }); async function openOptions(toolbox) { diff --git a/devtools/client/accessibility/test/browser/head.js b/devtools/client/accessibility/test/browser/head.js index 5bc67d2ba984..d3e67286c390 100644 --- a/devtools/client/accessibility/test/browser/head.js +++ b/devtools/client/accessibility/test/browser/head.js @@ -37,8 +37,6 @@ const { // Enable the Accessibility panel Services.prefs.setBoolPref("devtools.accessibility.enabled", true); -// Disable auto-init -Services.prefs.setBoolPref("devtools.accessibility.auto-init.enabled", false); const SIMULATION_MENU_BUTTON_ID = "#simulation-menu-button"; const TREE_FILTERS_MENU_ID = "accessibility-tree-filters-menu"; @@ -79,20 +77,21 @@ async function initA11y() { * Wait for accessibility service to shut down. We consider it shut down when * an "a11y-init-or-shutdown" event is received with a value of "0". */ -function shutdownA11y() { - if (!Services.appinfo.accessibilityEnabled) { - return Promise.resolve(); - } - - // Force collections to speed up accessibility service shutdown. - Cu.forceGC(); - Cu.forceCC(); - Cu.forceShrinkingGC(); - +function waitForAccessibilityShutdown() { return new Promise(resolve => { + if (!Services.appinfo.accessibilityEnabled) { + resolve(); + return; + } + const observe = (subject, topic, data) => { if (data === "0") { Services.obs.removeObserver(observe, "a11y-init-or-shutdown"); + // Sanity check + ok( + !Services.appinfo.accessibilityEnabled, + "Accessibility disabled in this process" + ); resolve(); } }; @@ -101,12 +100,24 @@ function shutdownA11y() { // accessibility service naturally if there are no more XPCOM references to // a11y related objects (after GC/CC). Services.obs.addObserver(observe, "a11y-init-or-shutdown"); + + // Force garbage collection. + SpecialPowers.gc(); + SpecialPowers.forceShrinkingGC(); + SpecialPowers.forceCC(); }); } +/** + * Ensure that accessibility is completely shutdown. + */ +async function shutdownAccessibility(browser) { + await waitForAccessibilityShutdown(); + await SpecialPowers.spawn(browser, [], waitForAccessibilityShutdown); +} + registerCleanupFunction(async () => { info("Cleaning up..."); - await shutdownA11y(); Services.prefs.clearUserPref("devtools.accessibility.auto-init.enabled"); Services.prefs.clearUserPref("devtools.accessibility.enabled"); }); @@ -154,23 +165,6 @@ async function addTestTab(url) { }; } -/** - * Turn off accessibility features from within the panel. We call it before the - * cleanup function to make sure that the panel is still present. - */ -async function disableAccessibilityInspector(env) { - const { doc, win, panel } = env; - // Disable accessibility service through the panel and wait for the shutdown - // event. - const shutdown = panel.accessibilityProxy.accessibilityFront.once("shutdown"); - const disableButton = await BrowserTestUtils.waitForCondition( - () => doc.getElementById("accessibility-disable-button"), - "Wait for the disable button." - ); - EventUtils.sendMouseEvent({ type: "click" }, disableButton, win); - await shutdown; -} - /** * Open the Accessibility panel for the given tab. * @@ -805,6 +799,27 @@ function addA11yPanelTestsTask(tests, uri, msg, options) { addA11YPanelTask(msg, uri, env => runA11yPanelTests(tests, env), options); } +/** + * Borrowed from framework's shared head. Close toolbox, completely disable + * accessibility and remove the tab. + * @param {Tab} + * tab The tab to close. + * @return {Promise} + * Resolves when the toolbox and tab have been destroyed and closed. + */ +async function closeTabToolboxAccessibility(tab = gBrowser.selectedTab) { + if (TargetFactory.isKnownTab(tab)) { + const target = await TargetFactory.forTab(tab); + if (target) { + await gDevTools.closeToolbox(target); + } + } + + await shutdownAccessibility(gBrowser.getBrowserForTab(tab)); + await removeTab(tab); + await new Promise(resolve => setTimeout(resolve, 0)); +} + /** * A wrapper function around add_task that sets up the test environment, runs * the test and then disables accessibility tools. @@ -818,7 +833,7 @@ function addA11YPanelTask(msg, uri, task, options = {}) { info(msg); const env = await addTestTab(buildURL(uri, options)); await task(env); - await disableAccessibilityInspector(env); + await closeTabToolboxAccessibility(env.tab); }); }