Bug 407453 - "Column reordering broken when ordinal > 9 (comparing numbers as strings)" [p=skrulx@gmail.com (Steve Krulewitz) r=Enn a1.9=schrep]

This commit is contained in:
reed@reedloden.com 2008-01-04 22:47:42 -08:00
parent 451bff79a2
commit e2a623f614
4 changed files with 246 additions and 11 deletions

View File

@ -79,6 +79,7 @@ _TEST_FILES = test_bug360220.xul \
test_tree_single.xul \
test_tree_hier.xul \
test_tree_hier_cell.xul \
test_tree_column_reorder.xul \
tree_shared.js \
test_textbox_number.xul \
xul_selectcontrol.js \

View File

@ -0,0 +1,77 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
<!--
XUL Widget Test for reordering tree columns
-->
<window title="Tree" width="500" height="600"
onload="setTimeout(testtag_tree_column_reorder, 0);"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script src="tree_shared.js"/>
<tree id="tree-column-reorder" rows="1" enableColumnDrag="true">
<treecols>
<treecol id="col_0" label="col_0" flex="1"/>
<splitter class="tree-splitter"/>
<treecol id="col_1" label="col_1" flex="1"/>
<splitter class="tree-splitter"/>
<treecol id="col_2" label="col_2" flex="1"/>
<splitter class="tree-splitter"/>
<treecol id="col_3" label="col_3" flex="1"/>
<splitter class="tree-splitter"/>
<treecol id="col_4" label="col_4" flex="1"/>
<splitter class="tree-splitter"/>
<treecol id="col_5" label="col_5" flex="1"/>
<splitter class="tree-splitter"/>
<treecol id="col_6" label="col_6" flex="1"/>
<splitter class="tree-splitter"/>
<treecol id="col_7" label="col_7" flex="1"/>
<splitter class="tree-splitter"/>
<treecol id="col_8" label="col_8" flex="1"/>
<splitter class="tree-splitter"/>
<treecol id="col_9" label="col_9" flex="1"/>
<splitter class="tree-splitter"/>
<treecol id="col_10" label="col_10" flex="1"/>
<splitter class="tree-splitter"/>
<treecol id="col_11" label="col_11" flex="1"/>
<splitter class="tree-splitter"/>
<treecol id="col_12" label="col_12" flex="1"/>
</treecols>
<treechildren id="treechildren-column-reorder">
<treeitem>
<treerow>
<treecell label="col_0"/>
<treecell label="col_1"/>
<treecell label="col_2"/>
<treecell label="col_3"/>
<treecell label="col_4"/>
<treecell label="col_5"/>
<treecell label="col_6"/>
<treecell label="col_7"/>
<treecell label="col_8"/>
<treecell label="col_9"/>
<treecell label="col_10"/>
<treecell label="col_11"/>
<treecell label="col_12"/>
</treerow>
</treeitem>
</treechildren>
</tree>
<!-- test resuls are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
]]>
</script>
</window>

View File

@ -986,6 +986,148 @@ function testtag_tree_TreeSelection_State(tree, testid, current, selected, viewi
is(compareArrays(selected, actualSelected), true, testid + " range selection [" + selected + "]");
}
function testtag_tree_column_reorder()
{
// Make sure the tree is scrolled into the view, otherwise the test will
// fail
var testframe = window.parent.document.getElementById("testframe");
if (testframe) {
testframe.scrollIntoView();
}
var tree = document.getElementById("tree-column-reorder");
var numColumns = tree.columns.count;
var reference = [];
for (var i = 0; i < numColumns; i++) {
reference.push("col_" + i);
}
// Drag the first column to each position
for (var i = 0; i < numColumns - 1; i++) {
synthesizeColumnDrag(tree, i, i + 1, true);
arrayMove(reference, i, i + 1, true);
checkColumns(tree, reference, "drag first column right");
}
// And back
for (var i = numColumns - 1; i >= 1; i--) {
synthesizeColumnDrag(tree, i, i - 1, false);
arrayMove(reference, i, i - 1, false);
checkColumns(tree, reference, "drag last column left");
}
// Drag each column one column left
for (var i = 1; i < numColumns; i++) {
synthesizeColumnDrag(tree, i, i - 1, false);
arrayMove(reference, i, i - 1, false);
checkColumns(tree, reference, "drag each column left");
}
// And back
for (var i = numColumns - 2; i >= 0; i--) {
synthesizeColumnDrag(tree, i, i + 1, true);
arrayMove(reference, i, i + 1, true);
checkColumns(tree, reference, "drag each column right");
}
// Drag each column 5 to the right
for (var i = 0; i < numColumns - 5; i++) {
synthesizeColumnDrag(tree, i, i + 5, true);
arrayMove(reference, i, i + 5, true);
checkColumns(tree, reference, "drag each column 5 to the right");
}
// And to the left
for (var i = numColumns - 6; i >= 5; i--) {
synthesizeColumnDrag(tree, i, i - 5, false);
arrayMove(reference, i, i - 5, false);
checkColumns(tree, reference, "drag each column 5 to the left");
}
// Test that moving a column after itself does not move anything
synthesizeColumnDrag(tree, 0, 0, true);
checkColumns(tree, reference, "drag to itself");
is(document.treecolDragging, null, "drag to itself completed");
SimpleTest.finish();
}
function synthesizeColumnDrag(aTree, aMouseDownColumnNumber, aMouseUpColumnNumber, aAfter)
{
var columns = getSortedColumnArray(aTree);
var down = columns[aMouseDownColumnNumber].element;
var up = columns[aMouseUpColumnNumber].element;
// Target the initial mousedown in the middle of the column header so we
// avoid the extra hit test space given to the splitter
var columnWidth = down.boxObject.width;
var splitterHitWidth = columnWidth / 2;
synthesizeMouse(down, splitterHitWidth, 0, { type: "mousedown"});
var offsetX = 0;
if (aAfter) {
offsetX = columnWidth;
}
if (aMouseUpColumnNumber > aMouseDownColumnNumber) {
for (var i = aMouseDownColumnNumber; i <= aMouseUpColumnNumber; i++) {
var move = columns[i].element;
synthesizeMouse(move, offsetX, 0, { type: "mousemove"});
}
}
else {
for (var i = aMouseDownColumnNumber; i >= aMouseUpColumnNumber; i--) {
var move = columns[i].element;
synthesizeMouse(move, offsetX, 0, { type: "mousemove"});
}
}
synthesizeMouse(up, offsetX, 0, { type: "mouseup"});
}
function arrayMove(aArray, aFrom, aTo, aAfter)
{
var o = aArray.splice(aFrom, 1)[0];
if (aTo > aFrom) {
aTo--;
}
if (aAfter) {
aTo++;
}
aArray.splice(aTo, 0, o);
}
function getSortedColumnArray(aTree)
{
var columns = aTree.columns;
var a = [];
for (var i = 0; i < columns.length; i++) {
a.push(columns.getColumnAt(i));
}
a.sort(function(a, b) {
var o1 = parseInt(a.element.getAttribute("ordinal"));
var o2 = parseInt(b.element.getAttribute("ordinal"));
return o1 - o2;
});
return a;
}
function checkColumns(aTree, aReference, aMessage)
{
var columns = getSortedColumnArray(aTree);
var ids = [];
columns.forEach(function(e) {
ids.push(e.element.id);
});
is(compareArrays(ids, aReference), true, aMessage);
}
function mouseOnCell(tree, row, column, testname)
{
var x = {}, y = {}, width = {}, height = {};

View File

@ -170,7 +170,7 @@
var i;
var cols = [];
var col = this.columns.getColumnFor(aColBefore);
if (aColBefore.ordinal < aColMove.ordinal) {
if (parseInt(aColBefore.ordinal) < parseInt(aColMove.ordinal)) {
if (aBefore)
cols.push(aColBefore);
for (col = col.getNext(); col.element != aColMove;
@ -179,7 +179,7 @@
aColMove.ordinal = cols[0].ordinal;
for (i = 0; i < cols.length; ++i)
cols[i].ordinal += 2;
cols[i].ordinal = parseInt(cols[i].ordinal) + 2;
} else if (aColBefore.ordinal != aColMove.ordinal) {
if (!aBefore)
cols.push(aColBefore);
@ -189,7 +189,7 @@
aColMove.ordinal = cols[0].ordinal;
for (i = 0; i < cols.length; ++i)
cols[i].ordinal -= 2;
cols[i].ordinal = parseInt(cols[i].ordinal) - 2;
}
]]></body>
</method>
@ -1194,16 +1194,31 @@
// remove insertbefore/after attributes
var before = col.mTargetCol.hasAttribute("insertbefore");
col.mTargetCol.removeAttribute(before ? "insertbefore" : "insertafter");
if (before) {
var sib = col.mTargetCol._previousVisibleColumn;
if (sib)
sib.removeAttribute("insertafter");
var sib = col.mTargetCol._previousVisibleColumn;
if (before && sib) {
sib.removeAttribute("insertafter");
}
// move the column
if (col != col.mTargetCol)
// Move the column only if it will result in a different column
// ordering
var move = true;
// If this is a before move and the previous visible column is
// the same as the column we're moving, don't move
if (before && col == sib) {
move = false;
}
else if (!before && col == col.mTargetCol) {
// If this is an after move and the column we're moving is
// the same as the target column, don't move.
move = false;
}
if (move) {
col.parentNode.parentNode._reorderColumn(col, col.mTargetCol, before);
}
// repaint to remove lines
col.parentNode.parentNode.treeBoxObject.invalidate();