Bug 1398992 = Make 'Recently Bookmarked' in Photon panels support browser.bookmarks.openInTabClosesMenu pref. r?jaws draft
authorTawny Hoover <stayopenmenu@gmail.com>
Fri, 24 Nov 2017 21:54:54 -0500
changeset 703376 5b091a1d22835b0aaeeb247037318d99917a498b
parent 700200 3a0aac55195fd50ca4b1b41be450bfbaaafc191c
child 741749 b810f6b5890faffe02dcce78de5b2596537577f5
push id90795
push userbmo:stayopenmenu@gmail.com
push dateSat, 25 Nov 2017 02:58:31 +0000
reviewersjaws
bugs1398992
milestone59.0a1
Bug 1398992 = Make 'Recently Bookmarked' in Photon panels support browser.bookmarks.openInTabClosesMenu pref. r?jaws MozReview-Commit-ID: 3Rio9EjwilT
browser/components/customizableui/test/browser_947914_button_history.js
browser/components/places/content/browserPlacesViews.js
browser/components/places/tests/browser/browser_stayopenmenu.js
--- a/browser/components/customizableui/test/browser_947914_button_history.js
+++ b/browser/components/customizableui/test/browser_947914_button_history.js
@@ -31,16 +31,16 @@ add_task(async function() {
   ok(historyPanel.getAttribute("current"), "History Panel is in view");
 
   let browserLoaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
   let panelHiddenPromise = promiseOverflowHidden(window);
 
   let historyItems = document.getElementById("appMenu_historyMenu");
   let historyItemForURL = historyItems.querySelector("toolbarbutton.bookmark-item[label='Happy History Hero']");
   ok(historyItemForURL, "Should have a history item for the history we just made.");
-  historyItemForURL.click();
+  EventUtils.synthesizeMouseAtCenter(historyItemForURL, {});
   await browserLoaded;
   is(gBrowser.currentURI.spec, TEST_PATH + "dummy_history_item.html", "Should have expected page load");
 
   await panelHiddenPromise;
   await BrowserTestUtils.removeTab(tab);
   info("Menu panel was closed");
 });
--- a/browser/components/places/content/browserPlacesViews.js
+++ b/browser/components/places/content/browserPlacesViews.js
@@ -2119,18 +2119,18 @@ this.PlacesPanelview = class extends Pla
 
   get panelMultiView() {
     return this._viewElt.panelMultiView;
   }
 
   handleEvent(event) {
     switch (event.type) {
       case "click":
-        // For left and middle clicks, fall through to the command handler.
-        if (event.button >= 2) {
+        // For middle clicks, fall through to the command handler.
+        if (event.button != 1) {
           break;
         }
       case "command":
         this._onCommand(event);
         break;
       case "dragend":
         this._onDragEnd(event);
         break;
@@ -2149,18 +2149,32 @@ this.PlacesPanelview = class extends Pla
     }
   }
 
   _onCommand(event) {
     let button = event.originalTarget;
     if (!button._placesNode)
       return;
 
+    let modifKey = AppConstants.platform === "macosx" ? event.metaKey
+                                                      : event.ctrlKey;
+    if (!PlacesUIUtils.openInTabClosesMenu && modifKey) {
+      // If 'Recent Bookmarks' in Bookmarks Panel.
+      if (button.parentNode.id == "panelMenu_bookmarksMenu") {
+        button.setAttribute("closemenu", "none");
+      }
+    } else {
+      button.removeAttribute("closemenu");
+    }
     PlacesUIUtils.openNodeWithEvent(button._placesNode, event);
-    this.panelMultiView.closest("panel").hidePopup();
+    // Unlike left-click, middle-click requires manual menu closing.
+    if (button.parentNode.id != "panelMenu_bookmarksMenu" ||
+        (event.type == "click" && event.button == 1 && PlacesUIUtils.openInTabClosesMenu)) {
+      this.panelMultiView.closest("panel").hidePopup();
+    }
   }
 
   _onDragEnd() {
     this._draggedElt = null;
   }
 
   _onDragStart(event) {
     let draggedElt = event.originalTarget;
--- a/browser/components/places/tests/browser/browser_stayopenmenu.js
+++ b/browser/components/places/tests/browser/browser_stayopenmenu.js
@@ -1,29 +1,23 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Menus should stay open (if pref is set) after ctrl-click, middle-click,
 // and contextmenu's "Open in a new tab" click.
 
 async function locateBookmarkAndTestCtrlClick(menupopup) {
-  let menuitem = null;
-  for (let node of menupopup.childNodes) {
-    if (node.label == "Test1") {
-      menuitem = node;
-      let promiseTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, null);
-      EventUtils.synthesizeMouseAtCenter(menuitem,
-        AppConstants.platform === "macosx" ? {metaKey: true} : {ctrlKey: true});
-      let newTab = await promiseTabOpened;
-      ok(true, "Bookmark ctrl-click opened new tab.");
-      await BrowserTestUtils.removeTab(newTab);
-      break;
-    }
-  }
-  return menuitem;
+  let testMenuitem = [...menupopup.childNodes].find(node => node.label == "Test1");
+  ok(testMenuitem, "Found test bookmark.");
+  let promiseTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, null);
+  EventUtils.synthesizeMouseAtCenter(testMenuitem, {accelKey: true});
+  let newTab = await promiseTabOpened;
+  ok(true, "Bookmark ctrl-click opened new tab.");
+  await BrowserTestUtils.removeTab(newTab);
+  return testMenuitem;
 }
 
 async function testContextmenu(menuitem) {
   let doc = menuitem.ownerDocument;
   let cm = doc.getElementById("placesContext");
   let promiseEvent = BrowserTestUtils.waitForEvent(cm, "popupshown");
   EventUtils.synthesizeMouseAtCenter(menuitem, {type: "contextmenu", button: 2});
   await promiseEvent;
@@ -117,16 +111,53 @@ add_task(async function testStayopenBook
   ok(true, "Bookmark contextmenu opened new tab.");
   ok(BMB.open, "Bookmarks Menu Button's Popup should still be open.");
   promiseEvent = BrowserTestUtils.waitForEvent(BMBpopup, "popuphidden");
   BMB.open = false;
   await promiseEvent;
   info("Closing menu");
   await BrowserTestUtils.removeTab(newTab);
 
+  // Test App Menu's Bookmarks Library stayopen clicks.
+  let appMenu = document.getElementById("PanelUI-menu-button");
+  let appMenuPopup = document.getElementById("appMenu-popup");
+  let PopupShownPromise = BrowserTestUtils.waitForEvent(appMenuPopup, "popupshown");
+  appMenu.click();
+  await PopupShownPromise;
+  let libView = document.getElementById("appMenu-libraryView");
+  let libraryBtn = document.getElementById("appMenu-library-button");
+  let ViewShownPromise = BrowserTestUtils.waitForEvent(libView, "ViewShown");
+  libraryBtn.click();
+  await ViewShownPromise;
+  info("Library panel shown.");
+  let bookmarks = document.getElementById("appMenu-library-bookmarks-button");
+  let BMview = document.getElementById("PanelUI-bookmarks");
+  ViewShownPromise = BrowserTestUtils.waitForEvent(BMview, "ViewShown");
+  bookmarks.click();
+  await ViewShownPromise;
+  info("Library's bookmarks panel shown.");
+
+  // Test App Menu's Bookmarks Library stayopen clicks: Ctrl-click.
+  let menu = document.getElementById("panelMenu_bookmarksMenu");
+  var testMenuitem = await locateBookmarkAndTestCtrlClick(menu);
+  ok(appMenu.open, "Menu should remain open.");
+
+  // Test App Menu's Bookmarks Library stayopen clicks: middle-click.
+  promiseTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, null);
+  EventUtils.synthesizeMouseAtCenter(testMenuitem, {button: 1});
+  newTab = await promiseTabOpened;
+  ok(true, "Bookmark middle-click opened new tab.");
+  await BrowserTestUtils.removeTab(newTab);
+  is(PanelUI.multiView.current.id, "PanelUI-bookmarks", "Should still show the bookmarks subview");
+  ok(appMenu.open, "Menu should remain open.");
+
+  // Close the App Menu
+  appMenuPopup.hidePopup();
+  ok(!appMenu.open, "The menu should now be closed.");
+
   // Disable the rest of the tests on Mac due to Mac's handling of menus being
   // slightly different to the other platforms.
   if (AppConstants.platform === "macosx") {
     return;
   }
 
   // Test Bookmarks Menu (menubar) stayopen clicks: Ctrl-click.
   let BM = document.getElementById("bookmarksMenu");