add_task(async function testMozSelectModifyOptions() {
let target = await testHelpers.renderTemplate();
let select = target.querySelector("moz-select");
await select.updateComplete;
let options = select.inputEl.querySelectorAll("option");
let mozOptions = select.querySelectorAll("moz-option");
is(select.value, "1", "moz-select value correct");
is(options[0].textContent.trim(), "One", "First option text correct");
is(options[0].value, "1", "First option value correct");
is(
options[1].textContent.trim(), "Initial", "Second option text correct"
);
is(options[1].value, "value", "Second option value correct");
is(select.value, "i", "moz-select value updated");
is(options[0].textContent.trim(), "First", "First option text updated");
is(options[0].value, "i", "First option value updated");
is(
options[1].textContent.trim(), "Second", "Second option text updated"
);
is(options[1].value, "ii", "Second option value updated");
});
add_task(async function testMozSelectOptionWithIcon() {
let target = await testHelpers.renderTemplate();
let select = target.querySelector("moz-select");
await select.updateComplete;
is(select.value, "1", "First option is selected");
let selectWrapper = select.shadowRoot.querySelector(".select-wrapper");
ok(
!selectWrapper.classList.contains("with-icon"), "Select doesn't have an icon"
);
info("New iconSrc value was added to the selected option.");
ok(selectWrapper.classList.contains("with-icon"), "Select has an icon");
is( select.shadowRoot.querySelector(".select-option-icon").src,
mozOptions[0].iconSrc, "Select displays the icon of the selected option"
);
select.value = "value";
await select.updateComplete;
is(select.value, "value", "Second option is selected");
is( select.inputEl.value, select.value, "Select element value is updated"
);
is( select.shadowRoot.querySelector(".select-option-icon").src,
mozOptions[1].iconSrc, "Select displays the icon of the newly selected option"
);
});
function openSelectAndGetMenuPopup(select) {
let topWindow = window.docShell.chromeEventHandler.documentGlobal;
let pickerOpened = BrowserTestUtils.waitForSelectPopupShown(topWindow); select.focus();
synthesizeKey(" ");
return pickerOpened;
}
/**
* Test that hidden and disabled moz-option are reflected in the popup menu.
*/
add_task(async function testMozSelectHiddenAndDisabledOptions() {
let target = await testHelpers.renderTemplate();
let select = target.querySelector("moz-select");
await select.updateComplete;
let mozOptions = select.querySelectorAll("moz-option");
// Open select and verify all elements are visible and enabled.
let popup = await openSelectAndGetMenuPopup(select);
let popupItems = Array.from(popup.children);
// Items that are hidden are not included in the popup's children.
is(popupItems.length, mozOptions.length, "All options are shown");
for (let i = 0; i < popupItems.length; i++) {
ok(!popupItems[i].disabled, `Option ${i} is enabled`);
}
// Close popup.
let hiddenPromise = BrowserTestUtils.waitForPopupEvent(popup, "hidden");
popup.hidePopup();
await hiddenPromise;
// open select and verify first option is disabled and second option is hidden.
popup = await openSelectAndGetMenuPopup(select);
popupItems = Array.from(popup.children);
is(
popupItems.length,
mozOptions.length - 1, "All but one option shown"
);
ok(popupItems[0].disabled, "First option is disabled");
is(popupItems[0].label, mozOptions[0].label, "First option is visible");
ok(!popupItems[1].disabled, "Second option is enabled");
is(popupItems[1].label, mozOptions[2].label, "Third option is visible");
ok(!popupItems[2].disabled, "Third option is enabled");
is(
popupItems[2].label,
mozOptions[3].label, "Fourth option is visible"
);
// Close popup.
hiddenPromise = BrowserTestUtils.waitForPopupEvent(popup, "hidden");
popup.hidePopup();
await hiddenPromise;
add_task(async function testEmptyMozSelect() {
// The only thing we test is that this doesn't throw.
await testHelpers.renderTemplate(
testHelpers.html`<moz-select></moz-select>`
);
});
add_task(async function testMozSelectOptionWithSeparator() {
let target = await testHelpers.renderTemplate(
testHelpers.html`<moz-select><moz-option value="1"label="One"></moz-option><hr>
<moz-option value="2"label="Two"></moz-option></moz-select>`
);
let mozSelect = target.querySelector("moz-select");
await mozSelect.updateComplete;
const embeddedHr = mozSelect.querySelector("hr");
ok(embeddedHr, "Renders the hr");
is(mozSelect.children[1], embeddedHr, "Renders hr as the second child");
const renderedHr = mozSelect.shadowRoot.querySelector("hr");
ok(renderedHr, "Renders the hr");
const select = mozSelect.shadowRoot.querySelector("select");
is(select.children.length, 4, "moz-select renders four child elements");
is(select.children[2], renderedHr, "Renders hr as the third child");
is(
renderedHr.parentElement, select, "Renders the hr as a direct descendant of select"
);
});
</script>
</head>
<body></body>
</html>
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-08-25)
¤
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.