Bug 1639057 - Simplify Bug 426082.html to not depend on paint events. r=mstange

I removed some outlines in gtk which causes some repaints not to show
up. However I think this test should be simplified a bit instead.

When this test landed in bug 426082, snapshots and such were the only
way to test this because it was a widget hack, effectively. Nowadays,
that "forward hover and active state from label to labeled element"
happens at the event state manager level, and thus we can test it much
more easily using simple selector-matching.

Differential Revision: https://phabricator.services.mozilla.com/D76602
This commit is contained in:
Emilio Cobos Álvarez 2020-05-23 17:26:56 +00:00
Родитель 5e67b31c1f
Коммит a361d764b1
1 изменённых файлов: 63 добавлений и 113 удалений

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

@ -7,19 +7,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=426082
<title>Test for Bug 426082</title> <title>Test for Bug 426082</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script> <script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script> <script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/WindowSnapshot.js"></script> <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<style>
canvas {
display: none;
}
</style>
</head> </head>
<body> <body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=426082">Mozilla Bug 426082</a> <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=426082">Mozilla Bug 426082</a>
<p id="display"></p> <p id="display"></p>
<div id="content" style="display: none"> <div id="content" style="display: none">
</div> </div>
<p><input type="button" value="Button" id="button"></p> <p><input type="button" value="Button" id="button"></p>
<p><label for="button" id="label">Label</label></p> <p><label for="button" id="label">Label</label></p>
@ -29,136 +22,93 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=426082
/** Test for Bug 426082 **/ /** Test for Bug 426082 **/
var normalButtonCanvas, pressedButtonCanvas, normalFocusedButtonCanvas,
pressedFocusedButtonCanvas, currentSnapshot, button, label, outside;
function runTests() { function runTests() {
button = $("button"); SimpleTest.executeSoon(tests);
label = $("label");
outside = $("outside");
SimpleTest.executeSoon(executeTests);
} }
SimpleTest.waitForFocus(runTests); SimpleTest.waitForFocus(runTests);
function isRectContainedInRectFromRegion(rect, region) { function oneTick() {
return Array.prototype.some.call(region, function (r) { return new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
return rect.left >= r.left &&
rect.top >= r.top &&
rect.right <= r.right &&
rect.bottom <= r.bottom;
});
} }
function paintListener(e) { function sendMouseEvent(t, elem) {
if (isRectContainedInRectFromRegion(buttonRect(), SpecialPowers.wrap(e).clientRects)) { let r = elem.getBoundingClientRect();
gNeedsPaint = false; synthesizeMouse(elem, r.width / 2, r.height / 2, {type: t});
currentSnapshot = takeSnapshot();
}
} }
var gNeedsPaint = false; async function tests() {
function executeTests() { let button = document.getElementById("button");
var testYielder = tests(); let label = document.getElementById("label");
function execNext() { let outside = document.getElementById("outside");
if (!gNeedsPaint) {
let {done} = testYielder.next();
if (done) {
return;
}
button.getBoundingClientRect(); // Flush.
gNeedsPaint = true;
}
SimpleTest.executeSoon(execNext);
}
execNext();
}
function* tests() { let is = window.opener.is;
window.addEventListener("MozAfterPaint", paintListener); let ok = window.opener.ok;
normalButtonCanvas = takeSnapshot();
// Press the button.
sendMouseEvent("mousemove", button);
sendMouseEvent("mousedown", button);
yield undefined;
pressedFocusedButtonCanvas = takeSnapshot();
compareSnapshots_(normalButtonCanvas, pressedFocusedButtonCanvas, false, "Pressed focused buttons should look different from normal buttons.");
// Release.
sendMouseEvent("mouseup", button);
yield undefined;
// make sure the button is focused as this doesn't happen on click on Mac
button.focus();
normalFocusedButtonCanvas = takeSnapshot();
compareSnapshots_(normalFocusedButtonCanvas, pressedFocusedButtonCanvas, false, "Pressed focused buttons should look different from normal focused buttons.");
// Unfocus the button.
sendMouseEvent("mousedown", outside);
sendMouseEvent("mouseup", outside);
yield undefined;
// Press the label. // Press the label.
sendMouseEvent("mousemove", label); sendMouseEvent("mousemove", label);
sendMouseEvent("mousedown", label); sendMouseEvent("mousedown", label);
yield undefined;
compareSnapshots_(normalButtonCanvas, currentSnapshot, false, "Pressing the label should have pressed the button."); await oneTick();
pressedButtonCanvas = takeSnapshot();
ok(label.matches(":hover"), "Label is hovered");
ok(button.matches(":hover"), "Button should be hovered too");
ok(label.matches(":active"), "Label is active");
ok(button.matches(":active"), "Button should be active too");
// Move the mouse down from the label. // Move the mouse down from the label.
sendMouseEvent("mousemove", outside); sendMouseEvent("mousemove", outside);
yield undefined;
compareSnapshots_(normalButtonCanvas, currentSnapshot, true, "Moving the mouse down from the label should have unpressed the button."); await oneTick();
// ... and up again.
ok(!label.matches(":hover"), "Label is no longer hovered");
ok(!button.matches(":hover"), "Button should not be hovered too");
ok(label.matches(":active"), "Label is still active");
ok(button.matches(":active"), "Button is still active too");
// And up again.
sendMouseEvent("mousemove", label); sendMouseEvent("mousemove", label);
yield undefined;
compareSnapshots_(pressedButtonCanvas, currentSnapshot, true, "Moving the mouse back on top of the label should have pressed the button."); await oneTick();
ok(label.matches(":hover"), "Label hovered again");
ok(button.matches(":hover"), "Button be hovered again");
ok(label.matches(":active"), "Label is still active");
ok(button.matches(":active"), "Button is still active too");
// Release. // Release.
sendMouseEvent("mouseup", label); sendMouseEvent("mouseup", label);
yield undefined;
var focusOnMouse = (navigator.platform.indexOf("Mac") != 0); await oneTick();
compareSnapshots_(focusOnMouse ? normalFocusedButtonCanvas : normalButtonCanvas,
currentSnapshot, true, "Releasing the mouse over the label should have unpressed" + ok(!label.matches(":active"), "Label is no longer active");
(focusOnMouse ? " (and focused)" : "") + " the button."); ok(!button.matches(":active"), "Button is no longer active");
ok(label.matches(":hover"), "Label is still hovered");
ok(button.matches(":hover"), "Button is still hovered");
// Press the label and remove it. // Press the label and remove it.
sendMouseEvent("mousemove", label); sendMouseEvent("mousemove", label);
sendMouseEvent("mousedown", label); sendMouseEvent("mousedown", label);
yield undefined;
await oneTick();
label.remove(); label.remove();
yield undefined;
compareSnapshots_(normalButtonCanvas, currentSnapshot, true, "Removing the label should have unpressed the button."); await oneTick();
ok(!label.matches(":active"), "Removing label should have unpressed it");
ok(!label.matches(":focus"), "Removing label should have unpressed it");
ok(!label.matches(":hover"), "Removing label should have unhovered it");
ok(!button.matches(":active"), "Removing label should have unpressed the button");
ok(!button.matches(":focus"), "Removing label should have unpressed the button");
ok(!button.matches(":hover"), "Removing label should have unhovered the button");
sendMouseEvent("mouseup", label); sendMouseEvent("mouseup", label);
window.removeEventListener("MozAfterPaint", paintListener);
window.opener.finishTests(); window.opener.finishTests();
}
function sendMouseEvent(t, elem) {
var r = elem.getBoundingClientRect();
synthesizeMouse(elem, r.width / 2, r.height / 2, {type: t});
}
function compareSnapshots_(c1, c2, shouldBeIdentical, msg) {
var [correct, c1url, c2url] = compareSnapshots(c1, c2, shouldBeIdentical);
if (correct) {
if (shouldBeIdentical) {
window.opener.ok(true, msg + " - expected " + c1url);
} else {
window.opener.ok(true, msg + " - got " + c1url + " and " + c2url);
}
} else {
if (shouldBeIdentical) {
window.opener.ok(false, msg + " - expected " + c1url + " but got " + c2url);
} else {
window.opener.ok(false, msg + " - expected something other than " + c1url);
}
}
}
function takeSnapshot() {
var r = buttonRect();
adjustedRect = { left: r.left - 2, top: r.top - 2,
width: r.width + 4, height: r.height + 4 };
return SpecialPowers.snapshotRect(window, adjustedRect);
}
function buttonRect() {
return button.getBoundingClientRect();
} }
</script> </script>
</pre> </pre>