tor-browser

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

test_focus_selects.html (5770B)


      1 <html>
      2 
      3 <head>
      4  <title>Accessible focus testing</title>
      5 
      6  <link rel="stylesheet" type="text/css"
      7        href="chrome://mochikit/content/tests/SimpleTest/test.css" />
      8 
      9  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     10  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
     11 
     12  <script type="application/javascript"
     13          src="../common.js"></script>
     14  <script type="application/javascript"
     15          src="../promisified-events.js"></script>
     16  <script type="application/javascript"
     17          src="../role.js"></script>
     18  <script type="application/javascript"
     19          src="../states.js"></script>
     20 
     21  <script type="application/javascript">
     22    // gA11yEventDumpID = "eventdump"; // debug stuff
     23    // gA11yEventDumpToConsole = true;
     24    var gQueue = null;
     25 
     26    async function doTests() {
     27      // Bug 746534 - File causes crash or hang on OS X
     28      if (MAC) {
     29        todo(false, "Bug 746534 - test file causes crash or hang on OS X");
     30        SimpleTest.finish();
     31        return;
     32      }
     33 
     34      let p = waitForEvent(EVENT_FOCUS, "orange");
     35      // first item is focused until there's selection
     36      getNode("list").focus();
     37      await p;
     38 
     39      p = waitForEvents({
     40        expected: [[EVENT_SELECTION, "orange"]],
     41        unexpected: [
     42          [EVENT_FOCUS],
     43          stateChangeEventArgs("orange", EXT_STATE_ACTIVE, true, true),
     44        ],
     45      });
     46      // item is selected and stays focused and active
     47      synthesizeKey("VK_DOWN");
     48      await p;
     49 
     50      p = waitForEvents([
     51        stateChangeEventArgs("orange", EXT_STATE_ACTIVE, false, true),
     52        stateChangeEventArgs("apple", EXT_STATE_ACTIVE, true, true),
     53        [EVENT_FOCUS, "apple"],
     54      ]);
     55      // last selected item is focused
     56      synthesizeKey("VK_DOWN", { shiftKey: true });
     57      await p;
     58 
     59      p = waitForEvents({
     60        expected: [
     61          [EVENT_FOCUS, "orange"],
     62          stateChangeEventArgs("orange", EXT_STATE_ACTIVE, true, true),
     63        ],
     64        unexpected: [
     65          [EVENT_FOCUS, "apple"],
     66          stateChangeEventArgs("apple", EXT_STATE_ACTIVE, true, true),
     67        ],
     68      });
     69      // no focus event if nothing is changed
     70      synthesizeKey("VK_DOWN");
     71      // current item is focused
     72      synthesizeKey("VK_UP", { ctrlKey: true });
     73      await p;
     74 
     75      p = waitForEvent(EVENT_FOCUS, "emptylist");
     76      // focus on empty list (no items to be focused)
     77      synthesizeKey("VK_TAB");
     78      await p;
     79 
     80      p = waitForEvents({
     81        expected: [[EVENT_FOCUS, "orange"]],
     82        unexpected: [stateChangeEventArgs("orange", EXT_STATE_ACTIVE, true, true)],
     83      });
     84      // current item is focused
     85      synthesizeKey("VK_TAB", { shiftKey: true });
     86      await p;
     87 
     88      p = waitForEvent(EVENT_FOCUS, "combobox");
     89      getNode("combobox").focus();
     90      await p;
     91 
     92      p = waitForEvents({
     93        expected: [[EVENT_SELECTION, "cb_apple"]],
     94        unexpected: [
     95          [EVENT_FOCUS],
     96          stateChangeEventArgs("cb_apple", EXT_STATE_ACTIVE, true, true),
     97        ],
     98      });
     99      // collapsed combobox keeps a focus
    100      synthesizeKey("VK_DOWN");
    101      await p;
    102 
    103      // no focus events for unfocused list controls when current item is
    104      // changed
    105 
    106      p = waitForEvent(EVENT_FOCUS, "emptylist");
    107      getNode("emptylist").focus();
    108      await p;
    109 
    110      p = waitForEvents({
    111        expected: [[EVENT_SELECTION, "orange"]],
    112        unexpected: [
    113          [EVENT_FOCUS],
    114          stateChangeEventArgs("orange", EXT_STATE_ACTIVE, true, true),
    115        ],
    116      });
    117      // An unfocused selectable list gets selection change events,
    118      // but not active or focus change events.
    119      getNode("list").selectedIndex = getNode("orange").index;
    120      await p;
    121 
    122      p = waitForEvents({
    123        expected: [[EVENT_SELECTION, "cb_orange"]],
    124        unexpected: [
    125          [EVENT_FOCUS],
    126          stateChangeEventArgs("cb_orange", EXT_STATE_ACTIVE, true, true),
    127        ],
    128      });
    129      // An unfocused selectable combobox gets selection change events,
    130      // but not focus events nor active state change events.
    131      getNode("cb_orange").selected = true;
    132      await p;
    133 
    134      // Bug 1838983: Make sure we don't fail a C++ assertion when the focused
    135      // active item is destroyed.
    136      info("Focusing recreate");
    137      p = waitForEvent(EVENT_FOCUS, "recreateA");
    138      const recreate = getNode("recreate");
    139      recreate.focus();
    140      await p;
    141      info("Changing recreate size");
    142      p = waitForEvent(EVENT_FOCUS, recreate);
    143      // This will recreate the select and its children.
    144      recreate.size = 1;
    145      await p;
    146 
    147      SimpleTest.finish();
    148    }
    149 
    150    SimpleTest.waitForExplicitFinish();
    151    addA11yLoadEvent(doTests);
    152  </script>
    153 </head>
    154 
    155 <body>
    156 
    157  <a target="_blank"
    158     href="https://bugzilla.mozilla.org/show_bug.cgi?id=433418"
    159     title="Accessibles for focused HTML Select elements are not getting focused state">
    160    Mozilla Bug 433418
    161  </a>
    162  <a target="_blank"
    163     href="https://bugzilla.mozilla.org/show_bug.cgi?id=474893"
    164     title="List controls should fire a focus event on the selected child when tabbing or when the selected child changes while the list is focused">
    165    Mozilla Bug 474893
    166  </a>
    167  <p id="display"></p>
    168  <div id="content" style="display: none"></div>
    169  <pre id="test">
    170  </pre>
    171 
    172  <select id="list" size="5" multiple="">
    173    <option id="orange">Orange</option>
    174    <option id="apple">Apple</option>
    175  </select>
    176 
    177  <select id="emptylist" size="5"></select>
    178 
    179  <select id="combobox">
    180    <option id="cb_orange">Orange</option>
    181    <option id="cb_apple">Apple</option>
    182  </select>
    183 
    184  <select id="recreate" size="5">
    185    <option id="recreateA">a</option>
    186  </select>
    187 
    188  <div id="eventdump"></div>
    189 </body>
    190 </html>