tor-browser

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

browser_obj_group.js (14492B)


      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/attributes.js */
      8 loadScripts({ name: "attributes.js", dir: MOCHITESTS_DIR });
      9 
     10 /**
     11 * select elements
     12 */
     13 addAccessibleTask(
     14  `<select>
     15    <option id="opt1-nosize">option1</option>
     16    <option id="opt2-nosize">option2</option>
     17    <option id="opt3-nosize">option3</option>
     18    <option id="opt4-nosize">option4</option>
     19  </select>
     20 
     21  <select size="4">
     22    <option id="opt1">option1</option>
     23    <option id="opt2">option2</option>
     24  </select>
     25 
     26  <select size="4">
     27    <optgroup id="select2_optgroup" label="group">
     28      <option id="select2_opt1">option1</option>
     29      <option id="select2_opt2">option2</option>
     30    </optgroup>
     31    <option id="select2_opt3">option3</option>
     32    <option id="select2_opt4">option4</option>
     33  </select>`,
     34  async function (browser, accDoc) {
     35    let getAcc = id => findAccessibleChildByID(accDoc, id);
     36 
     37    // ////////////////////////////////////////////////////////////////////////
     38    // HTML select with no size attribute.
     39    testGroupAttrs(getAcc("opt1-nosize"), 1, 4);
     40    testGroupAttrs(getAcc("opt2-nosize"), 2, 4);
     41    testGroupAttrs(getAcc("opt3-nosize"), 3, 4);
     42    testGroupAttrs(getAcc("opt4-nosize"), 4, 4);
     43 
     44    // Container should have item count and not hierarchical
     45    testGroupParentAttrs(getAcc("opt1-nosize").parent, 4, false);
     46 
     47    // ////////////////////////////////////////////////////////////////////////
     48    // HTML select
     49    testGroupAttrs(getAcc("opt1"), 1, 2);
     50    testGroupAttrs(getAcc("opt2"), 2, 2);
     51 
     52    // ////////////////////////////////////////////////////////////////////////
     53    // HTML select with optgroup
     54    testGroupAttrs(getAcc("select2_opt3"), 1, 2, 1);
     55    testGroupAttrs(getAcc("select2_opt4"), 2, 2, 1);
     56    testGroupAttrs(getAcc("select2_opt1"), 1, 2, 2);
     57    testGroupAttrs(getAcc("select2_opt2"), 2, 2, 2);
     58  },
     59  {
     60    topLevel: true,
     61    iframe: true,
     62    remoteIframe: true,
     63    chrome: true,
     64  }
     65 );
     66 
     67 /**
     68 * HTML radios
     69 */
     70 addAccessibleTask(
     71  `<form>
     72    <input type="radio" id="radio1" name="group1"/>
     73    <input type="radio" id="radio2" name="group1"/>
     74  </form>
     75 
     76  <input type="radio" id="radio3" name="group2"/>
     77  <label><input type="radio" id="radio4" name="group2"/></label>
     78 
     79  <form>
     80    <input type="radio" style="display: none;" name="group3">
     81    <input type="radio" id="radio5" name="group3">
     82    <input type="radio" id="radio6" name="group4">
     83  </form>
     84 
     85  <input type="radio" id="radio7">`,
     86  async function (browser, accDoc) {
     87    let getAcc = id => findAccessibleChildByID(accDoc, id);
     88 
     89    // ////////////////////////////////////////////////////////////////////////
     90    // HTML input@type="radio" within form
     91    testGroupAttrs(getAcc("radio1"), 1, 2);
     92    testGroupAttrs(getAcc("radio2"), 2, 2);
     93 
     94    // ////////////////////////////////////////////////////////////////////////
     95    // HTML input@type="radio" within document
     96    testGroupAttrs(getAcc("radio3"), 1, 2);
     97    // radio4 is wrapped in a label
     98    testGroupAttrs(getAcc("radio4"), 2, 2);
     99 
    100    // ////////////////////////////////////////////////////////////////////////
    101    // Hidden HTML input@type="radio"
    102    testGroupAttrs(getAcc("radio5"), 1, 1);
    103 
    104    // ////////////////////////////////////////////////////////////////////////
    105    // HTML input@type="radio" with different name but same parent
    106    testGroupAttrs(getAcc("radio6"), 1, 1);
    107 
    108    // ////////////////////////////////////////////////////////////////////////
    109    // HTML input@type="radio" with no name
    110    testGroupAttrs(getAcc("radio7"), 0, 0);
    111  },
    112  {
    113    topLevel: true,
    114    iframe: true,
    115    remoteIframe: true,
    116    chrome: true,
    117  }
    118 );
    119 
    120 /**
    121 * lists
    122 */
    123 addAccessibleTask(
    124  `<ul id="ul">
    125    <li id="li1">Oranges</li>
    126    <li id="li2">Apples</li>
    127    <li id="li3">Bananas</li>
    128  </ul>
    129 
    130  <ol id="ol">
    131    <li id="li4">Oranges</li>
    132    <li id="li5">Apples</li>
    133    <li id="li6">Bananas
    134      <ul id="ol_nested">
    135        <li id="n_li4">Oranges</li>
    136        <li id="n_li5">Apples</li>
    137        <li id="n_li6">Bananas</li>
    138      </ul>
    139    </li>
    140  </ol>
    141 
    142  <span role="list" id="aria-list_1">
    143    <span role="listitem" id="li7">Oranges</span>
    144    <span role="listitem" id="li8">Apples</span>
    145    <span role="listitem" id="li9">Bananas</span>
    146  </span>
    147 
    148  <span role="list" id="aria-list_2">
    149    <span role="listitem" id="li10">Oranges</span>
    150    <span role="listitem" id="li11">Apples</span>
    151    <span role="listitem" id="li12">Bananas
    152      <span role="list" id="aria-list_2_1">
    153        <span role="listitem" id="n_li10">Oranges</span>
    154        <span role="listitem" id="n_li11">Apples</span>
    155        <span role="listitem" id="n_li12">Bananas</span>
    156      </span>
    157    </span>
    158  </span>
    159 
    160  <div role="list" id="aria-list_3">
    161    <div role="listitem" id="lgt_li1">Item 1
    162      <div role="group">
    163        <div role="listitem" id="lgt_li1_nli1">Item 1A</div>
    164        <div role="listitem" id="lgt_li1_nli2">Item 1B</div>
    165      </div>
    166    </div>
    167    <div role="listitem" id="lgt_li2">Item 2
    168      <div role="group">
    169        <div role="listitem" id="lgt_li2_nli1">Item 2A</div>
    170        <div role="listitem" id="lgt_li2_nli2">Item 2B</div>
    171      </div>
    172    </div>
    173  </div>`,
    174  async function (browser, accDoc) {
    175    let getAcc = id => findAccessibleChildByID(accDoc, id);
    176 
    177    // ////////////////////////////////////////////////////////////////////////
    178    // HTML ul/ol
    179    testGroupAttrs(getAcc("li1"), 1, 3);
    180    testGroupAttrs(getAcc("li2"), 2, 3);
    181    testGroupAttrs(getAcc("li3"), 3, 3);
    182 
    183    // ul should have item count and not hierarchical
    184    testGroupParentAttrs(getAcc("ul"), 3, false);
    185 
    186    // ////////////////////////////////////////////////////////////////////////
    187    // HTML ul/ol (nested lists)
    188 
    189    testGroupAttrs(getAcc("li4"), 1, 3, 1);
    190    testGroupAttrs(getAcc("li5"), 2, 3, 1);
    191    testGroupAttrs(getAcc("li6"), 3, 3, 1);
    192    // ol with nested list should have 1st level item count and be hierarchical
    193    testGroupParentAttrs(getAcc("ol"), 3, true);
    194 
    195    testGroupAttrs(getAcc("n_li4"), 1, 3, 2);
    196    testGroupAttrs(getAcc("n_li5"), 2, 3, 2);
    197    testGroupAttrs(getAcc("n_li6"), 3, 3, 2);
    198    // nested ol should have item count and be hierarchical
    199    testGroupParentAttrs(getAcc("ol_nested"), 3, true);
    200 
    201    // ////////////////////////////////////////////////////////////////////////
    202    // ARIA list
    203    testGroupAttrs(getAcc("li7"), 1, 3);
    204    testGroupAttrs(getAcc("li8"), 2, 3);
    205    testGroupAttrs(getAcc("li9"), 3, 3);
    206    // simple flat aria list
    207    testGroupParentAttrs(getAcc("aria-list_1"), 3, false);
    208 
    209    // ////////////////////////////////////////////////////////////////////////
    210    // ARIA list (nested lists: list -> listitem -> list -> listitem)
    211    testGroupAttrs(getAcc("li10"), 1, 3, 1);
    212    testGroupAttrs(getAcc("li11"), 2, 3, 1);
    213    testGroupAttrs(getAcc("li12"), 3, 3, 1);
    214    // aria list with nested list
    215    testGroupParentAttrs(getAcc("aria-list_2"), 3, true);
    216 
    217    testGroupAttrs(getAcc("n_li10"), 1, 3, 2);
    218    testGroupAttrs(getAcc("n_li11"), 2, 3, 2);
    219    testGroupAttrs(getAcc("n_li12"), 3, 3, 2);
    220    // nested aria list.
    221    testGroupParentAttrs(getAcc("aria-list_2_1"), 3, true);
    222 
    223    // ////////////////////////////////////////////////////////////////////////
    224    // ARIA list (nested lists: list -> listitem -> group -> listitem)
    225    testGroupAttrs(getAcc("lgt_li1"), 1, 2, 1);
    226    testGroupAttrs(getAcc("lgt_li1_nli1"), 1, 2, 2);
    227    testGroupAttrs(getAcc("lgt_li1_nli2"), 2, 2, 2);
    228    testGroupAttrs(getAcc("lgt_li2"), 2, 2, 1);
    229    testGroupAttrs(getAcc("lgt_li2_nli1"), 1, 2, 2);
    230    testGroupAttrs(getAcc("lgt_li2_nli2"), 2, 2, 2);
    231    // aria list with nested list
    232    testGroupParentAttrs(getAcc("aria-list_3"), 2, true);
    233  },
    234  {
    235    topLevel: true,
    236    iframe: true,
    237    remoteIframe: true,
    238    chrome: true,
    239  }
    240 );
    241 
    242 addAccessibleTask(
    243  `<ul role="menubar" id="menubar">
    244    <li role="menuitem" aria-haspopup="true" id="menu_item1">File
    245      <ul role="menu" id="menu">
    246        <li role="menuitem" id="menu_item1.1">New</li>
    247        <li role="menuitem" id="menu_item1.2">Open…</li>
    248        <li role="separator">-----</li>
    249        <li role="menuitem" id="menu_item1.3">Item</li>
    250        <li role="menuitemradio" id="menu_item1.4">Radio</li>
    251        <li role="menuitemcheckbox" id="menu_item1.5">Checkbox</li>
    252      </ul>
    253    </li>
    254    <li role="menuitem" aria-haspopup="false" id="menu_item2">Help</li>
    255  </ul>`,
    256  async function (browser, accDoc) {
    257    let getAcc = id => findAccessibleChildByID(accDoc, id);
    258 
    259    // ////////////////////////////////////////////////////////////////////////
    260    // ARIA menu (menuitem, separator, menuitemradio and menuitemcheckbox)
    261    testGroupAttrs(getAcc("menu_item1"), 1, 2);
    262    testGroupAttrs(getAcc("menu_item2"), 2, 2);
    263    testGroupAttrs(getAcc("menu_item1.1"), 1, 2);
    264    testGroupAttrs(getAcc("menu_item1.2"), 2, 2);
    265    testGroupAttrs(getAcc("menu_item1.3"), 1, 3);
    266    testGroupAttrs(getAcc("menu_item1.4"), 2, 3);
    267    testGroupAttrs(getAcc("menu_item1.5"), 3, 3);
    268    // menu bar item count
    269    testGroupParentAttrs(getAcc("menubar"), 2, false);
    270    // Bug 1492529. Menu should have total number of items 5 from both sets,
    271    // but only has the first 2 item set.
    272    todoAttr(getAcc("menu"), "child-item-count", "5");
    273  },
    274  {
    275    topLevel: true,
    276    iframe: true,
    277    remoteIframe: true,
    278    chrome: true,
    279  }
    280 );
    281 
    282 addAccessibleTask(
    283  `<ul id="tablist_1" role="tablist">
    284    <li id="tab_1" role="tab">Crust</li>
    285    <li id="tab_2" role="tab">Veges</li>
    286    <li id="tab_3" role="tab">Carnivore</li>
    287  </ul>`,
    288  async function (browser, accDoc) {
    289    let getAcc = id => findAccessibleChildByID(accDoc, id);
    290 
    291    // ////////////////////////////////////////////////////////////////////////
    292    // ARIA tab
    293    testGroupAttrs(getAcc("tab_1"), 1, 3);
    294    testGroupAttrs(getAcc("tab_2"), 2, 3);
    295    testGroupAttrs(getAcc("tab_3"), 3, 3);
    296    // tab list tab count
    297    testGroupParentAttrs(getAcc("tablist_1"), 3, false);
    298  },
    299  {
    300    topLevel: true,
    301    iframe: true,
    302    remoteIframe: true,
    303    chrome: true,
    304  }
    305 );
    306 
    307 addAccessibleTask(
    308  `<ul id="rg1" role="radiogroup">
    309    <li id="r1" role="radio" aria-checked="false">Thai</li>
    310    <li id="r2" role="radio" aria-checked="false">Subway</li>
    311    <li id="r3" role="radio" aria-checked="false">Jimmy Johns</li>
    312  </ul>`,
    313  async function (browser, accDoc) {
    314    let getAcc = id => findAccessibleChildByID(accDoc, id);
    315 
    316    // ////////////////////////////////////////////////////////////////////////
    317    // ARIA radio
    318    testGroupAttrs(getAcc("r1"), 1, 3);
    319    testGroupAttrs(getAcc("r2"), 2, 3);
    320    testGroupAttrs(getAcc("r3"), 3, 3);
    321    // explicit aria radio group
    322    testGroupParentAttrs(getAcc("rg1"), 3, false);
    323  },
    324  {
    325    topLevel: true,
    326    iframe: true,
    327    remoteIframe: true,
    328    chrome: true,
    329  }
    330 );
    331 
    332 addAccessibleTask(
    333  `<table role="tree" id="tree_1">
    334    <tr role="presentation">
    335      <td role="treeitem" aria-expanded="true" aria-level="1"
    336          id="ti1">vegetables</td>
    337    </tr>
    338    <tr role="presentation">
    339      <td role="treeitem" aria-level="2" id="ti2">cucumber</td>
    340    </tr>
    341    <tr role="presentation">
    342      <td role="treeitem" aria-level="2" id="ti3">carrot</td>
    343    </tr>
    344    <tr role="presentation">
    345      <td role="treeitem" aria-expanded="false" aria-level="1"
    346          id="ti4">cars</td>
    347    </tr>
    348    <tr role="presentation">
    349      <td role="treeitem" aria-level="2" id="ti5">mercedes</td>
    350    </tr>
    351    <tr role="presentation">
    352      <td role="treeitem" aria-level="2" id="ti6">BMW</td>
    353    </tr>
    354    <tr role="presentation">
    355      <td role="treeitem" aria-level="2" id="ti7">Audi</td>
    356    </tr>
    357    <tr role="presentation">
    358      <td role="treeitem" aria-level="1" id="ti8">people</td>
    359    </tr>
    360  </table>
    361 
    362  <ul role="tree" id="tree_2">
    363    <li role="treeitem" id="tree2_ti1">Item 1
    364      <ul role="group">
    365        <li role="treeitem" id="tree2_ti1a">Item 1A</li>
    366        <li role="treeitem" id="tree2_ti1b">Item 1B</li>
    367      </ul>
    368    </li>
    369    <li role="treeitem" id="tree2_ti2">Item 2
    370      <ul role="group">
    371        <li role="treeitem" id="tree2_ti2a">Item 2A</li>
    372        <li role="treeitem" id="tree2_ti2b">Item 2B</li>
    373      </ul>
    374    </li>
    375  </div>
    376 
    377  <div role="tree" id="tree_3">
    378    <div role="treeitem" id="tree3_ti1">Item 1</div>
    379    <div role="group">
    380      <li role="treeitem" id="tree3_ti1a">Item 1A</li>
    381      <li role="treeitem" id="tree3_ti1b">Item 1B</li>
    382    </div>
    383    <div role="treeitem" id="tree3_ti2">Item 2</div>
    384    <div role="group">
    385      <div role="treeitem" id="tree3_ti2a">Item 2A</div>
    386      <div role="treeitem" id="tree3_ti2b">Item 2B</div>
    387    </div>
    388  </div>`,
    389  async function (browser, accDoc) {
    390    let getAcc = id => findAccessibleChildByID(accDoc, id);
    391 
    392    // ////////////////////////////////////////////////////////////////////////
    393    // ARIA tree
    394    testGroupAttrs(getAcc("ti1"), 1, 3, 1);
    395    testGroupAttrs(getAcc("ti2"), 1, 2, 2);
    396    testGroupAttrs(getAcc("ti3"), 2, 2, 2);
    397    testGroupAttrs(getAcc("ti4"), 2, 3, 1);
    398    testGroupAttrs(getAcc("ti5"), 1, 3, 2);
    399    testGroupAttrs(getAcc("ti6"), 2, 3, 2);
    400    testGroupAttrs(getAcc("ti7"), 3, 3, 2);
    401    testGroupAttrs(getAcc("ti8"), 3, 3, 1);
    402    testGroupParentAttrs(getAcc("tree_1"), 3, true);
    403 
    404    // ////////////////////////////////////////////////////////////////////////
    405    // ARIA tree (tree -> treeitem -> group -> treeitem)
    406    testGroupAttrs(getAcc("tree2_ti1"), 1, 2, 1);
    407    testGroupAttrs(getAcc("tree2_ti1a"), 1, 2, 2);
    408    testGroupAttrs(getAcc("tree2_ti1b"), 2, 2, 2);
    409    testGroupAttrs(getAcc("tree2_ti2"), 2, 2, 1);
    410    testGroupAttrs(getAcc("tree2_ti2a"), 1, 2, 2);
    411    testGroupAttrs(getAcc("tree2_ti2b"), 2, 2, 2);
    412    testGroupParentAttrs(getAcc("tree_2"), 2, true);
    413 
    414    // ////////////////////////////////////////////////////////////////////////
    415    // ARIA tree (tree -> treeitem, group -> treeitem)
    416    testGroupAttrs(getAcc("tree3_ti1"), 1, 2, 1);
    417    testGroupAttrs(getAcc("tree3_ti1a"), 1, 2, 2);
    418    testGroupAttrs(getAcc("tree3_ti1b"), 2, 2, 2);
    419    testGroupAttrs(getAcc("tree3_ti2"), 2, 2, 1);
    420    testGroupAttrs(getAcc("tree3_ti2a"), 1, 2, 2);
    421    testGroupAttrs(getAcc("tree3_ti2b"), 2, 2, 2);
    422    testGroupParentAttrs(getAcc("tree_3"), 2, true);
    423  },
    424  {
    425    topLevel: true,
    426    iframe: true,
    427    remoteIframe: true,
    428    chrome: true,
    429  }
    430 );