blob: 89e1c68c7c2e925d9027f7362155061080eac421 [file] [log] [blame]
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<select id="selectElement" multiple title="selectElement">
<option SELECTED>Option 0</option>
<option>Option 1</option>
<option>Option 2</option>
<option DISABLED>Option 3</option>
</select>
<select id="selectElement2" title="selectElement">
<option SELECTED>Option 0</option>
<option>Option 1</option>
<option>Option 2</option>
<option DISABLED>Option 3</option>
</select>
<p>This tests that we can adjust focus and selection via accessibility API.</p>
<p id="notDRT">This test should only be run inside of DumpRenderTree.</p>
<p id="console"></p>
<script>
function dumpSelection(element)
{
var options = element.options;
for (var i = 0; i < options.length; ++i)
debug("Option " + i + " is " + (options[i].selected ? "" : "not ") + "selected.");
debug("");
}
if (window.testRunner && window.accessibilityController) {
document.getElementById("notDRT").style.visibility = "hidden";
document.body.focus();
shouldBe('accessibilityController.focusedElement.role', '"document"');
var anonymousBlock = accessibilityController.focusedElement.childAtIndex(0);
// Focus the select element.
var select = anonymousBlock.childAtIndex(0);
select.takeFocus();
shouldBe('accessibilityController.focusedElement.role', '"AXList"');
debug("");
var selectElement = document.getElementById("selectElement");
// Option 0 selected
accessibilityController.focusedElement.childAtIndex(0).takeSelection();
dumpSelection(selectElement);
// Option 1 selected
accessibilityController.focusedElement.childAtIndex(1).takeSelection();
dumpSelection(selectElement);
// Options 1, 2 selected
accessibilityController.focusedElement.childAtIndex(2).addSelection();
dumpSelection(selectElement);
// Option 2 selected
accessibilityController.focusedElement.childAtIndex(1).removeSelection();
dumpSelection(selectElement);
// Option 2 selected
accessibilityController.focusedElement.childAtIndex(0).removeSelection();
dumpSelection(selectElement);
// Options 0, 2 selected
accessibilityController.focusedElement.childAtIndex(0).addSelection();
dumpSelection(selectElement);
// Options 0, 2 selected
accessibilityController.focusedElement.childAtIndex(0).addSelection();
dumpSelection(selectElement);
// Option 2 selected
accessibilityController.focusedElement.childAtIndex(0).removeSelection();
dumpSelection(selectElement);
// No options selected
accessibilityController.focusedElement.childAtIndex(2).removeSelection();
dumpSelection(selectElement);
// No options selected (option at index 3 is disabled)
accessibilityController.focusedElement.childAtIndex(3).addSelection();
dumpSelection(selectElement);
debug("== single select ==");
var selectElement2 = document.getElementById("selectElement2");
selectElement2.focus();
var popupMenu = accessibilityController.focusedElement.childAtIndex(0);
// Option 0 is selected
popupMenu.childAtIndex(0).takeSelection();
dumpSelection(selectElement2);
// Option 1 selected
popupMenu.childAtIndex(1).takeSelection();
dumpSelection(selectElement2);
// Options 1 selected - addSelection() is not valid for single-select.
popupMenu.childAtIndex(2).addSelection();
dumpSelection(selectElement2);
// Options 1 selected - removeSelection() is not valid for single-select.
popupMenu.childAtIndex(1).removeSelection();
dumpSelection(selectElement2);
// Options 1 selected - option at index 3 is disabled
popupMenu.childAtIndex(3).takeSelection();
dumpSelection(selectElement2);
}
</script>
</body>
</html>