Bug 1395176 - Lint testing/marionette for var usage. r?automatedtester
MozReview-Commit-ID: FCcyuUVJC7J
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -1,18 +1,18 @@
/* 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";
/* global XPCNativeWrapper */
-var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
-
-var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
+const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
+
+const loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader);
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("chrome://marionette/content/accessibility.js");
@@ -52,23 +52,22 @@ Cu.import("chrome://marionette/content/p
Cu.import("chrome://marionette/content/reftest.js");
Cu.import("chrome://marionette/content/session.js");
const {wait, TimedPromise} = Cu.import("chrome://marionette/content/wait.js", {});
Cu.importGlobalProperties(["URL"]);
this.EXPORTED_SYMBOLS = ["GeckoDriver", "Context"];
-var FRAME_SCRIPT = "chrome://marionette/content/listener.js";
+const FRAME_SCRIPT = "chrome://marionette/content/listener.js";
+const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const CLICK_TO_START_PREF = "marionette.debugging.clicktostart";
const CONTENT_LISTENER_PREF = "marionette.contentListener";
-const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
-
const SUPPORTED_STRATEGIES = new Set([
element.Strategy.ClassName,
element.Strategy.Selector,
element.Strategy.ID,
element.Strategy.TagName,
element.Strategy.XPath,
element.Strategy.Anon,
element.Strategy.AnonAttribute,
@@ -81,25 +80,16 @@ const globalMessageManager = Cc["@mozill
/**
* The Marionette WebDriver services provides a standard conforming
* implementation of the W3C WebDriver specification.
*
* @see {@link https://w3c.github.io/webdriver/webdriver-spec.html}
* @namespace driver
*/
-// This is used to prevent newSession from returning before the telephony
-// API's are ready; see bug 792647. This assumes that marionette-server.js
-// will be loaded before the 'system-message-listener-ready' message
-// is fired. If this stops being true, this approach will have to change.
-var systemMessageListenerReady = false;
-Services.obs.addObserver(function() {
- systemMessageListenerReady = true;
-}, "system-message-listener-ready");
-
/**
* @enum
* @memberof driver
*/
this.Context = {
CHROME: "chrome",
CONTENT: "content",
};
--- a/testing/marionette/event.js
+++ b/testing/marionette/event.js
@@ -496,61 +496,60 @@ event.isKeypressFiredKey = function(key)
* and then a keyup event are fired in sequence.
* @param {Window=} window
* Window object. Defaults to the current window.
*
* @throws {TypeError}
* If unknown key.
*/
event.synthesizeKey = function(key, event, win = undefined) {
- var TIP = getTIP_(win);
+ let TIP = getTIP_(win);
if (!TIP) {
return;
}
- var KeyboardEvent = getKeyboardEvent_(win);
- var modifiers = emulateToActivateModifiers_(TIP, event, win);
- var keyEventDict = createKeyboardEventDictionary_(key, event, win);
- var keyEvent = new KeyboardEvent("", keyEventDict.dictionary);
- var dispatchKeydown =
+ let KeyboardEvent = getKeyboardEvent_(win);
+ let modifiers = emulateToActivateModifiers_(TIP, event, win);
+ let keyEventDict = createKeyboardEventDictionary_(key, event, win);
+ let keyEvent = new KeyboardEvent("", keyEventDict.dictionary);
+ let dispatchKeydown =
!("type" in event) || event.type === "keydown" || !event.type;
- var dispatchKeyup =
+ let dispatchKeyup =
!("type" in event) || event.type === "keyup" || !event.type;
try {
if (dispatchKeydown) {
TIP.keydown(keyEvent, keyEventDict.flags);
if ("repeat" in event && event.repeat > 1) {
keyEventDict.dictionary.repeat = true;
- var repeatedKeyEvent = new KeyboardEvent("", keyEventDict.dictionary);
- for (var i = 1; i < event.repeat; i++) {
+ let repeatedKeyEvent = new KeyboardEvent("", keyEventDict.dictionary);
+ for (let i = 1; i < event.repeat; i++) {
TIP.keydown(repeatedKeyEvent, keyEventDict.flags);
}
}
}
if (dispatchKeyup) {
TIP.keyup(keyEvent, keyEventDict.flags);
}
} finally {
emulateToInactivateModifiers_(TIP, modifiers, win);
}
};
-var TIPMap = new WeakMap();
+const TIPMap = new WeakMap();
function getTIP_(win, callback) {
if (!win) {
win = window;
}
- var tip;
+ let tip;
if (TIPMap.has(win)) {
tip = TIPMap.get(win);
} else {
- tip =
- Cc["@mozilla.org/text-input-processor;1"].
- createInstance(Ci.nsITextInputProcessor);
+ tip = Cc["@mozilla.org/text-input-processor;1"]
+ .createInstance(Ci.nsITextInputProcessor);
TIPMap.set(win, tip);
}
if (!tip.beginInputTransactionForTests(win, callback)) {
tip = null;
TIPMap.delete(win);
}
return tip;
}
@@ -567,23 +566,23 @@ function getKeyboardEvent_(win = window)
}
if (typeof content != "undefined" && ("KeyboardEvent" in content)) {
return content.KeyboardEvent;
}
return win.KeyboardEvent;
}
function createKeyboardEventDictionary_(key, keyEvent, win = window) {
- var result = {dictionary: null, flags: 0};
- var keyCodeIsDefined = "keyCode" in keyEvent &&
+ let result = {dictionary: null, flags: 0};
+ let keyCodeIsDefined = "keyCode" in keyEvent &&
keyEvent.keyCode != undefined;
- var keyCode =
+ let keyCode =
(keyCodeIsDefined && keyEvent.keyCode >= 0 && keyEvent.keyCode <= 255) ?
keyEvent.keyCode : 0;
- var keyName = "Unidentified";
+ let keyName = "Unidentified";
if (key.indexOf("KEY_") == 0) {
keyName = key.substr("KEY_".length);
result.flags |= Ci.nsITextInputProcessor.KEY_NON_PRINTABLE_KEY;
} else if (key.indexOf("VK_") == 0) {
keyCode = Ci.nsIDOMKeyEvent["DOM_" + key];
if (!keyCode) {
throw "Unknown key: " + key;
}
@@ -599,17 +598,17 @@ function createKeyboardEventDictionary_(
if (!keyCode) {
result.flags |= Ci.nsITextInputProcessor.KEY_KEEP_KEYCODE_ZERO;
}
// only force printable if "raw character" and event key match, like "a"
if (!("key" in keyEvent && key != keyEvent.key)) {
result.flags |= Ci.nsITextInputProcessor.KEY_FORCE_PRINTABLE_KEY;
}
}
- var locationIsDefined = "location" in keyEvent;
+ let locationIsDefined = "location" in keyEvent;
if (locationIsDefined && keyEvent.location === 0) {
result.flags |= Ci.nsITextInputProcessor.KEY_KEEP_KEY_LOCATION_STANDARD;
}
result.dictionary = {
key: "key" in keyEvent ? keyEvent.key : keyName,
code: "code" in keyEvent ? keyEvent.code : "",
location: locationIsDefined ? keyEvent.location : 0,
repeat: "repeat" in keyEvent ? keyEvent.repeat === true : false,
@@ -617,19 +616,19 @@ function createKeyboardEventDictionary_(
};
return result;
}
function emulateToActivateModifiers_(TIP, keyEvent, win = window) {
if (!keyEvent) {
return null;
}
- var KeyboardEvent = getKeyboardEvent_(win);
+ let KeyboardEvent = getKeyboardEvent_(win);
- var modifiers = {
+ let modifiers = {
normal: [
{key: "Alt", attr: "altKey"},
{key: "AltGraph", attr: "altGraphKey"},
{key: "Control", attr: "ctrlKey"},
{key: "Fn", attr: "fnKey"},
{key: "Meta", attr: "metaKey"},
{key: "OS", attr: "osKey"},
{key: "Shift", attr: "shiftKey"},
@@ -710,17 +709,17 @@ function isMac_(win = window) {
return win.navigator.platform.indexOf("Mac") > -1;
} catch (ex) {}
}
return navigator.platform.indexOf("Mac") > -1;
}
/* eslint-disable */
function guessKeyNameFromKeyCode_(aKeyCode, win = window) {
- var KeyboardEvent = getKeyboardEvent_(win);
+ let KeyboardEvent = getKeyboardEvent_(win);
switch (aKeyCode) {
case KeyboardEvent.DOM_VK_CANCEL:
return "Cancel";
case KeyboardEvent.DOM_VK_HELP:
return "Help";
case KeyboardEvent.DOM_VK_BACK_SPACE:
return "Backspace";
case KeyboardEvent.DOM_VK_TAB:
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -2,23 +2,24 @@
* 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/. */
/* eslint-env mozilla/frame-script */
/* global XPCNativeWrapper */
"use strict";
-var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
+const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
-var uuidGen = Cc["@mozilla.org/uuid-generator;1"]
+const uuidGen = Cc["@mozilla.org/uuid-generator;1"]
.getService(Ci.nsIUUIDGenerator);
-
-var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
+const loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader);
+const winUtil = content.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowUtils);
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("chrome://marionette/content/accessibility.js");
Cu.import("chrome://marionette/content/action.js");
@@ -42,90 +43,90 @@ Cu.import("chrome://marionette/content/e
Cu.import("chrome://marionette/content/interaction.js");
Cu.import("chrome://marionette/content/legacyaction.js");
Cu.import("chrome://marionette/content/navigate.js");
Cu.import("chrome://marionette/content/proxy.js");
Cu.import("chrome://marionette/content/session.js");
Cu.importGlobalProperties(["URL"]);
-var marionetteTestName;
-var winUtil = content.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindowUtils);
-var listenerId = null; // unique ID of this listener
-var curContainer = {frame: content, shadowRoot: null};
-var previousContainer = null;
+let marionetteTestName;
-var seenEls = new element.Store();
-var SUPPORTED_STRATEGIES = new Set([
+let listenerId = null; // unique ID of this listener
+let curContainer = {frame: content, shadowRoot: null};
+let previousContainer = null;
+
+const seenEls = new element.Store();
+const SUPPORTED_STRATEGIES = new Set([
element.Strategy.ClassName,
element.Strategy.Selector,
element.Strategy.ID,
element.Strategy.Name,
element.Strategy.LinkText,
element.Strategy.PartialLinkText,
element.Strategy.TagName,
element.Strategy.XPath,
]);
-var capabilities;
+let capabilities;
-var legacyactions = new legacyaction.Chain(checkForInterrupted);
+let legacyactions = new legacyaction.Chain(checkForInterrupted);
// the unload handler
-var onunload;
+let onunload;
// Flag to indicate whether an async script is currently running or not.
-var asyncTestRunning = false;
-var asyncTestCommandId;
-var asyncTestTimeoutId;
+let asyncTestRunning = false;
+let asyncTestCommandId;
+let asyncTestTimeoutId;
-var inactivityTimeoutId = null;
+let inactivityTimeoutId = null;
-var originalOnError;
+let originalOnError;
// Send move events about this often
-var EVENT_INTERVAL = 30; // milliseconds
+let EVENT_INTERVAL = 30; // milliseconds
// last touch for each fingerId
-var multiLast = {};
-var asyncChrome = proxy.toChromeAsync({
+let multiLast = {};
+
+const asyncChrome = proxy.toChromeAsync({
addMessageListener: addMessageListenerId.bind(this),
removeMessageListener: removeMessageListenerId.bind(this),
sendAsyncMessage: sendAsyncMessage.bind(this),
});
-var syncChrome = proxy.toChrome(sendSyncMessage.bind(this));
+const syncChrome = proxy.toChrome(sendSyncMessage.bind(this));
-var logger = Log.repository.getLogger("Marionette");
+const logger = Log.repository.getLogger("Marionette");
// Append only once to avoid duplicated output after listener.js gets reloaded
if (logger.ownAppenders.length == 0) {
logger.addAppender(new Log.DumpAppender());
}
-var modalHandler = function() {
+const modalHandler = function() {
// This gets called on the system app only since it receives the
// mozbrowserprompt event
sendSyncMessage("Marionette:switchedToFrame",
{frameValue: null, storePrevious: true});
let isLocal = sendSyncMessage("MarionetteFrame:handleModal", {})[0].value;
if (isLocal) {
previousContainer = curContainer;
}
curContainer = {frame: content, shadowRoot: null};
};
// sandbox storage and name of the current sandbox
-var sandboxes = new Sandboxes(() => curContainer.frame);
-var sandboxName = "default";
+const sandboxes = new Sandboxes(() => curContainer.frame);
+let sandboxName = "default";
/**
* The load listener singleton helps to keep track of active page load
* activities, and can be used by any command which might cause a navigation
* to happen. In the specific case of a reload of the frame script it allows
* to continue observing the current page load.
*/
-var loadListener = {
+const loadListener = {
commandID: null,
seenBeforeUnload: false,
seenUnload: false,
timeout: null,
timerPageLoad: null,
timerPageUnload: null,
/**
@@ -538,41 +539,41 @@ function addMessageListenerId(messageNam
/**
* Remove a message listener that's tied to our listenerId.
*/
function removeMessageListenerId(messageName, handler) {
removeMessageListener(messageName + listenerId, handler);
}
-var getPageSourceFn = dispatch(getPageSource);
-var getActiveElementFn = dispatch(getActiveElement);
-var getElementAttributeFn = dispatch(getElementAttribute);
-var getElementPropertyFn = dispatch(getElementProperty);
-var getElementTextFn = dispatch(getElementText);
-var getElementTagNameFn = dispatch(getElementTagName);
-var getElementRectFn = dispatch(getElementRect);
-var isElementEnabledFn = dispatch(isElementEnabled);
-var findElementContentFn = dispatch(findElementContent);
-var findElementsContentFn = dispatch(findElementsContent);
-var isElementSelectedFn = dispatch(isElementSelected);
-var clearElementFn = dispatch(clearElement);
-var isElementDisplayedFn = dispatch(isElementDisplayed);
-var getElementValueOfCssPropertyFn = dispatch(getElementValueOfCssProperty);
-var switchToShadowRootFn = dispatch(switchToShadowRoot);
-var singleTapFn = dispatch(singleTap);
-var takeScreenshotFn = dispatch(takeScreenshot);
-var performActionsFn = dispatch(performActions);
-var releaseActionsFn = dispatch(releaseActions);
-var actionChainFn = dispatch(actionChain);
-var multiActionFn = dispatch(multiAction);
-var executeFn = dispatch(execute);
-var executeInSandboxFn = dispatch(executeInSandbox);
-var sendKeysToElementFn = dispatch(sendKeysToElement);
-var reftestWaitFn = dispatch(reftestWait);
+let getPageSourceFn = dispatch(getPageSource);
+let getActiveElementFn = dispatch(getActiveElement);
+let getElementAttributeFn = dispatch(getElementAttribute);
+let getElementPropertyFn = dispatch(getElementProperty);
+let getElementTextFn = dispatch(getElementText);
+let getElementTagNameFn = dispatch(getElementTagName);
+let getElementRectFn = dispatch(getElementRect);
+let isElementEnabledFn = dispatch(isElementEnabled);
+let findElementContentFn = dispatch(findElementContent);
+let findElementsContentFn = dispatch(findElementsContent);
+let isElementSelectedFn = dispatch(isElementSelected);
+let clearElementFn = dispatch(clearElement);
+let isElementDisplayedFn = dispatch(isElementDisplayed);
+let getElementValueOfCssPropertyFn = dispatch(getElementValueOfCssProperty);
+let switchToShadowRootFn = dispatch(switchToShadowRoot);
+let singleTapFn = dispatch(singleTap);
+let takeScreenshotFn = dispatch(takeScreenshot);
+let performActionsFn = dispatch(performActions);
+let releaseActionsFn = dispatch(releaseActions);
+let actionChainFn = dispatch(actionChain);
+let multiActionFn = dispatch(multiAction);
+let executeFn = dispatch(execute);
+let executeInSandboxFn = dispatch(executeInSandbox);
+let sendKeysToElementFn = dispatch(sendKeysToElement);
+let reftestWaitFn = dispatch(reftestWait);
/**
* Start all message listeners
*/
function startListeners() {
addMessageListenerId("Marionette:newSession", newSession);
addMessageListenerId("Marionette:execute", executeFn);
addMessageListenerId("Marionette:executeInSandbox", executeInSandboxFn);
@@ -1645,17 +1646,17 @@ function switchToFrame(msg) {
}
if (foundFrame === null) {
// Either the frame has been removed or we have a OOP frame
// so lets just get all the iframes and do a quick loop before
// throwing in the towel
const doc = curContainer.frame.document;
let iframes = doc.getElementsByTagName("iframe");
- for (var i = 0; i < iframes.length; i++) {
+ for (let i = 0; i < iframes.length; i++) {
let frameEl = iframes[i];
let wrappedEl = new XPCNativeWrapper(frameEl);
let wrappedWanted = new XPCNativeWrapper(wantedFrame);
if (wrappedEl == wrappedWanted) {
curContainer.frame = iframes[i];
foundFrame = i;
}
}
--- a/testing/marionette/message.js
+++ b/testing/marionette/message.js
@@ -1,15 +1,15 @@
/* 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";
-var {utils: Cu} = Components;
+const {utils: Cu} = Components;
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("chrome://marionette/content/assert.js");
Cu.import("chrome://marionette/content/error.js");
this.EXPORTED_SYMBOLS = [
"Command",
--- a/testing/marionette/proxy.js
+++ b/testing/marionette/proxy.js
@@ -19,17 +19,17 @@ this.EXPORTED_SYMBOLS = ["proxy"];
const uuidgen = Cc["@mozilla.org/uuid-generator;1"]
.getService(Ci.nsIUUIDGenerator);
const logger = Log.repository.getLogger("Marionette");
// Proxy handler that traps requests to get a property. Will prioritise
// properties that exist on the object's own prototype.
-var ownPriorityGetterTrap = {
+const ownPriorityGetterTrap = {
get: (obj, prop) => {
if (obj.hasOwnProperty(prop)) {
return obj[prop];
}
return (...args) => obj.send(prop, args);
},
};