Add tests also for blur event (bug 238987)

This commit is contained in:
Olli.Pettay@helsinki.fi 2007-07-03 09:27:28 -07:00
Родитель 0a80939806
Коммит ee3d7a8d83
1 изменённых файлов: 63 добавлений и 15 удалений

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

@ -23,10 +23,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=238987
var shouldStop = false;
var modifier = 0;
var expectedResult = "i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12";
var forwardArray = expectedResult.split(",");
var backwardArray = expectedResult.split(",");
// Adding 3 for "begin", "end", "begin" and one for the <a> in the Mochitest template.
var expectedWindowFocusCount = forwardArray.length + backwardArray.length + 4;
var forwardFocusArray = expectedResult.split(",");
var backwardFocusArray = expectedResult.split(",");
var forwardBlurArray = expectedResult.split(",");
var backwardBlurArray = expectedResult.split(",");
// Adding 3 for "begin", "end", "begin" and one for the <a> in the Mochitest template,
var expectedWindowFocusCount = forwardFocusArray.length + backwardFocusArray.length + 4;
// but the last blur event goes to i1, not "begin".
var expectedWindowBlurCount = forwardFocusArray.length + backwardFocusArray.length + 3;
// accessibility.tabfocus must be set to value 7 before running test also
// on a mac.
@ -54,13 +58,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=238987
} else if (e.target.id == "end") {
modifier = Components.interfaces.nsIDOMNSEvent.SHIFT_MASK;
} else if (modifier) {
var expected = backwardArray.pop();
var expected = backwardFocusArray.pop();
ok(expected == e.target.id,
"Backward tabbing, expected [" + expected + "], got [" + e.target.id + "]");
"(focus) Backward tabbing, expected [" +
expected + "], got [" + e.target.id + "]");
} else {
var expected = forwardArray.shift();
var expected = forwardFocusArray.shift();
ok(expected == e.target.id,
"Forward tabbing, expected [" + expected + "], got [" + e.target.id + "]");
"(focus) Forward tabbing, expected [" +
expected + "], got [" + e.target.id + "]");
}
}
@ -71,7 +77,33 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=238987
s = s + ", id=\"" + e.target.id + "\"";
}
ok(e.eventPhase == Components.interfaces.nsIDOMEvent.CAPTURING_PHASE,
"|window| should not have got focus, " + s + "\n");
"|window| should not have got a focus event, " + s);
}
function handleBlur(e) {
if (e.target.id == "begin" || e.target.id == "end") {
return;
} else if (modifier) {
var expected = backwardBlurArray.pop();
ok(expected == e.target.id,
"(blur) backward tabbing, expected [" +
expected + "], got [" + e.target.id + "]");
} else {
var expected = forwardBlurArray.shift();
ok(expected == e.target.id,
"(blur) forward tabbing, expected [" +
expected + "], got [" + e.target.id + "]");
}
}
function handleWindowBlur(e) {
--expectedWindowBlurCount;
var s = "target " + e.target;
if ("id" in e.target) {
s = s + ", id=\"" + e.target.id + "\"";
}
ok(e.eventPhase == Components.interfaces.nsIDOMEvent.CAPTURING_PHASE,
"|window| should not have got a blur event, " + s);
}
function tab() {
@ -84,12 +116,25 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=238987
utils.sendKeyEvent("keypress", key, 0, modifier);
utils.sendKeyEvent("keyup", key, 0, modifier);
if (shouldStop) {
ok(forwardArray.length == 0,
"Not all forward tabbing tests were run, " + forwardArray.toString());
ok(backwardArray.length == 0,
"Not all forward tabbing tests were run, " + backwardArray.toString());
// Did focus handling succeed
ok(forwardFocusArray.length == 0,
"Not all forward tabbing focus tests were run, " +
forwardFocusArray.toString());
ok(backwardFocusArray.length == 0,
"Not all backward tabbing focus tests were run, " +
backwardFocusArray.toString());
ok(expectedWindowFocusCount == 0,
"|window| didn't get right amount focus events")
"|window| didn't get the right amount of focus events");
// and blur.
ok(forwardBlurArray.length == 0,
"Not all forward tabbing blur tests were run, " +
forwardBlurArray.toString());
ok(backwardBlurArray.length == 0,
"Not all backward tabbing blur tests were run, " +
backwardBlurArray.toString());
ok(expectedWindowBlurCount == 0,
"|window| didn't get the right amount of blur events");
setOrRestoreTabFocus(0);
SimpleTest.finish();
} else {
@ -101,17 +146,20 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=238987
window.focus();
window.addEventListener("focus", handleWindowFocus, true);
window.addEventListener("focus", handleWindowFocus, false);
window.addEventListener("blur", handleWindowBlur, true);
window.addEventListener("blur", handleWindowBlur, false);
var elements = document.getElementsByTagName("*");
for (var i = 0; i < elements.length; ++i) {
if (elements[i].hasAttribute("id")) {
elements[i].addEventListener("focus", handleFocus, false);
elements[i].addEventListener("blur", handleBlur, false);
}
}
tab();
}
function doTest() {
setOrRestoreTabFocus(7)
setOrRestoreTabFocus(7);
setTimeout(start, 100);
}