|
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="nsIAccessibleTable selection methods on xul:listbox test."> |
|
8 |
|
9 <script type="application/javascript" |
|
10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> |
|
11 |
|
12 <script type="application/javascript" |
|
13 src="../common.js"></script> |
|
14 <script type="application/javascript" |
|
15 src="../table.js"></script> |
|
16 |
|
17 <script type="application/javascript"> |
|
18 <![CDATA[ |
|
19 function doTest() |
|
20 { |
|
21 var id = "listbox3"; |
|
22 var acc = getAccessible(id, [nsIAccessibleTable]); |
|
23 |
|
24 var rowCount = acc.rows; |
|
25 var colsCount = acc.columns; |
|
26 |
|
27 // columns selection |
|
28 testColumnSelection(id, acc, colsCount, 0, null); |
|
29 acc.selectColumn(0); |
|
30 testColumnSelection(id, acc, colsCount, 0, null); |
|
31 |
|
32 // rows selection |
|
33 testRowSelection(id, acc, rowCount, 0, null); |
|
34 acc.selectRow(0); |
|
35 testRowSelection(id, acc, rowCount, 1, [0]); |
|
36 acc.selectRow(1); |
|
37 testRowSelection(id, acc, rowCount, 1, [1]); |
|
38 acc.unselectRow(1); |
|
39 testRowSelection(id, acc, rowCount, 0, null); |
|
40 |
|
41 // cells selection |
|
42 testCellSelection(id, acc, rowCount, colsCount, 0, null); |
|
43 acc.selectRow(2); |
|
44 testCellSelection(id, acc, rowCount, colsCount, 3, [6, 7, 8]); |
|
45 acc.unselectRow(2); |
|
46 testCellSelection(id, acc, rowCount, colsCount, 0, null); |
|
47 |
|
48 SimpleTest.finish(); |
|
49 } |
|
50 |
|
51 /** |
|
52 * Helper function to test isColumnSelected(), selectedColumnCount and |
|
53 * getSelectedColumn() methods. |
|
54 */ |
|
55 function testColumnSelection(aId, aAcc, aCount, aSelCount, aSelIndexesArray) |
|
56 { |
|
57 // isColumnSelected |
|
58 for (var col = 0; col < aCount; col++) { |
|
59 if (aSelIndexesArray && aSelIndexesArray.indexOf(col) != -1) { |
|
60 is(aAcc.isColumnSelected(col), true, |
|
61 aId + ": column " + col + " should be selected"); |
|
62 } else { |
|
63 is(aAcc.isColumnSelected(col), false, |
|
64 aId + ": column " + col + " shouldn't be selected"); |
|
65 } |
|
66 } |
|
67 |
|
68 // selectedColumnCount |
|
69 is(aAcc.selectedColumnCount, aSelCount, |
|
70 aId + ": wrong number of selected columns"); |
|
71 |
|
72 // getSelectedColumns |
|
73 var selColsCount = {}, selCols = {}; |
|
74 aAcc.getSelectedColumnIndices(selColsCount, selCols); |
|
75 |
|
76 is(selColsCount.value, aSelCount, |
|
77 aId + ": wrong number of selected columns"); |
|
78 |
|
79 if (!aSelIndexesArray) { |
|
80 is(selCols.value, null, |
|
81 aId + ": no columns should be selected"); |
|
82 } else { |
|
83 for (var i = 0; i < selCols.length; i++) { |
|
84 is(selCols[i], aSelIndexesArray[i], |
|
85 aId + ": wrong selected column index " + i); |
|
86 } |
|
87 } |
|
88 } |
|
89 |
|
90 /** |
|
91 * Helper function to test isRowSelected(), selectedRowCount() and |
|
92 * getSelectedRow() methods. |
|
93 */ |
|
94 function testRowSelection(aId, aAcc, aCount, aSelCount, aSelIndexesArray) |
|
95 { |
|
96 // isRowSelected |
|
97 for (var row = 0; row < aCount; row++) { |
|
98 if (aSelIndexesArray && aSelIndexesArray.indexOf(row) != -1) { |
|
99 is(aAcc.isRowSelected(row), true, |
|
100 aId + ": row " + row + " should be selected"); |
|
101 } else { |
|
102 is(aAcc.isRowSelected(row), false, |
|
103 aId + ": row " + row + " shouldn't be selected"); |
|
104 } |
|
105 } |
|
106 |
|
107 // selectedRowCount |
|
108 is(aAcc.selectedRowCount, aSelCount, |
|
109 aId + ": wrong number of selected rows"); |
|
110 |
|
111 // getSelectedRows |
|
112 var selColsCount = {}, selCols = {}; |
|
113 aAcc.getSelectedRowIndices(selColsCount, selCols); |
|
114 |
|
115 is(selColsCount.value, aSelCount, |
|
116 aId + ": wrong number of selected rows"); |
|
117 |
|
118 if (!aSelIndexesArray) { |
|
119 is(selCols.value, null, |
|
120 aId + ": no row should be selected"); |
|
121 } else { |
|
122 for (var i = 0; i < selCols.length; i++) { |
|
123 is(selCols[i], aSelIndexesArray[i], |
|
124 aId + ": wrong selected row index " + i); |
|
125 } |
|
126 } |
|
127 } |
|
128 |
|
129 /** |
|
130 * Helper function to test isCellSelected(), selectedCellCount() and |
|
131 * getSelectedCells() methods. |
|
132 */ |
|
133 function testCellSelection(aId, aAcc, aRowCount, aColCount, |
|
134 aSelCount, aSelIndexesArray) |
|
135 { |
|
136 // isCellSelected |
|
137 for (var row = 0; row < aRowCount; row++) { |
|
138 for (var col = 0; col < aColCount; col++) { |
|
139 var index = aAcc.getIndexAt(row, col); |
|
140 if (aSelIndexesArray && aSelIndexesArray.indexOf(index) != -1) { |
|
141 is(aAcc.isCellSelected(row, col), true, |
|
142 aId + ": cell (" + row + ", " + col + ") should be selected"); |
|
143 } else { |
|
144 is(aAcc.isCellSelected(row, col), false, |
|
145 aId + ": cell (" + row + ", " + col + ") shouldn't be selected"); |
|
146 } |
|
147 } |
|
148 } |
|
149 |
|
150 // selectedCellCount |
|
151 is(aAcc.selectedCellCount, aSelCount, |
|
152 aId + ": wrong number of selected cells"); |
|
153 |
|
154 // getSelectedCells |
|
155 var selColsCount = {}, selCols = {}; |
|
156 aAcc.getSelectedCellIndices(selColsCount, selCols); |
|
157 |
|
158 is(selColsCount.value, aSelCount, |
|
159 aId + ": wrong number of selected cells"); |
|
160 |
|
161 if (!aSelIndexesArray) { |
|
162 is(selCols.value, null, |
|
163 aId + ": no cells should be selected"); |
|
164 } else { |
|
165 for (var i = 0; i < selCols.length; i++) { |
|
166 is(selCols[i], aSelIndexesArray[i], |
|
167 aId + ": wrong selected cell index " + i); |
|
168 } |
|
169 } |
|
170 } |
|
171 |
|
172 SimpleTest.waitForExplicitFinish(); |
|
173 addA11yLoadEvent(doTest); |
|
174 ]]> |
|
175 </script> |
|
176 |
|
177 <hbox style="overflow: auto;"> |
|
178 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
179 <a target="_blank" |
|
180 href="https://bugzilla.mozilla.org/show_bug.cgi?id=418371" |
|
181 title="implement the rest of methods of nsIAccessibleTable on xul:listbox"> |
|
182 Mozilla Bug 418371 |
|
183 </a> |
|
184 <a target="_blank" |
|
185 href="https://bugzilla.mozilla.org/show_bug.cgi?id=512424" |
|
186 title="implement IAccessibleTable2"> |
|
187 Mozilla Bug 512424 |
|
188 </a> |
|
189 |
|
190 <p id="display"></p> |
|
191 <div id="content" style="display: none"> |
|
192 </div> |
|
193 <pre id="test"> |
|
194 </pre> |
|
195 </body> |
|
196 |
|
197 <vbox flex="1"> |
|
198 |
|
199 <label control="listbox2" value="multicolumn listbox: "/> |
|
200 <listbox id="listbox2"> |
|
201 <listcols> |
|
202 <listcol flex="1"/> |
|
203 <listcol flex="1"/> |
|
204 </listcols> |
|
205 <listitem> |
|
206 <listcell label="cell1"/> |
|
207 <listcell label="cell2"/> |
|
208 </listitem> |
|
209 <listitem> |
|
210 <listcell label="cell1"/> |
|
211 <listcell label="cell2"/> |
|
212 </listitem> |
|
213 </listbox> |
|
214 |
|
215 <label control="listbox3" value="multicolumn listbox with header"/> |
|
216 <listbox id="listbox3"> |
|
217 <listhead> |
|
218 <listheader label="header1"/> |
|
219 <listheader label="header2"/> |
|
220 <listheader label="header3"/> |
|
221 </listhead> |
|
222 <listcols> |
|
223 <listcol flex="1"/> |
|
224 <listcol flex="1"/> |
|
225 <listcol flex="1"/> |
|
226 </listcols> |
|
227 <listitem> |
|
228 <listcell label="cell0"/> |
|
229 <listcell label="cell1"/> |
|
230 <listcell label="cell2"/> |
|
231 </listitem> |
|
232 <listitem> |
|
233 <listcell label="cell3"/> |
|
234 <listcell label="cell4"/> |
|
235 <listcell label="cell5"/> |
|
236 </listitem> |
|
237 <listitem> |
|
238 <listcell label="cell6"/> |
|
239 <listcell label="cell7"/> |
|
240 <listcell label="cell8"/> |
|
241 </listitem> |
|
242 </listbox> |
|
243 </vbox> |
|
244 </hbox> |
|
245 |
|
246 </window> |
|
247 |