diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 72061f7c27e3..32c12421f828 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -1425,10 +1425,16 @@ pref("privacy.trackingprotection.introURL", "https://www.mozilla.org/%LOCALE%/fi pref("privacy.userContext.enabled", true); pref("privacy.userContext.ui.enabled", true); pref("privacy.usercontext.about_newtab_segregation.enabled", true); + +// 0 disables long press, 1 when clicked, the menu is shown, 2 the menu is shown after X milliseconds. +pref("privacy.usercontext.longPressBehavior", 2); #else pref("privacy.userContext.enabled", false); pref("privacy.userContext.ui.enabled", false); pref("privacy.usercontext.about_newtab_segregation.enabled", false); + +// 0 disables long press, 1 when clicked, the menu is shown, 2 the menu is shown after X milliseconds. +pref("privacy.usercontext.longPressBehavior", 0); #endif #ifndef RELEASE_OR_BETA diff --git a/browser/base/content/tabbrowser.xml b/browser/base/content/tabbrowser.xml index f89011f68663..91d4882214fb 100644 --- a/browser/base/content/tabbrowser.xml +++ b/browser/base/content/tabbrowser.xml @@ -5469,14 +5469,16 @@ this._tabAnimationLoggingEnabled = false; } this._browserNewtabpageEnabled = Services.prefs.getBoolPref("browser.newtabpage.enabled"); + Services.prefs.addObserver("privacy.usercontext", this, false); this.observe(null, "nsPref:changed", "privacy.userContext.enabled"); - Services.prefs.addObserver("privacy.userContext.enabled", this, false); + this.observe(null, "nsPref:changed", "privacy.usercontext.longPressBehavior"); ]]> @@ -5512,17 +5514,35 @@ 2)) { + containersEnabled = false; + } + const newTab = document.getElementById("new-tab-button"); const newTab2 = document.getAnonymousElementByAttribute(this, "anonid", "tabs-newtab-button") - if (containersEnabled) { - for (let parent of [newTab, newTab2]) { - if (!parent) - continue; + for (let parent of [newTab, newTab2]) { + if (!parent) + continue; + + gClickAndHoldListenersOnElement.remove(parent); + parent.removeAttribute("type"); + if (parent.firstChild) { + parent.firstChild.remove(); + } + + if (containersEnabled) { let popup = document.createElementNS( "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "menupopup"); @@ -5535,19 +5555,14 @@ popup.setAttribute("position", "after_end"); parent.appendChild(popup); - gClickAndHoldListenersOnElement.add(parent); + // longPressBehavior == 2 means that the menu is shown after X + // millisecs. Otherwise, with 1, the menu is open immediatelly. + if (longPressBehavior == 2) { + gClickAndHoldListenersOnElement.add(parent); + } + parent.setAttribute("type", "menu"); } - } else { - for (let parent of [newTab, newTab2]) { - if (!parent) - continue; - gClickAndHoldListenersOnElement.remove(parent); - parent.removeAttribute("type"); - if (!parent.firstChild) - continue; - parent.firstChild.remove(); - } } break; diff --git a/browser/components/contextualidentity/test/browser/browser_newtabButton.js b/browser/components/contextualidentity/test/browser/browser_newtabButton.js index 3fc015fa0ff4..e60161b74672 100644 --- a/browser/components/contextualidentity/test/browser/browser_newtabButton.js +++ b/browser/components/contextualidentity/test/browser/browser_newtabButton.js @@ -3,9 +3,10 @@ // Testing that when the user opens the add tab menu and clicks menu items // the correct context id is opened -add_task(function* test() { +add_task(function* test_menu_with_timeout() { yield SpecialPowers.pushPrefEnv({"set": [ - ["privacy.userContext.enabled", true] + ["privacy.userContext.enabled", true], + ["privacy.usercontext.longPressBehavior", 2] ]}); let newTab = document.getElementById('tabbrowser-tabs'); @@ -34,6 +35,51 @@ add_task(function* test() { } }); +add_task(function* test_menu_without_timeout() { + yield SpecialPowers.pushPrefEnv({"set": [ + ["privacy.userContext.enabled", true], + ["privacy.usercontext.longPressBehavior", 1] + ]}); + + let newTab = document.getElementById('tabbrowser-tabs'); + let newTabButton = document.getAnonymousElementByAttribute(newTab, "anonid", "tabs-newtab-button"); + ok(newTabButton, "New tab button exists"); + ok(!newTabButton.hidden, "New tab button is visible"); + yield BrowserTestUtils.waitForCondition(() => !!document.getAnonymousElementByAttribute(newTab, "anonid", "newtab-popup"), "Wait for popup to exist"); + let popup = document.getAnonymousElementByAttribute(newTab, "anonid", "newtab-popup"); + + for (let i = 1; i <= 4; i++) { + let popupShownPromise = BrowserTestUtils.waitForEvent(popup, "popupshown"); + EventUtils.synthesizeMouseAtCenter(newTabButton, {type: "mousedown"}); + + yield popupShownPromise; + let contextIdItem = popup.querySelector(`menuitem[data-usercontextid="${i}"]`); + + ok(contextIdItem, `User context id ${i} exists`); + + let waitForTabPromise = BrowserTestUtils.waitForNewTab(gBrowser); + EventUtils.synthesizeMouseAtCenter(contextIdItem, {}); + + let tab = yield waitForTabPromise; + + is(tab.getAttribute('usercontextid'), i, `New tab has UCI equal ${i}`); + yield BrowserTestUtils.removeTab(tab); + } +}); + +add_task(function* test_no_menu() { + yield SpecialPowers.pushPrefEnv({"set": [ + ["privacy.userContext.enabled", true], + ["privacy.usercontext.longPressBehavior", 0] + ]}); + + let newTab = document.getElementById('tabbrowser-tabs'); + let newTabButton = document.getAnonymousElementByAttribute(newTab, "anonid", "tabs-newtab-button"); + ok(newTabButton, "New tab button exists"); + ok(!newTabButton.hidden, "New tab button is visible"); + let popup = document.getAnonymousElementByAttribute(newTab, "anonid", "newtab-popup"); + ok(!popup, "new tab should not have a popup"); +}); add_task(function* test_private_mode() { let privateWindow = yield BrowserTestUtils.openNewBrowserWindow({private: true});