tor-browser

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

test_selection.xhtml (9040B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
      3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
      4                 type="text/css"?>
      5 
      6 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      7        title="Selection event tests">
      8 
      9  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
     10  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
     11 
     12  <script type="application/javascript"
     13          src="../common.js" />
     14  <script type="application/javascript"
     15          src="../role.js" />
     16  <script type="application/javascript"
     17          src="../states.js" />
     18  <script type="application/javascript"
     19          src="../events.js" />
     20 
     21  <script type="application/javascript">
     22    function advanceTab(aTabsID, aDirection, aNextTabID)
     23    {
     24      var eventSeq1 = [
     25        new invokerChecker(EVENT_SELECTION, aNextTabID)
     26      ]
     27      defineScenario(this, eventSeq1);
     28 
     29      var eventSeq2 = [
     30        new invokerChecker(EVENT_HIDE, getAccessible(aNextTabID)),
     31        new invokerChecker(EVENT_SHOW, aNextTabID)
     32      ];
     33      defineScenario(this, eventSeq2);
     34 
     35      this.invoke = function advanceTab_invoke()
     36      {
     37        todo(false, "No accessible recreation should happen, just selection event");
     38        getNode(aTabsID).advanceSelectedTab(aDirection, true);
     39      }
     40 
     41      this.getID = function synthFocus_getID()
     42      {
     43        return "advanceTab on " + prettyName(aTabsID) + " to " + prettyName(aNextTabID);
     44      }
     45    }
     46 
     47    function select4FirstItems(aID)
     48    {
     49      this.listboxNode = getNode(aID);
     50      this.eventSeq = [
     51        new invokerChecker(EVENT_SELECTION_ADD, this.listboxNode.getItemAtIndex(0)),
     52        new invokerChecker(EVENT_SELECTION_ADD, this.listboxNode.getItemAtIndex(1)),
     53        new invokerChecker(EVENT_SELECTION_ADD, this.listboxNode.getItemAtIndex(2)),
     54        new invokerChecker(EVENT_SELECTION_ADD, this.listboxNode.getItemAtIndex(3))
     55      ];
     56 
     57      this.invoke = function select4FirstItems_invoke()
     58      {
     59        synthesizeKey("VK_DOWN", { shiftKey: true }); // selects two items
     60        synthesizeKey("VK_DOWN", { shiftKey: true });
     61        synthesizeKey("VK_DOWN", { shiftKey: true });
     62      }
     63 
     64      this.getID = function select4FirstItems_getID()
     65      {
     66        return "select 4 first items for " + prettyName(aID);
     67      }
     68    }
     69 
     70    function unselect4FirstItems(aID)
     71    {
     72      this.listboxNode = getNode(aID);
     73      this.eventSeq = [
     74        new invokerChecker(EVENT_SELECTION_REMOVE, this.listboxNode.getItemAtIndex(3)),
     75        new invokerChecker(EVENT_SELECTION_REMOVE, this.listboxNode.getItemAtIndex(2)),
     76        new invokerChecker(EVENT_SELECTION_REMOVE, this.listboxNode.getItemAtIndex(1)),
     77        new invokerChecker(EVENT_SELECTION_REMOVE, this.listboxNode.getItemAtIndex(0))
     78      ];
     79 
     80      this.invoke = function unselect4FirstItems_invoke()
     81      {
     82        synthesizeKey("VK_UP", { shiftKey: true });
     83        synthesizeKey("VK_UP", { shiftKey: true });
     84        synthesizeKey("VK_UP", { shiftKey: true });
     85        synthesizeKey(" ", { ctrlKey: true }); // unselect first item
     86      }
     87 
     88      this.getID = function unselect4FirstItems_getID()
     89      {
     90        return "unselect 4 first items for " + prettyName(aID);
     91      }
     92    }
     93 
     94    function selectAllItems(aID)
     95    {
     96      this.listboxNode = getNode(aID);
     97      this.eventSeq = [
     98        new invokerChecker(EVENT_SELECTION_WITHIN, getAccessible(this.listboxNode))
     99      ];
    100 
    101      this.invoke = function selectAllItems_invoke()
    102      {
    103        synthesizeKey("VK_END", { shiftKey: true });
    104      }
    105 
    106      this.getID = function selectAllItems_getID()
    107      {
    108        return "select all items for " + prettyName(aID);
    109      }
    110    }
    111 
    112    function unselectAllItemsButFirst(aID)
    113    {
    114      this.listboxNode = getNode(aID);
    115      this.eventSeq = [
    116        new invokerChecker(EVENT_SELECTION_WITHIN, getAccessible(this.listboxNode))
    117      ];
    118 
    119      this.invoke = function unselectAllItemsButFirst_invoke()
    120      {
    121        synthesizeKey("VK_HOME", { shiftKey: true });
    122      }
    123 
    124      this.getID = function unselectAllItemsButFirst_getID()
    125      {
    126        return "unselect all items for " + prettyName(aID);
    127      }
    128    }
    129 
    130    function unselectSelectItem(aID)
    131    {
    132      this.listboxNode = getNode(aID);
    133      this.eventSeq = [
    134        new invokerChecker(EVENT_SELECTION_REMOVE, this.listboxNode.getItemAtIndex(0)),
    135        new invokerChecker(EVENT_SELECTION_ADD, this.listboxNode.getItemAtIndex(0))
    136      ];
    137 
    138      this.invoke = function unselectSelectItem_invoke()
    139      {
    140        synthesizeKey(" ", { ctrlKey: true }); // select item
    141        synthesizeKey(" ", { ctrlKey: true }); // unselect item
    142      }
    143 
    144      this.getID = function unselectSelectItem_getID()
    145      {
    146        return "unselect and then select first item for " + prettyName(aID);
    147      }
    148    }
    149 
    150    /**
    151     * Do tests.
    152     */
    153    var gQueue = null;
    154 
    155    //enableLogging("events");
    156    //gA11yEventDumpToConsole = true; // debuggin
    157 
    158    function doTests()
    159    {
    160      gQueue = new eventQueue();
    161 
    162      //////////////////////////////////////////////////////////////////////////
    163      // tabbox
    164      gQueue.push(new advanceTab("tabs", 1, "tab3"));
    165 
    166      //////////////////////////////////////////////////////////////////////////
    167      // single selection listbox, the first item is selected by default
    168 
    169      gQueue.push(new synthClick("lb1_item2",
    170                                 new invokerChecker(EVENT_SELECTION, "lb1_item2")));
    171      gQueue.push(new synthUpKey("lb1_item2",
    172                                   new invokerChecker(EVENT_SELECTION, "lb1_item1")));
    173      gQueue.push(new synthDownKey("lb1_item1",
    174                                   new invokerChecker(EVENT_SELECTION, "lb1_item2")));
    175 
    176      //////////////////////////////////////////////////////////////////////////
    177      // multiselectable listbox
    178      gQueue.push(new synthClick("lb2_item1",
    179                                 new invokerChecker(EVENT_SELECTION, "lb2_item1")));
    180      gQueue.push(new synthDownKey("lb2_item1",
    181                                   new invokerChecker(EVENT_SELECTION_ADD, "lb2_item2"),
    182                                   { shiftKey: true }));
    183      gQueue.push(new synthUpKey("lb2_item2",
    184                                 new invokerChecker(EVENT_SELECTION_REMOVE, "lb2_item2"),
    185                                 { shiftKey: true }));
    186      gQueue.push(new synthKey("lb2_item1", " ", { ctrlKey: true },
    187                               new invokerChecker(EVENT_SELECTION_REMOVE, "lb2_item1")));
    188 
    189      //////////////////////////////////////////////////////////////////////////
    190      // selection event coalescence
    191 
    192      // fire 4 selection_add events
    193      gQueue.push(new select4FirstItems("listbox2"));
    194      // fire 4 selection_remove events
    195      gQueue.push(new unselect4FirstItems("listbox2"));
    196      // fire selection_within event
    197      gQueue.push(new selectAllItems("listbox2"));
    198      // fire selection_within event
    199      gQueue.push(new unselectAllItemsButFirst("listbox2"));
    200      // fire selection_remove/add events
    201      gQueue.push(new unselectSelectItem("listbox2"));
    202 
    203      gQueue.invoke(); // Will call SimpleTest.finish();
    204    }
    205 
    206    SimpleTest.waitForExplicitFinish();
    207    addA11yLoadEvent(doTests);
    208  </script>
    209 
    210  <hbox flex="1" style="overflow: auto;">
    211    <body xmlns="http://www.w3.org/1999/xhtml">
    212      <a target="_blank"
    213         href="https://bugzilla.mozilla.org/show_bug.cgi?id=414302"
    214         title="Incorrect selection events in HTML, XUL and ARIA">
    215        Mozilla Bug 414302
    216      </a>
    217      <p id="display"></p>
    218      <div id="content" style="display: none"></div>
    219      <pre id="test">
    220      </pre>
    221    </body>
    222 
    223    <tabbox id="tabbox" selectedIndex="1">
    224      <tabs id="tabs">
    225        <tab id="tab1" label="tab1"/>
    226        <tab id="tab2" label="tab2"/>
    227        <tab id="tab3" label="tab3"/>
    228        <tab id="tab4" label="tab4"/>
    229      </tabs>
    230      <tabpanels>
    231        <tabpanel><!-- tabpanel First elements go here --></tabpanel>
    232        <tabpanel><button id="b1" label="b1"/></tabpanel>
    233        <tabpanel><button id="b2" label="b2"/></tabpanel>
    234        <tabpanel></tabpanel>
    235      </tabpanels>
    236    </tabbox>
    237 
    238    <richlistbox id="listbox">
    239      <richlistitem id="lb1_item1"><label value="item1"/></richlistitem>
    240      <richlistitem id="lb1_item2"><label value="item2"/></richlistitem>
    241    </richlistbox>
    242 
    243    <richlistbox id="listbox2" seltype="multiple">
    244      <richlistitem id="lb2_item1"><label value="item1"/></richlistitem>
    245      <richlistitem id="lb2_item2"><label value="item2"/></richlistitem>
    246      <richlistitem id="lb2_item3"><label value="item3"/></richlistitem>
    247      <richlistitem id="lb2_item4"><label value="item4"/></richlistitem>
    248      <richlistitem id="lb2_item5"><label value="item5"/></richlistitem>
    249      <richlistitem id="lb2_item6"><label value="item6"/></richlistitem>
    250      <richlistitem id="lb2_item7"><label value="item7"/></richlistitem>
    251    </richlistbox>
    252 
    253  </hbox>
    254 </window>