Bug 1511799 - Enable valid-jsdoc, require-jsdoc (classes) and var-only-at-top-level for browser/components/search. r=adw

Depends on D11656

Differential Revision: https://phabricator.services.mozilla.com/D13749

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mark Banner 2018-12-07 15:33:53 +00:00
Родитель d3ce1d7179
Коммит bcc710f22a
11 изменённых файлов: 140 добавлений и 80 удалений

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

@ -0,0 +1,31 @@
"use strict";
module.exports = {
rules: {
"mozilla/var-only-at-top-level": "error",
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": false,
"MethodDefinition": false,
"ClassDeclaration": true,
"ArrowFunctionExpression": false,
"FunctionExpression": false
}
}],
"valid-jsdoc": ["error", {
prefer: {
return: "returns",
},
preferType: {
Boolean: "boolean",
Number: "number",
String: "string",
Object: "object",
bool: "boolean",
},
requireParamDescription: false,
requireReturn: false,
requireReturnDescription: false,
}],
}
};

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

@ -7,6 +7,10 @@
/* eslint-env mozilla/browser-window */
/* globals XULCommandEvent */
/**
* Defines the search one-off button elements. These are displayed at the bottom
* of the address bar or the search bar.
*/
class SearchOneOffs {
constructor(container) {
this.container = container;
@ -166,10 +170,14 @@ class SearchOneOffs {
get buttonWidth() {
return 49;
}
/**
* The popup that contains the one-offs. This is required, so it should
* never be null or undefined, except possibly before the one-offs are
* used.
*
* @param {DOMElement} val
* The new value to set.
*/
set popup(val) {
let events = [
@ -207,6 +215,9 @@ class SearchOneOffs {
* automatically keep the related one-offs UI up to date. Otherwise you
* can leave it null/undefined, and in that case you should update the
* query property manually.
*
* @param {DOMElement} val
* The new value to set.
*/
set textbox(val) {
if (this._textbox) {
@ -230,6 +241,9 @@ class SearchOneOffs {
* The query string currently shown in the one-offs. If the textbox
* property is non-null, then this is automatically updated on
* input.
*
* @param {string} val
* The new query string to set.
*/
set query(val) {
this._query = val;
@ -242,9 +256,13 @@ class SearchOneOffs {
get query() {
return this._query;
}
/**
* The selected one-off, a xul:button, including the add-engine button
* and the search-settings button. Null if no one-off is selected.
* and the search-settings button.
*
* @param {DOMElement|null} val
* The selected one-off button. Null if no one-off is selected.
*/
set selectedButton(val) {
if (val && val.classList.contains("dummy")) {
@ -276,9 +294,13 @@ class SearchOneOffs {
get selectedButton() {
return this._selectedButton;
}
/**
* The index of the selected one-off, including the add-engine button
* and the search-settings button. -1 if no one-off is selected.
* and the search-settings button.
*
* @param {number} val
* The new index to set, -1 for nothing selected.
*/
set selectedButtonIndex(val) {
let buttons = this.getSelectableButtons(true);
@ -622,7 +644,7 @@ class SearchOneOffs {
* Updates the popup and textbox for the currently selected or moused-over
* button.
*
* @param mousedOverButton
* @param {DOMElement} mousedOverButton
* The currently moused-over button, or null if there isn't one.
*/
_updateStateForButton(mousedOverButton) {
@ -696,7 +718,7 @@ class SearchOneOffs {
};
}
} else {
var newTabPref = Services.prefs.getBoolPref("browser.search.openintab");
let newTabPref = Services.prefs.getBoolPref("browser.search.openintab");
if ((aEvent instanceof KeyboardEvent && aEvent.altKey) ^ newTabPref &&
!gBrowser.selectedTab.isEmpty) {
where = "tab";
@ -716,10 +738,10 @@ class SearchOneOffs {
/**
* Increments or decrements the index of the currently selected one-off.
*
* @param aForward
* @param {boolean} aForward
* If true, the index is incremented, and if false, the index is
* decremented.
* @param aIncludeNonEngineButtons
* @param {boolean} aIncludeNonEngineButtons
* If true, non-dummy buttons that do not have engines are included.
* These buttons include the OpenSearch and settings buttons. For
* example, if the currently selected button is an engine button,
@ -728,11 +750,9 @@ class SearchOneOffs {
* settings to be selected. Passing false for this value would
* cause the selection to clear or wrap around, depending on what
* value you passed for the aWrapAround parameter.
* @param aWrapAround
* @param {boolean} aWrapAround
* If true, the selection wraps around between the first and last
* buttons.
* @return True if the selection can continue to advance after this method
* returns and false if not.
*/
advanceSelection(aForward, aIncludeNonEngineButtons, aWrapAround) {
let buttons = this.getSelectableButtons(aIncludeNonEngineButtons);
@ -764,18 +784,18 @@ class SearchOneOffs {
* If this method handles the key press, then event.defaultPrevented will
* be true when it returns.
*
* @param event
* @param {Event} event
* The key event.
* @param numListItems
* @param {number} numListItems
* The number of items in the list. The reason that this is a
* parameter at all is that the list may contain items at the end
* that should be ignored, depending on the consumer. That's true
* for the urlbar for example.
* @param allowEmptySelection
* @param {boolean} allowEmptySelection
* Pass true if it's OK that neither the list nor the one-off
* buttons contains a selection. Pass false if either the list or
* the one-off buttons (or both) should always contain a selection.
* @param textboxUserValue
* @param {string} [textboxUserValue]
* When the last list item is selected and the user presses Down,
* the first one-off becomes selected and the textbox value is
* restored to the value that the user typed. Pass that value here.
@ -965,13 +985,13 @@ class SearchOneOffs {
* one-off telemetry for it. this.telemetryOrigin will be appended to the
* computed source, so make sure you set that first.
*
* @param aEvent
* @param {Event} aEvent
* An event, like a click on a one-off button.
* @param aOpenUILinkWhere
* @param {string} aOpenUILinkWhere
* The "where" passed to openUILink.
* @param aOpenUILinkParams
* @param {object} aOpenUILinkParams
* The "params" passed to openUILink.
* @return True if telemetry was recorded and false if not.
* @returns {boolean} True if telemetry was recorded and false if not.
*/
maybeRecordTelemetry(aEvent, aOpenUILinkWhere, aOpenUILinkParams) {
if (!aEvent) {
@ -1233,4 +1253,3 @@ class SearchOneOffs {
}
window.SearchOneOffs = SearchOneOffs;

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

@ -27,12 +27,12 @@
if (Services.prefs.getBoolPref("browser.urlbar.clickSelectsAll"))
this.setAttribute("clickSelectsAll", true);
var textBox = document.getAnonymousElementByAttribute(this,
let textBox = document.getAnonymousElementByAttribute(this,
"anonid", "moz-input-box");
// Force the Custom Element to upgrade until Bug 1470242 handles this:
customElements.upgrade(textBox);
var cxmenu = textBox.menupopup;
let cxmenu = textBox.menupopup;
cxmenu.addEventListener("popupshowing",
() => { this.initContextMenu(cxmenu); },
{capture: true, once: true});
@ -167,7 +167,7 @@
return;
}
var popup = this.popup;
let popup = this.popup;
if (!popup.mPopupOpen) {
// Initially the panel used for the searchbar (PopupSearchAutoComplete
// in browser.xul) is hidden to avoid impacting startup / new
@ -189,8 +189,8 @@
document.popupNode = null;
var outerRect = this.getBoundingClientRect();
var innerRect = this.inputField.getBoundingClientRect();
let outerRect = this.getBoundingClientRect();
let innerRect = this.inputField.getBoundingClientRect();
let width = RTL_UI ?
innerRect.right - outerRect.left :
outerRect.right - innerRect.left;
@ -199,7 +199,7 @@
// invalidate() depends on the width attribute
popup._invalidate();
var yOffset = outerRect.bottom - innerRect.bottom;
let yOffset = outerRect.bottom - innerRect.bottom;
popup.openPopup(this.inputField, "after_start", 0, yOffset, false, false);
}
]]></body>
@ -299,7 +299,7 @@
doCommand(aCommand) {
switch (aCommand) {
case "cmd_clearhistory":
var param = this._self.getAttribute("autocompletesearchparam");
let param = this._self.getAttribute("autocompletesearchparam");
BrowserSearch.searchBar.FormHistory.update({ op: "remove", fieldname: param }, null);
this._self.value = "";
@ -343,7 +343,7 @@
<handler event="dragover">
<![CDATA[
var types = event.dataTransfer.types;
let types = event.dataTransfer.types;
if (types.includes("text/plain") || types.includes("text/x-moz-text-internal"))
event.preventDefault();
]]>
@ -351,8 +351,8 @@
<handler event="drop">
<![CDATA[
var dataTransfer = event.dataTransfer;
var data = dataTransfer.getData("text/plain");
let dataTransfer = event.dataTransfer;
let data = dataTransfer.getData("text/plain");
if (!data)
data = dataTransfer.getData("text/x-moz-text-internal");
if (data) {
@ -398,8 +398,8 @@
if (aEvent.button == 2)
return;
var searchBar = BrowserSearch.searchBar;
var popupForSearchBar = searchBar && searchBar.textbox == this.mInput;
let searchBar = BrowserSearch.searchBar;
let popupForSearchBar = searchBar && searchBar.textbox == this.mInput;
if (popupForSearchBar) {
searchBar.telemetrySearchDetails = {
index: this.selectedIndex,
@ -422,10 +422,10 @@
);
// Handle search bar popup clicks
var search = this.input.controller.getValueAt(this.selectedIndex);
let search = this.input.controller.getValueAt(this.selectedIndex);
// open the search results according to the clicking subtlety
var where = whereToOpenLink(aEvent, false, true);
let where = whereToOpenLink(aEvent, false, true);
let params = {};
// But open ctrl/cmd clicks on autocomplete items in a new background tab.

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

@ -23,11 +23,14 @@ function inheritAttribute(parent, child, attr) {
}
}
/**
* Defines the search bar element.
*/
class MozSearchbar extends MozXULElement {
static get observedAttributes() {
let unique = new Set();
for (var i in inheritsMap) {
for (let i in inheritsMap) {
inheritsMap[i].forEach(attr => unique.add(attr));
}
return Array.from(unique);
@ -162,7 +165,7 @@ class MozSearchbar extends MozXULElement {
}
get currentEngine() {
var currentEngine = Services.search.defaultEngine;
let currentEngine = Services.search.defaultEngine;
// Return a dummy engine if there is no currentEngine
return currentEngine || { name: "", uri: null };
}
@ -213,11 +216,11 @@ class MozSearchbar extends MozXULElement {
}
updateDisplay() {
var uri = this.currentEngine.iconURI;
let uri = this.currentEngine.iconURI;
this.setIcon(this, uri ? uri.spec : "");
var name = this.currentEngine.name;
var text = this._stringBundle.getFormattedString("searchtip", [name]);
let name = this.currentEngine.name;
let text = this._stringBundle.getFormattedString("searchtip", [name]);
this._textbox.label = text;
this._textbox.tooltipText = text;
}
@ -243,7 +246,7 @@ class MozSearchbar extends MozXULElement {
selectEngine(aEvent, isNextEngine) {
// Find the new index
var newIndex = this.engines.indexOf(this.currentEngine);
let newIndex = this.engines.indexOf(this.currentEngine);
newIndex += isNextEngine ? 1 : -1;
if (newIndex >= 0 && newIndex < this.engines.length) {
@ -257,7 +260,7 @@ class MozSearchbar extends MozXULElement {
}
handleSearchCommand(aEvent, aEngine, aForceNewTab) {
var where = "current";
let where = "current";
let params;
// Open ctrl/cmd clicks on one-off buttons in a new background tab.
@ -270,7 +273,7 @@ class MozSearchbar extends MozXULElement {
if (Services.prefs.getBoolPref("browser.tabs.loadInBackground"))
where += "-background";
} else {
var newTabPref = Services.prefs.getBoolPref("browser.search.openintab");
let newTabPref = Services.prefs.getBoolPref("browser.search.openintab");
if (((aEvent instanceof KeyboardEvent && aEvent.altKey) ^ newTabPref) &&
!gBrowser.selectedTab.isEmpty) {
where = "tab";
@ -288,8 +291,8 @@ class MozSearchbar extends MozXULElement {
}
handleSearchCommandWhere(aEvent, aEngine, aWhere, aParams) {
var textBox = this._textbox;
var textValue = textBox.value;
let textBox = this._textbox;
let textValue = textBox.value;
let selection = this.telemetrySearchDetails;
let oneOffRecorded = false;
@ -335,7 +338,7 @@ class MozSearchbar extends MozXULElement {
}
doSearch(aData, aWhere, aEngine, aParams, aOneOff) {
var textBox = this._textbox;
let textBox = this._textbox;
// Save the current value in the form history
if (aData && !PrivateBrowsingUtils.isWindowPrivate(window) && this.FormHistory.enabled) {
@ -351,7 +354,7 @@ class MozSearchbar extends MozXULElement {
}
let engine = aEngine || this.currentEngine;
var submission = engine.getSubmission(aData, null, "searchbar");
let submission = engine.getSubmission(aData, null, "searchbar");
let telemetrySearchDetails = this.telemetrySearchDetails;
this.telemetrySearchDetails = null;
if (telemetrySearchDetails && telemetrySearchDetails.index == -1) {
@ -390,7 +393,7 @@ class MozSearchbar extends MozXULElement {
this.currentEngine = target.engine;
} else if (target.classList.contains("addengine-item")) {
// Select the installed engine if the installation succeeds
var installCallback = {
let installCallback = {
onSuccess: engine => this.currentEngine = engine,
};
Services.search.addEngine(target.getAttribute("uri"), null,

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

@ -20,7 +20,7 @@ var SearchTestUtils = Object.freeze({
* Adds a search engine to the search service. It will remove the engine
* at the end of the test.
*
* @param {String} url The URL of the engine to add.
* @param {string} url The URL of the engine to add.
* @param {Function} registerCleanupFunction Pass the registerCleanupFunction
* from the test's scope.
* @returns {Promise} Returns a promise that is resolved with the new engine

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

@ -4,17 +4,17 @@ ChromeUtils.defineModuleGetter(this, "FormHistory",
function expectedURL(aSearchTerms) {
const ENGINE_HTML_BASE = "http://mochi.test:8888/browser/browser/components/search/test/browser/test.html";
var searchArg = Services.textToSubURI.ConvertAndEscape("utf-8", aSearchTerms);
let searchArg = Services.textToSubURI.ConvertAndEscape("utf-8", aSearchTerms);
return ENGINE_HTML_BASE + "?test=" + searchArg;
}
function simulateClick(aEvent, aTarget) {
var event = document.createEvent("MouseEvent");
var ctrlKeyArg = aEvent.ctrlKey || false;
var altKeyArg = aEvent.altKey || false;
var shiftKeyArg = aEvent.shiftKey || false;
var metaKeyArg = aEvent.metaKey || false;
var buttonArg = aEvent.button || 0;
let event = document.createEvent("MouseEvent");
let ctrlKeyArg = aEvent.ctrlKey || false;
let altKeyArg = aEvent.altKey || false;
let shiftKeyArg = aEvent.shiftKey || false;
let metaKeyArg = aEvent.metaKey || false;
let buttonArg = aEvent.button || 0;
event.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0,
ctrlKeyArg, altKeyArg, shiftKeyArg, metaKeyArg,
@ -24,9 +24,9 @@ function simulateClick(aEvent, aTarget) {
// modified from toolkit/components/satchel/test/test_form_autocomplete.html
function checkMenuEntries(expectedValues) {
var actualValues = getMenuEntries();
let actualValues = getMenuEntries();
is(actualValues.length, expectedValues.length, "Checking length of expected menu");
for (var i = 0; i < expectedValues.length; i++)
for (let i = 0; i < expectedValues.length; i++)
is(actualValues[i], expectedValues[i], "Checking menu entry #" + i);
}
@ -58,12 +58,12 @@ var searchButton;
var searchEntries = ["test"];
function promiseSetEngine() {
return new Promise(resolve => {
var ss = Services.search;
let ss = Services.search;
function observer(aSub, aTopic, aData) {
switch (aData) {
case "engine-added":
var engine = ss.getEngineByName("Bug 426329");
let engine = ss.getEngineByName("Bug 426329");
ok(engine, "Engine was added.");
ss.defaultEngine = engine;
break;
@ -88,7 +88,7 @@ function promiseSetEngine() {
function promiseRemoveEngine() {
return new Promise(resolve => {
var ss = Services.search;
let ss = Services.search;
function observer(aSub, aTopic, aData) {
if (aData == "engine-removed") {
@ -98,7 +98,7 @@ function promiseRemoveEngine() {
}
Services.obs.addObserver(observer, "browser-search-engine-modified");
var engine = ss.getEngineByName("Bug 426329");
let engine = ss.getEngineByName("Bug 426329");
ss.removeEngine(engine);
});
}
@ -217,15 +217,15 @@ add_task(async function testRightClick() {
});
add_task(async function testSearchHistory() {
var textbox = searchBar._textbox;
for (var i = 0; i < searchEntries.length; i++) {
let textbox = searchBar._textbox;
for (let i = 0; i < searchEntries.length; i++) {
let count = await countEntries(textbox.getAttribute("autocompletesearchparam"), searchEntries[i]);
ok(count > 0, "form history entry '" + searchEntries[i] + "' should exist");
}
});
add_task(async function testAutocomplete() {
var popup = searchBar.textbox.popup;
let popup = searchBar.textbox.popup;
let popupShownPromise = BrowserTestUtils.waitForEvent(popup, "popupshown");
searchBar.textbox.showHistoryPopup();
await popupShownPromise;

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

@ -33,7 +33,7 @@ function observer(aSubject, aTopic, aData) {
function checkEngine(checkObj, engineObj) {
info("Checking engine");
for (var prop in checkObj)
for (let prop in checkObj)
is(checkObj[prop], engineObj[prop], prop + " is correct");
}

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

@ -7,7 +7,7 @@
add_task(async function() {
const ss = Services.search;
const ENGINE_NAME = "Foo";
var contextMenu;
let contextMenu;
// We want select events to be fired.
await SpecialPowers.pushPrefEnv({set: [["dom.select_events.enabled", true]]});
@ -28,7 +28,7 @@ add_task(async function() {
function observer(aSub, aTopic, aData) {
switch (aData) {
case "engine-added":
var engine = ss.getEngineByName(ENGINE_NAME);
let engine = ss.getEngineByName(ENGINE_NAME);
ok(engine, "Engine was added.");
ss.defaultEngine = engine;
envService.set("XPCSHELL_TEST_PROFILE_DIR", originalValue);
@ -66,14 +66,14 @@ add_task(async function() {
});
});
var eventDetails = { type: "contextmenu", button: 2 };
let eventDetails = { type: "contextmenu", button: 2 };
let popupPromise = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
BrowserTestUtils.synthesizeMouseAtCenter("body", eventDetails, gBrowser.selectedBrowser);
await popupPromise;
info("checkContextMenu");
var searchItem = contextMenu.getElementsByAttribute("id", "context-searchselect")[0];
let searchItem = contextMenu.getElementsByAttribute("id", "context-searchselect")[0];
ok(searchItem, "Got search context menu item");
is(searchItem.label, "Search " + ENGINE_NAME + " for \u201ctest search\u201d", "Check context menu label");
is(searchItem.disabled, false, "Check that search context menu item is enabled");

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

@ -101,7 +101,7 @@ add_task(async function test_urlBarChangeEngine() {
* Promises that an engine change has happened for the current engine, which
* has resulted in the test engine now being the current engine.
*
* @return {Promise} Resolved once the test engine is set as the current engine.
* @returns {Promise} Resolved once the test engine is set as the current engine.
*/
function promiseCurrentEngineChanged() {
return new Promise(resolve => {
@ -121,13 +121,13 @@ function promiseCurrentEngineChanged() {
* Opens the specified urlbar/search popup and gets the test engine from the
* one-off buttons.
*
* @param {Boolean} isSearch true if the search popup should be opened; false
* @param {boolean} isSearch true if the search popup should be opened; false
* for the urlbar popup.
* @param {Object} popup The expected popup.
* @param {Object} oneOffInstance The expected one-off instance for the popup.
* @param {String} baseId The expected string for the id of the current
* @param {object} popup The expected popup.
* @param {object} oneOffInstance The expected one-off instance for the popup.
* @param {string} baseId The expected string for the id of the current
* engine button, without the engine name.
* @return {Object} Returns an object that represents the one off button for the
* @returns {object} Returns an object that represents the one off button for the
* test engine.
*/
async function openPopupAndGetEngineButton(isSearch, popup, oneOffInstance, baseId) {

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

@ -7,6 +7,13 @@ let gCUITestUtils = new CustomizableUITestUtils(window);
/**
* Recursively compare two objects and check that every property of expectedObj has the same value
* on actualObj.
*
* @param {object} expectedObj
* The expected object to find.
* @param {object} actualObj
* The object to inspect.
* @param {string} name
* The name of the engine, used for test detail logging.
*/
function isSubObjectOf(expectedObj, actualObj, name) {
for (let prop in expectedObj) {
@ -40,9 +47,9 @@ function promiseEvent(aTarget, aEventName, aPreventDefault) {
/**
* Adds a new search engine to the search service and confirms it completes.
*
* @param {String} basename The file to load that contains the search engine
* @param {string} basename The file to load that contains the search engine
* details.
* @param {Object} [options] Options for the test:
* @param {object} [options] Options for the test:
* - {String} [iconURL] The icon to use for the search engine.
* - {Boolean} [setAsCurrent] Whether to set the new engine to be the
* current engine or not.
@ -151,11 +158,11 @@ function promiseStateChangeURI() {
* Waits for a load (or custom) event to finish in a given tab. If provided
* load an uri into the tab.
*
* @param tab
* @param {object} tab
* The tab to load into.
* @param [optional] url
* @param {string} [url]
* The url to load, or the current url.
* @return {Promise} resolved when the event is handled.
* @returns {Promise} resolved when the event is handled.
* @resolves to the received event
* @rejects if a valid load event is not received within a meaningful interval
*/

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

@ -4,8 +4,8 @@
<head>
<script>
function installEngine() {
var query = window.location.search.substring(1);
var args = JSON.parse(decodeURIComponent(query));
let query = window.location.search.substring(1);
let args = JSON.parse(decodeURIComponent(query));
window.external.AddSearchProvider(...args);
}