Bug 1330745 - Add 'No Container' when longPressBehaviour is 1 for containers new tab context menu. r=baku,Gijs
authorJonathan Kingston <jkt@mozilla.com>
Mon, 25 Sep 2017 14:34:13 +0100
changeset 383258 193675c58378d942f7618a769d116b2c9e9b0946
parent 383257 96609bba12f3afbd78db214448491b55a4c2fed7
child 383259 2a235c8a50c0349c34dfe7b14ece19fed6252db0
push id52170
push userryanvm@gmail.com
push dateWed, 27 Sep 2017 16:18:03 +0000
treeherderautoland@193675c58378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, Gijs
bugs1330745
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1330745 - Add 'No Container' when longPressBehaviour is 1 for containers new tab context menu. r=baku,Gijs MozReview-Commit-ID: I2ptF9Dh7yL
browser/base/content/tabbrowser.xml
browser/base/content/utilityOverlay.js
browser/components/contextualidentity/test/browser/browser_newtabButton.js
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -8187,17 +8187,20 @@
           createUserContextMenu(event, {useAccessKeys: false});
           return;
         }
 
         let containersEnabled = Services.prefs.getBoolPref("privacy.userContext.enabled");
 
         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");
 
           containersTab.hidden = !containersEnabled;
           if (PrivateBrowsingUtils.isWindowPrivate(window)) {
             containersTab.setAttribute("disabled", "true");
           }
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -521,27 +521,28 @@ function checkForMiddleClick(node, event
   }
 }
 
 // Populate a menu with user-context menu items. This method should be called
 // by onpopupshowing passing the event as first argument.
 function createUserContextMenu(event, {
                                         isContextMenu = false,
                                         excludeUserContextId = 0,
+                                        showDefaultTab = false,
                                         useAccessKeys = true
                                       } = {}) {
   while (event.target.hasChildNodes()) {
     event.target.firstChild.remove();
   }
 
   let bundle = document.getElementById("bundle_browser");
   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"));
     menuitem.setAttribute("accesskey", bundle.getString("userContextNone.accesskey"));
 
     // We don't set an oncommand/command attribute because if we have
     // to exclude a userContextId we are generating the contextMenu and
     // isContextMenu will be true.
--- a/browser/components/contextualidentity/test/browser/browser_newtabButton.js
+++ b/browser/components/contextualidentity/test/browser/browser_newtabButton.js
@@ -43,31 +43,46 @@ add_task(async function test_menu_withou
 
   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");
   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;
     let contextIdItem = popup.querySelector(`menuitem[data-usercontextid="${i}"]`);
 
     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);
   }
 });
 
 add_task(async function test_no_menu() {
   await SpecialPowers.pushPrefEnv({"set": [
       ["privacy.userContext.enabled", true],
       ["privacy.userContext.longPressBehavior", 0]