add_task(async function testClearSearchButton() {
let input = document.getElementById("searchInput");
let clearButton = SpecialPowers.getInputButton(input);
isnot(clearButton, null, "Should find the clear button");
is(searchInput.value, "", "Search input should be blank at the start of test");
ok(!BrowserTestUtils.isVisible(clearButton), "Clear button is hidden when there is no value in the input");
is(clearButton.getAttribute("tabindex"), "-1", "Clear button should not be focusable");
is(clearButton.getAttribute("aria-hidden"), "true", "Clear button should be hidden from the accessibility tree");
searchInput.value = "abc";
ok(
BrowserTestUtils.isVisible(clearButton), "Clear button should be visible when text is present"
);
is(
clearButton.getAttribute("tabindex"), "-1", "Clear button should not be focusable when visible"
);
is(
clearButton.getAttribute("aria-hidden"), "true", "Clear button should be hidden from accessibilty tree when visible"
);
// Clear text input by clicking the clear button
synthesizeMouseAtCenter(clearButton, {});
ok(
!BrowserTestUtils.isVisible(clearButton), "Clear button should be hidden after clicking the clear button"
);
is(
searchInput.value, "", "Search input should be blank after using the clear button"
);
is(
clearButton.getAttribute("tabindex"), "-1", "Clear button should not be focusable when hidden again"
);
is(
clearButton.getAttribute("aria-hidden"), "true", "Clear button should be hidden from accessibilty tree when button is hidden again"
);
searchInput.value = "foo";
ok(
BrowserTestUtils.isVisible(clearButton), "Clear button should be visible when text is present"
);
is(
clearButton.getAttribute("tabindex"), "-1", "Clear button should not be focusable when visible"
);
is(
clearButton.getAttribute("aria-hidden"), "true", "Clear button should be hidden from accessibilty tree when visible"
);
});
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 und die Messung sind noch experimentell.