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)
This commit is contained in:
Gurzau Raul 2019-01-15 17:07:06 +02:00
Родитель 3530a3ec83
Коммит 50e42b691d
5 изменённых файлов: 27 добавлений и 262 удалений

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

@ -4,9 +4,6 @@
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.defineModuleGetter(this, "Bookmarks",
"resource://gre/modules/Bookmarks.jsm");
var {
DefaultMap,
ExtensionError,
@ -866,72 +863,6 @@ MenuItem.prototype = {
},
};
// 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 = {
@ -943,16 +874,17 @@ const menuTracker = {
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) {
@ -965,54 +897,10 @@ const menuTracker = {
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) {
@ -1037,23 +925,6 @@ const menuTracker = {
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 {

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

@ -81,7 +81,6 @@ skip-if = (verify && (os == 'linux' || os == 'mac'))
[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]

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

@ -2,13 +2,6 @@
/* 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() {
@ -521,8 +514,13 @@ add_task(async function testRemoveAllWithTwoExtensions() {
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"],
},
@ -554,19 +552,10 @@ function bookmarkContextMenuExtension() {
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(
@ -578,106 +567,14 @@ add_task(async function test_bookmark_contextmenu() {
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: {
@ -704,5 +601,5 @@ add_task(async function test_bookmark_context_requires_permission() {
closeChromeContextMenu("placesContext");
await extension.unload();
await toggleBookmarksToolbar(false);
setToolbarVisibility(bookmarksToolbar, false);
});

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

@ -165,6 +165,15 @@ add_task(async function test_hiddenPageActionContextMenu() {
});
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"],
@ -179,7 +188,7 @@ add_task(async function test_bookmarkContextMenu() {
},
});
await toggleBookmarksToolbar(true);
await showBookmarksToolbar();
await ext.startup();
await ext.awaitMessage("ready");
@ -192,7 +201,7 @@ add_task(async function test_bookmarkContextMenu() {
closeChromeContextMenu("placesContext", item);
await ext.unload();
await toggleBookmarksToolbar(false);
await showBookmarksToolbar(false);
});
add_task(async function test_tabContextMenu() {

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

@ -8,7 +8,6 @@
* getBrowserActionPopup getPageActionPopup getPageActionButton
* closeBrowserAction closePageAction
* promisePopupShown promisePopupHidden
* toggleBookmarksToolbar
* openContextMenu closeContextMenu
* openContextMenuInSidebar openContextMenuInPopup
* openExtensionContextMenu closeExtensionContextMenu
@ -288,16 +287,6 @@ function closeBrowserAction(extension, win = window) {
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);