tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_treeupdate_select_dropdown.js (2266B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /* import-globals-from ../../mochitest/role.js */
      8 loadScripts({ name: "role.js", dir: MOCHITESTS_DIR });
      9 
     10 const snippet = `
     11 <select id="select">
     12  <option>o1</option>
     13  <optgroup label="g1">
     14    <option>g1o1</option>
     15    <option>g1o2</option>
     16  </optgroup>
     17  <optgroup label="g2">
     18    <option>g2o1</option>
     19    <option>g2o2</option>
     20  </optgroup>
     21  <option>o2</option>
     22 </select>
     23 `;
     24 
     25 addAccessibleTask(
     26  snippet,
     27  async function (browser) {
     28    await invokeFocus(browser, "select");
     29    // Expand the select. A dropdown item should get focus.
     30    // Note that the dropdown is rendered in the parent process.
     31    let focused = waitForEvent(
     32      EVENT_FOCUS,
     33      event => event.accessible.role == ROLE_COMBOBOX_OPTION,
     34      "Dropdown item focused after select expanded"
     35    );
     36    await invokeContentTask(browser, [], () => {
     37      const { ContentTaskUtils } = ChromeUtils.importESModule(
     38        "resource://testing-common/ContentTaskUtils.sys.mjs"
     39      );
     40      const EventUtils = ContentTaskUtils.getEventUtils(content);
     41      EventUtils.synthesizeKey("VK_DOWN", { altKey: true }, content);
     42    });
     43    info("Waiting for parent focus");
     44    let event = await focused;
     45    let dropdown = event.accessible.parent;
     46 
     47    let selectedOptionChildren = [];
     48    if (MAC) {
     49      // Checkmark is part of the Mac menu styling.
     50      selectedOptionChildren = [{ STATICTEXT: [] }];
     51    }
     52    let tree = {
     53      COMBOBOX_LIST: [
     54        { COMBOBOX_OPTION: selectedOptionChildren },
     55        { GROUPING: [{ COMBOBOX_OPTION: [] }, { COMBOBOX_OPTION: [] }] },
     56        { GROUPING: [{ COMBOBOX_OPTION: [] }, { COMBOBOX_OPTION: [] }] },
     57        { COMBOBOX_OPTION: [] },
     58      ],
     59    };
     60    testAccessibleTree(dropdown, tree);
     61 
     62    // Collapse the select. Focus should return to the select.
     63    focused = waitForEvent(
     64      EVENT_FOCUS,
     65      "select",
     66      "select focused after collapsed"
     67    );
     68    EventUtils.synthesizeKey("VK_ESCAPE", {}, window);
     69    info("Waiting for child focus");
     70    await focused;
     71  },
     72  { iframe: true, remoteIframe: true }
     73 );