File: panel_test.js

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (339 lines) | stat: -rw-r--r-- 12,581 bytes parent folder | download | duplicates (5)
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
327
328
329
330
331
332
333
334
335
336
337
338
339
// 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.
 */
ChromeVoxMV2PanelTest = class extends ChromeVoxMV2PanelTestBase {
  /** @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;

    const panel = this.getPanel().instance;
    const original = panel.exec_.bind(panel);
    panel.exec_ = (command) => {
      original(command);
      this.onPanelCommandCalled();
    };
  }

  onPanelCommandCalled() {
    if (this.resolvePanelCommandPromise) {
      this.resolvePanelCommandPromise();
    }
  }

  prepareForPanelCommand() {
    this.panelCommandPromise =
        new Promise(resolve => this.resolvePanelCommandPromise = resolve);
  }

  waitForPanelCommand() {
    return this.panelCommandPromise;
  }

  fireMockEvent(key) {
    return function() {
      const obj = {};
      obj.preventDefault = function() {};
      obj.stopPropagation = function() {};
      obj.key = key;
      this.getPanel().instance.onKeyDown_(obj);
    }.bind(this);
  }

  fireMockQuery(query) {
    return function() {
      const evt = {};
      evt.target = {};
      evt.target.value = query;
      this.getPanel().instance.menuManager_.onSearchBarQuery(evt);
    }.bind(this);
  }

  assertActiveMenuItem(menuMsg, menuItemTitle, opt_menuItemShortcut) {
    const menu = this.getPanel().instance.menuManager_.activeMenu_;
    const menuItem = menu.items_[menu.activeIndex_];
    assertEquals(menuMsg, menu.menuMsg);
    assertEquals(menuItemTitle, menuItem.menuItemTitle);
    if (opt_menuItemShortcut) {
      assertEquals(opt_menuItemShortcut, menuItem.menuItemShortcut);
    }
  }

  assertActiveSearchMenuItem(menuItemTitle) {
    const searchMenu = this.getPanel().instance.menuManager_.searchMenu;
    const activeIndex = searchMenu.activeIndex_;
    const activeItem = searchMenu.items_[activeIndex];
    assertEquals(menuItemTitle, activeItem.menuItemTitle);
  }

  enableTouchMode() {
    EventSource.set(EventSourceType.TOUCH_GESTURE);
  }

  isMenuTitleMessage(menuTitleMessage) {
    const menu = this.getPanel().instance.menuManager_.activeMenu_;
    return menuTitleMessage === menu.menuMsg;
  }

  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('ChromeVoxMV2PanelTest', 'ActivateMenu', async function() {
  await this.runWithLoadedTree(this.linksDoc);
  new PanelCommand(PanelCommandType.OPEN_MENUS).send();
  await this.waitForMenu('panel_search_menu');
  this.fireMockEvent('ArrowRight')();
  this.assertActiveMenuItem('panel_menu_jump', 'Go To Beginning Of Table');
  this.fireMockEvent('ArrowRight')();
  this.assertActiveMenuItem(
      'panel_menu_speech', 'Announce Current Battery Status');
});

// TODO(https://crbug.com/1299765): Re-enable once flaky timeouts are fixed.
AX_TEST_F('ChromeVoxMV2PanelTest', 'DISABLED_LinkMenu', async function() {
  await this.runWithLoadedTree(this.linksDoc);
  CommandHandlerInterface.instance.onCommand('showLinksList');
  await this.waitForMenu('role_link');
  this.fireMockEvent('ArrowLeft')();
  this.assertActiveMenuItem('role_landmark', 'No items');
  this.fireMockEvent('ArrowRight')();
  this.assertActiveMenuItem('role_link', 'apple Internal link');
  this.fireMockEvent('ArrowUp')();
  this.assertActiveMenuItem('role_link', 'banana Internal link');
});

AX_TEST_F('ChromeVoxMV2PanelTest', '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')();
  this.assertActiveMenuItem('panel_menu_form_controls', 'OK Button');
  this.fireMockEvent('ArrowUp')();
  this.assertActiveMenuItem('panel_menu_form_controls', 'Cancel Button');
});


AX_TEST_F('ChromeVoxMV2PanelTest', '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(() => {
        this.fireMockQuery('jump')();
        this.assertActiveSearchMenuItem('Jump To Details');
      })
      .expectSpeech(/Jump/, 'Menu item', /[0-9]+ of [0-9]+/)
      .call(() => {
        this.fireMockEvent('ArrowDown')();
        this.assertActiveSearchMenuItem('Jump To The Bottom Of The Page');
      })
      .expectSpeech(/Jump/, 'Menu item', /[0-9]+ of [0-9]+/)
      .call(() => {
        this.fireMockEvent('ArrowDown')();
        this.assertActiveSearchMenuItem('Jump To The Top Of The Page');
      })
      .expectSpeech(/Jump/, 'Menu item', /[0-9]+ of [0-9]+/)
      .call(() => {
        this.fireMockEvent('ArrowDown')();
        this.assertActiveSearchMenuItem('Jump To Details');
      })
      .expectSpeech(/Jump/, 'Menu item', /[0-9]+ of [0-9]+/)
      .replay();
});

// TODO(crbug.com/1088438): flaky crashes.
AX_TEST_F('ChromeVoxMV2PanelTest', '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(
    'ChromeVoxMV2PanelTest', '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')();
      this.assertActiveMenuItem(
          'panel_menu_form_controls', 'espaƱol: Prueba Button');
      this.fireMockEvent('ArrowUp')();
      this.assertActiveMenuItem('panel_menu_form_controls', 'Test Button');
    });

AX_TEST_F('ChromeVoxMV2PanelTest', 'ActionsMenu', async function() {
  await this.runWithLoadedTree(this.linksDoc);
  CommandHandlerInterface.instance.onCommand('showActionsMenu');
  await this.waitForMenu('panel_menu_actions');
  this.fireMockEvent('ArrowDown')();
  this.assertActiveMenuItem('panel_menu_actions', 'Start Or End Selection');
  this.fireMockEvent('ArrowUp')();
  this.assertActiveMenuItem('panel_menu_actions', 'Click On Current Item');
});

AX_TEST_F('ChromeVoxMV2PanelTest', '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')();
  this.assertActiveMenuItem('panel_menu_actions', 'Long click on current item');
  this.fireMockEvent('ArrowDown')();
  this.assertActiveMenuItem('panel_menu_actions', 'Click On Current Item');
});

AX_TEST_F(
    'ChromeVoxMV2PanelTest', 'ShortcutsAreInternationalized', async function() {
      await this.runWithLoadedTree(this.linksDoc);
      new PanelCommand(PanelCommandType.OPEN_MENUS).send();
      await this.waitForMenu('panel_search_menu');
      this.fireMockEvent('ArrowRight')();
      this.assertActiveMenuItem(
          'panel_menu_jump', 'Go To Beginning Of Table',
          'Search+Alt+Shift+ArrowLeft');
      this.fireMockEvent('ArrowRight')();
      this.assertActiveMenuItem(
          'panel_menu_speech', 'Announce Current Battery Status',
          'Search+O, then B');
      this.fireMockEvent('ArrowRight')();
      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(
    'ChromeVoxMV2PanelTest', '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(this.isMenuTitleMessage('panel_menu_touchgestures'));
      } while (!this.isMenuTitleMessage('panel_search_menu'));
    });

// Ensure 'Touch Gesture' is in the panel menus when touch mode is enabled.
AX_TEST_F(
    'ChromeVoxMV2PanelTest', '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(this.isMenuTitleMessage('panel_search_menu'));
      } while (!this.isMenuTitleMessage('panel_menu_touchgestures'));

      this.assertActiveMenuItem(
          'panel_menu_touchgestures', 'Click on current item');
    });

// Ensure 'Perform default action' in the actions tab invokes a click event.
AX_TEST_F('ChromeVoxMV2PanelTest', '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')();
  this.assertActiveMenuItem('panel_menu_actions', 'Start Or End Selection');
  this.fireMockEvent('ArrowDown')();
  this.fireMockEvent('ArrowDown')();
  this.assertActiveMenuItem('panel_menu_actions', 'Perform default action');
  this.fireMockEvent('Enter')();
  await this.waitForEvent(button, chrome.automation.EventType.CLICKED);
});

AX_TEST_F(
    'ChromeVoxMV2PanelTest', 'PanVirtualBrailleDisplay', async function() {
      await this.runWithLoadedTree(this.linksDoc);

      this.prepareForPanelCommand();
      CommandHandlerInterface.instance.onCommand('toggleBrailleCaptions');
      this.waitForPanelCommand();

      // Locate the buttons to pan left and pan right in the display.
      const panelDocument = this.getPanelWindow().document;
      const panLeftButton = panelDocument.getElementById('braille-pan-left');
      assertNotNullNorUndefined(panLeftButton);
      const panRightButton = panelDocument.getElementById('braille-pan-right');
      assertNotNullNorUndefined(panRightButton);

      // 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};

      panLeftButton.click();
      await panLeftDone;

      panRightButton.click();
      await panRightDone;
    });