function runTests()
{
const all = Array.from(document.querySelectorAll('select'));
let i = 0;
all.forEach((elem) => {
elem.selectedIndex = -1;
++i;
if (!elem.id)
elem.id = "element " + i;
});
//
// Test DOWN key on a <select> with no selected options.
//
const listboxes = Array.from(document.querySelectorAll('select[size="3"]'));
listboxes.forEach((elem) => {
elem.focus();
synthesizeKey("KEY_ArrowDown");
is(""+elem.selectedIndex,
elem.getAttribute('firstNonDisabledIndex'),
elem.id + ": DOWN selected first non-disabled option");
});
const comboboxes = Array.from(document.querySelectorAll('select[size="1"]'));
// Mac shows the drop-down menu for DOWN, so skip this test there.
if (!kIsMac) {
comboboxes.forEach((elem) => {
elem.focus();
synthesizeKey("KEY_ArrowDown");
is(""+elem.selectedIndex,
elem.getAttribute('firstNonDisabledIndex'),
elem.id + ": DOWN selected first non-disabled option");
});
}
//
// Test SHIFT+DOWN on a <select> with no selected options.
//
listboxes.forEach((elem) => {
elem.focus();
synthesizeKey("KEY_ArrowDown", {shiftKey:true});
is(""+elem.selectedIndex,
elem.getAttribute('firstNonDisabledIndex'),
elem.id + ": SHIFT+DOWN selected first non-disabled option");
});
// Mac shows the drop-down menu for SHIFT+DOWN, so skip this test there.
if (!kIsMac) {
comboboxes.forEach((elem) => {
elem.focus();
synthesizeKey("KEY_ArrowDown", {shiftKey:true});
is(""+elem.selectedIndex,
elem.getAttribute('firstNonDisabledIndex'),
elem.id + ": SHIFT+DOWN selected first non-disabled option");
});
}
//
// Test CTRL+DOWN on a <select> with no selected options.
//
listboxes.forEach((elem) => {
elem.focus();
synthesizeKey("KEY_ArrowDown", {ctrlKey:true});
if (!elem.multiple)
is(""+elem.selectedIndex,
elem.getAttribute('firstNonDisabledIndex'),
elem.id + ": CTRL+DOWN selected first non-disabled option");
else
is(elem.selectedIndex, -1, elem.id + ": CTRL+DOWN did NOT select first any option");
});
// Mac shows the drop-down menu for CTRL+DOWN, so skip this test there.
if (!kIsMac) {
comboboxes.forEach((elem) => {
elem.focus();
synthesizeKey("KEY_ArrowDown", {ctrlKey:true});
is(""+elem.selectedIndex,
elem.getAttribute('firstNonDisabledIndex'),
elem.id + ": CTRL+DOWN selected first non-disabled option");
});
}
//
// Test SPACE on a <select> with no selected options.
//
listboxes.forEach((elem) => {
elem.focus();
sendString(" ");
is(""+elem.selectedIndex,
elem.getAttribute('firstNonDisabledIndex'),
elem.id + ": SPACE selected first non-disabled option");
});
// All platforms shows the drop-down menu for SPACE so skip testing that
// on the comboboxes.
//
// Test CTRL+SPACE on a <select> with no selected options.
//
listboxes.forEach((elem) => {
elem.focus();
synthesizeKey(" ", {ctrlKey:true});
is(""+elem.selectedIndex,
elem.getAttribute('firstNonDisabledIndex'),
elem.id + ": CTRL+SPACE selected first non-disabled option");
});
// non-Mac shows the drop-down menu for CTRL+SPACE, so skip this test there.
if (kIsMac) {
comboboxes.forEach((elem) => {
elem.focus();
synthesizeKey(" ", {ctrlKey:true});
is(""+elem.selectedIndex,
elem.getAttribute('firstNonDisabledIndex'),
elem.id + ": CTRL+SPACE selected first non-disabled option");
});
}
//
// Test SHIFT+SPACE on a <select> with no selected options.
//
listboxes.forEach((elem) => {
elem.focus();
synthesizeKey(" ", {shiftKey:true});
is(""+elem.selectedIndex,
elem.getAttribute('firstNonDisabledIndex'),
elem.id + ": SHIFT+SPACE selected first non-disabled option");
});
// All platforms shows the drop-down menu for SHIFT+SPACE so skip testing that
// on the comboboxes.
//
// Test CTRL+SHIFT+DOWN on a <select> with no selected options.
//
listboxes.forEach((elem) => {
elem.focus();
synthesizeKey("KEY_ArrowDown", {ctrlKey:true, shiftKey:true});
is(""+elem.selectedIndex,
elem.getAttribute('firstNonDisabledIndex'),
elem.id + ": CTRL+SHIFT+DOWN selected first non-disabled option");
});
// Mac shows the drop-down menu for CTRL+SHIFT+DOWN, so skip this test there.
if (!kIsMac) {
comboboxes.forEach((elem) => {
elem.focus();
synthesizeKey("KEY_ArrowDown", {ctrlKey:true, shiftKey:true});
is(""+elem.selectedIndex,
elem.getAttribute('firstNonDisabledIndex'),
elem.id + ": CTRL+SHIFT+DOWN selected first non-disabled option");
});
}
//
// Test CTRL+SHIFT+SPACE on a <select> with no selected options.
//
listboxes.forEach((elem) => {
elem.focus();
synthesizeKey(" ", {ctrlKey:true, shiftKey:true});
is(""+elem.selectedIndex,
elem.getAttribute('firstNonDisabledIndex'),
elem.id + ": CTRL+SHIFT+SPACE selected first non-disabled option");
});
// non-Mac shows the drop-down menu for CTRL+SHIFT+SPACE, so skip this test there.
if (kIsMac) {
comboboxes.forEach((elem) => {
elem.focus();
synthesizeKey(" ", {ctrlKey:true, shiftKey:true});
is(""+elem.selectedIndex,
elem.getAttribute('firstNonDisabledIndex'),
elem.id + ": CTRL+SHIFT+SPACE selected first non-disabled option");
});
}
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 ist noch experimentell.