зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1741441 - When the download panel is opened, focus the first item. r=Gijs
As suggested by :jamie, this patch causes focus to move to the item at the top of the list whenever the download panel is shown. In the event that the download panel is opened automatically because a new download has been started, this will have the effect of always bringing the new download directly to the attention of accessibility tools (because the panel itself also receives focus). Differential Revision: https://phabricator.services.mozilla.com/D133160
This commit is contained in:
Родитель
c5c7e8164e
Коммит
bf3e47d93b
|
@ -548,6 +548,7 @@ var DownloadsPanel = {
|
|||
}
|
||||
if (!element) {
|
||||
if (DownloadsView.richListBox.itemCount > 0) {
|
||||
DownloadsView.richListBox.selectedIndex = 0;
|
||||
DownloadsView.richListBox.focus();
|
||||
} else {
|
||||
DownloadsFooter.focus();
|
||||
|
|
|
@ -44,3 +44,4 @@ skip-if =
|
|||
[browser_go_to_download_page.js]
|
||||
[browser_pdfjs_preview.js]
|
||||
[browser_downloads_pauseResume.js]
|
||||
[browser_downloads_panel_focus.js]
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
add_task(async function setup() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.download.improvements_to_download_panel", true]],
|
||||
});
|
||||
|
||||
registerCleanupFunction(async () => {
|
||||
info("Resetting downloads and closing downloads panel");
|
||||
await task_resetState();
|
||||
});
|
||||
|
||||
let downloadList = await Downloads.getList(Downloads.ALL);
|
||||
let downloadCount = (await downloadList.getAll()).length;
|
||||
is(downloadCount, 0, "At the start of the test, there should be 0 downloads");
|
||||
});
|
||||
|
||||
// Test that the top item in the panel always gets focus upon opening the panel.
|
||||
add_task(async function test_focus() {
|
||||
info("creating a download and setting it to in progress");
|
||||
await task_addDownloads([{ state: DownloadsCommon.DOWNLOAD_DOWNLOADING }]);
|
||||
let publicList = await Downloads.getList(Downloads.PUBLIC);
|
||||
let downloads = await publicList.getAll();
|
||||
downloads[0].stopped = false;
|
||||
|
||||
info("waiting for the panel to open");
|
||||
await task_openPanel();
|
||||
|
||||
is(
|
||||
DownloadsView.richListBox.itemCount,
|
||||
1,
|
||||
"there should be exactly one download listed"
|
||||
);
|
||||
// Most of the time if we want to check which thing has focus, we can just ask
|
||||
// Services.focus to tell us. But the downloads panel uses a <richlistbox>,
|
||||
// and when an item in one of those has focus, the focus manager actually
|
||||
// thinks that *the list itself* has focus, and everything below that is
|
||||
// handled within the widget. So, the best we can do is check that the list is
|
||||
// focused and then that the selected item within the list is correct.
|
||||
is(
|
||||
Services.focus.focusedElement,
|
||||
DownloadsView.richListBox,
|
||||
"the downloads list should have focus"
|
||||
);
|
||||
is(
|
||||
DownloadsView.richListBox.itemChildren[0],
|
||||
DownloadsView.richListBox.selectedItem,
|
||||
"the focused item should be the only download in the list"
|
||||
);
|
||||
|
||||
info("closing the panel and creating a second download");
|
||||
DownloadsPanel.hidePanel();
|
||||
await task_addDownloads([{ state: DownloadsCommon.DOWNLOAD_DOWNLOADING }]);
|
||||
|
||||
info("waiting for the panel to open after starting the second download");
|
||||
await task_openPanel();
|
||||
|
||||
is(
|
||||
DownloadsView.richListBox.itemCount,
|
||||
2,
|
||||
"there should be two downloads listed"
|
||||
);
|
||||
is(
|
||||
Services.focus.focusedElement,
|
||||
DownloadsView.richListBox,
|
||||
"the downloads list should have focus"
|
||||
);
|
||||
is(
|
||||
DownloadsView.richListBox.itemChildren[0],
|
||||
DownloadsView.richListBox.selectedItem,
|
||||
"the focused item should be the first download in the list"
|
||||
);
|
||||
|
||||
info("closing the panel and creating a third download");
|
||||
DownloadsPanel.hidePanel();
|
||||
await task_addDownloads([{ state: DownloadsCommon.DOWNLOAD_DOWNLOADING }]);
|
||||
|
||||
info("waiting for the panel to open after starting the third download");
|
||||
await task_openPanel();
|
||||
|
||||
is(
|
||||
DownloadsView.richListBox.itemCount,
|
||||
3,
|
||||
"there should be three downloads listed"
|
||||
);
|
||||
is(
|
||||
Services.focus.focusedElement,
|
||||
DownloadsView.richListBox,
|
||||
"the downloads list should have focus"
|
||||
);
|
||||
is(
|
||||
DownloadsView.richListBox.itemChildren[0],
|
||||
DownloadsView.richListBox.selectedItem,
|
||||
"the focused item should be the first download in the list"
|
||||
);
|
||||
});
|
Загрузка…
Ссылка в новой задаче