mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
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
This commit is contained in:
parent
48a5a640b4
commit
2d0b0bc893
@ -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);
|
||||
});
|
||||
|
@ -6,6 +6,7 @@
|
||||
const TEST_URI = '<h1 id="h1">header</h1><p id="p">paragraph</p>';
|
||||
|
||||
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");
|
||||
});
|
||||
|
@ -6,6 +6,8 @@
|
||||
const TEST_URI = '<h1 id="h1">header</h1><p id="p">paragraph</p>';
|
||||
|
||||
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) {
|
||||
|
@ -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() {
|
||||
function waitForAccessibilityShutdown() {
|
||||
return new Promise(resolve => {
|
||||
if (!Services.appinfo.accessibilityEnabled) {
|
||||
return Promise.resolve();
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
// Force collections to speed up accessibility service shutdown.
|
||||
Cu.forceGC();
|
||||
Cu.forceCC();
|
||||
Cu.forceShrinkingGC();
|
||||
|
||||
return new Promise(resolve => {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user