Bug 1367235 - Enable eslint on testing/xpcshell - mechanical updates; r=Standard8

This commit is contained in:
Geoff Brown 2017-05-25 07:32:42 -06:00
parent 4e7a503b65
commit 6fe3dae59f
14 changed files with 87 additions and 91 deletions

View File

@ -37,7 +37,6 @@ python/**
rdf/**
servo/**
startupcache/**
testing/**
tools/update-packaging/**
uriloader/**
view/**
@ -295,6 +294,19 @@ security/nss/**
services/sync/modules/constants.js
services/sync/services-sync.js
# testing/ exclusions
testing/firefox-ui/**
testing/marionette/**
testing/mochitest/**
testing/modules/**
testing/mozbase/**
testing/profiles/**
testing/specialpowers/**
testing/talos/**
testing/web-platform/**
testing/xpcshell/moz-http2/**
testing/xpcshell/node-http2/**
# Third party services
services/common/kinto-http-client.js
services/common/kinto-offline-client.js

View File

@ -2,7 +2,7 @@
* 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';
"use strict";
const { Promise } = Cu.import("resource://gre/modules/Promise.jsm", {});
var { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
@ -19,8 +19,7 @@ const { BrowserTabList } = devtools.require("devtools/server/actors/webbrowser")
* Construct a root actor appropriate for use in a server running xpcshell
* tests. <snip boilerplate> :)
*/
function createRootActor(connection)
{
function createRootActor(connection) {
let parameters = {
tabList: new XPCSTTabList(connection),
globalActorFactories: DebuggerServer.globalActorFactories,
@ -37,8 +36,7 @@ function createRootActor(connection)
* A "stub" TabList implementation that provides no tabs.
*/
function XPCSTTabList(connection)
{
function XPCSTTabList(connection) {
BrowserTabList.call(this, connection);
}

View File

@ -0,0 +1,7 @@
"use strict";
module.exports = {
"extends": [
"plugin:mozilla/xpcshell-test"
]
};

View File

@ -4,8 +4,7 @@
var {classes: Cc, interfaces: Ci} = Components;
function check_profile_dir(profd)
{
function check_profile_dir(profd) {
Assert.ok(profd.exists());
Assert.ok(profd.isDirectory());
let dirSvc = Cc["@mozilla.org/file/directory_service;1"]
@ -17,8 +16,7 @@ function check_profile_dir(profd)
Assert.ok(profd.equals(profd2));
}
function check_do_get_profile(fireProfileAfterChange)
{
function check_do_get_profile(fireProfileAfterChange) {
const observedTopics = new Map([
["profile-do-change", 0],
["profile-after-change", 0],
@ -27,7 +25,7 @@ function check_do_get_profile(fireProfileAfterChange)
const obs = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
for (let [topic,] of observedTopics) {
for (let [topic, ] of observedTopics) {
obs.addObserver(() => {
let val = observedTopics.get(topic) + 1;
observedTopics.set(topic, val);

View File

@ -4,7 +4,7 @@
function run_test() {
let env = Components.classes["@mozilla.org/process/environment;1"]
.getService(Components.interfaces.nsIEnvironment);
do_check_throws_nsIException(function () {
do_check_throws_nsIException(function() {
env.QueryInterface(Components.interfaces.nsIFile);
}, "NS_NOINTERFACE");
}

View File

@ -2,7 +2,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ */
function run_test() {
do_check_throws_nsIException(function () {
do_check_throws_nsIException(function() {
throw Error("I find your relaxed dishabille unpalatable");
}, "NS_NOINTERFACE");
}

View File

@ -2,13 +2,13 @@
* http://creativecommons.org/publicdomain/zero/1.0/ */
function run_test() {
do_check_matches({x:1}, {x:1});
do_check_matches({x: 1}, {x: 1});
// Property order is irrelevant.
do_check_matches({x:"foo", y:"bar"}, {y:"bar", x:"foo"});// pass
do_check_matches({x: "foo", y: "bar"}, {y: "bar", x: "foo"});// pass
// Patterns nest.
do_check_matches({a:1, b:{c:2,d:3}}, {a:1, b:{c:2,d:3}});
do_check_matches({a: 1, b: {c: 2, d: 3}}, {a: 1, b: {c: 2, d: 3}});
do_check_matches([3,4,5], [3,4,5]);
do_check_matches([3, 4, 5], [3, 4, 5]);
}

View File

@ -2,11 +2,11 @@
* http://creativecommons.org/publicdomain/zero/1.0/ */
function run_test() {
do_check_matches({x:1}, {}); // fail: all pattern props required
do_check_matches({x:1}, {x:2}); // fail: values must match
do_check_matches({x:undefined}, {});
do_check_matches({x: 1}, {}); // fail: all pattern props required
do_check_matches({x: 1}, {x: 2}); // fail: values must match
do_check_matches({x: undefined}, {});
// 'length' property counts, even if non-enumerable.
do_check_matches([3,4,5], [3,5,5]); // fail; value doesn't match
do_check_matches([3,4,5], [3,4,5,6]);// fail; length doesn't match
do_check_matches([3, 4, 5], [3, 5, 5]); // fail; value doesn't match
do_check_matches([3, 4, 5], [3, 4, 5, 6]);// fail; length doesn't match
}

View File

@ -10,8 +10,8 @@
*/
function run_test() {
do_check_true(typeof(this['MODULE_IMPORTED']) == "undefined");
do_check_true(typeof(this['MODULE_URI']) == "undefined");
do_check_true(typeof(this["MODULE_IMPORTED"]) == "undefined");
do_check_true(typeof(this["MODULE_URI"]) == "undefined");
let uri = "resource://test/import_module.jsm";
Components.utils.import(uri);
do_check_true(MODULE_URI == uri);

View File

@ -13,9 +13,8 @@ function run_test() {
try {
load("file_that_does_not_exist.js");
subscriptLoaded = true;
}
catch (ex) {
do_check_eq(ex.message.substring(0,16), "cannot open file");
} catch (ex) {
do_check_eq(ex.message.substring(0, 16), "cannot open file");
}
do_check_false(subscriptLoaded, "load() should throw an error");
}

View File

@ -4,8 +4,7 @@
* 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/. */
function run_test()
{
function run_test() {
load("check_profile.js");
check_do_get_profile(false);
}

View File

@ -4,8 +4,7 @@
* 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/. */
function run_test()
{
function run_test() {
load("check_profile.js");
check_do_get_profile(true);
}

View File

@ -4,9 +4,9 @@
* 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/. */
/* This is the most basic testcase. It makes some trivial assertions,
* then sets a timeout, and exits the test harness when that timeout
* fires. This is meant to demonstrate that there is a complete event
/* This is the most basic testcase. It makes some trivial assertions,
* then sets a timeout, and exits the test harness when that timeout
* fires. This is meant to demonstrate that there is a complete event
* system available to test scripts.
* Available functions are described at:
* http://developer.mozilla.org/en/docs/Writing_xpcshell-based_unit_tests

View File

@ -38,13 +38,13 @@ var Assert = new AssertCls(function(err, message, stack) {
});
var _add_params = function (params) {
var _add_params = function(params) {
if (typeof _XPCSHELL_PROCESS != "undefined") {
params.xpcshell_process = _XPCSHELL_PROCESS;
}
};
var _dumpLog = function (raw_msg) {
var _dumpLog = function(raw_msg) {
dump("\n" + JSON.stringify(raw_msg) + "\n");
}
@ -66,8 +66,7 @@ try {
runningInParent = Components.classes["@mozilla.org/xre/runtime;1"].
getService(Components.interfaces.nsIXULRuntime).processType
== Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
}
catch (e) { }
} catch (e) { }
// Only if building of places is enabled.
if (runningInParent &&
@ -93,8 +92,7 @@ try {
prefs.setCharPref("network.dns.ipv4OnlyDomains", "localhost");
}
}
}
catch (e) { }
} catch (e) { }
// Configure crash reporting, if possible
// We rely on the Python harness to set MOZ_CRASHREPORTER,
@ -110,8 +108,7 @@ try {
crashReporter.UpdateCrashEventsDir();
crashReporter.minidumpPath = do_get_minidumpdir();
}
}
catch (e) { }
} catch (e) { }
// Configure a console listener so messages sent to it are logged as part
// of the test.
@ -122,14 +119,14 @@ try {
}
let listener = {
QueryInterface : function(iid) {
QueryInterface: function(iid) {
if (!iid.equals(Components.interfaces.nsISupports) &&
!iid.equals(Components.interfaces.nsIConsoleListener)) {
throw Components.results.NS_NOINTERFACE;
}
return this;
},
observe : function (msg) {
observe: function(msg) {
if (typeof do_print === "function")
do_print("CONSOLE_MESSAGE: (" + levelNames[msg.logLevel] + ") " + msg.toString());
}
@ -240,8 +237,7 @@ var _fakeIdleService = {
return this.registrar.contractIDToCID(this.contractID);
},
activate: function FIS_activate()
{
activate: function FIS_activate() {
if (!this.originalFactory) {
// Save original factory.
this.originalFactory =
@ -256,8 +252,7 @@ var _fakeIdleService = {
}
},
deactivate: function FIS_deactivate()
{
deactivate: function FIS_deactivate() {
if (this.originalFactory) {
// Unregister the mock.
this.registrar.unregisterFactory(this.CID, this.factory);
@ -270,14 +265,13 @@ var _fakeIdleService = {
factory: {
// nsIFactory
createInstance: function (aOuter, aIID)
{
createInstance: function(aOuter, aIID) {
if (aOuter) {
throw Components.results.NS_ERROR_NO_AGGREGATION;
}
return _fakeIdleService.QueryInterface(aIID);
},
lockFactory: function (aLock) {
lockFactory: function(aLock) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
},
QueryInterface: function(aIID) {
@ -293,8 +287,8 @@ var _fakeIdleService = {
get idleTime() {
return 0;
},
addIdleObserver: function () {},
removeIdleObserver: function () {},
addIdleObserver: function() {},
removeIdleObserver: function() {},
QueryInterface: function(aIID) {
// Useful for testing purposes, see test_get_idle.js.
@ -448,7 +442,7 @@ function _setupDebuggerServer(breakpointFiles, callback) {
function _initDebugging(port) {
let initialized = false;
let DebuggerServer = _setupDebuggerServer(_TEST_FILE, () => {initialized = true;});
let DebuggerServer = _setupDebuggerServer(_TEST_FILE, () => { initialized = true; });
do_print("");
do_print("*******************************************************************");
@ -505,7 +499,7 @@ function _execute_test() {
_PromiseTestUtils.Assert = Assert;
let coverageCollector = null;
if (typeof _JSCOV_DIR === 'string') {
if (typeof _JSCOV_DIR === "string") {
let _CoverageCollector = Components.utils.import("resource://testing-common/CoverageUtils.jsm", {}).CoverageCollector;
coverageCollector = new _CoverageCollector(_JSCOV_DIR);
}
@ -522,7 +516,7 @@ function _execute_test() {
}
if (_gTestHasOnly) {
_gTests = _gTests.filter(([props,]) => {
_gTests = _gTests.filter(([props, ]) => {
return ("_only" in props) && props._only;
});
}
@ -666,7 +660,7 @@ function _wrap_with_quotes_if_necessary(val) {
return typeof val == "string" ? '"' + val + '"' : val;
}
/************** Functions to be used from the tests **************/
/* ************* Functions to be used from the tests ************* */
/**
* Prints a message to the output log.
@ -711,14 +705,13 @@ function do_execute_soon(callback, aName) {
let stack = e.stack ? _format_stack(e.stack) : null;
_testLogger.testStatus(_TEST_NAME,
funcName,
'FAIL',
'PASS',
"FAIL",
"PASS",
_exception_message(e),
stack);
_do_quit();
}
}
finally {
} finally {
do_test_finished(funcName);
}
}
@ -930,7 +923,7 @@ function do_check_null(condition, stack) {
Assert.equal(condition, null);
}
function todo_check_null(condition, stack=Components.stack.caller) {
function todo_check_null(condition, stack = Components.stack.caller) {
todo_check_eq(condition, null, stack);
}
function do_check_matches(pattern, value) {
@ -940,10 +933,9 @@ function do_check_matches(pattern, value) {
// Check that |func| throws an nsIException that has
// |Components.results[resultName]| as the value of its 'result' property.
function do_check_throws_nsIException(func, resultName,
stack=Components.stack.caller, todo=false)
{
stack = Components.stack.caller, todo = false) {
let expected = Components.results[resultName];
if (typeof expected !== 'number') {
if (typeof expected !== "number") {
do_throw("do_check_throws_nsIException requires a Components.results" +
" property name, not " + uneval(resultName), stack);
}
@ -972,16 +964,15 @@ function do_check_throws_nsIException(func, resultName,
// Produce a human-readable form of |exception|. This looks up
// Components.results values, tries toString methods, and so on.
function legible_exception(exception)
{
function legible_exception(exception) {
switch (typeof exception) {
case 'object':
case "object":
if (exception instanceof Components.interfaces.nsIException) {
return "nsIException instance: " + uneval(exception.toString());
}
return exception.toString();
case 'number':
case "number":
for (let name in Components.results) {
if (exception === Components.results[name]) {
return "Components.results." + name;
@ -995,14 +986,14 @@ function legible_exception(exception)
}
function do_check_instanceof(value, constructor,
stack=Components.stack.caller, todo=false) {
stack = Components.stack.caller, todo = false) {
do_report_result(value instanceof constructor,
"value should be an instance of " + constructor.name,
stack, todo);
}
function todo_check_instanceof(value, constructor,
stack=Components.stack.caller) {
stack = Components.stack.caller) {
do_check_instanceof(value, constructor, stack, true);
}
@ -1047,8 +1038,7 @@ function do_get_file(path, allowNonexistent) {
}
return lf;
}
catch (ex) {
} catch (ex) {
do_throw(ex.toString(), Components.stack.caller);
}
@ -1090,7 +1080,7 @@ function do_parse_document(aPath, aType) {
}
let file = do_get_file(aPath),
ios = Components.classes['@mozilla.org/network/io-service;1']
ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService),
url = ios.newFileURI(file).spec;
file = null;
@ -1113,8 +1103,7 @@ function do_parse_document(aPath, aType) {
* @param aFunction
* The function to be called when the test harness has finished running.
*/
function do_register_cleanup(aFunction)
{
function do_register_cleanup(aFunction) {
_cleanupFunctions.push(aFunction);
}
@ -1236,8 +1225,7 @@ function do_get_profile(notifyProfileAfterChange = false) {
* (Note that you may use sendCommand without calling this function first; you
* simply won't have any of the functions in this file available.)
*/
function do_load_child_test_harness()
{
function do_load_child_test_harness() {
// Make sure this isn't called from child process
if (!runningInParent) {
do_throw("run_test_in_child cannot be called from child!");
@ -1259,7 +1247,7 @@ function do_load_child_test_harness()
+ "const _JSDEBUGGER_PORT=0; "
+ "const _XPCSHELL_PROCESS='child';";
if (typeof _JSCOV_DIR === 'string') {
if (typeof _JSCOV_DIR === "string") {
command += " const _JSCOV_DIR=" + uneval(_JSCOV_DIR) + ";";
}
@ -1284,12 +1272,11 @@ function do_load_child_test_harness()
* complete. If provided, the function must call do_test_finished();
* @return Promise Resolved when the test in the child is complete.
*/
function run_test_in_child(testFile, optionalCallback)
{
function run_test_in_child(testFile, optionalCallback) {
return new Promise((resolve) => {
var callback = () => {
resolve();
if (typeof optionalCallback == 'undefined') {
if (typeof optionalCallback == "undefined") {
do_test_finished();
} else {
optionalCallback();
@ -1317,8 +1304,7 @@ function run_test_in_child(testFile, optionalCallback)
* the function must call do_test_finished().
* @return Promise Promise that is resolved when the message is received.
*/
function do_await_remote_message(name, optionalCallback)
{
function do_await_remote_message(name, optionalCallback) {
return new Promise((resolve) => {
var listener = {
receiveMessage: function(message) {
@ -1354,10 +1340,10 @@ function do_send_remote_message(name) {
var sender;
if (runningInParent) {
mm = Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(Ci.nsIMessageBroadcaster);
sender = 'broadcastAsyncMessage';
sender = "broadcastAsyncMessage";
} else {
mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
sender = 'sendAsyncMessage';
sender = "sendAsyncMessage";
}
mm[sender](name);
}
@ -1518,21 +1504,19 @@ var _gRunningTest = null;
var _gTestIndex = 0; // The index of the currently running test.
var _gTaskRunning = false;
var _gTestHasOnly = false;
function run_next_test()
{
function run_next_test() {
if (_gTaskRunning) {
throw new Error("run_next_test() called from an add_task() test function. " +
"run_next_test() should not be called from inside add_task() " +
"under any circumstances!");
}
function _run_next_test()
{
function _run_next_test() {
if (_gTestIndex < _gTests.length) {
// Check for uncaught rejections as early and often as possible.
_PromiseTestUtils.assertNoUncaughtRejections();
let _properties;
[_properties, _gRunningTest,] = _gTests[_gTestIndex++];
[_properties, _gRunningTest, ] = _gTests[_gTestIndex++];
if (typeof(_properties.skip_if) == "function" && _properties.skip_if()) {
let _condition = _properties.skip_if.toSource().replace(/\(\)\s*=>\s*/, "");
let _message = _gRunningTest.name