зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset d842c744941e (bug 1333403)
This commit is contained in:
Родитель
05b61a9cc0
Коммит
ddda5460bc
|
@ -616,23 +616,16 @@ const menuTracker = {
|
|||
},
|
||||
};
|
||||
|
||||
var gExtensionCount = 0;
|
||||
|
||||
this.menusInternal = class extends ExtensionAPI {
|
||||
constructor(extension) {
|
||||
super(extension);
|
||||
|
||||
if (!gMenuMap.size) {
|
||||
menuTracker.register();
|
||||
}
|
||||
gMenuMap.set(extension, new Map());
|
||||
}
|
||||
|
||||
onShutdown(reason) {
|
||||
let {extension} = this;
|
||||
|
||||
if (gMenuMap.has(extension)) {
|
||||
gMenuMap.delete(extension);
|
||||
gRootItems.delete(extension);
|
||||
if (!gMenuMap.size) {
|
||||
if (--gExtensionCount == 0) {
|
||||
menuTracker.unregister();
|
||||
}
|
||||
}
|
||||
|
@ -641,6 +634,11 @@ this.menusInternal = class extends ExtensionAPI {
|
|||
getAPI(context) {
|
||||
let {extension} = context;
|
||||
|
||||
gMenuMap.set(extension, new Map());
|
||||
if (++gExtensionCount == 1) {
|
||||
menuTracker.register();
|
||||
}
|
||||
|
||||
return {
|
||||
menusInternal: {
|
||||
create: function(createProperties) {
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
const PAGE = "http://mochi.test:8888/browser/browser/components/extensions/test/browser/context.html";
|
||||
|
||||
add_task(async function test_permissions() {
|
||||
function background() {
|
||||
browser.test.sendMessage("apis", {
|
||||
|
@ -187,7 +185,8 @@ add_task(async function test_onclick_frameid() {
|
|||
}
|
||||
|
||||
const extension = ExtensionTestUtils.loadExtension({manifest, background});
|
||||
const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE);
|
||||
const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser,
|
||||
"http://mochi.test:8888/browser/browser/components/extensions/test/browser/context.html");
|
||||
|
||||
await extension.startup();
|
||||
await extension.awaitMessage("ready");
|
||||
|
@ -209,49 +208,3 @@ add_task(async function test_onclick_frameid() {
|
|||
await BrowserTestUtils.removeTab(tab);
|
||||
await extension.unload();
|
||||
});
|
||||
|
||||
add_task(async function test_multiple_contexts_init() {
|
||||
const manifest = {
|
||||
permissions: ["menus"],
|
||||
};
|
||||
|
||||
function background() {
|
||||
browser.menus.create({id: "parent", title: "parent"});
|
||||
browser.tabs.create({url: "tab.html", active: false});
|
||||
}
|
||||
|
||||
const files = {
|
||||
"tab.html": "<!DOCTYPE html><meta charset=utf-8><script src=tab.js></script>",
|
||||
"tab.js": function() {
|
||||
browser.menus.create({parentId: "parent", id: "child", title: "child"});
|
||||
|
||||
browser.menus.onClicked.addListener(info => {
|
||||
browser.test.sendMessage("click", info);
|
||||
});
|
||||
|
||||
browser.test.sendMessage("ready");
|
||||
},
|
||||
};
|
||||
|
||||
const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE);
|
||||
const extension = ExtensionTestUtils.loadExtension({manifest, background, files});
|
||||
|
||||
await extension.startup();
|
||||
await extension.awaitMessage("ready");
|
||||
|
||||
const menu = await openContextMenu();
|
||||
const items = menu.getElementsByAttribute("label", "parent");
|
||||
|
||||
is(items.length, 1, "Found parent menu item");
|
||||
is(items[0].tagName, "menu", "And it has children");
|
||||
|
||||
const popup = await openSubmenu(items[0]);
|
||||
is(popup.firstChild.label, "child", "Correct child menu item");
|
||||
await closeExtensionContextMenu(popup.firstChild);
|
||||
|
||||
const info = await extension.awaitMessage("click");
|
||||
is(info.menuItemId, "child", "onClicked the correct item");
|
||||
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
await extension.unload();
|
||||
});
|
||||
|
|
|
@ -309,7 +309,7 @@ async function closeExtensionContextMenu(itemToSelect, modifiers = {}) {
|
|||
let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
|
||||
let popupHiddenPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popuphidden");
|
||||
EventUtils.synthesizeMouseAtCenter(itemToSelect, modifiers);
|
||||
return popupHiddenPromise;
|
||||
await popupHiddenPromise;
|
||||
}
|
||||
|
||||
async function openChromeContextMenu(menuId, target, win = window) {
|
||||
|
|
|
@ -1010,7 +1010,7 @@ class SchemaAPIManager extends EventEmitter {
|
|||
|
||||
module.loaded = true;
|
||||
|
||||
return this.global[name];
|
||||
return this._initModule(module, this.global[name]);
|
||||
}
|
||||
/**
|
||||
* aSynchronously loads an API module, if not already loaded, and
|
||||
|
@ -1037,7 +1037,7 @@ class SchemaAPIManager extends EventEmitter {
|
|||
|
||||
module.loaded = true;
|
||||
|
||||
return this.global[name];
|
||||
return this._initModule(module, this.global[name]);
|
||||
});
|
||||
|
||||
return module.asyncLoaded;
|
||||
|
@ -1076,6 +1076,14 @@ class SchemaAPIManager extends EventEmitter {
|
|||
return true;
|
||||
}
|
||||
|
||||
_initModule(info, cls) {
|
||||
// FIXME: This both a) does nothing, and b) is not used anymore.
|
||||
cls.namespaceName = cls.namespaceName;
|
||||
cls.scopes = new Set(info.scopes);
|
||||
|
||||
return cls;
|
||||
}
|
||||
|
||||
_checkLoadModule(module, name) {
|
||||
if (!module) {
|
||||
throw new Error(`Module '${name}' does not exist`);
|
||||
|
|
Загрузка…
Ссылка в новой задаче