1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Include test fixture.
GEN_INCLUDE(['panel_test_base.js']);
/**
* Test fixture for Panel.
*/
ChromeVoxPanelTest = class extends ChromeVoxPanelTestBase {
/** @override */
testGenCppIncludes() {
super.testGenCppIncludes();
GEN(`#include "ui/accessibility/accessibility_features.h"`);
}
/** @override */
async setUpDeferred() {
await super.setUpDeferred();
globalThis.Gesture = chrome.accessibilityPrivate.Gesture;
globalThis.RoleType = chrome.automation.RoleType;
}
fireMockEvent(key) {
PanelBridge.fireMockEventForTest(key);
}
fireMockQuery(query) {
PanelBridge.fireMockQueryForTest(query);
}
async assertActiveMenuItem(menuMsg, menuItemTitle, opt_menuItemShortcut) {
const response = await PanelBridge.getActiveMenuDataForTest()
assertEquals(menuMsg, response.menuMsg);
assertEquals(menuItemTitle, response.menuItemTitle);
if (opt_menuItemShortcut) {
assertEquals(opt_menuItemShortcut, response.menuItemShortcut);
}
}
async assertActiveSearchMenuItem(menuItemTitle) {
const response = await PanelBridge.getActiveSearchMenuDataForTest();
assertEquals(menuItemTitle, response.menuItemTitle);
}
enableTouchMode() {
EventSource.set(EventSourceType.TOUCH_GESTURE);
}
async isMenuTitleMessage(menuTitleMessage) {
const response = await PanelBridge.getActiveMenuDataForTest()
return menuTitleMessage === response.menuMsg;
}
async waitForMenu(menuTitleMessage) {
// TODO(crbug.com/424764877): Replace polling.
let pollForMenu = async (resolve) => {
if (await this.isMenuTitleMessage(menuTitleMessage)) {
resolve();
} else {
setTimeout(() => pollForMenu(resolve), 500)
}
};
return new Promise(resolve => {
pollForMenu(resolve);
});
}
braillePanRight() {
PanelBridge.braillePanRightForTest();
}
braillePanLeft() {
PanelBridge.braillePanLeftForTest();
}
get linksDoc() {
return `
<p>start</p>
<a href="#">apple</a>
<a href="#">grape</a>
<a href="#">banana</a>
`;
}
get internationalButtonDoc() {
return `
<button lang="en">Test</button>
<button lang="es">Prueba</button>
`;
}
};
AX_TEST_F('ChromeVoxPanelTest', 'ActivateMenu', async function() {
await this.runWithLoadedTree(this.linksDoc);
new PanelCommand(PanelCommandType.OPEN_MENUS).send();
await this.waitForMenu('panel_search_menu');
this.fireMockEvent('ArrowRight');
await await this.assertActiveMenuItem(
'panel_menu_jump', 'Go To Beginning Of Table');
this.fireMockEvent('ArrowRight');
await this.assertActiveMenuItem(
'panel_menu_speech', 'Announce Current Battery Status');
});
AX_TEST_F('ChromeVoxPanelTest', 'LinkMenu', async function() {
await this.runWithLoadedTree(this.linksDoc);
CommandHandlerInterface.instance.onCommand('showLinksList');
await this.waitForMenu('role_link');
this.fireMockEvent('ArrowLeft');
await this.assertActiveMenuItem('role_landmark', 'No items');
this.fireMockEvent('ArrowRight');
await this.assertActiveMenuItem('role_link', 'apple Internal link');
this.fireMockEvent('ArrowUp');
await this.assertActiveMenuItem('role_link', 'banana Internal link');
});
AX_TEST_F('ChromeVoxPanelTest', 'FormControlsMenu', async function() {
await this.runWithLoadedTree(`<button>Cancel</button><button>OK</button>`);
CommandHandlerInterface.instance.onCommand('showFormsList');
await this.waitForMenu('panel_menu_form_controls');
this.fireMockEvent('ArrowDown');
await this.assertActiveMenuItem('panel_menu_form_controls', 'OK Button');
this.fireMockEvent('ArrowUp');
await this.assertActiveMenuItem('panel_menu_form_controls', 'Cancel Button');
});
AX_TEST_F('ChromeVoxPanelTest', 'SearchMenu', async function() {
const mockFeedback = this.createMockFeedback();
await this.runWithLoadedTree(this.linksDoc);
new PanelCommand(PanelCommandType.OPEN_MENUS).send();
await this.waitForMenu('panel_search_menu');
await mockFeedback
.expectSpeech('Search the menus', /Type to search the menus/)
.call(async () => {
this.fireMockQuery('jump');
await this.assertActiveSearchMenuItem('Jump To Details');
})
.expectSpeech(/Jump/, 'Menu item', /[0-9]+ of [0-9]+/)
.call(async () => {
this.fireMockEvent('ArrowDown');
await this.assertActiveSearchMenuItem('Jump To The Bottom Of The Page');
})
.expectSpeech(/Jump/, 'Menu item', /[0-9]+ of [0-9]+/)
.call(async () => {
this.fireMockEvent('ArrowDown');
await this.assertActiveSearchMenuItem('Jump To The Top Of The Page');
})
.expectSpeech(/Jump/, 'Menu item', /[0-9]+ of [0-9]+/)
.call(async () => {
this.fireMockEvent('ArrowDown');
await this.assertActiveSearchMenuItem('Jump To Details');
})
.expectSpeech(/Jump/, 'Menu item', /[0-9]+ of [0-9]+/)
.replay();
});
// TODO(crbug.com/1088438): flaky crashes.
AX_TEST_F('ChromeVoxPanelTest', 'DISABLED_Gestures', async function() {
const doGestureAsync = async gesture => {
doGesture(gesture)();
};
await this.runWithLoadedTree(`<button>Cancel</button><button>OK</button>`);
doGestureAsync(Gesture.TAP4);
await this.waitForMenu('panel_search_menu');
// GestureCommandHandler behaves in special ways only with range over
// the panel. Fake this out by setting range there.
const desktop = root.parent.root;
const panelNode = desktop.find(
{role: 'rootWebArea', attributes: {name: 'ChromeVox Panel'}});
ChromeVoxRange.set(CursorRange.fromNode(panelNode));
doGestureAsync(Gesture.SWIPE_RIGHT1);
await this.waitForMenu('panel_menu_jump');
doGestureAsync(Gesture.SWIPE_RIGHT1);
await this.waitForMenu('panel_menu_speech');
doGestureAsync(Gesture.SWIPE_LEFT1);
await this.waitForMenu('panel_menu_jump');
});
AX_TEST_F(
'ChromeVoxPanelTest', 'InternationalFormControlsMenu', async function() {
await this.runWithLoadedTree(this.internationalButtonDoc);
// Turn on language switching and set available voice list.
SettingsManager.set('languageSwitching', true);
LocaleOutputHelper.instance.availableVoices_ =
[{'lang': 'en-US'}, {'lang': 'es-ES'}];
CommandHandlerInterface.instance.onCommand('showFormsList');
await this.waitForMenu('panel_menu_form_controls');
this.fireMockEvent('ArrowDown');
await this.assertActiveMenuItem(
'panel_menu_form_controls', 'espaƱol: Prueba Button');
this.fireMockEvent('ArrowUp');
await this.assertActiveMenuItem(
'panel_menu_form_controls', 'Test Button');
});
AX_TEST_F('ChromeVoxPanelTest', 'ActionsMenu', async function() {
await this.runWithLoadedTree(this.linksDoc);
CommandHandlerInterface.instance.onCommand('showActionsMenu');
await this.waitForMenu('panel_menu_actions');
this.fireMockEvent('ArrowDown');
await this.assertActiveMenuItem(
'panel_menu_actions', 'Start Or End Selection');
this.fireMockEvent('ArrowUp');
await this.assertActiveMenuItem(
'panel_menu_actions', 'Click On Current Item');
});
AX_TEST_F('ChromeVoxPanelTest', 'ActionsMenuLongClick', async function() {
await this.runWithLoadedTree(this.linksDoc);
// Get the node that will be checked for actions.
const activeNode = ChromeVoxRange.current.start.node;
// Override the standard actions to have long click.
Object.defineProperty(activeNode, 'standardActions', {
value: ['longClick'],
writable: true,
});
CommandHandlerInterface.instance.onCommand('showActionsMenu');
await this.waitForMenu('panel_menu_actions');
// Go down three times
this.fireMockEvent('ArrowUp');
await this.assertActiveMenuItem(
'panel_menu_actions', 'Long click on current item');
this.fireMockEvent('ArrowDown');
await this.assertActiveMenuItem(
'panel_menu_actions', 'Click On Current Item');
});
AX_TEST_F(
'ChromeVoxPanelTest', 'ShortcutsAreInternationalized', async function() {
await this.runWithLoadedTree(this.linksDoc);
new PanelCommand(PanelCommandType.OPEN_MENUS).send();
await this.waitForMenu('panel_search_menu');
this.fireMockEvent('ArrowRight');
await this.assertActiveMenuItem(
'panel_menu_jump', 'Go To Beginning Of Table',
'Search+Alt+Shift+ArrowLeft');
this.fireMockEvent('ArrowRight');
await this.assertActiveMenuItem(
'panel_menu_speech', 'Announce Current Battery Status',
'Search+O, then B');
this.fireMockEvent('ArrowRight');
await this.assertActiveMenuItem(
'panel_menu_chromevox', 'Enable/Disable Sticky Mode',
'Search+Search');
});
// Ensure 'Touch Gestures' is not in the panel menus by default.
AX_TEST_F(
'ChromeVoxPanelTest', 'TouchGesturesMenuNotAvailableWhenNotInTouchMode',
async function() {
await this.runWithLoadedTree(this.linksDoc);
new PanelCommand(PanelCommandType.OPEN_MENUS).send();
await this.waitForMenu('panel_search_menu');
do {
this.fireMockEvent('ArrowRight');
assertFalse(await this.isMenuTitleMessage('panel_menu_touchgestures'));
} while (!await this.isMenuTitleMessage('panel_search_menu'));
});
// Ensure 'Touch Gesture' is in the panel menus when touch mode is enabled.
AX_TEST_F(
'ChromeVoxPanelTest', 'TouchGesturesMenuAvailableWhenInTouchMode',
async function() {
await this.runWithLoadedTree(this.linksDoc);
this.enableTouchMode();
new PanelCommand(PanelCommandType.OPEN_MENUS).send();
await this.waitForMenu('panel_search_menu');
// Look for Touch Gestures menu, fail if getting back to start.
do {
this.fireMockEvent('ArrowRight');
assertFalse(await this.isMenuTitleMessage('panel_search_menu'));
} while (!await this.isMenuTitleMessage('panel_menu_touchgestures'));
await this.assertActiveMenuItem(
'panel_menu_touchgestures', 'Click on current item');
});
// Ensure 'Perform default action' in the actions tab invokes a click event.
AX_TEST_F('ChromeVoxPanelTest', 'PerformDoDefaultAction', async function() {
const rootNode = await this.runWithLoadedTree(`<button>OK</button>`);
const button = rootNode.find({role: RoleType.BUTTON});
await this.waitForEvent(button, chrome.automation.EventType.FOCUS);
CommandHandlerInterface.instance.onCommand('showActionsMenu');
await this.waitForMenu('panel_menu_actions');
this.fireMockEvent('ArrowDown');
await this.assertActiveMenuItem(
'panel_menu_actions', 'Start Or End Selection');
this.fireMockEvent('ArrowDown');
this.fireMockEvent('ArrowDown');
await this.assertActiveMenuItem(
'panel_menu_actions', 'Perform default action');
this.fireMockEvent('Enter');
await this.waitForEvent(button, chrome.automation.EventType.CLICKED);
});
AX_TEST_F('ChromeVoxPanelTest', 'PanVirtualBrailleDisplay', async function() {
await this.runWithLoadedTree(this.linksDoc);
CommandHandlerInterface.instance.onCommand('toggleBrailleCaptions');
// Mock out ChromeVox.braille to confirm that the commands are routed from the
// panel context to the background context.
let panLeft;
let panRight;
const panLeftDone = new Promise(resolve => panLeft = resolve);
const panRightDone = new Promise(resolve => panRight = resolve);
ChromeVox.braille = {panLeft, panRight};
this.braillePanLeft();
await panLeftDone;
this.braillePanRight();
await panRightDone;
});
|