summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/table/test_sels_listbox.xul
blob: 83697e8d0d615310a4793fd13f6fb49dfc067473 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
                 type="text/css"?>

<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        title="nsIAccessibleTable selection methods on xul:listbox test.">

  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />

  <script type="application/javascript"
          src="../common.js"></script>
  <script type="application/javascript"
          src="../table.js"></script>

  <script type="application/javascript">
  <![CDATA[
    function doTest()
    {
      var id = "listbox3";
      var acc = getAccessible(id, [nsIAccessibleTable]);

      var rowCount = acc.rows;
      var colsCount = acc.columns;

      // columns selection
      testColumnSelection(id, acc, colsCount, 0, null);
      acc.selectColumn(0);
      testColumnSelection(id, acc, colsCount, 0, null);

      // rows selection
      testRowSelection(id, acc, rowCount, 0, null);
      acc.selectRow(0);
      testRowSelection(id, acc, rowCount, 1, [0]);
      acc.selectRow(1);
      testRowSelection(id, acc, rowCount, 1, [1]);
      acc.unselectRow(1);
      testRowSelection(id, acc, rowCount, 0, null);

      // cells selection
      testCellSelection(id, acc, rowCount, colsCount, 0, null);
      acc.selectRow(2);
      testCellSelection(id, acc, rowCount, colsCount, 3, [6, 7, 8]);
      acc.unselectRow(2);
      testCellSelection(id, acc, rowCount, colsCount, 0, null);

      SimpleTest.finish();
    }

    /**
     * Helper function to test isColumnSelected(), selectedColumnCount and
     * getSelectedColumn() methods.
     */
    function testColumnSelection(aId, aAcc, aCount, aSelCount, aSelIndexesArray)
    {
      // isColumnSelected
      for (var col = 0; col < aCount; col++) {
        if (aSelIndexesArray && aSelIndexesArray.indexOf(col) != -1) {
          is(aAcc.isColumnSelected(col), true,
             aId + ": column " + col + " should be selected");
        } else {
          is(aAcc.isColumnSelected(col), false,
             aId + ": column " + col + " shouldn't be selected");
        }
      }

      // selectedColumnCount
      is(aAcc.selectedColumnCount, aSelCount,
         aId + ": wrong number of selected columns");

      // getSelectedColumns
      var selColsCount = {}, selCols = {};
      aAcc.getSelectedColumnIndices(selColsCount, selCols);

      is(selColsCount.value, aSelCount,
         aId + ": wrong number of selected columns");

      if (!aSelIndexesArray) {
        is(selCols.value, undefined,
           aId + ": no columns should be selected");
      } else {
        for (var i = 0; i < selCols.length; i++) {
          is(selCols[i], aSelIndexesArray[i],
             aId + ": wrong selected column index " + i);
        }
      }
    }

    /**
     * Helper function to test isRowSelected(), selectedRowCount() and
     * getSelectedRow() methods.
     */
    function testRowSelection(aId, aAcc, aCount, aSelCount, aSelIndexesArray)
    {
      // isRowSelected
      for (var row = 0; row < aCount; row++) {
        if (aSelIndexesArray && aSelIndexesArray.indexOf(row) != -1) {
          is(aAcc.isRowSelected(row), true,
             aId + ": row " + row + " should be selected");
        } else {
          is(aAcc.isRowSelected(row), false,
             aId + ": row " + row + " shouldn't be selected");
        }
      }

      // selectedRowCount
      is(aAcc.selectedRowCount, aSelCount,
         aId + ": wrong number of selected rows");

      // getSelectedRows
      var selColsCount = {}, selCols = {};
      aAcc.getSelectedRowIndices(selColsCount, selCols);

      is(selColsCount.value, aSelCount,
         aId + ": wrong number of selected rows");

      if (!aSelIndexesArray) {
        is(selCols.value, undefined,
           aId + ": no row should be selected");
      } else {
        for (var i = 0; i < selCols.length; i++) {
          is(selCols[i], aSelIndexesArray[i],
             aId + ": wrong selected row index " + i);
        }
      }
    }

    /**
     * Helper function to test isCellSelected(), selectedCellCount() and
     * getSelectedCells() methods.
     */
    function testCellSelection(aId, aAcc, aRowCount, aColCount,
                               aSelCount, aSelIndexesArray)
    {
      // isCellSelected
      for (var row = 0; row < aRowCount; row++) {
        for (var col = 0; col < aColCount; col++) {
          var index = aAcc.getIndexAt(row, col);
          if (aSelIndexesArray && aSelIndexesArray.indexOf(index) != -1) {
            is(aAcc.isCellSelected(row, col), true,
               aId + ": cell (" + row + ", " + col + ") should be selected");
          } else {
            is(aAcc.isCellSelected(row, col), false,
               aId + ": cell (" + row + ", " + col + ") shouldn't be selected");
          }
        }
      }

      // selectedCellCount
      is(aAcc.selectedCellCount, aSelCount,
         aId + ": wrong number of selected cells");

      // getSelectedCells
      var selColsCount = {}, selCols = {};
      aAcc.getSelectedCellIndices(selColsCount, selCols);

      is(selColsCount.value, aSelCount,
         aId + ": wrong number of selected cells");

      if (!aSelIndexesArray) {
        is(selCols.value, undefined,
           aId + ": no cells should be selected");
      } else {
        for (var i = 0; i < selCols.length; i++) {
          is(selCols[i], aSelIndexesArray[i],
             aId + ": wrong selected cell index " + i);
        }
      }
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(doTest);
  ]]>
  </script>

  <hbox style="overflow: auto;">
  <body xmlns="http://www.w3.org/1999/xhtml">
    <a target="_blank"
       href="https://bugzilla.mozilla.org/show_bug.cgi?id=418371"
       title="implement the rest of methods of nsIAccessibleTable on xul:listbox">
      Mozilla Bug 418371
    </a>
    <a target="_blank"
       href="https://bugzilla.mozilla.org/show_bug.cgi?id=512424"
       title="implement IAccessibleTable2">
      Mozilla Bug 512424
    </a>

    <p id="display"></p>
    <div id="content" style="display: none">
    </div>
    <pre id="test">
    </pre>
  </body>

  <vbox flex="1">

    <label control="listbox2" value="multicolumn listbox: "/>
    <listbox id="listbox2">
      <listcols>
        <listcol flex="1"/>
        <listcol flex="1"/>
      </listcols>
      <listitem>
        <listcell label="cell1"/>
        <listcell label="cell2"/>
      </listitem>
      <listitem>
        <listcell label="cell1"/>
        <listcell label="cell2"/>
      </listitem>
    </listbox>

    <label control="listbox3" value="multicolumn listbox with header"/>
    <listbox id="listbox3">
      <listhead>
        <listheader label="header1"/>
        <listheader label="header2"/>
        <listheader label="header3"/>
      </listhead>
      <listcols>
        <listcol flex="1"/>
        <listcol flex="1"/>
        <listcol flex="1"/>
      </listcols>
      <listitem>
        <listcell label="cell0"/>
        <listcell label="cell1"/>
        <listcell label="cell2"/>
      </listitem>
      <listitem>
        <listcell label="cell3"/>
        <listcell label="cell4"/>
        <listcell label="cell5"/>
      </listitem>
      <listitem>
        <listcell label="cell6"/>
        <listcell label="cell7"/>
        <listcell label="cell8"/>
      </listitem>
    </listbox>
  </vbox>
  </hbox>

</window>