1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/tests/mochitest/events/test_selection.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,246 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 1.7 + type="text/css"?> 1.8 + 1.9 +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.10 + title="Selection event tests"> 1.11 + 1.12 + <script type="application/javascript" 1.13 + src="chrome://mochikit/content/MochiKit/packed.js" /> 1.14 + <script type="application/javascript" 1.15 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> 1.16 + <script type="application/javascript" 1.17 + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> 1.18 + 1.19 + <script type="application/javascript" 1.20 + src="../common.js" /> 1.21 + <script type="application/javascript" 1.22 + src="../role.js" /> 1.23 + <script type="application/javascript" 1.24 + src="../states.js" /> 1.25 + <script type="application/javascript" 1.26 + src="../events.js" /> 1.27 + 1.28 + <script type="application/javascript"> 1.29 + function advanceTab(aTabsID, aDirection, aNextTabID) 1.30 + { 1.31 + this.eventSeq = [ 1.32 + new invokerChecker(EVENT_SELECTION, aNextTabID) 1.33 + ]; 1.34 + 1.35 + this.invoke = function advanceTab_invoke() 1.36 + { 1.37 + getNode(aTabsID).advanceSelectedTab(aDirection, true); 1.38 + } 1.39 + 1.40 + this.getID = function synthFocus_getID() 1.41 + { 1.42 + return "advanceTab on " + prettyName(aTabsID) + " to " + prettyName(aNextTabID); 1.43 + } 1.44 + } 1.45 + 1.46 + function select4FirstItems(aID) 1.47 + { 1.48 + this.listboxNode = getNode(aID); 1.49 + this.eventSeq = [ 1.50 + new invokerChecker(EVENT_SELECTION_ADD, this.listboxNode.getItemAtIndex(0)), 1.51 + new invokerChecker(EVENT_SELECTION_ADD, this.listboxNode.getItemAtIndex(1)), 1.52 + new invokerChecker(EVENT_SELECTION_ADD, this.listboxNode.getItemAtIndex(2)), 1.53 + new invokerChecker(EVENT_SELECTION_ADD, this.listboxNode.getItemAtIndex(3)) 1.54 + ]; 1.55 + 1.56 + this.invoke = function select4FirstItems_invoke() 1.57 + { 1.58 + synthesizeKey("VK_DOWN", { shiftKey: true }); // selects two items 1.59 + synthesizeKey("VK_DOWN", { shiftKey: true }); 1.60 + synthesizeKey("VK_DOWN", { shiftKey: true }); 1.61 + } 1.62 + 1.63 + this.getID = function select4FirstItems_getID() 1.64 + { 1.65 + return "select 4 first items for " + prettyName(aID); 1.66 + } 1.67 + } 1.68 + 1.69 + function unselect4FirstItems(aID) 1.70 + { 1.71 + this.listboxNode = getNode(aID); 1.72 + this.eventSeq = [ 1.73 + new invokerChecker(EVENT_SELECTION_REMOVE, this.listboxNode.getItemAtIndex(3)), 1.74 + new invokerChecker(EVENT_SELECTION_REMOVE, this.listboxNode.getItemAtIndex(2)), 1.75 + new invokerChecker(EVENT_SELECTION_REMOVE, this.listboxNode.getItemAtIndex(1)), 1.76 + new invokerChecker(EVENT_SELECTION_REMOVE, this.listboxNode.getItemAtIndex(0)) 1.77 + ]; 1.78 + 1.79 + this.invoke = function unselect4FirstItems_invoke() 1.80 + { 1.81 + synthesizeKey("VK_UP", { shiftKey: true }); 1.82 + synthesizeKey("VK_UP", { shiftKey: true }); 1.83 + synthesizeKey("VK_UP", { shiftKey: true }); 1.84 + synthesizeKey(" ", { ctrlKey: true }); // unselect first item 1.85 + } 1.86 + 1.87 + this.getID = function unselect4FirstItems_getID() 1.88 + { 1.89 + return "unselect 4 first items for " + prettyName(aID); 1.90 + } 1.91 + } 1.92 + 1.93 + function selectAllItems(aID) 1.94 + { 1.95 + this.listboxNode = getNode(aID); 1.96 + this.eventSeq = [ 1.97 + new invokerChecker(EVENT_SELECTION_WITHIN, getAccessible(this.listboxNode)) 1.98 + ]; 1.99 + 1.100 + this.invoke = function selectAllItems_invoke() 1.101 + { 1.102 + synthesizeKey("VK_END", { shiftKey: true }); 1.103 + } 1.104 + 1.105 + this.getID = function selectAllItems_getID() 1.106 + { 1.107 + return "select all items for " + prettyName(aID); 1.108 + } 1.109 + } 1.110 + 1.111 + function unselectAllItemsButFirst(aID) 1.112 + { 1.113 + this.listboxNode = getNode(aID); 1.114 + this.eventSeq = [ 1.115 + new invokerChecker(EVENT_SELECTION_WITHIN, getAccessible(this.listboxNode)) 1.116 + ]; 1.117 + 1.118 + this.invoke = function unselectAllItemsButFirst_invoke() 1.119 + { 1.120 + synthesizeKey("VK_HOME", { shiftKey: true }); 1.121 + } 1.122 + 1.123 + this.getID = function unselectAllItemsButFirst_getID() 1.124 + { 1.125 + return "unselect all items for " + prettyName(aID); 1.126 + } 1.127 + } 1.128 + 1.129 + function unselectSelectItem(aID) 1.130 + { 1.131 + this.listboxNode = getNode(aID); 1.132 + this.eventSeq = [ 1.133 + new invokerChecker(EVENT_SELECTION_REMOVE, this.listboxNode.getItemAtIndex(0)), 1.134 + new invokerChecker(EVENT_SELECTION_ADD, this.listboxNode.getItemAtIndex(0)) 1.135 + ]; 1.136 + 1.137 + this.invoke = function unselectSelectItem_invoke() 1.138 + { 1.139 + synthesizeKey(" ", { ctrlKey: true }); // select item 1.140 + synthesizeKey(" ", { ctrlKey: true }); // unselect item 1.141 + } 1.142 + 1.143 + this.getID = function unselectSelectItem_getID() 1.144 + { 1.145 + return "unselect and then select first item for " + prettyName(aID); 1.146 + } 1.147 + } 1.148 + 1.149 + /** 1.150 + * Do tests. 1.151 + */ 1.152 + var gQueue = null; 1.153 + 1.154 + //gA11yEventDumpToConsole = true; // debuggin 1.155 + 1.156 + function doTests() 1.157 + { 1.158 + gQueue = new eventQueue(); 1.159 + 1.160 + ////////////////////////////////////////////////////////////////////////// 1.161 + // tabbox 1.162 + gQueue.push(new advanceTab("tabs", 1, "tab3")); 1.163 + 1.164 + ////////////////////////////////////////////////////////////////////////// 1.165 + // listbox 1.166 + gQueue.push(new synthClick("lb1_item1", 1.167 + new invokerChecker(EVENT_SELECTION, "lb1_item1"))); 1.168 + gQueue.push(new synthDownKey("lb1_item1", 1.169 + new invokerChecker(EVENT_SELECTION, "lb1_item2"))); 1.170 + 1.171 + ////////////////////////////////////////////////////////////////////////// 1.172 + // multiselectable listbox 1.173 + gQueue.push(new synthClick("lb2_item1", 1.174 + new invokerChecker(EVENT_SELECTION, "lb2_item1"))); 1.175 + gQueue.push(new synthDownKey("lb2_item1", 1.176 + new invokerChecker(EVENT_SELECTION_ADD, "lb2_item2"), 1.177 + { shiftKey: true })); 1.178 + gQueue.push(new synthUpKey("lb2_item2", 1.179 + new invokerChecker(EVENT_SELECTION_REMOVE, "lb2_item2"), 1.180 + { shiftKey: true })); 1.181 + gQueue.push(new synthKey("lb2_item1", " ", { ctrlKey: true }, 1.182 + new invokerChecker(EVENT_SELECTION_REMOVE, "lb2_item1"))); 1.183 + 1.184 + ////////////////////////////////////////////////////////////////////////// 1.185 + // selection event coalescence 1.186 + 1.187 + // fire 4 selection_add events 1.188 + gQueue.push(new select4FirstItems("listbox2")); 1.189 + // fire 4 selection_remove events 1.190 + gQueue.push(new unselect4FirstItems("listbox2")); 1.191 + // fire selection_within event 1.192 + gQueue.push(new selectAllItems("listbox2")); 1.193 + // fire selection_within event 1.194 + gQueue.push(new unselectAllItemsButFirst("listbox2")); 1.195 + // fire selection_remove/add events 1.196 + gQueue.push(new unselectSelectItem("listbox2")); 1.197 + 1.198 + gQueue.invoke(); // Will call SimpleTest.finish(); 1.199 + } 1.200 + 1.201 + SimpleTest.waitForExplicitFinish(); 1.202 + addA11yLoadEvent(doTests); 1.203 + </script> 1.204 + 1.205 + <hbox flex="1" style="overflow: auto;"> 1.206 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.207 + <a target="_blank" 1.208 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=414302" 1.209 + title="Incorrect selection events in HTML, XUL and ARIA"> 1.210 + Mozilla Bug 414302 1.211 + </a> 1.212 + <p id="display"></p> 1.213 + <div id="content" style="display: none"></div> 1.214 + <pre id="test"> 1.215 + </pre> 1.216 + </body> 1.217 + 1.218 + <tabbox id="tabbox" selectedIndex="1"> 1.219 + <tabs id="tabs"> 1.220 + <tab id="tab1" label="tab1"/> 1.221 + <tab id="tab2" label="tab2"/> 1.222 + <tab id="tab3" label="tab3"/> 1.223 + <tab id="tab4" label="tab4"/> 1.224 + </tabs> 1.225 + <tabpanels> 1.226 + <tabpanel><!-- tabpanel First elements go here --></tabpanel> 1.227 + <tabpanel><button id="b1" label="b1"/></tabpanel> 1.228 + <tabpanel><button id="b2" label="b2"/></tabpanel> 1.229 + <tabpanel></tabpanel> 1.230 + </tabpanels> 1.231 + </tabbox> 1.232 + 1.233 + <listbox id="listbox"> 1.234 + <listitem id="lb1_item1" label="item1"/> 1.235 + <listitem id="lb1_item2" label="item2"/> 1.236 + </listbox> 1.237 + 1.238 + <listbox id="listbox2" seltype="multiple"> 1.239 + <listitem id="lb2_item1" label="item1"/> 1.240 + <listitem id="lb2_item2" label="item2"/> 1.241 + <listitem id="lb2_item3" label="item3"/> 1.242 + <listitem id="lb2_item4" label="item4"/> 1.243 + <listitem id="lb2_item5" label="item5"/> 1.244 + <listitem id="lb2_item6" label="item6"/> 1.245 + <listitem id="lb2_item7" label="item7"/> 1.246 + </listbox> 1.247 + 1.248 + </hbox> 1.249 +</window>