function paintListener(e) {
if (isRectContainedInRectFromRegion(buttonRect(), SpecialPowers.wrap(e).clientRects)) {
gNeedsPaint = false;
currentSnapshot = takeSnapshot();
}
}
var gNeedsPaint = false;
function executeTests() { var testYielder = tests();
function execNext() {
if (!gNeedsPaint) {
let {done} = testYielder.next();
if (done) {
return;
} button.getBoundingClientRect(); // Flush.
gNeedsPaint = true;
}
SimpleTest.executeSoon(execNext);
}
execNext();
}
function* tests() {
window.addEventListener("MozAfterPaint", paintListener);
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.
sendMouseEvent("mousemove", label);
sendMouseEvent("mousedown", label);
yield undefined;
compareSnapshots_(normalButtonCanvas, currentSnapshot, false, "Pressing the label should have pressed the button.");
pressedButtonCanvas = takeSnapshot();
// Move the mouse down from the label.
sendMouseEvent("mousemove", outside);
yield undefined;
compareSnapshots_(normalButtonCanvas, currentSnapshot, true, "Moving the mouse down from the label should have unpressed the button.");
// ... and up again.
sendMouseEvent("mousemove", label);
yield undefined;
compareSnapshots_(pressedButtonCanvas, currentSnapshot, true, "Moving the mouse back on top of the label should have pressed the button.");
// Release.
sendMouseEvent("mouseup", label);
yield undefined; var focusOnMouse = SpecialPowers.getIntPref("accessibility.mouse_focuses_formcontrol") > 0;
compareSnapshots_(focusOnMouse ? normalFocusedButtonCanvas : normalButtonCanvas,
currentSnapshot, true, "Releasing the mouse over the label should have unpressed" +
(focusOnMouse ? " (and focused)" : "") + " the button.");
// Press the label and remove it.
sendMouseEvent("mousemove", label);
sendMouseEvent("mousedown", label);
yield undefined; label.remove();
yield undefined;
compareSnapshots_(normalButtonCanvas, currentSnapshot, true, "Removing the label should have unpressed the button.");
sendMouseEvent("mouseup", label);
window.removeEventListener("MozAfterPaint", paintListener);
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);
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.