blob: 73fce0922507fb37faa94a7f260605ca3468d4ff [file] [log] [blame]
<!DOCTYPE html>
<html>
<script src="../../resources/js-test.js"></script>
<label for="submit">Label for Submit</label>
<dialog>
<input id="text" type="text">
<input id="submit" type="submit">
</dialog>
<script>
function clickOn(element) {
if (!window.eventSender)
return;
var absoluteTop = 0;
var absoluteLeft = 0;
for (var parentNode = element; parentNode; parentNode = parentNode.offsetParent) {
absoluteLeft += parentNode.offsetLeft;
absoluteTop += parentNode.offsetTop;
}
var x = absoluteLeft + element.offsetWidth / 2;
var y = absoluteTop + element.offsetHeight / 2;
eventSender.mouseMoveTo(x, y);
eventSender.mouseDown();
eventSender.mouseUp();
eventSender.mouseMoveTo(0, 0);
}
description('Tests focusing of an inert label for a non-inert target. label.focus() should send focus ' +
'to the target, but clicking the label should be the same as clicking on the document body.');
document.querySelector('dialog').showModal();
document.querySelector('#text').focus();
debug('Testing that calling focus() on label sends focus to its target.');
label = document.querySelector('label');
label.focus();
shouldBe('document.activeElement', "document.querySelector('#submit')");
debug('Testing that clicking on the label sends focus to document.body.');
clickOn(label);
shouldBe('document.activeElement', 'document.body');
</script>
</html>