blob: af7e3ac3a3c3a1dcda5bd9cdbb316415c36c860d [file] [log] [blame]
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<select id="select" value="Select"></select>
<div id="slider" tabindex="0" role="slider" aria-valuenow="5">Slider</div>
<script>
async_test((t) => {
window.selectNotificationCount = 0;
window.sliderNotificationCount = 0;
window.globalNotificationCount = 0;
window.select = accessibilityController.accessibleElementById("select");
window.slider = accessibilityController.accessibleElementById("slider");
let expected_notifications = [
[select, "Focus"],
["global", "Focus", "AXRole: AXPopUpButton"],
[select, "Blur"],
["global", "Blur", "AXRole: AXPopUpButton"],
[slider, "Focus"],
["global", "Focus", "AXRole: AXSlider"],
[select, "TextChanged"],
["global", "TextChanged", "AXRole: AXPopUpButton"],
[select, "TextChanged"],
["global", "TextChanged", "AXRole: AXPopUpButton"],
[select, "InvalidStatusChanged"],
["global", "InvalidStatusChanged", "AXRole: AXPopUpButton"],
[slider, "ValueChanged"],
["global", "ValueChanged", "AXRole: AXSlider"]
];
document.getElementById("select").focus();
select.addNotificationListener(t.step_func(function(notification) {
selectNotificationCount++;
console.log("got " + notification + " on select");
let expected_notification = expected_notifications.shift();
assert_equals(expected_notification[0], select);
assert_equals(notification, expected_notification[1]);
}));
document.getElementById("slider").focus();
slider.addNotificationListener(t.step_func(function(notification) {
sliderNotificationCount++;
console.log("got " + notification + " on slider");
let expected_notification = expected_notifications.shift();
assert_equals(expected_notification[0], slider);
assert_equals(notification, expected_notification[1]);
}));
accessibilityController.addNotificationListener(t.step_func(function(element, notification) {
if (element.isEqual(slider) || element.isEqual(select)) {
globalNotificationCount++;
console.log("got " + notification + " on global");
let expected_notification = expected_notifications.shift();
assert_equals(expected_notification[0], "global");
assert_equals(notification, expected_notification[1]);
assert_equals(element.role, expected_notification[2]);
}
if (expected_notifications.length === 0) {
assert_equals(selectNotificationCount, 5);
assert_equals(sliderNotificationCount, 2);
assert_equals(globalNotificationCount, 7);
accessibilityController.removeNotificationListener();
select.removeNotificationListener();
slider.removeNotificationListener();
t.done();
}
}));
// This should trigger a "invalid status changed" notification on the select.
document.getElementById("select").setAttribute("aria-invalid", "true");
// This should trigger a "value changed" notification on the slider.
document.getElementById("slider").setAttribute("aria-valuenow", "6");
window.setTimeout(t.step_func_done(() => {
assert_unreached();
}), 100);
}, "This tests that a notification listener on an element only listens to that one element, and that a global notification listener listens to all notifications.");
</script>