<html>
<head>
  <title>[AccessFu] Improve reading of table semantics</title>

  <link rel="stylesheet" type="text/css"
        href="chrome://mochikit/content/tests/SimpleTest/test.css" />
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript"
          src="../common.js"></script>
  <script type="application/javascript"
          src="output.js"></script>
  <script type="application/javascript"
          src="jsatcommon.js"></script>
  <script type="application/javascript">

    function doTest() {
      // Test the following accOrElmOrID.
      var tests = [{
        accOrElmOrID: "table1",
        expectedUtterance: [[
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 2},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "col1",
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "col2",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "col1", "cell1",
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [2]}, "col2", "cell2"], ["col1",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "col2",
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "cell1",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "col1", "cell2",
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [2]}, "col2", {"string": "table"},
          {"string": "tblColumnInfo", "count": 2},
          {"string": "tblRowInfo", "count": 2}]],
        expectedBraille: [[
          {"string": "tableAbbr"},
          {"string": "tblColumnInfoAbbr", "count": 2},
          {"string": "tblRowInfoAbbr", "count": 2},
          {"string": "cellInfoAbbr", "args": [1, 1]}, "col1",
          {"string": "cellInfoAbbr", "args": [2, 1]}, "col2",
          {"string": "cellInfoAbbr", "args": [1, 2]}, "col1", "cell1",
          {"string": "cellInfoAbbr", "args": [2, 2]}, "col2", "cell2"], ["col1",
          {"string": "cellInfoAbbr", "args": [1, 1]}, "col2",
          {"string": "cellInfoAbbr", "args": [2, 1]}, "cell1",
          {"string": "cellInfoAbbr", "args": [1, 2]}, "col1", "cell2",
          {"string": "cellInfoAbbr", "args": [2, 2]}, "col2",
          {"string": "tableAbbr"},
          {"string": "tblColumnInfoAbbr", "count": 2},
          {"string": "tblRowInfoAbbr", "count": 2}]]
      }, {
        accOrElmOrID: "table2",
        expectedUtterance: [[
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 2},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "col1", "cell1",
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "col2",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 1},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "colheader",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "colheader", "bla",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "col1",
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [2]}, "col2"], ["cell1",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "col1", "colheader",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "bla",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "colheader",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 1},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "col2", "col1",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "col2",
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [2]}, {"string": "table"},
          {"string": "tblColumnInfo", "count": 2},
          {"string": "tblRowInfo", "count": 2}]],
        expectedBraille: [[{"string": "tableAbbr"},
          {"string": "tblColumnInfoAbbr", "count": 2},
          {"string": "tblRowInfoAbbr", "count": 2},
          {"string": "cellInfoAbbr", "args": [1, 1]}, "col1", "cell1",
          {"string": "cellInfoAbbr", "args": [2, 1]}, "col2",
          {"string": "tableAbbr"},
          {"string": "tblColumnInfoAbbr", "count": 1},
          {"string": "tblRowInfoAbbr", "count": 2},
          {"string": "cellInfoAbbr", "args": [1, 1]}, "colheader",
          {"string": "cellInfoAbbr", "args": [1, 2]}, "colheader", "bla",
          {"string": "cellInfoAbbr", "args": [1, 2]}, "col1",
          {"string": "cellInfoAbbr", "args": [2, 2]}, "col2"], ["cell1",
          {"string": "cellInfoAbbr", "args": [1, 1]}, "col1", "colheader",
          {"string": "cellInfoAbbr", "args": [1, 1]}, "bla",
          {"string": "cellInfoAbbr", "args": [1, 2]}, "colheader",
          {"string": "tableAbbr"},
          {"string": "tblColumnInfoAbbr", "count": 1},
          {"string": "tblRowInfoAbbr", "count": 2},
          {"string": "cellInfoAbbr", "args": [2, 1]}, "col2", "col1",
          {"string": "cellInfoAbbr", "args": [1, 2]}, "col2",
          {"string": "cellInfoAbbr", "args": [2, 2]},
          {"string": "tableAbbr"},
          {"string": "tblColumnInfoAbbr", "count": 2},
          {"string": "tblRowInfoAbbr", "count": 2}]]
      }, {
        accOrElmOrID: "table3",
        expectedUtterance: [[
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 2},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "col2",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 1},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "colheader",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "colheader", "bla"], ["colheader",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "bla",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "colheader",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 1},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "col2",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 2},
          {"string": "tblRowInfo", "count": 2}]],
        expectedBraille: [[
          {"string": "tableAbbr"},
          {"string": "tblColumnInfoAbbr", "count": 1},
          {"string": "tblRowInfoAbbr", "count": 2},
          {"string": "cellInfoAbbr", "args": [1, 1]}, "colheader",
          {"string": "cellInfoAbbr", "args": [1, 2]}, "colheader", "bla"],
          ["colheader",
          {"string": "cellInfoAbbr", "args": [1, 1]}, "bla",
          {"string": "cellInfoAbbr", "args": [1, 2]}, "colheader",
          {"string": "tableAbbr"},
          {"string": "tblColumnInfoAbbr", "count": 1},
          {"string": "tblRowInfoAbbr", "count": 2}]]
      }, {
        accOrElmOrID: "table4",
        expectedUtterance: [[
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 4},
          {"string": "tblRowInfo", "count": 3},
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "col1",
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "col2",
          {"string": "columnInfo", "args": [3]},
          {"string": "rowInfo", "args": [1]}, "col3",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]},
          {"string": "spansColumns", "args": [2]}, "col1", "row1",
          {"string": "columnInfo", "args": [3]},
          {"string": "rowInfo", "args": [2]}, "col3", "row1", "cell1",
          {"string": "columnInfo", "args": [4]},
          {"string": "rowInfo", "args": [2]},
          {"string": "spansRows", "args": [2]}, "row1", "cell2",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [3]}, "col1", "row2",
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [3]}, "col2", "row2", "cell3",
          {"string": "columnInfo", "args": [3]},
          {"string": "rowInfo", "args": [3]}, "col3", "row2", "cell4"], ["col1",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "col2",
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "col3",
          {"string": "columnInfo", "args": [3]},
          {"string": "rowInfo", "args": [1]}, "row1",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]},
          {"string": "spansColumns", "args": [2]}, "col1", "cell1",
          {"string": "columnInfo", "args": [3]},
          {"string": "rowInfo", "args": [2]}, "col3", "row1", "cell2",
          {"string": "columnInfo", "args": [4]},
          {"string": "rowInfo", "args": [2]},
          {"string": "spansRows", "args": [2]}, "row1", "row2",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [3]}, "col1", "cell3",
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [3]}, "col2", "row2", "cell4",
          {"string": "columnInfo", "args": [3]},
          {"string": "rowInfo", "args": [3]}, "col3", "row2",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 4},
          {"string": "tblRowInfo", "count": 3}]],
        expectedBraille: [[
          {"string": "tableAbbr"},
          {"string": "tblColumnInfoAbbr", "count": 4},
          {"string": "tblRowInfoAbbr", "count": 3},
          {"string": "cellInfoAbbr", "args": [1, 1]}, "col1",
          {"string": "cellInfoAbbr", "args": [2, 1]}, "col2",
          {"string": "cellInfoAbbr", "args": [3, 1]}, "col3",
          {"string": "cellInfoAbbr", "args": [1, 2]}, "col1", "row1",
          {"string": "cellInfoAbbr", "args": [3, 2]}, "col3", "row1", "cell1",
          {"string": "cellInfoAbbr", "args": [4, 2]}, "row1", "cell2",
          {"string": "cellInfoAbbr", "args": [1, 3]}, "col1", "row2",
          {"string": "cellInfoAbbr", "args": [2, 3]}, "col2", "row2", "cell3",
          {"string": "cellInfoAbbr", "args": [3, 3]}, "col3", "row2", "cell4"],
          ["col1",
          {"string": "cellInfoAbbr", "args": [1, 1]}, "col2",
          {"string": "cellInfoAbbr", "args": [2, 1]}, "col3",
          {"string": "cellInfoAbbr", "args": [3, 1]}, "row1",
          {"string": "cellInfoAbbr", "args": [1, 2]}, "col1", "cell1",
          {"string": "cellInfoAbbr", "args": [3, 2]}, "col3", "row1", "cell2",
          {"string": "cellInfoAbbr", "args": [4, 2]}, "row1", "row2",
          {"string": "cellInfoAbbr", "args": [1, 3]}, "col1", "cell3",
          {"string": "cellInfoAbbr", "args": [2, 3]}, "col2", "row2", "cell4",
          {"string": "cellInfoAbbr", "args": [3, 3]}, "col3", "row2",
          {"string": "tableAbbr"},
          {"string": "tblColumnInfoAbbr", "count": 4},
          {"string": "tblRowInfoAbbr", "count": 3}]]
      }, {
        accOrElmOrID: "table5",
        expectedUtterance: [["Row1", "Row2"], ["Row1", "Row2"]],
        expectedBraille: [["Row1", "Row2"], ["Row1", "Row2"]]
      }, {
        // Test pivot to table1_th1 from table1.
        accOrElmOrID: "table1_th1",
        oldAccOrElmOrID: "table1",
        expectedUtterance: [[
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "col1"], ["col1",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}]],
        expectedBraille: [[
          {"string": "cellInfoAbbr", "args": [1, 1]}, "col1"], ["col1",
          {"string": "cellInfoAbbr", "args": [1, 1]}]]
      }, {
        // Test pivot to table1_td2 from table1.
        accOrElmOrID: "table1_td2",
        oldAccOrElmOrID: "table1",
        expectedUtterance: [[
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [2]}, "col2", "cell2"], ["cell2",
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [2]}, "col2"]],
        expectedBraille: [
          [{"string": "cellInfoAbbr", "args": [2, 2]}, "col2", "cell2"],
          ["cell2", {"string": "cellInfoAbbr", "args": [2, 2]}, "col2"]]
      }, {
        // Test pivot to table1_td2 from table1_th1.
        accOrElmOrID: "table1_td2",
        oldAccOrElmOrID: "table1_th1",
        expectedUtterance: [[
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [2]}, "col2", "cell2"], ["cell2",
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [2]}, "col2"]],
        expectedBraille: [
          [{"string": "cellInfoAbbr", "args": [2, 2]}, "col2", "cell2"],
          ["cell2", {"string": "cellInfoAbbr", "args": [2, 2]}, "col2"]]
      }, {
        // Test pivot to table1_td2 from table1_td1.
        accOrElmOrID: "table1_td2",
        oldAccOrElmOrID: "table1_td1",
        expectedUtterance: [[
          {"string": "columnInfo", "args": [2]}, "col2", "cell2"], ["cell2",
          {"string": "columnInfo", "args": [2]}, "col2"]],
        expectedBraille: [
          [{"string": "cellInfoAbbr", "args": [2, 2]}, "col2", "cell2"],
          ["cell2", {"string": "cellInfoAbbr", "args": [2, 2]}, "col2"]]
      }, {
        // Test pivot to table2_cell_1 from table2.
        accOrElmOrID: "table2_cell_1",
        oldAccOrElmOrID: "table2",
        expectedUtterance: [[
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "col1", "cell1"], ["cell1",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "col1"]],
        expectedBraille: [
          [{"string": "cellInfoAbbr", "args": [1, 1]}, "col1", "cell1"],
          ["cell1", {"string": "cellInfoAbbr", "args": [1, 1]}, "col1"]]
      }, {
        // Test pivot to table2_cell_2 from table2.
        accOrElmOrID: "table2_cell_2",
        oldAccOrElmOrID: "table2",
        expectedUtterance: [[
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "col2",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 1},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "colheader",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "colheader", "bla"], ["colheader",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [1]}, "bla",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "colheader",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 1},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "col2"]],
        expectedBraille: [[
          {"string": "cellInfoAbbr", "args": [2, 1]}, "col2",
          {"string": "tableAbbr"},
          {"string": "tblColumnInfoAbbr", "count": 1},
          {"string": "tblRowInfoAbbr", "count": 2},
          {"string": "cellInfoAbbr", "args": [1, 1]}, "colheader",
          {"string": "cellInfoAbbr", "args": [1, 2]}, "colheader", "bla"],
          ["colheader",
          {"string": "cellInfoAbbr", "args": [1, 1]}, "bla",
          {"string": "cellInfoAbbr", "args": [1, 2]}, "colheader",
          {"string": "tableAbbr"},
          {"string": "tblColumnInfoAbbr", "count": 1},
          {"string": "tblRowInfoAbbr", "count": 2},
          {"string": "cellInfoAbbr", "args": [2, 1]}, "col2"]]
      }, {
        // Test pivot to table2_cell_1 from table2_cell_2.
        accOrElmOrID: "table2_cell_1",
        oldAccOrElmOrID: "table2_cell_2",
        expectedUtterance: [[
          {"string": "columnInfo", "args": [1]}, "col1", "cell1"], ["cell1",
          {"string": "columnInfo", "args": [1]}, "col1"]],
        expectedBraille: [
          [{"string": "cellInfoAbbr", "args": [1, 1]}, "col1", "cell1"],
          ["cell1", {"string": "cellInfoAbbr", "args": [1, 1]}, "col1"]]
      }, {
        // Test pivot to table3_cell from table2.
        accOrElmOrID: "table3_cell",
        oldAccOrElmOrID: "table2",
        expectedUtterance: [[
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "col2",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 1},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "colheader", "bla"], ["bla",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "colheader",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 1},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "col2"]],
        expectedBraille: [
          [{"string": "cellInfoAbbr", "args": [1, 2]}, "colheader", "bla"],
          ["bla", {"string": "cellInfoAbbr", "args": [1, 2]}, "colheader"]]
      }, {
        // Test pivot to table3_cell from table2_cell_1.
        accOrElmOrID: "table3_cell",
        oldAccOrElmOrID: "table2_cell_1",
        expectedUtterance: [[
          {"string": "columnInfo", "args": [2]}, "col2",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 1},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "colheader", "bla"], ["bla",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "colheader",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 1},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "col2"]],
        expectedBraille: [
          [{"string": "cellInfoAbbr", "args": [1, 2]}, "colheader", "bla"],
          ["bla", {"string": "cellInfoAbbr", "args": [1, 2]}, "colheader"]]
      }, {
        // Test pivot to table3_cell from table3_ch.
        accOrElmOrID: "table3_cell",
        oldAccOrElmOrID: "table3_ch",
        expectedUtterance: [[
          {"string": "rowInfo", "args": [2]}, "bla"], ["bla",
          {"string": "rowInfo", "args": [2]}]],
        expectedBraille: [
          [{"string": "cellInfoAbbr", "args": [1, 2]}, "bla"],
          ["bla", {"string": "cellInfoAbbr", "args": [1, 2]}]]
      }, {
        // Test pivot to table3_cell from table1_td1.
        accOrElmOrID: "table3_cell",
        oldAccOrElmOrID: "table1_td1",
        expectedUtterance: [[
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 2},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "col2",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 1},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "colheader", "bla"], ["bla",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]}, "colheader",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 1},
          {"string": "tblRowInfo", "count": 2},
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [1]}, "col2",
          {"string": "table"},
          {"string": "tblColumnInfo", "count": 2},
          {"string": "tblRowInfo", "count": 2}]],
        expectedBraille: [
          [{"string": "cellInfoAbbr", "args": [1, 2]}, "colheader", "bla"],
          ["bla", {"string": "cellInfoAbbr", "args": [1, 2]}, "colheader"]]
      }, {
        // Test pivot to table4_ch_3 from table4.
        accOrElmOrID: "table4_ch_3",
        oldAccOrElmOrID: "table4",
        expectedUtterance: [[
          {"string": "columnInfo", "args": [3]},
          {"string": "rowInfo", "args": [1]}, "col3"], ["col3",
          {"string": "columnInfo", "args": [3]},
          {"string": "rowInfo", "args": [1]}]],
        expectedBraille: [
          [{"string": "cellInfoAbbr", "args": [3, 1]}, "col3"],
          ["col3", {"string": "cellInfoAbbr", "args": [3, 1]}]]
      }, {
        // Test pivot to table4_rh_1 from table4_ch_3.
        accOrElmOrID: "table4_rh_1",
        oldAccOrElmOrID: "table4_ch_3",
        expectedUtterance: [[
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]},
          {"string": "spansColumns", "args": [2]}, "col1", "row1"], ["row1",
          {"string": "columnInfo", "args": [1]},
          {"string": "rowInfo", "args": [2]},
          {"string": "spansColumns", "args": [2]}, "col1"]],
        expectedBraille: [
          [{"string": "cellInfoAbbr", "args": [1, 2]}, "col1", "row1"],
          ["row1", {"string": "cellInfoAbbr", "args": [1, 2]}, "col1"]]
      }, {
        // Test pivot to table4_cell_3 from table4_rh_1.
        accOrElmOrID: "table4_cell_3",
        oldAccOrElmOrID: "table4_rh_1",
        expectedUtterance: [[
          {"string": "columnInfo", "args": [4]},
          {"string": "spansRows", "args": [2]}, "cell2"], ["cell2",
          {"string": "columnInfo", "args": [4]},
          {"string": "spansRows", "args": [2]}]],
        expectedBraille: [
          [{"string": "cellInfoAbbr", "args": [4, 2]}, "cell2"],
          ["cell2", {"string": "cellInfoAbbr", "args": [4, 2]}]]
      }, {
        // Test pivot to table4_cell_5 from table4_cell_3.
        accOrElmOrID: "table4_cell_5",
        oldAccOrElmOrID: "table4_cell_3",
        expectedUtterance: [[
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [3]}, "col2", "row2", "cell3"],
          ["cell3",
          {"string": "columnInfo", "args": [2]},
          {"string": "rowInfo", "args": [3]}, "col2", "row2"]],
        expectedBraille: [
          [{"string": "cellInfoAbbr", "args": [2, 3]}, "col2", "row2", "cell3"],
          ["cell3", {"string": "cellInfoAbbr", "args": [2, 3]}, "col2", "row2"]]
      }];

      // Test outputs (utterance and braille) for tables including their
      // headers and cells.
      function testOutputOrder(aOutputOrder) {
        return function() {
          SpecialPowers.pushPrefEnv({
            "set": [[PREF_UTTERANCE_ORDER, aOutputOrder]]
          }, function() {
            tests.forEach(function run(test) {
              testOutput(test.expectedUtterance[aOutputOrder], test.accOrElmOrID,
                test.oldAccOrElmOrID, 1);
              testOutput(test.expectedBraille[aOutputOrder], test.accOrElmOrID,
                test.oldAccOrElmOrID, 0);
            });
            AccessFuTest.nextTest();
          });
        };
      }

      AccessFuTest.addFunc(testOutputOrder(0));
      AccessFuTest.addFunc(testOutputOrder(1));
      AccessFuTest.waitForExplicitFinish();
      AccessFuTest.runTests();
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(doTest);
  </script>
</head>
<body>
  <div id="root">
    <a target="_blank"
       href="https://bugzilla.mozilla.org/show_bug.cgi?id=830748"
       title="[AccessFu] Improve reading of table semantics">
       Mozilla Bug 830748
       </a>
    <p id="display"></p>
    <div id="content" style="display: none"></div>
    <pre id="test"></pre>
    <table id="table1">
      <thead>
        <tr>
          <th id="table1_th1">col1</th>
          <th>col2</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td id="table1_td1">cell1</td>
          <td id="table1_td2">cell2</td>
        </tr>
      </tbody>
    </table>
    <table id="table2" border="1">
      <tr>
        <td id="table2_cell_1" headers="table2_ch_1">cell1</td>
        <td id="table2_cell_2" headers="table2_ch_2">
          <table id="table3">
            <thead>
              <tr>
                <th id="table3_ch">colheader</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td id="table3_cell">bla</td>
              </tr>
            </tbody>
          </table>
        </td>
      </tr>
      <tr>
        <td id="table2_ch_1" scope="col">col1</td>
        <td id="table2_ch_2" scope="col">col2</td>
      </tr>
    </table>
    <table id="table4" border="1">
      <thead>
        <tr>
          <th id="table4_ch_1">col1</th>
          <th id="table4_ch_2">col2</th>
          <td id="table4_ch_3" scope="col">col3</td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th id="table4_rh_1" colspan="2">row1</th>
          <td id="table4_cell_2">cell1</td>
          <td id="table4_cell_3" rowspan="2">cell2</td>
        </tr>
        <tr>
          <td id="table4_rh_2" scope="row">row2</td>
          <td id="table4_cell_5">cell3</td>
          <td id="table4_cell_6">cell4</td>
        </tr>
      </tbody>
    </table>
    <table id="table5">
      <tr><td>Row1</td></tr>
      <tr><td>Row2</td></tr>
    </table>
  </div>
</body>
</html>