accessible/tests/mochitest/table/test_sels_listbox.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/tests/mochitest/table/test_sels_listbox.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,247 @@
     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="nsIAccessibleTable selection methods on xul:listbox test.">
    1.11 +
    1.12 +  <script type="application/javascript"
    1.13 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
    1.14 +
    1.15 +  <script type="application/javascript"
    1.16 +          src="../common.js"></script>
    1.17 +  <script type="application/javascript"
    1.18 +          src="../table.js"></script>
    1.19 +
    1.20 +  <script type="application/javascript">
    1.21 +  <![CDATA[
    1.22 +    function doTest()
    1.23 +    {
    1.24 +      var id = "listbox3";
    1.25 +      var acc = getAccessible(id, [nsIAccessibleTable]);
    1.26 +
    1.27 +      var rowCount = acc.rows;
    1.28 +      var colsCount = acc.columns;
    1.29 +
    1.30 +      // columns selection
    1.31 +      testColumnSelection(id, acc, colsCount, 0, null);
    1.32 +      acc.selectColumn(0);
    1.33 +      testColumnSelection(id, acc, colsCount, 0, null);
    1.34 +
    1.35 +      // rows selection
    1.36 +      testRowSelection(id, acc, rowCount, 0, null);
    1.37 +      acc.selectRow(0);
    1.38 +      testRowSelection(id, acc, rowCount, 1, [0]);
    1.39 +      acc.selectRow(1);
    1.40 +      testRowSelection(id, acc, rowCount, 1, [1]);
    1.41 +      acc.unselectRow(1);
    1.42 +      testRowSelection(id, acc, rowCount, 0, null);
    1.43 +
    1.44 +      // cells selection
    1.45 +      testCellSelection(id, acc, rowCount, colsCount, 0, null);
    1.46 +      acc.selectRow(2);
    1.47 +      testCellSelection(id, acc, rowCount, colsCount, 3, [6, 7, 8]);
    1.48 +      acc.unselectRow(2);
    1.49 +      testCellSelection(id, acc, rowCount, colsCount, 0, null);
    1.50 +
    1.51 +      SimpleTest.finish();
    1.52 +    }
    1.53 +
    1.54 +    /**
    1.55 +     * Helper function to test isColumnSelected(), selectedColumnCount and
    1.56 +     * getSelectedColumn() methods.
    1.57 +     */
    1.58 +    function testColumnSelection(aId, aAcc, aCount, aSelCount, aSelIndexesArray)
    1.59 +    {
    1.60 +      // isColumnSelected
    1.61 +      for (var col = 0; col < aCount; col++) {
    1.62 +        if (aSelIndexesArray && aSelIndexesArray.indexOf(col) != -1) {
    1.63 +          is(aAcc.isColumnSelected(col), true,
    1.64 +             aId + ": column " + col + " should be selected");
    1.65 +        } else {
    1.66 +          is(aAcc.isColumnSelected(col), false,
    1.67 +             aId + ": column " + col + " shouldn't be selected");
    1.68 +        }
    1.69 +      }
    1.70 +
    1.71 +      // selectedColumnCount
    1.72 +      is(aAcc.selectedColumnCount, aSelCount,
    1.73 +         aId + ": wrong number of selected columns");
    1.74 +
    1.75 +      // getSelectedColumns
    1.76 +      var selColsCount = {}, selCols = {};
    1.77 +      aAcc.getSelectedColumnIndices(selColsCount, selCols);
    1.78 +
    1.79 +      is(selColsCount.value, aSelCount,
    1.80 +         aId + ": wrong number of selected columns");
    1.81 +
    1.82 +      if (!aSelIndexesArray) {
    1.83 +        is(selCols.value, null,
    1.84 +           aId + ": no columns should be selected");
    1.85 +      } else {
    1.86 +        for (var i = 0; i < selCols.length; i++) {
    1.87 +          is(selCols[i], aSelIndexesArray[i],
    1.88 +             aId + ": wrong selected column index " + i);
    1.89 +        }
    1.90 +      }
    1.91 +    }
    1.92 +
    1.93 +    /**
    1.94 +     * Helper function to test isRowSelected(), selectedRowCount() and
    1.95 +     * getSelectedRow() methods.
    1.96 +     */
    1.97 +    function testRowSelection(aId, aAcc, aCount, aSelCount, aSelIndexesArray)
    1.98 +    {
    1.99 +      // isRowSelected
   1.100 +      for (var row = 0; row < aCount; row++) {
   1.101 +        if (aSelIndexesArray && aSelIndexesArray.indexOf(row) != -1) {
   1.102 +          is(aAcc.isRowSelected(row), true,
   1.103 +             aId + ": row " + row + " should be selected");
   1.104 +        } else {
   1.105 +          is(aAcc.isRowSelected(row), false,
   1.106 +             aId + ": row " + row + " shouldn't be selected");
   1.107 +        }
   1.108 +      }
   1.109 +
   1.110 +      // selectedRowCount
   1.111 +      is(aAcc.selectedRowCount, aSelCount,
   1.112 +         aId + ": wrong number of selected rows");
   1.113 +
   1.114 +      // getSelectedRows
   1.115 +      var selColsCount = {}, selCols = {};
   1.116 +      aAcc.getSelectedRowIndices(selColsCount, selCols);
   1.117 +
   1.118 +      is(selColsCount.value, aSelCount,
   1.119 +         aId + ": wrong number of selected rows");
   1.120 +
   1.121 +      if (!aSelIndexesArray) {
   1.122 +        is(selCols.value, null,
   1.123 +           aId + ": no row should be selected");
   1.124 +      } else {
   1.125 +        for (var i = 0; i < selCols.length; i++) {
   1.126 +          is(selCols[i], aSelIndexesArray[i],
   1.127 +             aId + ": wrong selected row index " + i);
   1.128 +        }
   1.129 +      }
   1.130 +    }
   1.131 +
   1.132 +    /**
   1.133 +     * Helper function to test isCellSelected(), selectedCellCount() and
   1.134 +     * getSelectedCells() methods.
   1.135 +     */
   1.136 +    function testCellSelection(aId, aAcc, aRowCount, aColCount,
   1.137 +                               aSelCount, aSelIndexesArray)
   1.138 +    {
   1.139 +      // isCellSelected
   1.140 +      for (var row = 0; row < aRowCount; row++) {
   1.141 +        for (var col = 0; col < aColCount; col++) {
   1.142 +          var index = aAcc.getIndexAt(row, col);
   1.143 +          if (aSelIndexesArray && aSelIndexesArray.indexOf(index) != -1) {
   1.144 +            is(aAcc.isCellSelected(row, col), true,
   1.145 +               aId + ": cell (" + row + ", " + col + ") should be selected");
   1.146 +          } else {
   1.147 +            is(aAcc.isCellSelected(row, col), false,
   1.148 +               aId + ": cell (" + row + ", " + col + ") shouldn't be selected");
   1.149 +          }
   1.150 +        }
   1.151 +      }
   1.152 +
   1.153 +      // selectedCellCount
   1.154 +      is(aAcc.selectedCellCount, aSelCount,
   1.155 +         aId + ": wrong number of selected cells");
   1.156 +
   1.157 +      // getSelectedCells
   1.158 +      var selColsCount = {}, selCols = {};
   1.159 +      aAcc.getSelectedCellIndices(selColsCount, selCols);
   1.160 +
   1.161 +      is(selColsCount.value, aSelCount,
   1.162 +         aId + ": wrong number of selected cells");
   1.163 +
   1.164 +      if (!aSelIndexesArray) {
   1.165 +        is(selCols.value, null,
   1.166 +           aId + ": no cells should be selected");
   1.167 +      } else {
   1.168 +        for (var i = 0; i < selCols.length; i++) {
   1.169 +          is(selCols[i], aSelIndexesArray[i],
   1.170 +             aId + ": wrong selected cell index " + i);
   1.171 +        }
   1.172 +      }
   1.173 +    }
   1.174 +
   1.175 +    SimpleTest.waitForExplicitFinish();
   1.176 +    addA11yLoadEvent(doTest);
   1.177 +  ]]>
   1.178 +  </script>
   1.179 +
   1.180 +  <hbox style="overflow: auto;">
   1.181 +  <body xmlns="http://www.w3.org/1999/xhtml">
   1.182 +    <a target="_blank"
   1.183 +       href="https://bugzilla.mozilla.org/show_bug.cgi?id=418371"
   1.184 +       title="implement the rest of methods of nsIAccessibleTable on xul:listbox">
   1.185 +      Mozilla Bug 418371
   1.186 +    </a>
   1.187 +    <a target="_blank"
   1.188 +       href="https://bugzilla.mozilla.org/show_bug.cgi?id=512424"
   1.189 +       title="implement IAccessibleTable2">
   1.190 +      Mozilla Bug 512424
   1.191 +    </a>
   1.192 +
   1.193 +    <p id="display"></p>
   1.194 +    <div id="content" style="display: none">
   1.195 +    </div>
   1.196 +    <pre id="test">
   1.197 +    </pre>
   1.198 +  </body>
   1.199 +
   1.200 +  <vbox flex="1">
   1.201 +
   1.202 +    <label control="listbox2" value="multicolumn listbox: "/>
   1.203 +    <listbox id="listbox2">
   1.204 +      <listcols>
   1.205 +        <listcol flex="1"/>
   1.206 +        <listcol flex="1"/>
   1.207 +      </listcols>
   1.208 +      <listitem>
   1.209 +        <listcell label="cell1"/>
   1.210 +        <listcell label="cell2"/>
   1.211 +      </listitem>
   1.212 +      <listitem>
   1.213 +        <listcell label="cell1"/>
   1.214 +        <listcell label="cell2"/>
   1.215 +      </listitem>
   1.216 +    </listbox>
   1.217 +
   1.218 +    <label control="listbox3" value="multicolumn listbox with header"/>
   1.219 +    <listbox id="listbox3">
   1.220 +      <listhead>
   1.221 +        <listheader label="header1"/>
   1.222 +        <listheader label="header2"/>
   1.223 +        <listheader label="header3"/>
   1.224 +      </listhead>
   1.225 +      <listcols>
   1.226 +        <listcol flex="1"/>
   1.227 +        <listcol flex="1"/>
   1.228 +        <listcol flex="1"/>
   1.229 +      </listcols>
   1.230 +      <listitem>
   1.231 +        <listcell label="cell0"/>
   1.232 +        <listcell label="cell1"/>
   1.233 +        <listcell label="cell2"/>
   1.234 +      </listitem>
   1.235 +      <listitem>
   1.236 +        <listcell label="cell3"/>
   1.237 +        <listcell label="cell4"/>
   1.238 +        <listcell label="cell5"/>
   1.239 +      </listitem>
   1.240 +      <listitem>
   1.241 +        <listcell label="cell6"/>
   1.242 +        <listcell label="cell7"/>
   1.243 +        <listcell label="cell8"/>
   1.244 +      </listitem>
   1.245 +    </listbox>
   1.246 +  </vbox>
   1.247 +  </hbox>
   1.248 +
   1.249 +</window>
   1.250 +

mercurial