tor-browser

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

browser_test_selection.js (3506B)


      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 /**
      8 * Test implicit selected state.
      9 */
     10 addAccessibleTask(
     11  `
     12 <div role="tablist">
     13  <div id="noSel" role="tab" tabindex="0">noSel</div>
     14  <div id="noSel2" role="tab" tabindex="0">noSel2</div>
     15 </div>
     16 <div role="listbox" aria-multiselectable="true">
     17  <div id="multiNoSel" role="option" tabindex="0">multiNoSel</div>
     18 </div>
     19 <div role="grid">
     20  <div role="row">
     21    <div id="gridcell" role="gridcell" tabindex="0">gridcell</div>
     22  </div>
     23 </div>
     24  `,
     25  async function (browser, docAcc) {
     26    const noSel = findAccessibleChildByID(docAcc, "noSel");
     27    testStates(noSel, 0, 0, STATE_FOCUSED | STATE_SELECTED, 0);
     28    info("Focusing noSel");
     29    let focused = waitForEvent(EVENT_FOCUS, noSel);
     30    noSel.takeFocus();
     31    await focused;
     32    testStates(noSel, STATE_FOCUSED | STATE_SELECTED, 0, 0, 0);
     33 
     34    const noSel2 = findAccessibleChildByID(docAcc, "noSel2");
     35    testStates(noSel2, 0, 0, STATE_FOCUSED | STATE_SELECTED, 0);
     36    info("Focusing noSel2");
     37    focused = waitForEvent(EVENT_FOCUS, noSel2);
     38    noSel2.takeFocus();
     39    await focused;
     40    testStates(noSel2, STATE_FOCUSED | STATE_SELECTED, 0, 0, 0);
     41 
     42    const multiNoSel = findAccessibleChildByID(docAcc, "multiNoSel");
     43    testStates(multiNoSel, 0, 0, STATE_FOCUSED | STATE_SELECTED, 0);
     44    info("Focusing multiNoSel");
     45    focused = waitForEvent(EVENT_FOCUS, multiNoSel);
     46    multiNoSel.takeFocus();
     47    await focused;
     48    testStates(multiNoSel, STATE_FOCUSED, 0, STATE_SELECTED, 0);
     49 
     50    const gridcell = findAccessibleChildByID(docAcc, "gridcell");
     51    testStates(gridcell, 0, 0, STATE_FOCUSED | STATE_SELECTED, 0);
     52    info("Focusing gridcell");
     53    focused = waitForEvent(EVENT_FOCUS, gridcell);
     54    gridcell.takeFocus();
     55    await focused;
     56    testStates(gridcell, STATE_FOCUSED, 0, STATE_SELECTED, 0);
     57  },
     58  { topLevel: true, iframe: true, remoteIframe: true, chrome: true }
     59 );
     60 
     61 // Ensure explicit selection gets priority over implicit selection
     62 addAccessibleTask(
     63  `
     64  <div role="listbox" id="listbox">
     65    <div role="option" aria-selected="true" id="o1">a</div>
     66    <div role="option" tabindex="0" id="o2">b</div>
     67  </div>
     68  `,
     69  async function testExplicitSelection(browser, accDoc) {
     70    const o1 = findAccessibleChildByID(accDoc, "o1");
     71    const o2 = findAccessibleChildByID(accDoc, "o2");
     72 
     73    await untilCacheOk(() => {
     74      const [states] = getStates(o1);
     75      return (states & STATE_SELECTED) != 0;
     76    }, "option 1 should be selected");
     77    await untilCacheOk(() => {
     78      const [states] = getStates(o2);
     79      return (states & STATE_SELECTED) == 0;
     80    }, "option 2 should NOT be selected");
     81 
     82    // Focus the second option.
     83    const e = waitForEvents({
     84      expected: [[EVENT_FOCUS, "o2"]],
     85      unexpected: [[EVENT_SELECTION, "o2"]],
     86    });
     87    await invokeContentTask(browser, [], () => {
     88      content.document.getElementById("o2").focus();
     89    });
     90    await e;
     91 
     92    await untilCacheOk(() => {
     93      const [states] = getStates(o1);
     94      return (states & STATE_SELECTED) != 0;
     95    }, "option 1 should be selected");
     96    await untilCacheOk(() => {
     97      const [states] = getStates(o2);
     98      return (states & STATE_SELECTED) == 0 && (states & STATE_FOCUSED) != 0;
     99    }, "option 2 should NOT be selected but should be focused");
    100  },
    101  { chrome: true, iframe: true, remoteIframe: true }
    102 );