Bug 1605435 - pass simulate function to a11y panel client instead of the actual simulator actor. r=rcaliman

Differential Revision: https://phabricator.services.mozilla.com/D58544

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Yura Zenevich 2020-02-21 04:35:45 +00:00
Родитель 0dd01e36db
Коммит b7c111cdad
10 изменённых файлов: 41 добавлений и 25 удалений

Просмотреть файл

@ -33,6 +33,10 @@ class AccessibilityStartup {
return this._accessibility.accessibleWalkerFront; return this._accessibility.accessibleWalkerFront;
} }
get simulator() {
return this._accessibility.simulatorFront;
}
/** /**
* Determine which features are supported based on the version of the server. * Determine which features are supported based on the version of the server.
* @return {Promise} * @return {Promise}

Просмотреть файл

@ -64,10 +64,6 @@ AccessibilityView.prototype = {
* - fluentBundles {Array} * - fluentBundles {Array}
* array of FluentBundles elements for * array of FluentBundles elements for
* localization * localization
* - simulator {Object}
* front for simulator actor
* responsible for setting color
* matrices in docShell
* - toolbox {Object} * - toolbox {Object}
* devtools toolbox. * devtools toolbox.
* - getAccessibilityTreeRoot {Function} * - getAccessibilityTreeRoot {Function}
@ -84,17 +80,21 @@ AccessibilityView.prototype = {
* Audit function that will start * Audit function that will start
* accessibility audit for given types * accessibility audit for given types
* of accessibility issues. * of accessibility issues.
* - simulate {null|Function}
* Apply simulation of a given type
* (by setting color matrices in
* docShell).
*/ */
async initialize({ async initialize({
front, front,
supports, supports,
fluentBundles, fluentBundles,
simulator,
toolbox, toolbox,
getAccessibilityTreeRoot, getAccessibilityTreeRoot,
startListeningForAccessibilityEvents, startListeningForAccessibilityEvents,
stopListeningForAccessibilityEvents, stopListeningForAccessibilityEvents,
audit, audit,
simulate,
}) { }) {
// Make sure state is reset every time accessibility panel is initialized. // Make sure state is reset every time accessibility panel is initialized.
await this.store.dispatch(reset(front, supports)); await this.store.dispatch(reset(front, supports));
@ -102,12 +102,12 @@ AccessibilityView.prototype = {
const mainFrame = MainFrame({ const mainFrame = MainFrame({
accessibility: front, accessibility: front,
fluentBundles, fluentBundles,
simulator,
toolbox, toolbox,
getAccessibilityTreeRoot, getAccessibilityTreeRoot,
startListeningForAccessibilityEvents, startListeningForAccessibilityEvents,
stopListeningForAccessibilityEvents, stopListeningForAccessibilityEvents,
audit, audit,
simulate,
}); });
// Render top level component // Render top level component
const provider = createElement(Provider, { store: this.store }, mainFrame); const provider = createElement(Provider, { store: this.store }, mainFrame);

Просмотреть файл

@ -6,8 +6,7 @@
const { SIMULATE } = require("devtools/client/accessibility/constants"); const { SIMULATE } = require("devtools/client/accessibility/constants");
exports.simulate = (simulator, simTypes = []) => dispatch => exports.simulate = (simulateFunc, simTypes = []) => dispatch =>
simulator simulateFunc(simTypes)
.simulate({ types: simTypes })
.then(success => dispatch({ error: !success, simTypes, type: SIMULATE })) .then(success => dispatch({ error: !success, simTypes, type: SIMULATE }))
.catch(error => dispatch({ error, type: SIMULATE })); .catch(error => dispatch({ error, type: SIMULATE }));

Просмотреть файл

@ -59,12 +59,12 @@ class MainFrame extends Component {
dispatch: PropTypes.func.isRequired, dispatch: PropTypes.func.isRequired,
auditing: PropTypes.array.isRequired, auditing: PropTypes.array.isRequired,
supports: PropTypes.object, supports: PropTypes.object,
simulator: PropTypes.object,
toolbox: PropTypes.object.isRequired, toolbox: PropTypes.object.isRequired,
getAccessibilityTreeRoot: PropTypes.func.isRequired, getAccessibilityTreeRoot: PropTypes.func.isRequired,
startListeningForAccessibilityEvents: PropTypes.func.isRequired, startListeningForAccessibilityEvents: PropTypes.func.isRequired,
stopListeningForAccessibilityEvents: PropTypes.func.isRequired, stopListeningForAccessibilityEvents: PropTypes.func.isRequired,
audit: PropTypes.func.isRequired, audit: PropTypes.func.isRequired,
simulate: PropTypes.func,
}; };
} }
@ -128,7 +128,7 @@ class MainFrame extends Component {
fluentBundles, fluentBundles,
enabled, enabled,
auditing, auditing,
simulator, simulate,
toolbox, toolbox,
getAccessibilityTreeRoot, getAccessibilityTreeRoot,
startListeningForAccessibilityEvents, startListeningForAccessibilityEvents,
@ -150,7 +150,7 @@ class MainFrame extends Component {
Toolbar({ Toolbar({
accessibility, accessibility,
audit, audit,
simulator, simulate,
toolboxDoc: toolbox.doc, toolboxDoc: toolbox.doc,
}), }),
isAuditing && AuditProgressOverlay(), isAuditing && AuditProgressOverlay(),

Просмотреть файл

@ -58,7 +58,7 @@ const SIMULATION_MENU_LABELS = {
class SimulationMenuButton extends Component { class SimulationMenuButton extends Component {
static get propTypes() { static get propTypes() {
return { return {
simulator: PropTypes.object.isRequired, simulate: PropTypes.func,
simulation: PropTypes.object.isRequired, simulation: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired, dispatch: PropTypes.func.isRequired,
toolboxDoc: PropTypes.object.isRequired, toolboxDoc: PropTypes.object.isRequired,
@ -72,20 +72,20 @@ class SimulationMenuButton extends Component {
} }
disableSimulation() { disableSimulation() {
const { dispatch, simulator } = this.props; const { dispatch, simulate: simulateFunc } = this.props;
dispatch(actions.simulate(simulator)); dispatch(actions.simulate(simulateFunc));
} }
toggleSimulation(simKey) { toggleSimulation(simKey) {
const { dispatch, simulation, simulator } = this.props; const { dispatch, simulation, simulate: simulateFunc } = this.props;
if (!simulation[simKey]) { if (!simulation[simKey]) {
if (gTelemetry) { if (gTelemetry) {
gTelemetry.keyedScalarAdd(TELEMETRY_SIMULATION_ACTIVATED, simKey, 1); gTelemetry.keyedScalarAdd(TELEMETRY_SIMULATION_ACTIVATED, simKey, 1);
} }
dispatch(actions.simulate(simulator, [simKey])); dispatch(actions.simulate(simulateFunc, [simKey]));
return; return;
} }

Просмотреть файл

@ -41,9 +41,9 @@ class Toolbar extends Component {
dispatch: PropTypes.func.isRequired, dispatch: PropTypes.func.isRequired,
accessibility: PropTypes.object.isRequired, accessibility: PropTypes.object.isRequired,
canBeDisabled: PropTypes.bool.isRequired, canBeDisabled: PropTypes.bool.isRequired,
simulator: PropTypes.object,
toolboxDoc: PropTypes.object.isRequired, toolboxDoc: PropTypes.object.isRequired,
audit: PropTypes.func.isRequired, audit: PropTypes.func.isRequired,
simulate: PropTypes.func,
}; };
} }
@ -86,7 +86,7 @@ class Toolbar extends Component {
} }
render() { render() {
const { canBeDisabled, simulator, toolboxDoc, audit } = this.props; const { canBeDisabled, simulate, toolboxDoc, audit } = this.props;
const { disabling } = this.state; const { disabling } = this.state;
const disableButtonStr = disabling const disableButtonStr = disabling
? "accessibility.disabling" ? "accessibility.disabling"
@ -102,13 +102,13 @@ class Toolbar extends Component {
title = L10N.getStr("accessibility.disable.disabledTitle"); title = L10N.getStr("accessibility.disable.disabledTitle");
} }
const optionalSimulationSection = simulator const optionalSimulationSection = simulate
? [ ? [
div({ div({
role: "separator", role: "separator",
className: "devtools-separator", className: "devtools-separator",
}), }),
SimulationMenuButton({ simulator, toolboxDoc }), SimulationMenuButton({ simulate, toolboxDoc }),
] ]
: []; : [];

Просмотреть файл

@ -64,6 +64,7 @@ function AccessibilityPanel(iframeWindow, toolbox, startup) {
this this
); );
this.audit = this.audit.bind(this); this.audit = this.audit.bind(this);
this.simulate = this.simulate.bind(this);
EventEmitter.decorate(this); EventEmitter.decorate(this);
} }
@ -104,7 +105,6 @@ AccessibilityPanel.prototype = {
await this.startup.initAccessibility(); await this.startup.initAccessibility();
this.picker = new Picker(this); this.picker = new Picker(this);
this.simulator = await this.front.getSimulator();
this.fluentBundles = await this.createFluentBundles(); this.fluentBundles = await this.createFluentBundles();
this.updateA11YServiceDurationTimer(); this.updateA11YServiceDurationTimer();
@ -183,7 +183,6 @@ AccessibilityPanel.prototype = {
front: this.front, front: this.front,
supports: this.supports, supports: this.supports,
fluentBundles: this.fluentBundles, fluentBundles: this.fluentBundles,
simulator: this.simulator,
toolbox: this._toolbox, toolbox: this._toolbox,
getAccessibilityTreeRoot: this.getAccessibilityTreeRoot, getAccessibilityTreeRoot: this.getAccessibilityTreeRoot,
startListeningForAccessibilityEvents: this startListeningForAccessibilityEvents: this
@ -191,6 +190,7 @@ AccessibilityPanel.prototype = {
stopListeningForAccessibilityEvents: this stopListeningForAccessibilityEvents: this
.stopListeningForAccessibilityEvents, .stopListeningForAccessibilityEvents,
audit: this.audit, audit: this.audit,
simulate: this.startup.simulator && this.simulate,
}); });
}, },
@ -353,6 +353,10 @@ AccessibilityPanel.prototype = {
}); });
}, },
simulate(types) {
return this.startup.simulator.simulate({ types });
},
get front() { get front() {
return this.startup.accessibility; return this.startup.accessibility;
}, },

Просмотреть файл

@ -44,13 +44,21 @@ add_task(async function() {
"The AccessibleWalkerFront was returned" "The AccessibleWalkerFront was returned"
); );
const a11ySimulator = await accessibility.getSimulator(); const a11ySimulator = accessibility.simulatorFront;
const webRenderEnabled = isWebRenderEnabled(window); const webRenderEnabled = isWebRenderEnabled(window);
is( is(
!!a11ySimulator, !!a11ySimulator,
webRenderEnabled, webRenderEnabled,
`The SimulatorFront was${webRenderEnabled ? "" : " not"} returned.` `The SimulatorFront was${webRenderEnabled ? "" : " not"} returned.`
); );
if (webRenderEnabled) {
ok(accessibility.simulatorFront, "Accessible simulator was initialized");
is(
a11ySimulator,
accessibility.simulatorFront,
"The SimulatorFront was returned"
);
}
checkAccessibilityState(accessibility, { checkAccessibilityState(accessibility, {
enabled: false, enabled: false,

Просмотреть файл

@ -72,7 +72,7 @@ add_task(async function() {
MAIN_DOMAIN + "doc_accessibility.html" MAIN_DOMAIN + "doc_accessibility.html"
); );
const simulator = await accessibility.getSimulator(); const simulator = accessibility.simulatorFront;
if (!simulator) { if (!simulator) {
ok(!isWebRenderEnabled(window), "Web render is disabled."); ok(!isWebRenderEnabled(window), "Web render is disabled.");

Просмотреть файл

@ -199,6 +199,7 @@ class AccessibilityFront extends FrontClassWithSpec(accessibilitySpec) {
// correctly. // correctly.
async bootstrap() { async bootstrap() {
this.accessibleWalkerFront = await super.getWalker(); this.accessibleWalkerFront = await super.getWalker();
this.simulatorFront = await super.getSimulator();
({ ({
enabled: this.enabled, enabled: this.enabled,
canBeEnabled: this.canBeEnabled, canBeEnabled: this.canBeEnabled,