bug 481435 - Refactor the test_nsiAccessibleTable*.html files, r=surkov
authorMarco Zehe <marco.zehe@googlemail.com>
Thu, 05 Mar 2009 13:55:54 +0100
changeset 25765 563c82941f41ce401b1b8dcc8007dc5c5b01c3d4
parent 25764 8948ec7f81951e77f758e2b79452a9305b043a6a
child 25766 416767d733ad061eb4fbba957589e3fbec6f5f0f
push id5731
push usermzehe@mozilla.com
push dateThu, 05 Mar 2009 12:56:16 +0000
treeherdermozilla-central@563c82941f41 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov
bugs481435
milestone1.9.2a1pre
bug 481435 - Refactor the test_nsiAccessibleTable*.html files, r=surkov
accessible/tests/mochitest/Makefile.in
accessible/tests/mochitest/common.js
accessible/tests/mochitest/test_nsIAccessibleTable_1.html
accessible/tests/mochitest/test_nsIAccessibleTable_2.html
accessible/tests/mochitest/test_nsIAccessibleTable_3.html
accessible/tests/mochitest/test_nsIAccessibleTable_4.html
accessible/tests/mochitest/test_table_1.html
accessible/tests/mochitest/test_table_2.html
accessible/tests/mochitest/test_table_3.html
accessible/tests/mochitest/test_table_4.html
--- a/accessible/tests/mochitest/Makefile.in
+++ b/accessible/tests/mochitest/Makefile.in
@@ -87,33 +87,33 @@ include $(topsrcdir)/config/rules.mk
  		test_nsIAccessible_selects.html \
 		test_nsIAccessible_focus.html \
 		test_nsIAccessibleDocument.html \
 		test_nsIAccessibleEditableText.html \
 		test_nsIAccessibleHyperLink.html \
 		test_nsIAccessibleHyperLink.xul \
 		test_nsIAccessibleHyperText.html \
 		test_nsIAccessibleImage.html \
-		test_nsIAccessibleTable_1.html \
-		test_nsIAccessibleTable_2.html \
-		test_nsIAccessibleTable_3.html \
-		test_nsIAccessibleTable_4.html \
 		$(warning test_nsIAccessibleTable_listboxes.xul temporarily disabled) \
 		test_nsIAccessNode_utils.html \
 		test_nsOuterDocAccessible.html \
  		test_objectattrs.html \
 		test_relations.html \
 		test_relations.xul \
 		test_role_nsHyperTextAcc.html \
 		test_role_table_cells.html \
 		test_states.html \
 		test_states_editablebody.html \
 		test_states_doc.html \
 		test_states_docarticle.html \
 		test_states_frames.html \
+		test_table_1.html \
+		test_table_2.html \
+		test_table_3.html \
+		test_table_4.html \
 		test_textattrs.html \
 		test_textboxes.html \
 		test_textboxes.xul \
 		testTextboxes.js \
 		treeview.js \
 		test_bug434464.html \
 		z_states_frame.html \
 		z_states_framearticle.html \
--- a/accessible/tests/mochitest/common.js
+++ b/accessible/tests/mochitest/common.js
@@ -42,16 +42,17 @@ const nsIDOMHTMLDocument = Components.in
 const nsIDOMNode = Components.interfaces.nsIDOMNode;
 const nsIDOMWindow = Components.interfaces.nsIDOMWindow;
 
 const nsIPropertyElement = Components.interfaces.nsIPropertyElement;
 
 ////////////////////////////////////////////////////////////////////////////////
 // Roles
 
+const ROLE_ALERT = nsIAccessibleRole.ROLE_ALERT;
 const ROLE_PUSHBUTTON = nsIAccessibleRole.ROLE_PUSHBUTTON;
 const ROLE_CELL = nsIAccessibleRole.ROLE_CELL;
 const ROLE_CHROME_WINDOW = nsIAccessibleRole.ROLE_CHROME_WINDOW;
 const ROLE_COMBOBOX = nsIAccessibleRole.ROLE_COMBOBOX;
 const ROLE_COMBOBOX_LIST = nsIAccessibleRole.ROLE_COMBOBOX_LIST;
 const ROLE_COMBOBOX_OPTION = nsIAccessibleRole.ROLE_COMBOBOX_OPTION;
 const ROLE_DOCUMENT = nsIAccessibleRole.ROLE_DOCUMENT;
 const ROLE_ENTRY = nsIAccessibleRole.ROLE_ENTRY;
@@ -66,16 +67,17 @@ const ROLE_INTERNAL_FRAME = nsIAccessibl
 const ROLE_LABEL = nsIAccessibleRole.ROLE_LABEL;
 const ROLE_LINK = nsIAccessibleRole.ROLE_LINK;
 const ROLE_LIST = nsIAccessibleRole.ROLE_LIST;
 const ROLE_LISTBOX = nsIAccessibleRole.ROLE_LISTBOX;
 const ROLE_OPTION = nsIAccessibleRole.ROLE_OPTION;
 const ROLE_PARAGRAPH = nsIAccessibleRole.ROLE_PARAGRAPH;
 const ROLE_PASSWORD_TEXT = nsIAccessibleRole.ROLE_PASSWORD_TEXT;
 const ROLE_SECTION = nsIAccessibleRole.ROLE_SECTION;
+const ROLE_TABLE = nsIAccessibleRole.ROLE_TABLE;
 const ROLE_TEXT_CONTAINER = nsIAccessibleRole.ROLE_TEXT_CONTAINER;
 const ROLE_TEXT_LEAF = nsIAccessibleRole.ROLE_TEXT_LEAF;
 const ROLE_TOGGLE_BUTTON = nsIAccessibleRole.ROLE_TOGGLE_BUTTON;
 
 ////////////////////////////////////////////////////////////////////////////////
 // States
 
 const STATE_CHECKED = nsIAccessibleStates.STATE_CHECKED;
@@ -260,21 +262,23 @@ function getAccessible(aAccOrElmOrID, aI
     ok(false, "Can't query " + aInterfaces + " for " + aID);
     return null;
   }
   
   return acc;
 }
 
 /**
- * Return true if the given identifier has an accessible.
+ * Return true if the given identifier has an accessible, or exposes the wanted
+ * interfaces.
  */
-function isAccessible(aAccOrElmOrID)
+function isAccessible(aAccOrElmOrID, aInterfaces)
 {
-  return getAccessible(aAccOrElmOrID, null, null, DONOTFAIL_IF_NO_ACC) ?
+  return getAccessible(aAccOrElmOrID, aInterfaces, null,
+                       DONOTFAIL_IF_NO_ACC | DONOTFAIL_IF_NO_INTERFACE) ?
     true : false;
 }
 
 /**
  * Run through accessible tree of the given identifier so that we ensure
  * accessible tree is created.
  */
 function ensureAccessibleTree(aAccOrElmOrID)
rename from accessible/tests/mochitest/test_nsIAccessibleTable_1.html
rename to accessible/tests/mochitest/test_table_1.html
--- a/accessible/tests/mochitest/test_nsIAccessibleTable_1.html
+++ b/accessible/tests/mochitest/test_table_1.html
@@ -1,82 +1,81 @@
 <!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
 <html>
  <head>
   <meta http-equiv="content-type" content="text/html; charset=UTF-8">
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
-  <script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
-  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/MochiKit/packed.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+
+  <script type="application/javascript"
+          src="chrome://mochikit/content/a11y/accessible/common.js"></script>
+
   <script type="application/javascript">
 
 function doTest()
 {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var table = document.getElementById("table");
-  var accService = Components.classes["@mozilla.org/accessibleRetrieval;1"].
-                   getService(Components.interfaces.nsIAccessibleRetrieval);
-  var accTable   = accService.getAccessibleFor(table).
-                   QueryInterface(Components.interfaces.nsIAccessibleTable);
+  var accTable = getAccessible("table", [nsIAccessibleTable]);
   var caption = accTable.caption;
   is(caption.firstChild.name, "Test Table", "wrong text inside caption");
-  const nsIAccessNode = Components.interfaces.nsIAccessible;
 
-  is(caption.children.queryElementAt(0, nsIAccessNode).name, "Test Table",
+  is(caption.children.queryElementAt(0, nsIAccessible).name, "Test Table",
      "wrong text inside caption");
 
   is(accTable.summary, "this is a test table for nsIAccessibleTable",
      "wrong summary on table");
-  is(accTable.columns, 4,"wrong number of columns");
+  is(accTable.columns, 4, "wrong number of columns");
   is(accTable.rows, 3, "wrong number of rows");
 
   var s = window.getSelection();
   if (s.rangeCount > 0)
     s.removeAllRanges();
 
-  var cell = document.getElementById("col2b");
+  var cell = getNode("col2b");
   var range = document.createRange();
   range.selectNode(cell);
   s.addRange(range);
 
-  is(accTable.selectedCellsCount, 1,"only one cell selected");
-  cell = document.getElementById("col2a");
+  is(accTable.selectedCellsCount, 1, "only one cell selected");
+  cell = getNode("col2a");
   range.selectNode(cell);
   s.addRange(range);
-  cell = document.getElementById("col2c");
+  cell = getNode("col2c");
   range.selectNode(cell);
   s.addRange(range);
   is(accTable.selectedColumnsCount, 1, "only one column selected");
-  cell = document.getElementById("row2a");
+  cell = getNode("row2a");
   range.selectNode(cell);
   s.addRange(range);
-  cell = document.getElementById("row2b");
+  cell = getNode("row2b");
   range.selectNode(cell);
   s.addRange(range);
-  cell = document.getElementById("row2c");
+  cell = getNode("row2c");
   range.selectNode(cell);
   s.addRange(range);
 
   is(accTable.selectedRowsCount, 1, "no cells selected");
 
   var rowheader;
-  var works;
-  works = true;
+  var works = true;
   try {
-    rowheader  = accTable.rowHeader;
+    rowheader = accTable.rowHeader;
   }
   catch (e) {
     works = false;
   }
   todo(works, "rowHeader should not throw");
 
   var columnHeader;
   works = true;
   try {
     columnHeader = accTable.columnHeader;
-    columnHeaderIndex =columnHeader.getIndexAt(0,2);
+    columnHeaderIndex = columnHeader.getIndexAt(0, 2);
     is(columnHeaderIndex, 2, "columnheaderindex is wrong");
   }
   catch (e) {
     works = false;
   }
   if (!works)
     todo(works, "columnHeader should not throw");
 
rename from accessible/tests/mochitest/test_nsIAccessibleTable_2.html
rename to accessible/tests/mochitest/test_table_2.html
--- a/accessible/tests/mochitest/test_nsIAccessibleTable_2.html
+++ b/accessible/tests/mochitest/test_table_2.html
@@ -1,45 +1,42 @@
 <!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
 <html>
  <head>
   <meta http-equiv="content-type" content="text/html; charset=UTF-8">
   <title> nsIAccessibleTable Interface Test Case </title>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
-  <script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
-  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/MochiKit/packed.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+
+  <script type="application/javascript"
+          src="chrome://mochikit/content/a11y/accessible/common.js"></script>
+
   <script type="text/javascript">
 
 function doTest()
 {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
-  var accService = Components.classes["@mozilla.org/accessibleRetrieval;1"].
-                   getService(Components.interfaces.nsIAccessibleRetrieval);
-
   // bug 410052
-  var table = document.getElementById("table");
-  var accTable = accService.getAccessibleFor(table).
-                 QueryInterface(Components.interfaces.nsIAccessibleTable);
+  var accTable = getAccessible("table", [nsIAccessibleTable]);
 
   is(accTable.getIndexAt(2,4), 17, "wrong index returned");
-  is(accTable.getColumnAtIndex(18), 5,"got wrong column");
+  is(accTable.getColumnAtIndex(18), 5, "got wrong column");
   is(accTable.getRowAtIndex(10), 1, "wrong row");
   is(accTable.getColumnExtentAt(2,2), 2, "colspan wrong");
   is(accTable.getColumnExtentAt(0,3), 2, "colspan wrong");
   is(accTable.getColumnExtentAt(3,5), 1, "colspan");
   is(accTable.getRowExtentAt(0,7), 4, "rowspan wrong");
   is(accTable.getRowExtentAt(2,7), 4,"rowspan wrong");
   is(accTable.getColumnExtentAt(2,3), 1, "colspan wrong");
   is(accTable.cellRefAt(2,1).firstChild.name, "c1", "wrong cell");
 
   // bug 417912
-  var table2 = document.getElementById("table2");
-  var accTable2 = accService.getAccessibleFor(table2).
-                  QueryInterface(Components.interfaces.nsIAccessibleTable);
+  var accTable2 = getAccessible("table2", [nsIAccessibleTable]);
   testCellAt(accTable2, 0, 0, true);
   testCellAt(accTable2, 0, 1, true);
   testCellAt(accTable2, 0, 2, true);
   testCellAt(accTable2, 1, 0, true);
   testCellAt(accTable2, 1, 1, false);
   testCellAt(accTable2, 1, 2, true);
   testCellAt(accTable2, 2, 0, true);
   testCellAt(accTable2, 2, 1, true);
rename from accessible/tests/mochitest/test_nsIAccessibleTable_3.html
rename to accessible/tests/mochitest/test_table_3.html
--- a/accessible/tests/mochitest/test_nsIAccessibleTable_3.html
+++ b/accessible/tests/mochitest/test_table_3.html
@@ -1,39 +1,36 @@
 <!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
 <html>
  <head>
   <meta http-equiv="content-type" content="text/html; charset=UTF-8">
   <title> nsIAccessibleTable Interface Test Case </title>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
-  <script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
-  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/MochiKit/packed.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+
+  <script type="application/javascript"
+          src="chrome://mochikit/content/a11y/accessible/common.js"></script>
+
   <script type="text/javascript">
 
 function doTest()
 {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var table = document.getElementById("table");
-  var accService = Components.classes["@mozilla.org/accessibleRetrieval;1"].
-                   getService(Components.interfaces.nsIAccessibleRetrieval);
-
-  var accTable = accService.getAccessibleFor(table).
-                 QueryInterface(Components.interfaces.nsIAccessibleTable);
+  var accTable = getAccessible("table", [nsIAccessibleTable]);
     
   is(accTable.getSelectedCells({}).length, 0, "no cell selected");
   for (var i = 0; i < 4; i++) {
     accTable.selectRow(i);
-    for (var j = 0; j < 4; j++) {
-      if (i == j) {
+    for (var j = 0; j < 4; j++)
+      if (i == j)
         ok(accTable.isRowSelected(i),"row not selected");
-      }
-      else {
+      else
         todo(!accTable.isRowSelected(i),"row selected");
-      }
-    }
   }
   todo_is(accTable.selectedRowsCount, 1, "only one row should be selected");
   todo_is(accTable.getSelectedRows({}).length, 1,
          "only one row should be selected");
 
   for (var i = 0; i < 4; i++) {
     accTable.unselectRow(i);
     ok(!accTable.isRowSelected(i), "row still selected");
@@ -43,24 +40,21 @@ function doTest()
   var s = window.getSelection();
   if (s.rangeCount > 0)
     s.removeAllRanges();
 
   is(accTable.getSelectedCells({}).length, 0, "no cell selected");
   is(accTable.selectedCellsCount, 0, "no cell selected");
   for (var i = 0; i < 8; i++) {
     accTable.selectColumn(i);
-    for (var j = 0; j < 8; j++) {
-      if (i ==j) {
+    for (var j = 0; j < 8; j++)
+      if (i ==j)
         ok(accTable.isColumnSelected(i),"column not selected");
-      }
-      else {
+      else
         todo(!accTable.isColumnSelected(i),"column is selected");
-      }
-    }
   }
   todo_is(accTable.selectedColumnsCount, 1,
           "only one column should be selected");
   todo_is(accTable.getSelectedColumns({}).length, 1,
           "only one column should be selected");
   for (var i = 0; i < 8; i++) {
     accTable.unselectColumn(i);
     ok(!accTable.isColumnSelected(i),"column still selected");
rename from accessible/tests/mochitest/test_nsIAccessibleTable_4.html
rename to accessible/tests/mochitest/test_table_4.html
--- a/accessible/tests/mochitest/test_nsIAccessibleTable_4.html
+++ b/accessible/tests/mochitest/test_table_4.html
@@ -1,128 +1,84 @@
 <!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
 <html>
  <head>
   <meta http-equiv="content-type" content="text/html; charset=UTF-8">
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
-  <script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
-  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/MochiKit/packed.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+
+  <script type="application/javascript"
+          src="chrome://mochikit/content/a11y/accessible/common.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/a11y/accessible/role.js"></script>
+
   <script type="text/javascript">
 
 function doTest()
 {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var accService = Components.classes["@mozilla.org/accessibleRetrieval;1"].
-                   getService(Components.interfaces.nsIAccessibleRetrieval);
-  var Ci = Components.interfaces;
-
   // Test table with display:inline. We shouldn't create table accessible and
   // table cell accessible in this case
-  var table1 = document.getElementById("table1");
-  var accNotCreated = false;
-  try {
-    var accTable1 = accService.getAccessibleFor(table1);
-  } catch (e) {
-    accNotCreated = true;
-  }
+  var accNotCreated = (!isAccessible("table1"));
   ok(accNotCreated, "wrongly created table accessible");
   
   if (accNotCreated) {
-    var div = document.getElementById("div");
-    var accDiv = accService.getAccessibleFor(div);
+    var accDiv = getAccessible("div");
     is(accDiv.firstChild.name, "cell", "wrongly created table cell accessible");
   }
 
   // Test table with display:inline and have an another outside table
-  var table2 = document.getElementById("table2");
-  accNotCreated = false;
-  try {
-    var accTable2 = accService.getAccessibleFor(table2);
-  } catch (e) {
-    accNotCreated = true;
-  }
+  accNotCreated = (!isAccessible("table2"));
   ok(accNotCreated, "wrongly created table accessible");
 
-  var cell = document.getElementById("cell");
-  accNotCreated = false;
-  try {
-    var accCell = accService.getAccessibleFor(cell);
-  } catch (e) {
-    accNotCreated = true;
-  }
+  accNotCreated = (!isAccessible("cell"));
   ok(accNotCreated, "wrongly created table cell accessible");
 
   // Test table with role=alert. 
-  var table3 = document.getElementById("table3");
-  var accTable3;
   var tableInterfaceExposed = true;
-  try {
-    accTable3 = accService.getAccessibleFor(table3).
-                QueryInterface(Components.interfaces.nsIAccessibleTable);
-  } catch (e) {
-    tableInterfaceExposed = false;
-  }
+  var accTable3 = getAccessible("table3", [nsIAccessibleTable], null, DONOTFAIL_IF_NO_INTERFACE);
+  if (!accTable3)
+    tableInterfaceExposed = false;  
   ok(tableInterfaceExposed, "table interface is not exposed");
 
   if (tableInterfaceExposed) {
-    is(accTable3.finalRole, Ci.nsIAccessibleRole.ROLE_ALERT, "wrong role");
+    testRole(accTable3, ROLE_ALERT);
 
     is(accTable3.cellRefAt(0,0).firstChild.name, "cell0", "wrong cell");
     is(accTable3.cellRefAt(0,1).firstChild.name, "cell1", "wrong cell");
   }
 
   // Test table with role=log and aria property in tr. We create accessible for
   // tr in this case.
-  var table4 = document.getElementById("table4");
-  var accTable4;
   tableInterfaceExposed = true;
-  try {
-    accTable4 = accService.getAccessibleFor(table4).
-                QueryInterface(Components.interfaces.nsIAccessibleTable);
-  } catch (e) {
+  var accTable4 = getAccessible("table4", [nsIAccessibleTable], null, DONOTFAIL_IF_NO_INTERFACE);
+  if (!accTable4)
     tableInterfaceExposed = false;
-  }
   ok(tableInterfaceExposed, "table interface is not exposed");
 
   if (tableInterfaceExposed) {
-    var tr = document.getElementById("tr");
-    accNotCreated = false;
-    try {
-      var accTr = accService.getAccessibleFor(tr);
-    } catch (e) {
-      accNotCreated = true;
-    }
+    accNotCreated = (!isAccessible("tr"));
     ok(!accNotCreated, "missed tr accessible");
 
-    is(accTable4.role, Ci.nsIAccessibleRole.ROLE_TABLE, "wrong role");
+    is(accTable4.role, ROLE_TABLE, "wrong role");
 
     is(accTable4.cellRefAt(0,0).firstChild.name, "cell0", "wrong cell");
     is(accTable4.cellRefAt(0,1).firstChild.name, "cell1", "wrong cell");
     is(accTable4.cellRefAt(1,0).firstChild.name, "cell2", "wrong cell");
     is(accTable4.cellRefAt(1,1).firstChild.name, "cell3", "wrong cell");
   }
 
   // Test table with display:inline and an outside table. We shouldn't be fooled
   // by the outside table and shouldn't create table accessible and table cell
   // accessible in this case
-  var table5 = document.getElementById("table5");
-  accNotCreated = false;
-  try {
-    var accTable1 = accService.getAccessibleFor(table1);
-  } catch (e) {
-    accNotCreated = true;
-  }
+  accNotCreated = (!isAccessible("table5"));
   ok(accNotCreated, "wrongly created table accessible");
-  var t5Cell = document.getElementById("t5_cell");
-  accNotCreated = false;
-  try {
-    var accCell = accService.getAccessibleFor(t5Cell);
-  } catch (e) {
-    accNotCreated = true;
-  }
+  accNotCreated = (!isAccessible("t5_cell"));
   ok(accNotCreated, "wrongly created table cell accessible");
 
   SimpleTest.finish();
 }
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(doTest);
   </script>
  </head>