/** Test for Bug 423523 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("untriaged");
function divIsFocused() {
// Check if div is directly focused. var divNode = document.getElementById("div1");
if (window.getSelection().focusNode == divNode) {
return true;
}
// Check if one of the div's children has focus. var node = window.getSelection().focusNode; var childNodes = divNode.childNodes;
for (var i=0; i<childNodes.length; i++) {
if (childNodes[i] == node) {
return true;
}
}
// Not focused (at least not the first gen kids, and
// that's ok for this test).
return false;
}
function selectionOffsetIs(expectedOffset) {
return window.getSelection().focusOffset == expectedOffset;
}
function sendMouseClick() { var rect=document.getElementById('div1').getBoundingClientRect(); var utils = SpecialPowers.getDOMWindowUtils(window);
utils.sendMouseEvent('mousedown', rect.left+1, rect.top+1, 0, 1, 0);
utils.sendMouseEvent('mouseup', rect.left+1, rect.top+1, 0, 1, 0);
}
function runtests() {
sendMouseClick();
window.getSelection().collapse(document.getElementById("div1").firstChild, 0);
ok(divIsFocused(), "Div should be focused [0].");
ok(divIsFocused(), "Div should be focused [1].");
ok(selectionOffsetIs(0), "Caret should be at offset 0");
synthesizeKey("KEY_ArrowLeft");
ok(divIsFocused(), "Div should be focused [2].");
ok(selectionOffsetIs(0), "Caret should be at offset 0");
synthesizeKey("KEY_ArrowRight");
ok(divIsFocused(), "Div should be focused [3].");
ok(selectionOffsetIs(1), "Caret should be at offset 1");
synthesizeKey("KEY_ArrowLeft");
ok(divIsFocused(), "Div should be focused [4].");
ok(selectionOffsetIs(0), "Caret should be at offset 0");
ok(divIsFocused(), "Div should be focused [5].");
ok(selectionOffsetIs(0), "Caret should be at offset 0");
sendMouseClick();
ok(divIsFocused(), "Div should be focused [6].");
ok(selectionOffsetIs(0), "Caret should be at offset 0");
synthesizeKey("KEY_ArrowLeft");
ok(divIsFocused(), "Div should be focused [7].");
ok(selectionOffsetIs(0), "Caret should be at offset 0");
SimpleTest.finish();
}
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.