diff --git a/browser/base/content/tabbrowser.js b/browser/base/content/tabbrowser.js index ce869df35d1b..2c9ce9f91d79 100644 --- a/browser/base/content/tabbrowser.js +++ b/browser/base/content/tabbrowser.js @@ -5268,6 +5268,10 @@ var TabContextMenu = { let contextUnpinSelectedTabs = document.getElementById("context_unpinSelectedTabs"); contextUnpinSelectedTabs.hidden = !this.contextTab.pinned || !multiselectionContext; + // Hide the "Duplicate Tab" if there is a selection present + let contextDuplicateTab = document.getElementById("context_duplicateTab"); + contextDuplicateTab.hidden = multiselectionContext; + // Disable "Close Tabs to the Right" if there are no tabs // following it. document.getElementById("context_closeTabsToTheEnd").disabled = diff --git a/browser/base/content/test/tabs/browser.ini b/browser/base/content/test/tabs/browser.ini index 8f33a525b6d7..19e1bc37f333 100644 --- a/browser/base/content/test/tabs/browser.ini +++ b/browser/base/content/test/tabs/browser.ini @@ -27,6 +27,7 @@ support-files = [browser_multiselect_tabs_close_using_shortcuts.js] [browser_multiselect_tabs_close.js] [browser_multiselect_tabs_copy_through_drag_and_drop.js] +[browser_multiselect_tabs_duplicate.js] [browser_multiselect_tabs_event.js] [browser_multiselect_tabs_move_to_another_window_drag.js] [browser_multiselect_tabs_move_to_new_window_contextmenu.js] diff --git a/browser/base/content/test/tabs/browser_multiselect_tabs_duplicate.js b/browser/base/content/test/tabs/browser_multiselect_tabs_duplicate.js new file mode 100644 index 000000000000..7e46152a6e2c --- /dev/null +++ b/browser/base/content/test/tabs/browser_multiselect_tabs_duplicate.js @@ -0,0 +1,48 @@ +const PREF_MULTISELECT_TABS = "browser.tabs.multiselect"; + +add_task(async function setPref() { + await SpecialPowers.pushPrefEnv({ + set: [[PREF_MULTISELECT_TABS, true]] + }); +}); + +add_task(async function test() { + let tab1 = await addTab(); + let tab2 = await addTab(); + let tab3 = await addTab(); + + let menuItemDuplicateTab = document.getElementById("context_duplicateTab"); + + is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs"); + + await BrowserTestUtils.switchTab(gBrowser, tab1); + await triggerClickOn(tab2, { ctrlKey: true }); + + ok(tab1.multiselected, "Tab1 is multiselected"); + ok(tab2.multiselected, "Tab2 is multiselected"); + ok(!tab3.multiselected, "Tab3 is not multiselected"); + + // Check the context menu with a multiselected tabs + updateTabContextMenu(tab2); + is(menuItemDuplicateTab.hidden, true, "Duplicate Tab is hidden"); + + // Check the context menu with a non-multiselected tab + updateTabContextMenu(tab3); + is(menuItemDuplicateTab.hidden, false, "Duplicate Tab is visible"); + + let newTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, "http://mochi.test:8888/"); + window.TabContextMenu.contextTab = tab3; // Set proper context for command handler + menuItemDuplicateTab.click(); + let tab4 = await newTabOpened; + + // Selection should be cleared after duplication + ok(!tab1.multiselected, "Tab1 is not multiselected"); + ok(!tab2.multiselected, "Tab2 is not multiselected"); + ok(!tab4.multiselected, "Tab3 is not multiselected"); + ok(!tab3.multiselected, "Tab4 is not multiselected"); + + BrowserTestUtils.removeTab(tab1); + BrowserTestUtils.removeTab(tab2); + BrowserTestUtils.removeTab(tab3); + BrowserTestUtils.removeTab(tab4); +});