Bug 1531246: Support keyboard activation (space/enter) of the Downloads toolbar button when focused. r=Gijs
authorJames Teh <jteh@mozilla.com>
Fri, 01 Mar 2019 12:00:45 +0000
changeset 520077 8cdde0ff59a15f59736e810524a649a4c8a5a7ef
parent 520076 fa59aea64e120e5be00269d062c2f04569278320
child 520079 fd67a4332060ea5389d448b3453ea23064e50b5e
child 520080 f362c19c19633e5c4d9dad794b85a9ad6905b9c5
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1531246
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1531246: Support keyboard activation (space/enter) of the Downloads toolbar button when focused. r=Gijs Depends on D21614 Differential Revision: https://phabricator.services.mozilla.com/D21615
browser/base/content/browser.xul
browser/base/content/test/keyboard/browser_toolbarButtonKeyPress.js
browser/components/downloads/content/indicator.js
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -1056,16 +1056,17 @@ xmlns="http://www.w3.org/1999/xhtml"
 
         <!-- This is a placeholder for the Downloads Indicator.  It is visible
              during the customization of the toolbar, in the palette, and before
              the Downloads Indicator overlay is loaded. -->
         <toolbarbutton id="downloads-button"
                        class="toolbarbutton-1 chromeclass-toolbar-additional badged-button"
                        key="key_openDownloads"
                        onmousedown="DownloadsIndicatorView.onCommand(event);"
+                       onkeypress="DownloadsIndicatorView.onCommand(event);"
                        ondrop="DownloadsIndicatorView.onDrop(event);"
                        ondragover="DownloadsIndicatorView.onDragOver(event);"
                        ondragenter="DownloadsIndicatorView.onDragOver(event);"
                        label="&downloads.label;"
                        removable="true"
                        overflows="false"
                        cui-areatype="toolbar"
                        hidden="true"
--- a/browser/base/content/test/keyboard/browser_toolbarButtonKeyPress.js
+++ b/browser/base/content/test/keyboard/browser_toolbarButtonKeyPress.js
@@ -261,8 +261,25 @@ add_task(async function testOverflowButt
   await focused;
   ok(true, "Focus inside overflow menu after toolbar button pressed");
   let panel = document.getElementById("widget-overflow");
   let hidden = BrowserTestUtils.waitForEvent(panel, "popuphidden");
   panel.hidePopup();
   await hidden;
   CustomizableUI.reset();
 });
+
+// Test activation of the Downloads button from the keyboard.
+// The Downloads panel should appear and focus should move inside it.
+add_task(async function testDownloadsButtonPress() {
+  DownloadsButton.unhide();
+  let button = document.getElementById("downloads-button");
+  forceFocus(button);
+  let panel = document.getElementById("downloadsPanel");
+  let focused = BrowserTestUtils.waitForEvent(panel, "focus", true);
+  EventUtils.synthesizeKey(" ");
+  await focused;
+  ok(true, "Focus inside Downloads panel after toolbar button pressed");
+  let hidden = BrowserTestUtils.waitForEvent(panel, "popuphidden");
+  panel.hidePopup();
+  await hidden;
+  DownloadsButton.hide();
+});
--- a/browser/components/downloads/content/indicator.js
+++ b/browser/components/downloads/content/indicator.js
@@ -536,17 +536,19 @@ const DownloadsIndicatorView = {
   // User interface event functions
 
   onWindowUnload() {
     // This function is registered as an event listener, we can't use "this".
     DownloadsIndicatorView.ensureTerminated();
   },
 
   onCommand(aEvent) {
-    if (aEvent.type == "mousedown" && aEvent.button != 0) {
+    if ((aEvent.type == "mousedown" && aEvent.button != 0) ||
+        (aEvent.type == "keypress" &&
+         aEvent.key != " " && aEvent.key != "Enter")) {
       return;
     }
 
     DownloadsPanel.showPanel();
     aEvent.stopPropagation();
   },
 
   onDragOver(aEvent) {