Bug 1330745 - Add 'No Container' when longPressBehaviour is 1 for containers new tab context menu. r=baku,Gijs

MozReview-Commit-ID: I2ptF9Dh7yL

--HG--
extra : rebase_source : ff586de60c0a172d766259c10fe136242b75d647
This commit is contained in:
Jonathan Kingston 2017-09-25 14:34:13 +01:00
Родитель 23296a78c9
Коммит 9f55478dda
3 изменённых файлов: 27 добавлений и 8 удалений

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

@ -8192,7 +8192,10 @@
if (event.target.getAttribute("anonid") == "newtab-popup" ||
event.target.id == "newtab-popup") {
createUserContextMenu(event, {useAccessKeys: false});
createUserContextMenu(event, {
useAccessKeys: false,
showDefaultTab: Services.prefs.getIntPref("privacy.userContext.longPressBehavior") == 1
});
} else {
document.getElementById("alltabs-popup-separator-1").hidden = !containersEnabled;
let containersTab = document.getElementById("alltabs_containersTab");

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

@ -526,6 +526,7 @@ function checkForMiddleClick(node, event) {
function createUserContextMenu(event, {
isContextMenu = false,
excludeUserContextId = 0,
showDefaultTab = false,
useAccessKeys = true
} = {}) {
while (event.target.hasChildNodes()) {
@ -536,7 +537,7 @@ function createUserContextMenu(event, {
let docfrag = document.createDocumentFragment();
// If we are excluding a userContextId, we want to add a 'no-container' item.
if (excludeUserContextId) {
if (excludeUserContextId || showDefaultTab) {
let menuitem = document.createElement("menuitem");
menuitem.setAttribute("data-usercontextid", "0");
menuitem.setAttribute("label", bundle.getString("userContextNone.label"));

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

@ -48,8 +48,18 @@ add_task(async function test_menu_without_timeout() {
await 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");
let popupShownPromise = BrowserTestUtils.waitForEvent(popup, "popupshown");
let popupHiddenPromise = BrowserTestUtils.waitForEvent(popup, "popuphidden");
EventUtils.synthesizeMouseAtCenter(newTabButton, {type: "mousedown"});
await popupShownPromise;
let contextIdItems = popup.querySelectorAll("menuitem");
// 4 + default + manage containers
is(contextIdItems.length, 6, "Has 6 menu items");
popup.hidePopup();
await popupHiddenPromise;
for (let i = 0; i <= 4; i++) {
popupShownPromise = BrowserTestUtils.waitForEvent(popup, "popupshown");
EventUtils.synthesizeMouseAtCenter(newTabButton, {type: "mousedown"});
await popupShownPromise;
@ -57,12 +67,17 @@ add_task(async function test_menu_without_timeout() {
ok(contextIdItem, `User context id ${i} exists`);
let waitForTabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
// waitForNewTab doesn't work for default tabs due to a different code path that doesn't cause a load event
let waitForTabPromise = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabOpen");
EventUtils.synthesizeMouseAtCenter(contextIdItem, {});
let tab = await waitForTabPromise;
is(tab.getAttribute("usercontextid"), i, `New tab has UCI equal ${i}`);
let tabEvent = await waitForTabPromise;
let tab = tabEvent.target;
if (i > 0) {
is(tab.getAttribute("usercontextid"), i, `New tab has UCI equal ${i}`);
} else {
ok(!tab.hasAttribute("usercontextid"), `New tab has no UCI`);
}
await BrowserTestUtils.removeTab(tab);
}
});