tor-browser

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

browser_aria_haspopup.js (8475B)


      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 /**
     15 * Test aria-haspopup
     16 */
     17 addAccessibleTask(
     18  `
     19  <button aria-haspopup="false" id="false">action</button>
     20 
     21  <button aria-haspopup="menu" id="menu">action</button>
     22 
     23  <button aria-haspopup="listbox" id="listbox">action</button>
     24 
     25  <button aria-haspopup="tree" id="tree">action</button>
     26 
     27  <button aria-haspopup="grid" id="grid">action</button>
     28 
     29  <button aria-haspopup="dialog" id="dialog">action</button>
     30 
     31  `,
     32  async (browser, accDoc) => {
     33    // FALSE
     34    let falseID = getNativeInterface(accDoc, "false");
     35    is(
     36      falseID.getAttributeValue("AXHasPopup"),
     37      0,
     38      "Correct AXHasPopup val for button with false"
     39    );
     40    is(
     41      falseID.getAttributeValue("AXPopupValue"),
     42      null,
     43      "Correct AXPopupValue val for button with false"
     44    );
     45    let attrChanged = waitForEvent(EVENT_STATE_CHANGE, "false");
     46    await SpecialPowers.spawn(browser, [], () => {
     47      content.document
     48        .getElementById("false")
     49        .setAttribute("aria-haspopup", "true");
     50    });
     51    await attrChanged;
     52 
     53    is(
     54      falseID.getAttributeValue("AXPopupValue"),
     55      "true",
     56      "Correct AXPopupValue after change for false"
     57    );
     58    is(
     59      falseID.getAttributeValue("AXHasPopup"),
     60      1,
     61      "Correct AXHasPopup val for button with true"
     62    );
     63 
     64    let stateChanged = waitForEvent(EVENT_STATE_CHANGE, "false");
     65    await SpecialPowers.spawn(browser, [], () => {
     66      content.document.getElementById("false").removeAttribute("aria-haspopup");
     67    });
     68    await stateChanged;
     69 
     70    is(
     71      falseID.getAttributeValue("AXPopupValue"),
     72      null,
     73      "Correct AXPopupValue after remove for false"
     74    );
     75    is(
     76      falseID.getAttributeValue("AXHasPopup"),
     77      0,
     78      "Correct AXHasPopup val for button after remove"
     79    );
     80 
     81    // MENU
     82    let menuID = getNativeInterface(accDoc, "menu");
     83    is(
     84      menuID.getAttributeValue("AXPopupValue"),
     85      "menu",
     86      "Correct AXPopupValue val for button with menu"
     87    );
     88    is(
     89      menuID.getAttributeValue("AXHasPopup"),
     90      1,
     91      "Correct AXHasPopup val for button with menu"
     92    );
     93 
     94    await SpecialPowers.spawn(browser, [], () => {
     95      content.document
     96        .getElementById("menu")
     97        .setAttribute("aria-haspopup", "true");
     98    });
     99 
    100    await untilCacheIs(
    101      () => menuID.getAttributeValue("AXPopupValue"),
    102      "true",
    103      "Correct AXPopupValue after change for menu"
    104    );
    105    is(
    106      menuID.getAttributeValue("AXHasPopup"),
    107      1,
    108      "Correct AXHasPopup val for button with menu"
    109    );
    110 
    111    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "menu");
    112    await SpecialPowers.spawn(browser, [], () => {
    113      content.document.getElementById("menu").removeAttribute("aria-haspopup");
    114    });
    115    await stateChanged;
    116 
    117    await untilCacheIs(
    118      () => menuID.getAttributeValue("AXPopupValue"),
    119      null,
    120      "Correct AXPopupValue after remove for menu"
    121    );
    122    is(
    123      menuID.getAttributeValue("AXHasPopup"),
    124      0,
    125      "Correct AXHasPopup val for button after remove"
    126    );
    127 
    128    // LISTBOX
    129    let listboxID = getNativeInterface(accDoc, "listbox");
    130    is(
    131      listboxID.getAttributeValue("AXPopupValue"),
    132      "listbox",
    133      "Correct AXPopupValue for button with listbox"
    134    );
    135    is(
    136      listboxID.getAttributeValue("AXHasPopup"),
    137      1,
    138      "Correct AXHasPopup for button with listbox"
    139    );
    140 
    141    await SpecialPowers.spawn(browser, [], () => {
    142      content.document
    143        .getElementById("listbox")
    144        .setAttribute("aria-haspopup", "true");
    145    });
    146 
    147    await untilCacheIs(
    148      () => listboxID.getAttributeValue("AXPopupValue"),
    149      "true",
    150      "Correct AXPopupValue after change for listbox"
    151    );
    152    is(
    153      listboxID.getAttributeValue("AXHasPopup"),
    154      1,
    155      "Correct AXHasPopup for button with listbox"
    156    );
    157 
    158    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "listbox");
    159    await SpecialPowers.spawn(browser, [], () => {
    160      content.document
    161        .getElementById("listbox")
    162        .removeAttribute("aria-haspopup");
    163    });
    164    await stateChanged;
    165 
    166    is(
    167      listboxID.getAttributeValue("AXPopupValue"),
    168      null,
    169      "Correct AXPopupValue after remove for listbox"
    170    );
    171    is(
    172      listboxID.getAttributeValue("AXHasPopup"),
    173      0,
    174      "Correct AXHasPopup for button with listbox"
    175    );
    176 
    177    // TREE
    178    let treeID = getNativeInterface(accDoc, "tree");
    179    is(
    180      treeID.getAttributeValue("AXPopupValue"),
    181      "tree",
    182      "Correct AXPopupValue for button with tree"
    183    );
    184    is(
    185      treeID.getAttributeValue("AXHasPopup"),
    186      1,
    187      "Correct AXHasPopup for button with tree"
    188    );
    189 
    190    await SpecialPowers.spawn(browser, [], () => {
    191      content.document
    192        .getElementById("tree")
    193        .setAttribute("aria-haspopup", "true");
    194    });
    195 
    196    await untilCacheIs(
    197      () => treeID.getAttributeValue("AXPopupValue"),
    198      "true",
    199      "Correct AXPopupValue after change for tree"
    200    );
    201    is(
    202      treeID.getAttributeValue("AXHasPopup"),
    203      1,
    204      "Correct AXHasPopup for button with tree"
    205    );
    206 
    207    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "tree");
    208    await SpecialPowers.spawn(browser, [], () => {
    209      content.document.getElementById("tree").removeAttribute("aria-haspopup");
    210    });
    211    await stateChanged;
    212 
    213    is(
    214      treeID.getAttributeValue("AXPopupValue"),
    215      null,
    216      "Correct AXPopupValue after remove for tree"
    217    );
    218    is(
    219      treeID.getAttributeValue("AXHasPopup"),
    220      0,
    221      "Correct AXHasPopup for button with tree after remove"
    222    );
    223 
    224    // GRID
    225    let gridID = getNativeInterface(accDoc, "grid");
    226    is(
    227      gridID.getAttributeValue("AXPopupValue"),
    228      "grid",
    229      "Correct AXPopupValue for button with grid"
    230    );
    231    is(
    232      gridID.getAttributeValue("AXHasPopup"),
    233      1,
    234      "Correct AXHasPopup for button with grid"
    235    );
    236 
    237    await SpecialPowers.spawn(browser, [], () => {
    238      content.document
    239        .getElementById("grid")
    240        .setAttribute("aria-haspopup", "true");
    241    });
    242 
    243    await untilCacheIs(
    244      () => gridID.getAttributeValue("AXPopupValue"),
    245      "true",
    246      "Correct AXPopupValue after change for grid"
    247    );
    248    is(
    249      gridID.getAttributeValue("AXHasPopup"),
    250      1,
    251      "Correct AXHasPopup for button with grid"
    252    );
    253 
    254    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "grid");
    255    await SpecialPowers.spawn(browser, [], () => {
    256      content.document.getElementById("grid").removeAttribute("aria-haspopup");
    257    });
    258    await stateChanged;
    259 
    260    is(
    261      gridID.getAttributeValue("AXPopupValue"),
    262      null,
    263      "Correct AXPopupValue after remove for grid"
    264    );
    265    is(
    266      gridID.getAttributeValue("AXHasPopup"),
    267      0,
    268      "Correct AXHasPopup for button with grid after remove"
    269    );
    270 
    271    // DIALOG
    272    let dialogID = getNativeInterface(accDoc, "dialog");
    273    is(
    274      dialogID.getAttributeValue("AXPopupValue"),
    275      "dialog",
    276      "Correct AXPopupValue for button with dialog"
    277    );
    278    is(
    279      dialogID.getAttributeValue("AXHasPopup"),
    280      1,
    281      "Correct AXHasPopup for button with dialog"
    282    );
    283 
    284    await SpecialPowers.spawn(browser, [], () => {
    285      content.document
    286        .getElementById("dialog")
    287        .setAttribute("aria-haspopup", "true");
    288    });
    289 
    290    await untilCacheIs(
    291      () => dialogID.getAttributeValue("AXPopupValue"),
    292      "true",
    293      "Correct AXPopupValue after change for dialog"
    294    );
    295    is(
    296      dialogID.getAttributeValue("AXHasPopup"),
    297      1,
    298      "Correct AXHasPopup for button with dialog"
    299    );
    300 
    301    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "dialog");
    302    await SpecialPowers.spawn(browser, [], () => {
    303      content.document
    304        .getElementById("dialog")
    305        .removeAttribute("aria-haspopup");
    306    });
    307    await stateChanged;
    308 
    309    is(
    310      dialogID.getAttributeValue("AXPopupValue"),
    311      null,
    312      "Correct AXPopupValue after remove for dialog"
    313    );
    314    is(
    315      dialogID.getAttributeValue("AXHasPopup"),
    316      0,
    317      "Correct AXHasPopup for button with dialog after remove"
    318    );
    319  }
    320 );