Backed out 3 changesets (bug 1515810, bug 1419195) for failing at /browser/browser_ext_contextMenus.js on a CLOSED TREE
authorGurzau Raul <rgurzau@mozilla.com>
Tue, 15 Jan 2019 17:07:06 +0200
changeset 511037 65b6d0b670b410489153b2086d8dc1a1b66a3231
parent 511036 6f5998401e959eaf8c60862cf1349a2e3d6a0c40
child 511038 0c8548aec7059aa1f19da3a3d2ad02ef43f88622
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1515810, 1419195
milestone66.0a1
backs out437003de9fffafd6656b79ea4bcbeab0aa652eef
c04c2376a2133c875df0e71749572688abe562a0
d9a81de35ac3bee7f1e69d59d90a6ad7ee82c5c9
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
Backed out 3 changesets (bug 1515810, bug 1419195) for failing at /browser/browser_ext_contextMenus.js on a CLOSED TREE Backed out changeset 437003de9fff (bug 1515810) Backed out changeset c04c2376a213 (bug 1419195) Backed out changeset d9a81de35ac3 (bug 1419195)
browser/components/extensions/parent/ext-menus.js
browser/components/extensions/test/browser/browser-common.ini
browser/components/extensions/test/browser/browser_ext_contextMenus.js
browser/components/extensions/test/browser/browser_ext_menus.js
browser/components/extensions/test/browser/head.js
--- a/browser/components/extensions/parent/ext-menus.js
+++ b/browser/components/extensions/parent/ext-menus.js
@@ -1,17 +1,14 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-ChromeUtils.defineModuleGetter(this, "Bookmarks",
-                               "resource://gre/modules/Bookmarks.jsm");
-
 var {
   DefaultMap,
   ExtensionError,
 } = ExtensionUtils;
 
 ChromeUtils.import("resource://gre/modules/ExtensionParent.jsm");
 
 var {
@@ -861,163 +858,54 @@ MenuItem.prototype = {
         return false;
       }
     }
 
     return true;
   },
 };
 
-// windowTracker only looks as browser windows, but we're also interested in
-// the Library window.  Helper for menuTracker below.
-const libraryTracker = {
-  libraryWindowType: "Places:Organizer",
-
-  isLibraryWindow(window) {
-    let winType = window.document.documentElement.getAttribute("windowtype");
-    return winType === this.libraryWindowType;
-  },
-
-  init(listener) {
-    this._listener = listener;
-    Services.ww.registerNotification(this);
-
-    // See WindowTrackerBase#*browserWindows in ext-tabs-base.js for why we
-    // can't use the enumerator's windowtype filter.
-    for (let window of Services.wm.getEnumerator("")) {
-      if (window.document.readyState === "complete") {
-        if (this.isLibraryWindow(window)) {
-          this.notify(window);
-        }
-      } else {
-        window.addEventListener("load", this, {once: true});
-      }
-    }
-  },
-
-  // cleanupWindow is called on any library window that's open.
-  uninit(cleanupWindow) {
-    Services.ww.unregisterNotification(this);
-
-    for (let window of Services.wm.getEnumerator(this.libraryWindowType)) {
-      try {
-        window.removeEventListener("load", this);
-        cleanupWindow(window);
-      } catch (e) {
-        Cu.reportError(e);
-      }
-    }
-  },
-
-  // Gets notifications from Services.ww.registerNotification.
-  // Defer actually doing anything until the window's loaded, though.
-  observe(window, topic) {
-    if (topic === "domwindowopened") {
-      window.addEventListener("load", this, {once: true});
-    }
-  },
-
-  // Gets the load event for new windows(registered in observe()).
-  handleEvent(event) {
-    let window = event.target.defaultView;
-    if (this.isLibraryWindow(window)) {
-      this.notify(window);
-    }
-  },
-
-  notify(window) {
-    try {
-      this._listener.call(null, window);
-    } catch (e) {
-      Cu.reportError(e);
-    }
-  },
-};
-
 // While any extensions are active, this Tracker registers to observe/listen
 // for menu events from both Tools and context menus, both content and chrome.
 const menuTracker = {
   menuIds: ["placesContext", "menu_ToolsPopup", "tabContextMenu"],
 
   register() {
     Services.obs.addObserver(this, "on-build-contextmenu");
     for (const window of windowTracker.browserWindows()) {
       this.onWindowOpen(window);
     }
     windowTracker.addOpenListener(this.onWindowOpen);
-    libraryTracker.init(this.onLibraryOpen);
   },
 
   unregister() {
     Services.obs.removeObserver(this, "on-build-contextmenu");
     for (const window of windowTracker.browserWindows()) {
-      this.cleanupWindow(window);
+      for (const id of this.menuIds) {
+        const menu = window.document.getElementById(id);
+        menu.removeEventListener("popupshowing", this);
+      }
     }
     windowTracker.removeOpenListener(this.onWindowOpen);
-    libraryTracker.uninit(this.cleanupLibrary);
   },
 
   observe(subject, topic, data) {
     subject = subject.wrappedJSObject;
     gMenuBuilder.build(subject);
   },
 
   onWindowOpen(window) {
     for (const id of menuTracker.menuIds) {
       const menu = window.document.getElementById(id);
       menu.addEventListener("popupshowing", menuTracker);
     }
-
-    const sidebarHeader = window.document.getElementById("sidebar-switcher-target");
-    sidebarHeader.addEventListener("SidebarShown", menuTracker.onSidebarShown);
-    if (window.SidebarUI.currentID === "viewBookmarksSidebar") {
-      menuTracker.onSidebarShown({currentTarget: window.SidebarUI.browser});
-    }
-  },
-
-  cleanupWindow(window) {
-    for (const id of this.menuIds) {
-      const menu = window.document.getElementById(id);
-      menu.removeEventListener("popupshowing", this);
-    }
-
-    const sidebarHeader = window.document.getElementById("sidebar-switcher-target");
-    sidebarHeader.removeEventListener("SidebarShown", this.onSidebarShown);
-
-    if (window.SidebarUI.currentID === "viewBookmarksSidebar") {
-      const menu = window.SidebarUI.browser.contentDocument
-                         .getElementById("placesContext");
-      menu.removeEventListener("popupshowing", this.onBookmarksContextMenu);
-    }
-  },
-
-  onSidebarShown(event) {
-    // The listener is on the sidebar <browser>, so window is the regular
-    // browser window that contains the sidebar.
-    const window = event.currentTarget.ownerGlobal;
-    if (window.SidebarUI.currentID === "viewBookmarksSidebar") {
-      const menu = window.SidebarUI.browser.contentDocument
-                         .getElementById("placesContext");
-      menu.addEventListener("popupshowing", menuTracker.onBookmarksContextMenu);
-    }
-  },
-
-  onLibraryOpen(window) {
-    const menu = window.document.getElementById("placesContext");
-    menu.addEventListener("popupshowing", menuTracker.onBookmarksContextMenu);
-  },
-
-  cleanupLibrary(window) {
-    const menu = window.document.getElementById("placesContext");
-    menu.removeEventListener("popupshowing", menuTracker.onBookmarksContextMenu);
   },
 
   handleEvent(event) {
     const menu = event.target;
-
     if (menu.id === "placesContext") {
       const trigger = menu.triggerNode;
       if (!trigger._placesNode) {
         return;
       }
 
       gMenuBuilder.build({
         menu,
@@ -1032,33 +920,16 @@ const menuTracker = {
     }
     if (menu.id === "tabContextMenu") {
       const trigger = menu.triggerNode;
       const tab = trigger.localName === "tab" ? trigger : tabTracker.activeTab;
       const pageUrl = tab.linkedBrowser.currentURI.spec;
       gMenuBuilder.build({menu, tab, pageUrl, onTab: true});
     }
   },
-
-  onBookmarksContextMenu(event) {
-    const menu = event.target;
-    const tree = menu.triggerNode.parentElement;
-    const cell = tree.boxObject.getCellAt(event.x, event.y);
-    const node = tree.view.nodeForTreeIndex(cell.row);
-
-    if (!node.bookmarkGuid || Bookmarks.isVirtualRootItem(node.bookmarkGuid)) {
-      return;
-    }
-
-    gMenuBuilder.build({
-      menu,
-      bookmarkId: node.bookmarkGuid,
-      onBookmark: true,
-    });
-  },
 };
 
 this.menusInternal = class extends ExtensionAPI {
   constructor(extension) {
     super(extension);
 
     if (!gMenuMap.size) {
       menuTracker.register();
--- a/browser/components/extensions/test/browser/browser-common.ini
+++ b/browser/components/extensions/test/browser/browser-common.ini
@@ -76,17 +76,16 @@ skip-if = (os == 'mac' || os == 'win' ||
 skip-if = (verify && (os == 'linux' || os == 'mac'))
 [browser_ext_commands_execute_sidebar_action.js]
 [browser_ext_commands_getAll.js]
 [browser_ext_commands_onCommand.js]
 [browser_ext_commands_update.js]
 [browser_ext_connect_and_move_tabs.js]
 [browser_ext_contentscript_connect.js]
 [browser_ext_contextMenus.js]
-support-files = !/browser/components/places/tests/browser/head.js
 [browser_ext_contextMenus_checkboxes.js]
 [browser_ext_contextMenus_commands.js]
 [browser_ext_contextMenus_icons.js]
 [browser_ext_contextMenus_onclick.js]
 [browser_ext_contextMenus_radioGroups.js]
 [browser_ext_contextMenus_targetUrlPatterns.js]
 [browser_ext_contextMenus_uninstall.js]
 [browser_ext_contextMenus_urlPatterns.js]
--- a/browser/components/extensions/test/browser/browser_ext_contextMenus.js
+++ b/browser/components/extensions/test/browser/browser_ext_contextMenus.js
@@ -1,19 +1,12 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-Services.scriptloader.loadSubScript(
-  "chrome://mochitests/content/browser/browser/components/places/tests/browser/head.js",
-  this);
-/* globals withSidebarTree, synthesizeClickOnSelectedTreeCell,
- * promiseLibrary, promiseLibraryClosed
- */
-
 const PAGE = "http://mochi.test:8888/browser/browser/components/extensions/test/browser/context.html";
 
 add_task(async function() {
   let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE);
 
   gBrowser.selectedTab = tab1;
 
   let extension = ExtensionTestUtils.loadExtension({
@@ -516,18 +509,23 @@ add_task(async function testRemoveAllWit
   await confirmMenuItems("gamma");
   await closeContextMenu();
 
   await first.unload();
   await second.unload();
   BrowserTestUtils.removeTab(tab);
 });
 
-function bookmarkContextMenuExtension() {
-  return ExtensionTestUtils.loadExtension({
+add_task(async function test_bookmark_contextmenu() {
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE);
+
+  const bookmarksToolbar = document.getElementById("PersonalToolbar");
+  setToolbarVisibility(bookmarksToolbar, true);
+
+  const extension = ExtensionTestUtils.loadExtension({
     manifest: {
       permissions: ["contextMenus", "bookmarks", "activeTab"],
     },
     async background() {
       const url = "https://example.com/";
       const title = "Example";
       let newBookmark = await browser.bookmarks.create({
         url,
@@ -549,140 +547,39 @@ function bookmarkContextMenuExtension() 
         browser.test.assertFalse(info.hasOwnProperty("pageUrl"), "Context menu does not expose pageUrl");
         await browser.bookmarks.remove(info.bookmarkId);
         browser.test.sendMessage("test-finish");
       });
       browser.contextMenus.create({
         title: "Get bookmark",
         contexts: ["bookmark"],
       }, () => {
-        browser.test.sendMessage("bookmark-created", newBookmark.id);
+        browser.test.sendMessage("bookmark-created");
       });
     },
   });
-}
-
-add_task(async function test_bookmark_contextmenu() {
-  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE);
-
-  await toggleBookmarksToolbar(true);
-
-  const extension = bookmarkContextMenuExtension();
-
   await extension.startup();
   await extension.awaitMessage("bookmark-created");
   let menu = await openChromeContextMenu(
     "placesContext",
     "#PersonalToolbar .bookmark-item:last-child");
 
   let menuItem = menu.getElementsByAttribute("label", "Get bookmark")[0];
   closeChromeContextMenu("placesContext", menuItem);
 
   await extension.awaitMessage("test-finish");
   await extension.unload();
-  await toggleBookmarksToolbar(false);
+  setToolbarVisibility(bookmarksToolbar, false);
 
   BrowserTestUtils.removeTab(tab);
 });
 
-add_task(async function test_bookmark_sidebar_contextmenu() {
-  await withSidebarTree("bookmarks", async (tree) => {
-    let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE);
-
-    let extension = bookmarkContextMenuExtension();
-    await extension.startup();
-    let bookmarkGuid = await extension.awaitMessage("bookmark-created");
-
-    let sidebar = window.SidebarUI.browser;
-    let menu = sidebar.contentDocument.getElementById("placesContext");
-    tree.selectItems([bookmarkGuid]);
-    let shown = BrowserTestUtils.waitForEvent(menu, "popupshown");
-    synthesizeClickOnSelectedTreeCell(tree, {type: "contextmenu"});
-    await shown;
-
-    let menuItem = menu.getElementsByAttribute("label", "Get bookmark")[0];
-    closeChromeContextMenu("placesContext", menuItem, sidebar.contentWindow);
-    await extension.awaitMessage("test-finish");
-    await extension.unload();
-
-    BrowserTestUtils.removeTab(tab);
-  });
-});
-
-function bookmarkFolderContextMenuExtension() {
-  return ExtensionTestUtils.loadExtension({
-    manifest: {
-      permissions: ["contextMenus", "bookmarks"],
-    },
-    async background() {
-      const title = "Example";
-      let newBookmark = await browser.bookmarks.create({
-        title,
-        parentId: "toolbar_____",
-      });
-      await new Promise(resolve =>
-        browser.contextMenus.create({
-          title: "Get bookmark",
-          contexts: ["bookmark"],
-        }, resolve));
-      browser.contextMenus.onClicked.addListener(async (info) => {
-        browser.test.assertEq(newBookmark.id, info.bookmarkId, "Bookmark ID matches");
-
-        let [bookmark] = await browser.bookmarks.get(info.bookmarkId);
-        browser.test.assertEq(title, bookmark.title, "Bookmark title matches");
-        browser.test.assertFalse(info.hasOwnProperty("pageUrl"), "Context menu does not expose pageUrl");
-        await browser.bookmarks.remove(info.bookmarkId);
-        browser.test.sendMessage("test-finish");
-      });
-      browser.test.sendMessage("bookmark-created", newBookmark.id);
-    },
-  });
-}
-
-add_task(async function test_organizer_contextmenu() {
-  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE);
-  let library = await promiseLibrary("BookmarksToolbar");
-
-  let menu = library.document.getElementById("placesContext");
-  let mainTree = library.document.getElementById("placeContent");
-  let leftTree = library.document.getElementById("placesList");
-
-  let tests = [
-    [mainTree, bookmarkContextMenuExtension],
-    [mainTree, bookmarkFolderContextMenuExtension],
-    [leftTree, bookmarkFolderContextMenuExtension],
-  ];
-
-  if (AppConstants.DEBUG) {
-    // Avoid intermittent leak - bug 1520047
-    tests.pop();
-  }
-
-  for (let [tree, makeExtension] of tests) {
-    let extension = makeExtension();
-    await extension.startup();
-    let bookmarkGuid = await extension.awaitMessage("bookmark-created");
-
-    tree.selectItems([bookmarkGuid]);
-    let shown = BrowserTestUtils.waitForEvent(menu, "popupshown");
-    synthesizeClickOnSelectedTreeCell(tree, {type: "contextmenu"});
-    await shown;
-
-    let menuItem = menu.getElementsByAttribute("label", "Get bookmark")[0];
-    closeChromeContextMenu("placesContext", menuItem, library);
-    await extension.awaitMessage("test-finish");
-    await extension.unload();
-  }
-
-  await promiseLibraryClosed(library);
-  BrowserTestUtils.removeTab(tab);
-});
-
 add_task(async function test_bookmark_context_requires_permission() {
-  await toggleBookmarksToolbar(true);
+  const bookmarksToolbar = document.getElementById("PersonalToolbar");
+  setToolbarVisibility(bookmarksToolbar, true);
 
   const extension = ExtensionTestUtils.loadExtension({
     manifest: {
       permissions: ["contextMenus"],
     },
     background() {
       browser.contextMenus.create({
         title: "Get bookmark",
@@ -699,10 +596,10 @@ add_task(async function test_bookmark_co
     "#PersonalToolbar .bookmark-item:last-child");
 
   Assert.equal(menu.getElementsByAttribute("label", "Get bookmark").length, 0,
                "bookmark context menu not created with `bookmarks` permission.");
 
   closeChromeContextMenu("placesContext");
 
   await extension.unload();
-  await toggleBookmarksToolbar(false);
+  setToolbarVisibility(bookmarksToolbar, false);
 });
--- a/browser/components/extensions/test/browser/browser_ext_menus.js
+++ b/browser/components/extensions/test/browser/browser_ext_menus.js
@@ -160,44 +160,53 @@ add_task(async function test_hiddenPageA
   await closeChromeContextMenu(menu.id);
   await closeChromeContextMenu(BrowserPageActions.panelNode.id);
 
   BrowserTestUtils.removeTab(tab);
   await extension.unload();
 });
 
 add_task(async function test_bookmarkContextMenu() {
+  async function showBookmarksToolbar(visible = true) {
+    let bt = document.getElementById("PersonalToolbar");
+    let transitionPromise =
+      BrowserTestUtils.waitForEvent(bt, "transitionend",
+                                    e => e.propertyName == "max-height");
+    setToolbarVisibility(bt, visible);
+    await transitionPromise;
+  }
+
   const ext = ExtensionTestUtils.loadExtension({
     manifest: {
       permissions: ["menus", "bookmarks"],
     },
     background() {
       browser.menus.onShown.addListener(() => {
         browser.test.sendMessage("hello");
       });
       browser.menus.create({title: "blarg", contexts: ["bookmark"]}, () => {
         browser.test.sendMessage("ready");
       });
     },
   });
 
-  await toggleBookmarksToolbar(true);
+  await showBookmarksToolbar();
   await ext.startup();
   await ext.awaitMessage("ready");
 
   let menu = await openChromeContextMenu("placesContext",
                                          "#PlacesToolbarItems .bookmark-item");
   let children = Array.from(menu.children);
   let item = children[children.length - 1];
   is(item.label, "blarg", "Menu item label is correct");
   await ext.awaitMessage("hello"); // onShown listener fired
 
   closeChromeContextMenu("placesContext", item);
   await ext.unload();
-  await toggleBookmarksToolbar(false);
+  await showBookmarksToolbar(false);
 });
 
 add_task(async function test_tabContextMenu() {
   const first = ExtensionTestUtils.loadExtension({
     manifest: {
       permissions: ["menus"],
     },
     async background() {
--- a/browser/components/extensions/test/browser/head.js
+++ b/browser/components/extensions/test/browser/head.js
@@ -3,17 +3,16 @@
 "use strict";
 
 /* exported CustomizableUI makeWidgetId focusWindow forceGC
  *          getBrowserActionWidget
  *          clickBrowserAction clickPageAction
  *          getBrowserActionPopup getPageActionPopup getPageActionButton
  *          closeBrowserAction closePageAction
  *          promisePopupShown promisePopupHidden
- *          toggleBookmarksToolbar
  *          openContextMenu closeContextMenu
  *          openContextMenuInSidebar openContextMenuInPopup
  *          openExtensionContextMenu closeExtensionContextMenu
  *          openActionContextMenu openSubmenu closeActionContextMenu
  *          openTabContextMenu closeTabContextMenu
  *          openToolsMenu closeToolsMenu
  *          imageBuffer imageBufferFromDataURI
  *          getListStyleImage getPanelForNode
@@ -283,26 +282,16 @@ function closeBrowserAction(extension, w
   let group = getBrowserActionWidget(extension);
 
   let node = win.document.getElementById(group.viewId);
   CustomizableUI.hidePanelForNode(node);
 
   return Promise.resolve();
 }
 
-async function toggleBookmarksToolbar(visible = true) {
-  let bookmarksToolbar = document.getElementById("PersonalToolbar");
-  let transitionPromise =
-    BrowserTestUtils.waitForEvent(bookmarksToolbar, "transitionend",
-                                  e => e.propertyName == "max-height");
-
-  setToolbarVisibility(bookmarksToolbar, visible);
-  await transitionPromise;
-}
-
 async function openContextMenuInPopup(extension, selector = "body") {
   let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
   let browser = await awaitExtensionPanel(extension);
   let popupShownPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popupshown");
   await BrowserTestUtils.synthesizeMouseAtCenter(selector, {type: "mousedown", button: 2}, browser);
   await BrowserTestUtils.synthesizeMouseAtCenter(selector, {type: "contextmenu"}, browser);
   await popupShownPromise;
   return contentAreaContextMenu;