tor-browser

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

browser_popupbutton.js (5172B)


      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 /* import-globals-from ../../mochitest/states.js */
      9 loadScripts(
     10  { name: "role.js", dir: MOCHITESTS_DIR },
     11  { name: "states.js", dir: MOCHITESTS_DIR }
     12 );
     13 
     14 // Test dropdown select element
     15 addAccessibleTask(
     16  `<select id="select" aria-label="Choose a number">
     17    <option id="one" selected>One</option>
     18    <option id="two">Two</option>
     19    <option id="three">Three</option>
     20    <option id="four" disabled>Four</option>
     21  </select>`,
     22  async (browser, accDoc) => {
     23    // Test combobox
     24    let select = getNativeInterface(accDoc, "select");
     25    is(
     26      select.getAttributeValue("AXRole"),
     27      "AXPopUpButton",
     28      "select has AXPopupButton role"
     29    );
     30    ok(select.attributeNames.includes("AXValue"), "select advertises AXValue");
     31    is(
     32      select.getAttributeValue("AXValue"),
     33      "One",
     34      "select has correctt initial value"
     35    );
     36    ok(
     37      !select.attributeNames.includes("AXHasPopup"),
     38      "select does not advertise AXHasPopup"
     39    );
     40    is(
     41      select.getAttributeValue("AXHasPopup"),
     42      null,
     43      "select does not provide value for AXHasPopup"
     44    );
     45 
     46    ok(select.actionNames.includes("AXPress"), "Selectt has press action");
     47    // These four events happen in quick succession when select is pressed
     48    let events = Promise.all([
     49      waitForMacEvent("AXMenuOpened"),
     50      waitForMacEvent("AXSelectedChildrenChanged"),
     51      waitForMacEvent(
     52        "AXFocusedUIElementChanged",
     53        e => e.getAttributeValue("AXRole") == "AXPopUpButton"
     54      ),
     55      waitForMacEvent(
     56        "AXFocusedUIElementChanged",
     57        e => e.getAttributeValue("AXRole") == "AXMenuItem"
     58      ),
     59    ]);
     60    select.performAction("AXPress");
     61    // Only capture the target of AXMenuOpened (first element)
     62    let [menu] = await events;
     63 
     64    is(menu.getAttributeValue("AXRole"), "AXMenu", "dropdown has AXMenu role");
     65    is(
     66      menu.getAttributeValue("AXSelectedChildren").length,
     67      1,
     68      "dropdown has single selected child"
     69    );
     70 
     71    let selectedChildren = menu.getAttributeValue("AXSelectedChildren");
     72    is(selectedChildren.length, 1, "Only one child is selected");
     73    is(selectedChildren[0].getAttributeValue("AXRole"), "AXMenuItem");
     74    is(selectedChildren[0].getAttributeValue("AXTitle"), "One");
     75 
     76    let menuParent = menu.getAttributeValue("AXParent");
     77    is(
     78      menuParent.getAttributeValue("AXRole"),
     79      "AXPopUpButton",
     80      "dropdown parent is a popup button"
     81    );
     82 
     83    let menuItems = menu.getAttributeValue("AXChildren").map(c => {
     84      return [
     85        c.getAttributeValue("AXMenuItemMarkChar"),
     86        c.getAttributeValue("AXRole"),
     87        c.getAttributeValue("AXTitle"),
     88        c.getAttributeValue("AXEnabled"),
     89      ];
     90    });
     91 
     92    Assert.deepEqual(
     93      menuItems,
     94      [
     95        ["✓", "AXMenuItem", "One", true],
     96        [null, "AXMenuItem", "Two", true],
     97        [null, "AXMenuItem", "Three", true],
     98        [null, "AXMenuItem", "Four", false],
     99      ],
    100      "Menu items have correct checkmark on current value, correctt roles, correct titles, and correct AXEnabled value"
    101    );
    102 
    103    events = Promise.all([
    104      waitForMacEvent("AXSelectedChildrenChanged"),
    105      waitForMacEvent("AXFocusedUIElementChanged"),
    106    ]);
    107    EventUtils.synthesizeKey("KEY_ArrowDown");
    108    let [, menuItem] = await events;
    109    is(
    110      menuItem.getAttributeValue("AXTitle"),
    111      "Two",
    112      "Focused menu item has correct title"
    113    );
    114 
    115    selectedChildren = menu.getAttributeValue("AXSelectedChildren");
    116    is(selectedChildren.length, 1, "Only one child is selected");
    117    is(
    118      selectedChildren[0].getAttributeValue("AXTitle"),
    119      "Two",
    120      "Selected child matches focused item"
    121    );
    122 
    123    events = Promise.all([
    124      waitForMacEvent("AXSelectedChildrenChanged"),
    125      waitForMacEvent("AXFocusedUIElementChanged"),
    126    ]);
    127    EventUtils.synthesizeKey("KEY_ArrowDown");
    128    [, menuItem] = await events;
    129    is(
    130      menuItem.getAttributeValue("AXTitle"),
    131      "Three",
    132      "Focused menu item has correct title"
    133    );
    134 
    135    selectedChildren = menu.getAttributeValue("AXSelectedChildren");
    136    is(selectedChildren.length, 1, "Only one child is selected");
    137    is(
    138      selectedChildren[0].getAttributeValue("AXTitle"),
    139      "Three",
    140      "Selected child matches focused item"
    141    );
    142 
    143    events = Promise.all([
    144      waitForMacEvent("AXMenuClosed"),
    145      waitForMacEvent("AXFocusedUIElementChanged"),
    146      waitForMacEvent("AXSelectedChildrenChanged"),
    147    ]);
    148    menuItem.performAction("AXPress");
    149    let [, newFocus] = await events;
    150    is(
    151      newFocus.getAttributeValue("AXRole"),
    152      "AXPopUpButton",
    153      "Newly focused element is AXPopupButton"
    154    );
    155    is(
    156      newFocus.getAttributeValue("AXDOMIdentifier"),
    157      "select",
    158      "Should return focus to select"
    159    );
    160    is(
    161      newFocus.getAttributeValue("AXValue"),
    162      "Three",
    163      "select has correct new value"
    164    );
    165  }
    166 );