Bug 356295, fix up tests caused by EventUtils.js switch to ClientRects instead of box objects

This commit is contained in:
Neil Deakin 2008-08-27 08:08:41 -04:00
Родитель 3bc01da920
Коммит 63c725757c
4 изменённых файлов: 50 добавлений и 39 удалений

Просмотреть файл

@ -16,6 +16,7 @@ SimpleTest.waitForExplicitFinish();
var gDragInfo;
var gDataTransfer = null;
var gExtraDragTests = 0;
function runTests()
{
@ -24,7 +25,13 @@ function runTests()
window.getSelection().selectAllChildren(draggable);
synthesizeMouse(draggable, 6, 6, { type: "mousedown" });
synthesizeMouse(draggable, 14, 14, { type: "mousemove" });
// drags are asynchronous on Linux, so this extra event is needed to make
// sure the drag gets processed
synthesizeMouse(draggable, 15, 15, { type: "mousemove" });
}
function afterDragTests()
{
// the dragstart should have occured due to moving the mouse. gDataTransfer
// caches the dataTransfer that was used, however it should now be empty and
// be read only.
@ -44,6 +51,17 @@ function runTests()
expectError(function() gDataTransfer.addElement(draggable),
"NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR", "addElement when read only");
var evt = document.createEvent("dragevent");
ok(evt instanceof DragEvent, "synthetic dragevent class")
ok(evt instanceof MouseEvent, "synthetic event inherits from MouseEvent")
evt.initDragEvent("dragstart", true, true, window, 1, null);
$("synthetic").dispatchEvent(evt);
var evt = document.createEvent("dragevents");
ok(evt instanceof DragEvent, "synthetic dragevents class")
evt.initDragEvent("dragover", true, true, window, 0, null);
$("synthetic2").dispatchEvent(evt);
// next, dragging links and images
sendMouseEventsForDrag("link");
sendMouseEventsForDrag("image");
@ -56,38 +74,22 @@ function runTests()
// sendMouseEventsForDrag("input");
// next, check if the draggable attribute can be used to adjust the drag target
gDragInfo = { target: $("dragtrue"), testid: "draggable true node" };
sendMouseEventsForDrag("dragtrue");
ok(gDragInfo.itemCount == 0 && gDragInfo.types.length == 0 && gDragInfo.target == $("dragtrue"), "draggable true node");
gDragInfo = { target: $("dragtrue"), testid: "draggable true child" };
sendMouseEventsForDrag("spantrue");
ok(gDragInfo.itemCount == 0 && gDragInfo.types.length == 0 && gDragInfo.target == $("dragtrue"), "draggable true child");
gDragInfo = { target: $("dragfalse").firstChild, testid: "draggable false node" };
sendMouseEventsForDrag("dragfalse");
ok(gDragInfo.itemCount == 0 && gDragInfo.types.length == 0 && gDragInfo.target == $("dragfalse").firstChild,
"draggable false node");
gDragInfo = { target: $("spanfalse").firstChild, testid: "draggable false child" };
sendMouseEventsForDrag("spanfalse");
ok(gDragInfo.itemCount == 0 && gDragInfo.types.length == 0 && gDragInfo.target == $("spanfalse").firstChild,
"draggable false child");
var evt = document.createEvent("dragevent");
ok(evt instanceof DragEvent, "synthetic dragevent class")
ok(evt instanceof MouseEvent, "synthetic event inherits from MouseEvent")
evt.initDragEvent("dragstart", true, true, window, 1, null);
$("synthetic").dispatchEvent(evt);
var evt = document.createEvent("dragevents");
ok(evt instanceof DragEvent, "synthetic dragevents class")
evt.initDragEvent("dragover", true, true, window, 0, null);
$("synthetic2").dispatchEvent(evt);
SimpleTest.finish();
}
function sendMouseEventsForDrag(nodeid)
{
gDragInfo = null;
var draggable = $(nodeid);
synthesizeMouse(draggable, 3, 3, { type: "mousedown" });
synthesizeMouse(draggable, 10, 10, { type: "mousemove" });
synthesizeMouse(draggable, 12, 12, { type: "mousemove" });
}
function doDragStartSelection(event)
@ -122,6 +124,7 @@ function doDragStartSelection(event)
dt.clearData("text/_moz_htmlcontext");
test_DataTransfer(dt);
setTimeout(afterDragTests, 0);
}
function test_DataTransfer(dt)
@ -383,6 +386,8 @@ function doDragStartLink(event)
is(dt.getData("text/plain"), "http://www.mozilla.org/", "link text/plain");
event.preventDefault();
gExtraDragTests++;
}
function doDragStartImage(event)
@ -398,6 +403,8 @@ function doDragStartImage(event)
is(dt.getData("text/plain"), dataurl, "image text/plain");
event.preventDefault();
gExtraDragTests++;
}
function doDragStartInput(event)
@ -443,7 +450,11 @@ return;
function onDragStartDraggable(event)
{
var dt = event.dataTransfer;
gDragInfo = { itemCount: dt.mozItemCount, types: dt.types, target: event.originalTarget };
ok(dt.mozItemCount == 0 && dt.types.length == 0 && event.originalTarget == gDragInfo.target, gDragInfo.testid);
gExtraDragTests++;
if (gExtraDragTests == 6)
SimpleTest.finish();
}
function checkOneDataItem(dt, expectedtypes, expecteddata, index, testid)

Просмотреть файл

@ -66,8 +66,8 @@ function popupShowingEventOccured(event)
var trigger = document.getElementById(event.target.id == "outerpopup" ? "outer" : "inner");
var rect = trigger.getBoundingClientRect();
is(event.clientX, Math.round(rect.left) + 4, testname + "clientX");
is(event.clientY, Math.round(rect.top) + 5, testname + "clientY");
is(event.clientX, Math.floor(rect.left) + 4, testname + "clientX");
is(event.clientY, Math.floor(rect.top) + 5, testname + "clientY");
// rangeOffset should be just after the trigger element. As rangeOffset
// considers the zeroth position to be before the first element, the value
// should be one higher than its index within its parent.

Просмотреть файл

@ -1127,7 +1127,7 @@ function synthesizeColumnDrag(aTree, aMouseDownColumnNumber, aMouseUpColumnNumbe
// 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"});
synthesizeMouse(down, splitterHitWidth, 3, { type: "mousedown"});
var offsetX = 0;
if (aAfter) {
@ -1137,17 +1137,17 @@ function synthesizeColumnDrag(aTree, aMouseDownColumnNumber, aMouseUpColumnNumbe
if (aMouseUpColumnNumber > aMouseDownColumnNumber) {
for (var i = aMouseDownColumnNumber; i <= aMouseUpColumnNumber; i++) {
var move = columns[i].element;
synthesizeMouse(move, offsetX, 0, { type: "mousemove"});
synthesizeMouse(move, offsetX, 3, { type: "mousemove"});
}
}
else {
for (var i = aMouseDownColumnNumber; i >= aMouseUpColumnNumber; i--) {
var move = columns[i].element;
synthesizeMouse(move, offsetX, 0, { type: "mousemove"});
synthesizeMouse(move, offsetX, 3, { type: "mousemove"});
}
}
synthesizeMouse(up, offsetX, 0, { type: "mouseup"});
synthesizeMouse(up, offsetX, 3, { type: "mouseup"});
}
function arrayMove(aArray, aFrom, aTo, aAfter)

Просмотреть файл

@ -16,12 +16,12 @@
<box tooltiptext="Box Tooltip">
<button id="withtext" label="Tooltip Text" tooltiptext="Button Tooltip"
style="-moz-appearance: none;"/>
<button id="without" label="No Tooltip" style="-moz-appearance: none;"/>
style="-moz-appearance: none; padding: 0;"/>
<button id="without" label="No Tooltip" style="-moz-appearance: none; padding: 0;"/>
<!-- remove the native theme and borders to avoid some platform
specific sizing differences -->
<button id="withtooltip" label="Tooltip Element" tooltip="thetooltip"
class="plain" style="-moz-appearance: none;"/>
class="plain" style="-moz-appearance: none; padding: 0;"/>
</box>
<script class="testbody" type="application/javascript">
@ -44,9 +44,9 @@ function checkCoords(event)
var rect = gButton.getBoundingClientRect();
var popupstyle = window.getComputedStyle(gButton, "");
is(event.clientX, Math.round(rect.left) + parseInt(popupstyle.borderLeftWidth) + mod,
is(event.clientX, Math.floor(rect.left) + mod,
"step " + (gTestIndex + 1) + " clientX");
is(event.clientY, Math.round(rect.top) + parseInt(popupstyle.borderTopWidth) + mod,
is(event.clientY, Math.floor(rect.top) + mod,
"step " + (gTestIndex + 1) + " clientY");
ok(event.screenX > 0, "step " + (gTestIndex + 1) + " screenX");
ok(event.screenY > 0, "step " + (gTestIndex + 1) + " screenY");
@ -97,10 +97,10 @@ var popupTests = [
var rect = document.getElementById("thetooltip").getBoundingClientRect();
var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), "");
is(Math.round(rect.left), Math.round(buttonrect.left) +
is(Math.floor(rect.left), Math.floor(buttonrect.left) +
parseInt(popupstyle.marginLeft) + 6,
testname + " top position of tooltip");
is(Math.round(rect.top), Math.round(buttonrect.top) +
is(Math.floor(rect.top), Math.floor(buttonrect.top) +
parseInt(popupstyle.marginTop) + 6,
testname + " top position of tooltip");
@ -139,10 +139,10 @@ var popupTests = [
var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), "");
var buttonstyle = window.getComputedStyle(document.getElementById("withtooltip"), "");
is(Math.round(rect.left), Math.round(buttonrect.left) +
is(Math.floor(rect.left), Math.floor(buttonrect.left) +
parseInt(popupstyle.marginLeft) + 4,
testname + " top position of tooltip");
is(Math.round(rect.top), Math.round(buttonrect.top) +
is(Math.floor(rect.top), Math.floor(buttonrect.top) +
parseInt(popupstyle.marginTop) + 4,
testname + " top position of tooltip");
@ -182,10 +182,10 @@ var popupTests = [
var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), "");
var buttonstyle = window.getComputedStyle(document.getElementById("withtooltip"), "");
is(Math.round(rect.left), Math.round(buttonrect.left) +
is(Math.floor(rect.left), Math.floor(buttonrect.left) +
parseInt(popupstyle.marginLeft) + 6,
testname + " top position of tooltip");
is(Math.round(rect.top), Math.round(buttonrect.top) +
is(Math.floor(rect.top), Math.floor(buttonrect.top) +
parseInt(popupstyle.marginTop) + 6,
testname + " top position of tooltip");