Bug 1571389: For page actions which show an iframe, focus the iframe when the action is activated. r=jaws

This includes the Save to Pocket action.
Previously, keyboard users had to press f6 twice to focus the iframe.
Worse, screen reader users weren't aware anything popped up at all.

Differential Revision: https://phabricator.services.mozilla.com/D40913

--HG--
extra : moz-landing-system : lando
This commit is contained in:
James Teh 2019-08-07 21:03:42 +00:00
parent 9775cca0a1
commit ee21b9ffb2
2 changed files with 36 additions and 0 deletions

View file

@ -362,6 +362,13 @@ var BrowserPageActions = {
},
{ once: true }
);
panelNode.addEventListener(
"popupshown",
() => {
iframeNode.focus();
},
{ once: true }
);
panelNode.addEventListener(
"popuphiding",
() => {

View file

@ -302,3 +302,32 @@ add_task(async function testDownloadsButtonPress() {
await hidden;
DownloadsButton.hide();
});
// Test activation of the Save to Pocket button from the keyboard.
// This is a page action button which shows an iframe (wantsIframe: true).
// The Pocket iframe should appear and focus should move inside it.
add_task(async function testPocketButtonPress() {
await BrowserTestUtils.withNewTab("https://example.com", async function(
aBrowser
) {
let button = document.getElementById("pocket-button");
forceFocus(button);
// The panel is created on the fly, so we can't simply wait for focus
// inside it.
let showing = BrowserTestUtils.waitForEvent(document, "popupshowing", true);
EventUtils.synthesizeKey(" ");
let event = await showing;
let panel = event.target;
is(panel.id, "pageActionActivatedActionPanel");
let focused = BrowserTestUtils.waitForEvent(panel, "focus", true);
await focused;
is(
document.activeElement.tagName,
"iframe",
"Focus inside Pocket iframe after Bookmark button pressed"
);
let hidden = BrowserTestUtils.waitForEvent(panel, "popuphidden");
EventUtils.synthesizeKey("KEY_Escape");
await hidden;
});
});