gecko/accessible/tests/mochitest/test_bug368835.xul
2008-02-24 14:40:26 -08:00

254 lines
8.0 KiB
XML

<?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"?>
<!--
Bug 368835 - fire TreeViewChanged/TreeRowCountChanged events.
-->
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="Mozilla Bug 368835">
<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 type="application/javascript">
<![CDATA[
function inTreeView() { }
inTreeView.prototype =
{
mRowCount: 0,
mTree: null,
mData: {},
get rowCount() { return this.mRowCount; },
setTree: function(aTree) { this.mTree = aTree; },
getCellText: function(aRow, aCol)
{
var key = String(aRow) + aCol.id;
if (key in this.mData)
return this.mData[key];
return "hello";
},
getRowProperties: function(aIndex, aProperties) {},
getCellProperties: function(aIndex, aCol, aProperties) {},
getColumnProperties: function(aCol, aProperties) {},
getParentIndex: function(aRowIndex) { },
hasNextSibling: function(aRowIndex, aAfterIndex) { },
getLevel: function(aIndex) {},
getImageSrc: function(aRow, aCol) {},
getProgressMode: function(aRow, aCol) {},
getCellValue: function(aRow, aCol) {},
isContainer: function(aIndex) {},
isContainerOpen: function(aIndex) {},
isContainerEmpty: function(aIndex) {},
isSeparator: function(aIndex) {},
isSorted: function() {},
toggleOpenState: function(aIndex) {},
selectionChanged: function() {},
cycleHeader: function(aCol) {},
cycleCell: function(aRow, aCol) {},
isEditable: function(aRow, aCol) {},
isSelectable: function(aRow, aCol) {},
setCellValue: function(aRow, aCol, aValue) {},
setCellText: function(aRow, aCol, aValue) { },
performAction: function(aAction) {},
performActionOnRow: function(aAction, aRow) {},
performActionOnCell: function(aAction, aRow, aCol) {}
};
var gTreeViewChanged = false;
function TreeViewChangedHandler(aEvent)
{
gTreeViewChanged = true;
}
var gTreeRowCountChanged = false;
function TreeRowCountChangedHandler(aEvent)
{
gTreeRowCountChanged = true;
var index = aEvent.getData("index");
is(index, 0, "Wrong 'index' data of 'treeRowCountChanged' event.");
var count = aEvent.getData("count");
is(count, 1, "Wrong 'count' data of 'treeRowCountChanged' event.");
}
var gTreeInvalidatedCount = 0;
function TreeInvalidatedHandler(aEvent)
{
gTreeInvalidatedCount++;
switch (gTreeInvalidatedCount) {
case 2:
TreeColumnInvalidatedHandler(aEvent);
break;
case 3:
TreeRowInvalidatedHandler(aEvent);
break;
}
}
var gTreeColumnInvalidated = false;
function TreeColumnInvalidatedHandler(aEvent)
{
var startRow = aEvent.getData("startrow");
is(startRow, null,
"Wrong 'startrow' of 'treeInvalidated' event on InvalidateColumn().");
var endRow = aEvent.getData("endrow");
is(endRow, null,
"Wrong 'endrow' of 'treeInvalidated' event on InvalidateColumn().");
var startCol = aEvent.getData("startcolumn");
is(startCol, 0,
"Wrong 'startcolumn' of 'treeInvalidated' event on InvalidateColumn().");
var endCol = aEvent.getData("endcolumn");
is(endCol, 0,
"Wrong 'endcolumn' of 'treeInvalidated' event on InvalidateColumn().");
gTreeColumnInvalidated = true;
}
var gTreeRowInvalidated = false;
function TreeRowInvalidatedHandler(aEvent)
{
var startRow = aEvent.getData("startrow");
is(startRow, 1,
"Wrong 'startrow' of 'treeInvalidated' event on InvalidateColumn().");
var endRow = aEvent.getData("endrow");
is(endRow, 1,
"Wrong 'endrow' of 'treeInvalidated' event on InvalidateColumn().");
var startCol = aEvent.getData("startcolumn");
is(startCol, null,
"Wrong 'startcolumn' of 'treeInvalidated' event on InvalidateColumn().");
var endCol = aEvent.getData("endcolumn");
is(endCol, null,
"Wrong 'endcolumn' of 'treeInvalidated' event on InvalidateColumn().");
gTreeRowInvalidated = true;
}
function CheckEvents()
{
// If these fail then it doesn't mean actually events are not fired,
// possibly setTimeout was executed earlier than events have beenS fired.
ok(gTreeViewChanged,
"TreeViewChanged event should have been fired.");
ok(gTreeRowCountChanged,
"TreeRowCountChanged event should have been fired.");
ok(gTreeColumnInvalidated,
"TreeInvalidated event should have been fired for InvalidateColumn().");
ok(gTreeRowInvalidated,
"TreeInvalidated event should have been fired for InvalidateRow().");
document.removeEventListener("TreeViewChanged",
TreeViewChangedHandler, true);
document.removeEventListener("TreeRowCountChanged",
TreeRowCountChangedHandler, true);
document.removeEventListener("TreeInvalidated",
TreeInvalidatedHandler, true);
SimpleTest.finish();
}
var gAccService = null;
function doTest()
{
// Check whether accessibility support is enabled.
if (!("@mozilla.org/accessibleRetrieval;1" in Components.classes)) {
SimpleTest.finish();
return;
}
// Activate accessibility, otherwise events aren't fired.
gAccService = Components.classes["@mozilla.org/accessibleRetrieval;1"].
getService(Components.interfaces.nsIAccessibleRetrieval);
// Add event listeners
document.addEventListener("TreeViewChanged",
TreeViewChangedHandler, true);
document.addEventListener("TreeRowCountChanged",
TreeRowCountChangedHandler, true);
document.addEventListener("TreeInvalidated",
TreeInvalidatedHandler, true);
// Initialize the tree
var tree = document.getElementById("tree");
var treeBox = tree.treeBoxObject;
var view = new inTreeView();
view.mRowCount = 5;
// Fire 'TreeViewChanged' event
treeBox.view = view;
// Fire 'TreeRowCountChanged' changed
++view.mRowCount;
treeBox.rowCountChanged(0, 1);
// Fire 'TreeInvalidated' event by InvalidateColumn()
var firstCol = treeBox.columns.getFirstColumn();
for (var i = 0; i < view.mRowCount; i++) {
var key = String(i) + firstCol.id;
view.mData[key] = key + "_col";
}
treeBox.invalidateColumn(firstCol);
// Fire 'TreeInvalidated' event by InvalidateRow()
var colCount = tree.columns.count;
for (var i = 0; i < colCount; i++) {
var key = "1" + tree.columns.getColumnAt(i).id;
view.mData[key] = key + "_row";
}
treeBox.invalidateRow(1);
// Wait for events.
if (gTreeViewChanged && gTreeRowCountChanged &&
gTreeColumnInvalidated)
CheckEvents();
else
window.setTimeout(CheckEvents, 1000);
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(doTest);
]]>
</script>
<body xmlns="http://www.w3.org/1999/xhtml">
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=368835">
Mozilla Bug 368835
</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
<tree id="tree" flex="1">
<treecols>
<treecol id="col" flex="1" primary="true" label="column"/>
<treecol id="scol" flex="1" label="column 2"/>
</treecols>
<treechildren id="treechildren"/>
</tree>
</window>