blob: d6e5bb002d1e5ef1025f5bc71024f70ce8767fba [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="resources/accessibility-helper.js"></script>
</head>
<body id="body" onkeydown="return keydown();">
<script>
function preventKeyboardDOMEventDispatch(webArea) {
return webArea.boolAttributeValue("AXPreventKeyboardDOMEventDispatch");
}
function setPreventKeyboardDOMEventDispatch(webArea, value) {
webArea.setBoolAttributeValue("AXPreventKeyboardDOMEventDispatch", value);
}
function keydown(event) {
var element = document.getElementById("keydowncount");
element.innerHTML = parseInt(element.innerHTML) + 1;
return false;
}
function keycount() {
return document.getElementById("keydowncount").innerHTML;
}
</script>
<div>
<p>1</p>
<p>2</p>
<p id="keydowncount">0<p>
</div>
<div id="console"></div>
<script>
description("This tests ignoring javascript key handlers that consume key events.");
if (window.testRunner) {
testRunner.dumpAsText();
if (window.accessibilityController && window.eventSender) {
var webArea = clearSelectionAndFocusOnWebArea();
accessibilityController.enableEnhancedAccessibility(false);
shouldBe("accessibilityController.enhancedAccessibilityEnabled", "false");
setPreventKeyboardDOMEventDispatch(webArea, false);
shouldBe("preventKeyboardDOMEventDispatch(webArea)", "false");
// Arrowing before enabling AX and ignore dom handlers won't move the caret
shouldBe("elementAtStartMarkerOfSelectedTextMarkerRange(webArea).stringValue", "'AXValue: 1'");
eventSender.keyDown("rightArrow");
shouldBe("elementAtStartMarkerOfSelectedTextMarkerRange(webArea).stringValue", "'AXValue: 1'");
eventSender.keyDown("rightArrow");
shouldBe("elementAtStartMarkerOfSelectedTextMarkerRange(webArea).stringValue", "'AXValue: 1'");
// Validate that the handler received 2 keys events
shouldBe("keycount()", "'2'");
// Enable enhanced accessibility (necessary for accessibility specific selection handling).
accessibilityController.enableEnhancedAccessibility(true);
shouldBe("accessibilityController.enhancedAccessibilityEnabled", "true");
// Enable IgnoreDOMKeyEventHandlers so that the javascript handler will be skipped
setPreventKeyboardDOMEventDispatch(webArea, true);
shouldBe("preventKeyboardDOMEventDispatch(webArea)", "true");
shouldBe("elementAtStartMarkerOfSelectedTextMarkerRange(webArea).stringValue", "'AXValue: 1'");
eventSender.keyDown("rightArrow");
shouldBe("elementAtStartMarkerOfSelectedTextMarkerRange(webArea).stringValue", "'AXValue: 1'");
eventSender.keyDown("rightArrow");
shouldBe("elementAtStartMarkerOfSelectedTextMarkerRange(webArea).stringValue", "'AXValue: 2'");
// Validate that the handler didn't receive any more key events
shouldBe("keycount()", "'2'");
setPreventKeyboardDOMEventDispatch(webArea, false);
}
}
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>