Bug 1642878 - update context menu items disabled states after _maybeSelectAll in contextmenu open. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D91151
This commit is contained in:
tanner drake 2020-09-30 14:22:42 +00:00
Родитель 47a5f60a37
Коммит 60df9c6452
2 изменённых файлов: 100 добавлений и 4 удалений

Просмотреть файл

@ -600,6 +600,12 @@
BrowserSearch.searchBar._textbox.closePopup();
// Make sure the context menu isn't opened via keyboard shortcut. Check for text selection
// before updating the state of any menu items.
if (event.button) {
this._maybeSelectAll();
}
// Update disabled state of menu items
for (let item of this._menupopup.querySelectorAll("menuitem[cmd]")) {
let command = item.getAttribute("cmd");
@ -616,10 +622,6 @@
this._menupopup.openPopupAtScreen(event.screenX, event.screenY, true);
// Make sure the context menu isn't opened via keyboard shortcut.
if (event.button) {
this._maybeSelectAll();
}
event.preventDefault();
});
}

Просмотреть файл

@ -58,6 +58,10 @@ add_task(async function test_emptybar() {
contextMenu.getElementsByAttribute("cmd", "cmd_copy")[0].disabled,
"Should have disabled the copy menuitem"
);
Assert.ok(
contextMenu.getElementsByAttribute("cmd", "cmd_delete")[0].disabled,
"Should have disabled the delete menuitem"
);
let popupHiddenPromise = BrowserTestUtils.waitForEvent(
contextMenu,
@ -95,6 +99,96 @@ add_task(async function test_text_in_bar() {
!contextMenu.getElementsByAttribute("cmd", "cmd_copy")[0].disabled,
"Should have enabled the copy menuitem"
);
Assert.ok(
!contextMenu.getElementsByAttribute("cmd", "cmd_delete")[0].disabled,
"Should have enabled the delete menuitem"
);
let popupHiddenPromise = BrowserTestUtils.waitForEvent(
contextMenu,
"popuphidden"
);
contextMenu.hidePopup();
await popupHiddenPromise;
});
add_task(async function test_unfocused_emptybar() {
const searchbar = win.BrowserSearch.searchBar;
// clear searchbar value from previous test
searchbar.value = "";
// force focus onto another component
win.gURLBar.focus();
let contextMenu = searchbar.querySelector(".textbox-contextmenu");
let contextMenuPromise = BrowserTestUtils.waitForEvent(
contextMenu,
"popupshown"
);
searchbar.focus();
await EventUtils.synthesizeMouseAtCenter(
searchbar,
{ type: "contextmenu", button: 2 },
win
);
await contextMenuPromise;
Assert.ok(
contextMenu.getElementsByAttribute("cmd", "cmd_cut")[0].disabled,
"Should have disabled the cut menuitem"
);
Assert.ok(
contextMenu.getElementsByAttribute("cmd", "cmd_copy")[0].disabled,
"Should have disabled the copy menuitem"
);
Assert.ok(
contextMenu.getElementsByAttribute("cmd", "cmd_delete")[0].disabled,
"Should have disabled the delete menuitem"
);
let popupHiddenPromise = BrowserTestUtils.waitForEvent(
contextMenu,
"popuphidden"
);
contextMenu.hidePopup();
await popupHiddenPromise;
});
add_task(async function test_text_in_unfocused_bar() {
const searchbar = win.BrowserSearch.searchBar;
searchbar.value = "Test";
// force focus onto another component
win.gURLBar.focus();
let contextMenu = searchbar.querySelector(".textbox-contextmenu");
let contextMenuPromise = BrowserTestUtils.waitForEvent(
contextMenu,
"popupshown"
);
searchbar.focus();
await EventUtils.synthesizeMouseAtCenter(
searchbar,
{ type: "contextmenu", button: 2 },
win
);
await contextMenuPromise;
Assert.ok(
!contextMenu.getElementsByAttribute("cmd", "cmd_cut")[0].disabled,
"Should have enabled the cut menuitem"
);
Assert.ok(
!contextMenu.getElementsByAttribute("cmd", "cmd_copy")[0].disabled,
"Should have enabled the copy menuitem"
);
Assert.ok(
!contextMenu.getElementsByAttribute("cmd", "cmd_delete")[0].disabled,
"Should have enabled the delete menuitem"
);
let popupHiddenPromise = BrowserTestUtils.waitForEvent(
contextMenu,