diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/content/tests/browser/browser_richlistbox_keyboard.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/content/tests/browser/browser_richlistbox_keyboard.js')
-rw-r--r-- | toolkit/content/tests/browser/browser_richlistbox_keyboard.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/toolkit/content/tests/browser/browser_richlistbox_keyboard.js b/toolkit/content/tests/browser/browser_richlistbox_keyboard.js new file mode 100644 index 0000000000..a1287335b4 --- /dev/null +++ b/toolkit/content/tests/browser/browser_richlistbox_keyboard.js @@ -0,0 +1,81 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_richlistbox_keyboard() { + await SpecialPowers.pushPrefEnv({ set: [["accessibility.tabfocus", 7]] }); + await BrowserTestUtils.withNewTab("about:about", browser => { + let document = browser.contentDocument; + let box = document.createXULElement("richlistbox"); + + function checkTabIndices(selectedLine) { + for (let button of box.querySelectorAll(`.line${selectedLine} button`)) { + is( + button.tabIndex, + 0, + `Should have ensured buttons inside selected line ${selectedLine} are focusable` + ); + } + for (let otherButton of box.querySelectorAll( + `richlistitem:not(.line${selectedLine}) button` + )) { + is( + otherButton.tabIndex, + -1, + `Should have ensured buttons outside selected line ${selectedLine} are not focusable` + ); + } + } + + let poem = `I wandered lonely as a cloud + That floats on high o'er vales and hills + When all at once I saw a crowd + A host, of golden daffodils; + Beside the lake, beneath the trees, + Fluttering and dancing in the breeze.`; + let items = poem.split("\n").map((line, index) => { + let item = document.createXULElement("richlistitem"); + item.className = `line${index + 1}`; + let button1 = document.createXULElement("button"); + button1.textContent = "Like"; + let button2 = document.createXULElement("button"); + button2.textContent = "Subscribe"; + item.append(line.trim(), button1, button2); + return item; + }); + box.append(...items); + document.body.prepend(box); + box.focus(); + box.getBoundingClientRect(); // force a flush + box.selectedItem = box.firstChild; + checkTabIndices(1); + EventUtils.synthesizeKey("VK_DOWN", {}, document.defaultView); + is( + box.selectedItem.className, + "line2", + "Should have moved selection to the next line." + ); + checkTabIndices(2); + EventUtils.synthesizeKey("VK_TAB", {}, document.defaultView); + is( + document.activeElement, + box.selectedItem.querySelector("button"), + "Initial button gets focus in the selected list item." + ); + EventUtils.synthesizeKey("VK_UP", {}, document.defaultView); + checkTabIndices(1); + is( + document.activeElement, + box.selectedItem.querySelector("button"), + "Initial button gets focus in the selected list item when moving up with arrow key." + ); + EventUtils.synthesizeKey("VK_DOWN", {}, document.defaultView); + checkTabIndices(2); + is( + document.activeElement, + box.selectedItem.querySelector("button"), + "Initial button gets focus in the selected list item when moving down with arrow key." + ); + }); +}); |