Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
-
CI results over the last 21 days
- Manifest: browser/components/multilineeditor/tests/chrome/chrome.toml
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Multiline editor placeholder hints test</title>
<link
rel="stylesheet"
/>
<link rel="stylesheet" href="chrome://global/skin/global.css" />
<script src="../../../../../toolkit/content/tests/widgets/lit-test-helpers.js"></script>
<script
type="module"
src="chrome://browser/content/multilineeditor/multiline-editor.mjs"
></script>
<script>
let html;
let testHelpers;
add_setup(async function setup() {
testHelpers = new LitTestHelpers();
({ html } = await testHelpers.setupLit());
testHelpers.setupTests({
templateFn: (attributes) => html`<moz-multiline-editor ${attributes}></moz-multiline-editor>`,
});
const MultilineEditor = await customElements.whenDefined("moz-multiline-editor");
const { PLACEHOLDER_HINT_DURATION_MS } = MultilineEditor;
MultilineEditor.PLACEHOLDER_HINT_DURATION_MS = 100;
SimpleTest.registerCleanupFunction(() => {
MultilineEditor.PLACEHOLDER_HINT_DURATION_MS = PLACEHOLDER_HINT_DURATION_MS;
});
});
function waitForCurrentHint(hints, index) {
return BrowserTestUtils.waitForMutationCondition(
hints,
{ attributeFilter: ["class"], subtree: true },
() => hints.children[index].classList.contains("current")
);
}
add_task(async function testPlaceholderHintsRendered() {
const result = await testHelpers.renderTemplate();
const editor = result.querySelector("moz-multiline-editor");
editor.placeholder = "Primary placeholder";
editor.placeholderHints = ["Hint one", "Hint two"];
await editor.updateComplete;
const carousel = editor.shadowRoot.querySelector(".placeholder-hints");
ok(carousel, "Placeholder carousel is rendered");
const items = carousel.querySelectorAll("li");
is(items.length, 3, "Carousel has expected number of items");
is(items[0].textContent, "Primary placeholder", "First item is primary placeholder");
is(items[1].textContent, "Hint one", "Second item is first hint");
is(items[2].textContent, "Hint two", "Third item is second hint");
});
add_task(async function testPlaceholderHintsNotRenderedWhenEmpty() {
const result = await testHelpers.renderTemplate();
const editor = result.querySelector("moz-multiline-editor");
editor.placeholder = "Just a placeholder";
editor.placeholderHints = [];
await editor.updateComplete;
const carousel = editor.shadowRoot.querySelector(".placeholder-hints");
ok(!carousel, "Placeholder carousel is not rendered when hints are empty");
const placeholder = editor.shadowRoot.querySelector(".placeholder");
ok(placeholder, "Regular placeholder is rendered instead");
});
add_task(async function testPlaceholderHintsVisibilityToggles() {
const result = await testHelpers.renderTemplate();
const editor = result.querySelector("moz-multiline-editor");
editor.placeholder = "Primary placeholder";
editor.placeholderHints = ["Hint one"];
await editor.updateComplete;
ok(
editor.shadowRoot.querySelector(".placeholder-hints"),
"Carousel visible when empty"
);
editor.value = "Some text";
await editor.updateComplete;
ok(
!editor.shadowRoot.querySelector(".placeholder-hints"),
"Carousel hidden with content"
);
editor.value = "";
await editor.updateComplete;
ok(
editor.shadowRoot.querySelector(".placeholder-hints"),
"Carousel visible again when cleared"
);
});
add_task(async function testShowPlaceholderAnimation() {
await SpecialPowers.pushPrefEnv({
set: [["ui.prefersReducedMotion", 0]],
});
const result = await testHelpers.renderTemplate();
const editor = result.querySelector("moz-multiline-editor");
editor.placeholder = "Primary placeholder";
editor.placeholderHints = ["Hint one", "Hint two"];
editor.showPlaceholderAnimation = true;
await editor.updateComplete;
let hints = editor.shadowRoot.querySelector(".placeholder-hints");
is(hints.children.length, 3, "All placeholder items are present");
ok(hints.children[0].classList.contains("current"), "Primary placeholder is shown first");
await waitForCurrentHint(hints, 1);
const [hidePrevious] = hints.children[0]
.getAnimations()
.filter(animation => animation.transitionProperty == "visibility");
is(
hidePrevious.effect.getKeyframes()[1].visibility,
"hidden",
"Previous hint is hidden after the transition"
);
editor.showPlaceholderAnimation = false;
await editor.updateComplete;
hints = editor.shadowRoot.querySelector(".placeholder-hints");
ok(
hints.children[0].classList.contains("current"),
"Primary placeholder is shown when the animation is disabled"
);
await SpecialPowers.popPrefEnv();
});
add_task(async function testReducedMotionStopsPlaceholderRotation() {
await SpecialPowers.pushPrefEnv({
set: [["ui.prefersReducedMotion", 0]],
});
const result = await testHelpers.renderTemplate();
const editor = result.querySelector("moz-multiline-editor");
editor.placeholder = "Primary placeholder";
editor.placeholderHints = ["Hint one", "Hint two"];
editor.showPlaceholderAnimation = true;
await editor.updateComplete;
const getHints = () => editor.shadowRoot.querySelector(".placeholder-hints");
const rotatingHints = getHints();
await waitForCurrentHint(rotatingHints, 1);
await SpecialPowers.pushPrefEnv({
set: [["ui.prefersReducedMotion", 1]],
});
await TestUtils.waitForCondition(
() => getHints() != rotatingHints,
"Placeholder hints are rebuilt when reduced motion is enabled"
);
const staticHints = getHints();
ok(staticHints.children[0].classList.contains("current"), "Primary placeholder is shown again");
is(
staticHints.style.getPropertyValue("--multiline-editor-placeholder-transition-duration"),
"",
"Rotation is not scheduled with reduced motion"
);
await SpecialPowers.flushPrefEnv();
});
add_task(async function testSingleHintEntersFromBelow() {
await SpecialPowers.pushPrefEnv({
set: [["ui.prefersReducedMotion", 0]],
});
const result = await testHelpers.renderTemplate();
const editor = result.querySelector("moz-multiline-editor");
editor.placeholder = "Primary placeholder";
editor.placeholderHints = ["Hint one"];
editor.showPlaceholderAnimation = true;
await editor.updateComplete;
const hints = editor.shadowRoot.querySelector(".placeholder-hints");
await waitForCurrentHint(hints, 1);
const [transition] = hints.children[1]
.getAnimations()
.filter(animation => animation.transitionProperty == "transform");
is(
transition.effect.getKeyframes()[0].transform,
"translateY(100%)",
"Hint enters from below"
);
await SpecialPowers.popPrefEnv();
});
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>