Bug 1269497 - eslint fixes for Menu API;r=jdescottes

MozReview-Commit-ID: 9iSJgWUBRbp
This commit is contained in:
Brian Grinstead 2016-05-03 07:42:20 -07:00
Родитель c77eeb7c73
Коммит 234d71531a
3 изменённых файлов: 37 добавлений и 30 удалений

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

@ -4,6 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/**
* A partial implementation of the MenuItem API provided by electron:
* https://github.com/electron/electron/blob/master/docs/api/menu-item.md.
@ -22,19 +24,21 @@
* Implemented features:
* @param Object options
* Function click
* Will be called with click(menuItem, browserWindow) when the menu item is clicked
* Will be called with click(menuItem, browserWindow) when the menu item
* is clicked
* String type
* Can be normal, separator, submenu, checkbox or radio
* String label
* Boolean enabled
* If false, the menu item will be greyed out and unclickable.
* Boolean checked
* Should only be specified for checkbox or radio type menu items.
* Menu submenu
* Should be specified for submenu type menu items. If submenu is specified, the type: 'submenu' can be omitted. If the value is not a Menu then it will be automatically converted to one using Menu.buildFromTemplate.
* Boolean enabled
* If false, the menu item will be greyed out and unclickable.
* Boolean checked
* Should only be specified for checkbox or radio type menu items.
* Menu submenu
* Should be specified for submenu type menu items. If submenu is specified,
* the type: 'submenu' can be omitted. If the value is not a Menu then it
* will be automatically converted to one using Menu.buildFromTemplate.
* Boolean visible
* If false, the menu item will be entirely hidden.
*
*/
function MenuItem({
accesskey = null,

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

@ -4,7 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const MenuItem = require("./menu-item");
"use strict";
const EventEmitter = require("devtools/shared/event-emitter");
/**
@ -17,7 +18,7 @@ const EventEmitter = require("devtools/shared/event-emitter");
* @param String id (non standard)
* Needed so tests can confirm the XUL implementation is working
*/
function Menu({id=null} = {}) {
function Menu({ id = null } = {}) {
this.menuitems = [];
this.id = id;
@ -35,7 +36,7 @@ function Menu({id=null} = {}) {
*
* @param {MenuItem} menuItem
*/
Menu.prototype.append = function(menuItem) {
Menu.prototype.append = function (menuItem) {
this.menuitems.push(menuItem);
};
@ -45,8 +46,8 @@ Menu.prototype.append = function(menuItem) {
* @param {int} pos
* @param {MenuItem} menuItem
*/
Menu.prototype.insert = function(pos, menuItem) {
throw "Not implemented";
Menu.prototype.insert = function (pos, menuItem) {
throw Error("Not implemented");
};
/**
@ -61,7 +62,7 @@ Menu.prototype.insert = function(pos, menuItem) {
* @param Toolbox toolbox (non standard)
* Needed so we in which window to inject XUL
*/
Menu.prototype.popup = function(screenX, screenY, toolbox) {
Menu.prototype.popup = function (screenX, screenY, toolbox) {
let doc = toolbox.doc;
let popup = doc.createElement("menupopup");
popup.setAttribute("menu-api", "true");
@ -89,7 +90,7 @@ Menu.prototype.popup = function(screenX, screenY, toolbox) {
popup.openPopupAtScreen(screenX, screenY, true);
};
Menu.prototype._createMenuItems = function(parent) {
Menu.prototype._createMenuItems = function (parent) {
let doc = parent.ownerDocument;
this.menuitems.forEach(item => {
if (!item.visible) {
@ -139,15 +140,15 @@ Menu.prototype._createMenuItems = function(parent) {
};
Menu.setApplicationMenu = () => {
throw "Not implemented";
throw Error("Not implemented");
};
Menu.sendActionToFirstResponder = () => {
throw "Not implemented";
throw Error("Not implemented");
};
Menu.buildFromTemplate = () => {
throw "Not implemented";
throw Error("Not implemented");
};
module.exports = Menu;

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

@ -11,7 +11,7 @@ const URL = "data:text/html;charset=utf8,test page for menu api";
const Menu = require("devtools/client/framework/menu");
const MenuItem = require("devtools/client/framework/menu-item");
add_task(function*() {
add_task(function* () {
info("Create a test tab and open the toolbox");
let tab = yield addTab(URL);
let target = TargetFactory.forTab(tab);
@ -81,7 +81,8 @@ function* testMenuPopup(toolbox) {
ok(toolbox.doc.querySelector("#menu-popup"), "A popup is in the DOM");
let menuSeparators = toolbox.doc.querySelectorAll("#menu-popup > menuseparator");
let menuSeparators =
toolbox.doc.querySelectorAll("#menu-popup > menuseparator");
is(menuSeparators.length, 1, "A separator is in the menu");
let menuItems = toolbox.doc.querySelectorAll("#menu-popup > menuitem");
@ -91,23 +92,23 @@ function* testMenuPopup(toolbox) {
is(menuItems[0].getAttribute("label"), MENU_ITEMS[0].label, "Correct label");
is(menuItems[1].getAttribute("label"), MENU_ITEMS[1].label, "Correct label");
is(menuItems[1].getAttribute("type"), "checkbox", "Correct type attribute");
is(menuItems[1].getAttribute("checked"), "true", "Has checked attribute");
is(menuItems[1].getAttribute("type"), "checkbox", "Correct type attr");
is(menuItems[1].getAttribute("checked"), "true", "Has checked attr");
is(menuItems[2].getAttribute("label"), MENU_ITEMS[2].label, "Correct label");
is(menuItems[2].getAttribute("type"), "radio", "Correct type attribute");
ok(!menuItems[2].hasAttribute("checked"), "Doesn't have checked attribute");
is(menuItems[2].getAttribute("type"), "radio", "Correct type attr");
ok(!menuItems[2].hasAttribute("checked"), "Doesn't have checked attr");
is(menuItems[3].getAttribute("label"), MENU_ITEMS[3].label, "Correct label");
is(menuItems[3].getAttribute("disabled"), "true", "disabled attribute menuitem");
is(menuItems[3].getAttribute("disabled"), "true", "disabled attr menuitem");
yield once(menu, "open");
let closed = once(menu, "close");
EventUtils.synthesizeMouseAtCenter(menuItems[0], {}, toolbox.doc.defaultView);
EventUtils.synthesizeMouseAtCenter(menuItems[0], {}, toolbox.win);
yield closed;
ok(clickFired, "Click has fired");
ok(!toolbox.doc.querySelector("#menu-popup"), "The popup is removed from the DOM");
ok(!toolbox.doc.querySelector("#menu-popup"), "Popup removed from the DOM");
}
function* testSubmenu(toolbox) {
@ -132,11 +133,12 @@ function* testSubmenu(toolbox) {
menu.popup(0, 0, toolbox);
ok(toolbox.doc.querySelector("#menu-popup"), "A popup is in the DOM");
is(toolbox.doc.querySelectorAll("#menu-popup > menuitem").length, 0, "No menuitem children");
is(toolbox.doc.querySelectorAll("#menu-popup > menuitem").length, 0,
"No menuitem children");
let menus = toolbox.doc.querySelectorAll("#menu-popup > menu");
is(menus.length, 1, "Correct number of menus");
is(menus[0].getAttribute("label"), "Submenu parent", "Correct label for menus");
is(menus[0].getAttribute("label"), "Submenu parent", "Correct label");
let subMenuItems = menus[0].querySelectorAll("menupopup > menuitem");
is(subMenuItems.length, 1, "Correct number of submenu items");
@ -160,7 +162,7 @@ function* testSubmenu(toolbox) {
yield shown;
info("Clicking the submenu item");
EventUtils.synthesizeMouseAtCenter(subMenuItems[0], {}, toolbox.doc.defaultView);
EventUtils.synthesizeMouseAtCenter(subMenuItems[0], {}, toolbox.win);
yield closed;
ok(clickFired, "Click has fired");