Bug 1269497 - eslint fixes for Menu API;r=jdescottes draft
authorBrian Grinstead <bgrinstead@mozilla.com>
Mon, 02 May 2016 14:54:31 -0700
changeset 362670 decf762b5102ba6f2282fe26ceea4c07d86a7d59
parent 362669 46891b760b0bcc40d1e53b3907ead93242462290
child 519855 56285d7dfcae5edb221f6b88547e83026f758fae
push id17008
push userbgrinstead@mozilla.com
push dateMon, 02 May 2016 21:59:43 +0000
reviewersjdescottes
bugs1269497
milestone49.0a1
Bug 1269497 - eslint fixes for Menu API;r=jdescottes MozReview-Commit-ID: 9iSJgWUBRbp
devtools/client/framework/menu-item.js
devtools/client/framework/menu.js
devtools/client/framework/test/browser_menu_api.js
--- a/devtools/client/framework/menu-item.js
+++ b/devtools/client/framework/menu-item.js
@@ -1,14 +1,16 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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.
  *
  * Missing features:
  *   - id String - Unique within a single menu. If defined then it can be used
  *                 as a reference to this item by the position attribute.
  *   - role String - Define the action of the menu item; when specified the
@@ -18,27 +20,29 @@
  *   - icon NativeImage
  *   - visible Boolean - If false, the menu item will be entirely hidden.
  *   - position String - This field allows fine-grained definition of the
  *                       specific location within a given menu.
  *
  * 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.
- *
+ *    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.
  */
 function MenuItem({
     accesskey = null,
     checked = false,
     click = () => {},
     disabled = false,
     label = "",
     id = null,
--- a/devtools/client/framework/menu.js
+++ b/devtools/client/framework/menu.js
@@ -1,28 +1,29 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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");
 
 /**
  * A partial implementation of the Menu API provided by electron:
  * https://github.com/electron/electron/blob/master/docs/api/menu.md.
  *
  * Extra features:
  *  - Emits an 'open' and 'close' event when the menu is opened/closed
 
  * @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;
 
   Object.defineProperty(this, "items", {
     get() {
       return this.menuitems;
     }
   });
@@ -30,43 +31,43 @@ function Menu({id=null} = {}) {
   EventEmitter.decorate(this);
 }
 
 /**
  * Add an item to the end of the Menu
  *
  * @param {MenuItem} menuItem
  */
-Menu.prototype.append = function(menuItem) {
+Menu.prototype.append = function (menuItem) {
   this.menuitems.push(menuItem);
 };
 
 /**
  * Add an item to a specified position in the menu
  *
  * @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");
 };
 
 /**
  * Show the Menu at a specified location on the screen
  *
  * Missing features:
  *   - browserWindow - BrowserWindow (optional) - Default is null.
  *   - positioningItem Number - (optional) OS X
  *
  * @param {int} screenX
  * @param {int} screenY
  * @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");
 
   if (this.id) {
     popup.id = this.id;
   }
   this._createMenuItems(popup);
@@ -84,17 +85,17 @@ Menu.prototype.popup = function(screenX,
       this.emit("open");
     }
   });
 
   doc.querySelector("popupset").appendChild(popup);
   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) {
       return;
     }
 
     if (item.submenu) {
       let menupopup = doc.createElement("menupopup");
@@ -134,20 +135,20 @@ Menu.prototype._createMenuItems = functi
       }
 
       parent.appendChild(menuitem);
     }
   });
 };
 
 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;
--- a/devtools/client/framework/test/browser_menu_api.js
+++ b/devtools/client/framework/test/browser_menu_api.js
@@ -6,17 +6,17 @@
 "use strict";
 
 // Test that the Menu API works
 
 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);
   let toolbox = yield gDevTools.showToolbox(target, "webconsole");
 
   yield testMenuItems();
   yield testMenuPopup(toolbox);
   yield testSubmenu(toolbox);
@@ -76,43 +76,44 @@ function* testMenuPopup(toolbox) {
     label: "Invisible",
     visible: false,
   }));
 
   menu.popup(0, 0, 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");
   is(menuItems.length, MENU_ITEMS.length, "Correct number of menuitems");
 
   is(menuItems[0].id, MENU_ITEMS[0].id, "Correct id for menuitem");
   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) {
   let clickFired = false;
   let menu = new Menu({
     id: "menu-popup",
   });
   let submenu = new Menu({
@@ -127,21 +128,22 @@ function* testSubmenu(toolbox) {
   }));
   menu.append(new MenuItem({
     label: "Submenu parent",
     submenu: submenu,
   }));
 
   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");
   is(subMenuItems[0].getAttribute("label"), "Submenu item", "Correct label");
 
   yield once(menu, "open");
   let closed = once(menu, "close");
 
@@ -155,13 +157,13 @@ function* testSubmenu(toolbox) {
   EventUtils.synthesizeKey("VK_LEFT", {});
   yield hidden;
 
   shown = once(menus[0], "popupshown");
   EventUtils.synthesizeKey("VK_RIGHT", {});
   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");
 }