accessible/tests/mochitest/events/test_selection.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial