fune/browser/base/content/test/tabs/browser_tabContextMenu_keyboard.js
James Teh eeb98454b6 Bug 1200038: Don't use the system group for XUL tabbox keydown handlers. r=dao
Bug 1008772 moved all key handlers related to browser tabs to the system group to prevent websites from stealing tab switching keys.
However, this is only necessary for global tab switching keys; e.g. Control+Tab, Control+PageUp.
It is not necessary for keys which only operate when the tab bar is focused; e.g. Up/DownArrow.
This is because when the browser chrome is focused (including the tab bar), content key handlers can't intercept key presses.
Furthermore, having these in the system group gives them precedence over XUL context menus.
This causes tab switches to occur when the arrow keys are pressed while the context menu is open, which is highly undesirable.
Moving these (non-global) keydown handlers into the normal group fixes this.

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

--HG--
extra : moz-landing-system : lando
2018-09-04 09:34:23 +00:00

53 lines
2.2 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
async function openContextMenu() {
let contextMenu = document.getElementById("tabContextMenu");
let popupShown = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
EventUtils.synthesizeMouseAtCenter(gBrowser.selectedTab, {type: "contextmenu", button: 2});
await popupShown;
}
async function closeContextMenu() {
let contextMenu = document.getElementById("tabContextMenu");
let popupHidden = BrowserTestUtils.waitForEvent(contextMenu, "popuphidden");
EventUtils.synthesizeKey("KEY_Escape");
await popupHidden;
}
add_task(async function test() {
// Ensure tabs are focusable.
await SpecialPowers.pushPrefEnv({"set": [["accessibility.tabfocus", 7]]});
// There should be one tab when we start the test.
let tab1 = gBrowser.selectedTab;
let tab2 = BrowserTestUtils.addTab(gBrowser);
tab1.focus();
is(document.activeElement, tab1, "tab1 should be focused");
// Ensure that DownArrow doesn't switch to tab2 while the context menu is open.
await openContextMenu();
EventUtils.synthesizeKey("KEY_ArrowDown");
await closeContextMenu();
is(gBrowser.selectedTab, tab1, "tab1 should still be active");
if (AppConstants.platform == "macosx") {
// On Mac, focus doesn't return to the tab after dismissing the context menu.
// Since we're not testing that here, work around it by just focusing again.
tab1.focus();
}
is(document.activeElement, tab1, "tab1 should be focused");
// Switch to tab2 by pressing DownArrow.
await BrowserTestUtils.switchTab(gBrowser,
() => EventUtils.synthesizeKey("KEY_ArrowDown"));
is(gBrowser.selectedTab, tab2, "should have switched to tab2");
is(document.activeElement, tab2, "tab2 should now be focused");
// Ensure that UpArrow doesn't switch to tab1 while the context menu is open.
await openContextMenu();
EventUtils.synthesizeKey("KEY_ArrowUp");
await closeContextMenu();
is(gBrowser.selectedTab, tab2, "tab2 should still be active");
gBrowser.removeTab(tab2);
});