Skip to content

Commit

Permalink
[ChromeVox] Move bridge function to Braille
Browse files Browse the repository at this point in the history
Also forwards parameter `enabled` for GestureCommandHandler bridge.

Skipping test flakiness because there seems to be an unrelated flake regarding favicon database / lacros.

AX-Relnotes: Fixes a bug where gesture controls would break after using Learn Mode.
Bug: b/265481751
Test: New test added
Validate-Test-Flakiness: skip
Change-Id: Idc1b0107d0586c4aa5f79be418e73e72831a8b48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4761026
Auto-Submit: Anastasia Helfinstein <anastasi@google.com>
Reviewed-by: Kyungjun Lee <kyungjunlee@google.com>
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/main@{#1188560}
  • Loading branch information
anastasi-google authored and Chromium LUCI CQ committed Aug 25, 2023
1 parent 35650e7 commit beb76b5
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ export class BrailleCommandHandler {
}

static init() {
if (BrailleCommandHandler.instance) {
throw new Error(
'BrailleCommandHandler cannot be instantiated more than once');
}
BrailleCommandHandler.instance = new BrailleCommandHandler();

BridgeHelper.registerHandler(
BridgeConstants.BrailleCommandHandler.TARGET,
BridgeConstants.BrailleCommandHandler.Action.SET_ENABLED,
enabled => BrailleCommandHandler.setEnabled(enabled));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {BridgeHelper} from '../common/bridge_helper.js';
import {Spannable} from '../common/spannable.js';

import {AbstractEarcons} from './abstract_earcons.js';
import {BrailleCommandHandler} from './braille/braille_command_handler.js';
import {BrailleInterface} from './braille/braille_interface.js';
import {ChromeVoxState} from './chromevox_state.js';
import {TtsInterface} from './tts_interface.js';

export const ChromeVox = {
Expand All @@ -30,6 +32,15 @@ BridgeHelper.registerHandler(
BridgeConstants.Braille.Action.BACK_TRANSLATE,
cells => Promise.resolve(ChromeVox.braille?.backTranslate(cells)));

BridgeHelper.registerHandler(
BridgeConstants.Braille.TARGET,
BridgeConstants.Braille.Action.ENABLE_COMMAND_HANDLER, async enable => {
await ChromeVoxState.ready();
if (BrailleCommandHandler.instance) {
BrailleCommandHandler.setEnabled(enable);
}
});

BridgeHelper.registerHandler(
BridgeConstants.Braille.TARGET, BridgeConstants.Braille.Action.PAN_LEFT,
() => ChromeVox.braille?.panLeft());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ export class AutomationRichEditableText extends AutomationEditableText {
*/
class EditingRangeObserver {
constructor() {
ChromeVoxRange.addObserver(this);
ChromeVoxState.ready().then(() => ChromeVoxRange.addObserver(this));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ BackgroundBridge.Braille = {
BridgeConstants.Braille.Action.BACK_TRANSLATE, cells);
},

/**
* @param {boolean} enabled
* @return {!Promise}
*/
async enableCommandHandler(enabled) {
return BridgeHelper.sendMessage(
BridgeConstants.Braille.TARGET,
BridgeConstants.Braille.Action.ENABLE_COMMAND_HANDLER, enabled);
},

/** @return {!Promise} */
async panLeft() {
return BridgeHelper.sendMessage(
Expand All @@ -55,18 +65,6 @@ BackgroundBridge.Braille = {
},
};

BackgroundBridge.BrailleCommandHandler = {
/**
* @param {boolean} enabled
* @return {!Promise}
*/
async setEnabled(enabled) {
return BridgeHelper.sendMessage(
BridgeConstants.BrailleCommandHandler.TARGET,
BridgeConstants.BrailleCommandHandler.Action.SET_ENABLED, enabled);
},
};

BackgroundBridge.ChromeVoxPrefs = {
/**
* Get the prefs (not including keys).
Expand Down Expand Up @@ -176,7 +174,7 @@ BackgroundBridge.GestureCommandHandler = {
async setEnabled(enabled) {
return BridgeHelper.sendMessage(
BridgeConstants.GestureCommandHandler.TARGET,
BridgeConstants.GestureCommandHandler.Action.SET_ENABLED);
BridgeConstants.GestureCommandHandler.Action.SET_ENABLED, enabled);
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,13 @@ BridgeConstants.Braille = {
TARGET: 'Braille',
Action: {
BACK_TRANSLATE: 'backTranslate',
ENABLE_COMMAND_HANDLER: 'enableCommandHandler',
PAN_LEFT: 'panLeft',
PAN_RIGHT: 'panRight',
WRITE: 'write',
},
};

/** @public {!BridgeEntry} */
BridgeConstants.BrailleCommandHandler = {
TARGET: 'BrailleCommandHandler',
Action: {
SET_ENABLED: 'setEnabled',
},
};

/** @public {!BridgeEntry} */
BridgeConstants.ChromeVoxPrefs = {
TARGET: 'ChromeVoxPrefs',
Expand Down Expand Up @@ -122,6 +115,7 @@ BridgeConstants.LearnMode = {
ON_BRAILLE_KEY_EVENT: 'onBrailleKeyEvent',
ON_KEY_DOWN: 'onKeyDown',
ON_KEY_UP: 'onKeyUp',
READY: 'ready',
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ export class LearnModeBridge {
static onKeyUp(event) {
return BridgeHelper.sendMessage(TARGET, Action.ON_KEY_UP, event);
}

/** @return {!Promise} */
static ready() {
return BridgeHelper.sendMessage(TARGET, Action.READY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class LearnMode {
/**
* Initialize keyboard explorer.
*/
static async init() {
static init() {
// Export global objects from the background page context into this one.
window.backgroundWindow = chrome.extension.getBackgroundPage();

Expand All @@ -44,7 +44,7 @@ export class LearnMode {
chrome.accessibilityPrivate.onAccessibilityGesture.addListener(
LearnMode.onAccessibilityGesture);
chrome.accessibilityPrivate.setKeyboardListener(true, true);
BackgroundBridge.BrailleCommandHandler.setEnabled(false);
BackgroundBridge.Braille.enableCommandHandler(false);
BackgroundBridge.GestureCommandHandler.setEnabled(false);

ChromeVoxKbHandler.commandHandler = LearnMode.onCommand;
Expand All @@ -69,6 +69,9 @@ export class LearnMode {
TARGET, Action.ON_KEY_DOWN, event => LearnMode.onKeyDown(event));
BridgeHelper.registerHandler(
TARGET, Action.ON_KEY_UP, event => LearnMode.onKeyUp(event));
BridgeHelper.registerHandler(TARGET, Action.READY, () => readyPromise);

readyCallback();
}

/**
Expand Down Expand Up @@ -312,7 +315,7 @@ export class LearnMode {
chrome.accessibilityPrivate.onAccessibilityGesture.removeListener(
LearnMode.onAccessibilityGesture);
chrome.accessibilityPrivate.setKeyboardListener(true, false);
BackgroundBridge.BrailleCommandHandler.setEnabled(true);
BackgroundBridge.Braille.enableCommandHandler(true);
BackgroundBridge.GestureCommandHandler.setEnabled(true);
}

Expand Down Expand Up @@ -370,3 +373,9 @@ document.addEventListener('DOMContentLoaded', function() {
function $(id) {
return document.getElementById(id);
}

/** @private {function()} */
let readyCallback;

/** @private {!Promise} */
const readyPromise = new Promise(resolve => readyCallback = resolve);
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ ChromeVoxLearnModeTest = class extends ChromeVoxE2ETest {

await Promise.all([
// Alphabetical based on file path.
importModule(
'BrailleCommandHandler',
'/chromevox/background/braille/braille_command_handler.js'),
importModule(
'CommandHandlerInterface',
'/chromevox/background/command_handler_interface.js'),
importModule(
'GestureCommandHandler',
'/chromevox/background/gesture_command_handler.js'),
importModule(
['BrailleKeyEvent', 'BrailleKeyCommand'],
'/chromevox/common/braille/braille_key_types.js'),
Expand Down Expand Up @@ -206,3 +212,12 @@ AX_TEST_F('ChromeVoxLearnModeTest', 'HardwareFunctionKeys', async function() {

await mockFeedback.replay();
});

AX_TEST_F(
'ChromeVoxLearnModeTest', 'CommandHandlersDisabled', async function() {
const [mockFeedback, evt] = await this.runOnLearnModePage();
await LearnModeBridge.ready();
assertFalse(BrailleCommandHandler.instance.enabled_);
assertFalse(GestureCommandHandler.instance.enabled_);
await mockFeedback.replay();
});

0 comments on commit beb76b5

Please sign in to comment.