From 28220f084ae31f796ebfbe02deb580119fa494e3 Mon Sep 17 00:00:00 2001 From: Mithilan Date: Thu, 26 Oct 2017 16:56:18 -0400 Subject: [PATCH] Bug 1403956 - Enable ESLint from chrome/ directory. r=standard8 MozReview-Commit-ID: LHSMjEKeNAe --HG-- extra : rebase_source : 36c231e48283dc433fee748b8fbf4cf4ab13dd14 --- .eslintignore | 1 - chrome/test/.eslintrc.js | 7 ++++ chrome/test/unit/head_crtestutils.js | 3 +- chrome/test/unit/test_abi.js | 3 +- chrome/test/unit/test_bug292789.js | 6 +-- chrome/test/unit/test_bug380398.js | 17 +++------ chrome/test/unit/test_bug397073.js | 17 +++------ chrome/test/unit/test_bug399707.js | 17 +++------ chrome/test/unit/test_bug401153.js | 12 ++---- chrome/test/unit/test_bug415367.js | 11 ++---- chrome/test/unit/test_bug564667.js | 15 +++----- chrome/test/unit/test_bug848297.js | 4 +- chrome/test/unit/test_crlf.js | 5 +-- .../unit/test_data_protocol_registration.js | 18 ++++----- .../test/unit/test_no_remote_registration.js | 38 ++++++++----------- chrome/test/unit/test_resolve_uris.js | 14 +++---- chrome/test/unit_ipc/test_resolve_uris_ipc.js | 2 +- 17 files changed, 75 insertions(+), 115 deletions(-) create mode 100644 chrome/test/.eslintrc.js diff --git a/.eslintignore b/.eslintignore index fc801a815c8c..cdd0426e798b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -11,7 +11,6 @@ obj*/** # We ignore all these directories by default, until we get them enabled. # If you are enabling a directory, please add directory specific exclusions # below. -chrome/** docshell/** editor/** extensions/cookie/** diff --git a/chrome/test/.eslintrc.js b/chrome/test/.eslintrc.js new file mode 100644 index 000000000000..5de3f1618a1c --- /dev/null +++ b/chrome/test/.eslintrc.js @@ -0,0 +1,7 @@ +"use strict"; + +module.exports = { + "extends": [ + "plugin:mozilla/xpcshell-test" + ] +}; \ No newline at end of file diff --git a/chrome/test/unit/head_crtestutils.js b/chrome/test/unit/head_crtestutils.js index e3be96fd23e6..69f62e36da7e 100644 --- a/chrome/test/unit/head_crtestutils.js +++ b/chrome/test/unit/head_crtestutils.js @@ -6,8 +6,7 @@ var Ci = Components.interfaces; var Cr = Components.results; -function registerManifests(manifests) -{ +function registerManifests(manifests) { var reg = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); for (var manifest of manifests) reg.autoRegister(manifest); diff --git a/chrome/test/unit/test_abi.js b/chrome/test/unit/test_abi.js index 076fd3215f8a..84737e9c0a6f 100644 --- a/chrome/test/unit/test_abi.js +++ b/chrome/test/unit/test_abi.js @@ -15,8 +15,7 @@ function is_registered(name) { try { var d = catman.getCategoryEntry("abitest", name); return d == "found"; - } - catch (e) { + } catch (e) { return false; } } diff --git a/chrome/test/unit/test_bug292789.js b/chrome/test/unit/test_bug292789.js index 29b19c1e74f0..872246042df3 100644 --- a/chrome/test/unit/test_bug292789.js +++ b/chrome/test/unit/test_bug292789.js @@ -12,15 +12,13 @@ registerManifests(MANIFESTS); var gIOS; var gCR; -function check_accessibility(spec, desired) -{ +function check_accessibility(spec, desired) { var uri = gIOS.newURI(spec); var actual = gCR.allowContentToAccess(uri); do_check_eq(desired, actual); } -function run_test() -{ +function run_test() { gIOS = Cc["@mozilla.org/network/io-service;1"]. getService(Ci.nsIIOService); gCR = Cc["@mozilla.org/chrome/chrome-registry;1"]. diff --git a/chrome/test/unit/test_bug380398.js b/chrome/test/unit/test_bug380398.js index 42b81e66672b..46b43d2e32b9 100644 --- a/chrome/test/unit/test_bug380398.js +++ b/chrome/test/unit/test_bug380398.js @@ -27,31 +27,26 @@ chromeReg.checkForNewChrome(); var target = gIOS.newFileURI(do_get_file("data")); target = target.spec + "test/test.xul"; -function test_succeeded_mapping(namespace) -{ +function test_succeeded_mapping(namespace) { var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul"); try { var result = chromeReg.convertChromeURL(uri); do_check_eq(result.spec, target); - } - catch (ex) { + } catch (ex) { do_throw(namespace); } } -function test_failed_mapping(namespace) -{ +function test_failed_mapping(namespace) { var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul"); try { - var result = chromeReg.convertChromeURL(uri); + chromeReg.convertChromeURL(uri); do_throw(namespace); - } - catch (ex) { + } catch (ex) { } } -function run_test() -{ +function run_test() { test_succeeded_mapping("test1"); test_succeeded_mapping("test2"); test_succeeded_mapping("test3"); diff --git a/chrome/test/unit/test_bug397073.js b/chrome/test/unit/test_bug397073.js index e732cd36381f..ead7d3120ac2 100644 --- a/chrome/test/unit/test_bug397073.js +++ b/chrome/test/unit/test_bug397073.js @@ -27,31 +27,26 @@ chromeReg.checkForNewChrome(); var target = gIOS.newFileURI(do_get_file("data")); target = target.spec + "test/test.xul"; -function test_succeeded_mapping(namespace) -{ +function test_succeeded_mapping(namespace) { var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul"); try { var result = chromeReg.convertChromeURL(uri); do_check_eq(result.spec, target); - } - catch (ex) { + } catch (ex) { do_throw(namespace); } } -function test_failed_mapping(namespace) -{ +function test_failed_mapping(namespace) { var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul"); try { - var result = chromeReg.convertChromeURL(uri); + chromeReg.convertChromeURL(uri); do_throw(namespace); - } - catch (ex) { + } catch (ex) { } } -function run_test() -{ +function run_test() { test_succeeded_mapping("test1"); test_succeeded_mapping("test2"); diff --git a/chrome/test/unit/test_bug399707.js b/chrome/test/unit/test_bug399707.js index 126770a3e0a3..3b8c889a91f3 100644 --- a/chrome/test/unit/test_bug399707.js +++ b/chrome/test/unit/test_bug399707.js @@ -26,31 +26,26 @@ chromeReg.checkForNewChrome(); var target = gIOS.newFileURI(do_get_file("data")); target = target.spec + "test/test.xul"; -function test_succeeded_mapping(namespace) -{ +function test_succeeded_mapping(namespace) { var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul"); try { var result = chromeReg.convertChromeURL(uri); do_check_eq(result.spec, target); - } - catch (ex) { + } catch (ex) { do_throw(namespace); } } -function test_failed_mapping(namespace) -{ +function test_failed_mapping(namespace) { var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul"); try { - var result = chromeReg.convertChromeURL(uri); + chromeReg.convertChromeURL(uri); do_throw(namespace); - } - catch (ex) { + } catch (ex) { } } -function run_test() -{ +function run_test() { test_succeeded_mapping("test1"); test_succeeded_mapping("test2"); test_succeeded_mapping("test3"); diff --git a/chrome/test/unit/test_bug401153.js b/chrome/test/unit/test_bug401153.js index 6e70567d5610..e1ca72b1f0d9 100644 --- a/chrome/test/unit/test_bug401153.js +++ b/chrome/test/unit/test_bug401153.js @@ -26,27 +26,23 @@ chromeReg.checkForNewChrome(); var rph = gIOS.getProtocolHandler("resource") .QueryInterface(Ci.nsIResProtocolHandler); -function test_succeeded_mapping(namespace, target) -{ +function test_succeeded_mapping(namespace, target) { try { do_check_true(rph.hasSubstitution(namespace)); var uri = gIOS.newURI("resource://" + namespace); dump("### checking for " + target + ", getting " + rph.resolveURI(uri) + "\n"); do_check_eq(rph.resolveURI(uri), target); - } - catch (ex) { + } catch (ex) { dump(ex + "\n"); do_throw(namespace); } } -function test_failed_mapping(namespace) -{ +function test_failed_mapping(namespace) { do_check_false(rph.hasSubstitution(namespace)); } -function run_test() -{ +function run_test() { var data = gIOS.newFileURI(do_get_file("data")).spec; test_succeeded_mapping("test1", data + "test1/"); test_succeeded_mapping("test3", "jar:" + data + "test3.jar!/resources/"); diff --git a/chrome/test/unit/test_bug415367.js b/chrome/test/unit/test_bug415367.js index ee1115d48b2c..ed2cd53c2064 100644 --- a/chrome/test/unit/test_bug415367.js +++ b/chrome/test/unit/test_bug415367.js @@ -6,8 +6,7 @@ var gIOS = Cc["@mozilla.org/network/io-service;1"] .getService(Ci.nsIIOService); -function test_uri(obj) -{ +function test_uri(obj) { var uri = null; var failed = false; var message = ""; @@ -17,8 +16,7 @@ function test_uri(obj) failed = true; message = obj.uri + " should not be accepted as a valid URI"; } - } - catch (ex) { + } catch (ex) { if (obj.result) { failed = true; message = obj.uri + " should be accepted as a valid URI"; @@ -32,8 +30,7 @@ function test_uri(obj) } } -function run_test() -{ +function run_test() { var tests = [ {uri: "chrome://blah/content/blah.xul", result: true}, {uri: "chrome://blah/content/:/blah/blah.xul", result: false}, @@ -43,6 +40,6 @@ function run_test() {uri: "chrome://blah/content/blah.xul?param=:/blah/", result: true}, {uri: "chrome://blah/content/blah.xul?param=%252e%252e/blah/", result: true}, ]; - for (var i = 0; i < tests.length; ++ i) + for (var i = 0; i < tests.length; ++i) test_uri(tests[i]); } diff --git a/chrome/test/unit/test_bug564667.js b/chrome/test/unit/test_bug564667.js index 4e4671f2d213..a648527db329 100644 --- a/chrome/test/unit/test_bug564667.js +++ b/chrome/test/unit/test_bug564667.js @@ -22,8 +22,7 @@ function test_mapping(chromeURL, target) { try { var result = gCR.convertChromeURL(uri); do_check_eq(result.spec, target); - } - catch (ex) { + } catch (ex) { do_throw(chromeURL + " not Registered"); } } @@ -34,10 +33,9 @@ function test_mapping(chromeURL, target) { function test_removed_mapping(chromeURL, target) { var uri = gIOS.newURI(chromeURL); try { - var result = gCR.convertChromeURL(uri); + gCR.convertChromeURL(uri); do_throw(chromeURL + " not removed"); - } - catch (ex) { + } catch (ex) { // This should throw } } @@ -48,11 +46,8 @@ function test_removed_mapping(chromeURL, target) { * * @param type The type of overlay: overlay|style */ -function test_no_overlays(chromeURL, target, type) { - var type = type || "overlay"; +function test_no_overlays(chromeURL, target, type = "overlay") { var uri = gIOS.newURI(chromeURL); - var present = false, elem; - var overlays = (type == "overlay") ? gCR.getXULOverlays(uri) : gCR.getStyleOverlays(uri); @@ -84,7 +79,7 @@ function testManifest(manifestPath, baseURI) { test_mapping("chrome://test2/locale", baseURI + "test/test2.dtd"); // Test Adding Override - test_mapping("chrome://testOverride/content", 'file:///test1/override') + test_mapping("chrome://testOverride/content", "file:///test1/override") // Test Not-Adding Overlays test_no_overlays("chrome://test1/content/overlay.xul", diff --git a/chrome/test/unit/test_bug848297.js b/chrome/test/unit/test_bug848297.js index 0875370f7913..eddf72c09b81 100644 --- a/chrome/test/unit/test_bug848297.js +++ b/chrome/test/unit/test_bug848297.js @@ -37,12 +37,12 @@ function run_test() { do_check_eq(chromeReg.getSelectedLocale("basepack"), "en-US"); do_check_eq(chromeReg.getSelectedLocale("overpack"), "de"); do_check_matches(enum_to_array(chromeReg.getLocalesForPackage("basepack")), - ['en-US', 'fr']); + ["en-US", "fr"]); // with override prefService.setCharPref("chrome.override_package.basepack", "overpack"); do_check_eq(chromeReg.getSelectedLocale("basepack"), "de"); do_check_matches(enum_to_array(chromeReg.getLocalesForPackage("basepack")), - ['de', 'en-US']); + ["de", "en-US"]); } diff --git a/chrome/test/unit/test_crlf.js b/chrome/test/unit/test_crlf.js index b01336a71dbb..90ed175fde29 100644 --- a/chrome/test/unit/test_crlf.js +++ b/chrome/test/unit/test_crlf.js @@ -1,7 +1,6 @@ registerManifests([do_get_file("data/test_crlf.manifest")]); -function run_test() -{ +function run_test() { let cr = Cc["@mozilla.org/chrome/chrome-registry;1"]. getService(Ci.nsIChromeRegistry); @@ -10,6 +9,6 @@ function run_test() let sourceURI = ios.newURI("chrome://test_crlf/content/"); // this throws for packages that are not registered let file = cr.convertChromeURL(sourceURI).QueryInterface(Ci.nsIFileURL).file; - + do_check_true(file.equals(do_get_file("data/test_crlf.xul", true))); } diff --git a/chrome/test/unit/test_data_protocol_registration.js b/chrome/test/unit/test_data_protocol_registration.js index ba9f5baedd47..7d22f93a2f2f 100644 --- a/chrome/test/unit/test_data_protocol_registration.js +++ b/chrome/test/unit/test_data_protocol_registration.js @@ -9,11 +9,10 @@ var manifests = [ ]; registerManifests(manifests); -function run_test() -{ +function run_test() { const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator); - Components.utils.import("resource://testing-common/AppInfo.jsm", this); + let newAppInfo = Components.utils.import("resource://testing-common/AppInfo.jsm", {}).newAppInfo; let XULAppInfo = newAppInfo({ name: "XPCShell", ID: "{39885e5f-f6b4-4e2a-87e5-6259ecf79011}", @@ -26,7 +25,7 @@ function run_test() CID: uuidGenerator.generateUUID(), scheme: "XULAppInfo", contractID: XULAPPINFO_CONTRACTID, - createInstance: function (outer, iid) { + createInstance(outer, iid) { if (outer != null) throw Cr.NS_ERROR_NO_AGGREGATION; return XULAppInfo.QueryInterface(iid); @@ -58,17 +57,15 @@ function run_test() }); old_factories_inds.push(true); registrar.unregisterFactory(old_factories[i].CID, old_factories[i].factory); - } - else { + } else { dump(factory.scheme + " has never been registered. Registering...") old_factories.push({CID: "", factory: null}); old_factories_inds.push(false); } registrar.registerFactory(factory.CID, "test-" + factory.scheme, factory.contractID, factory); - } - else { - do_throw("CID " + factory.CID + " has already been registered!"); + } else { + do_throw("CID " + factory.CID + " has already been registered!"); } } @@ -88,8 +85,7 @@ function run_test() let uri = cr.convertChromeURL(sourceURI).spec; do_check_eq(expectedURI, uri); - } - catch (e) { + } catch (e) { dump(e + "\n"); do_throw("Should have registered our URI!"); } diff --git a/chrome/test/unit/test_no_remote_registration.js b/chrome/test/unit/test_no_remote_registration.js index 7473cb847d7e..97ecb5e1926d 100644 --- a/chrome/test/unit/test_no_remote_registration.js +++ b/chrome/test/unit/test_no_remote_registration.js @@ -3,6 +3,7 @@ * 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/. */ +/* globals newAppInfo */ var manifests = [ do_get_file("data/test_no_remote_registration.manifest"), @@ -11,8 +12,7 @@ registerManifests(manifests); Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); -function ProtocolHandler(aScheme, aFlags) -{ +function ProtocolHandler(aScheme, aFlags) { this.scheme = aScheme; this.protocolFlags = aFlags; this.contractID = "@mozilla.org/network/protocol;1?name=" + aScheme; @@ -22,8 +22,7 @@ ProtocolHandler.prototype = { defaultPort: -1, allowPort: () => false, - newURI: function(aSpec, aCharset, aBaseURI) - { + newURI(aSpec, aCharset, aBaseURI) { let uri = Cc["@mozilla.org/network/standard-url;1"]. createInstance(Ci.nsIURI); uri.spec = aSpec; @@ -33,8 +32,8 @@ ProtocolHandler.prototype = } return uri; }, - newChannel2: function() { throw Cr.NS_ERROR_NOT_IMPLEMENTED }, - newChannel: function() { throw Cr.NS_ERROR_NOT_IMPLEMENTED }, + newChannel2() { throw Cr.NS_ERROR_NOT_IMPLEMENTED }, + newChannel() { throw Cr.NS_ERROR_NOT_IMPLEMENTED }, QueryInterface: XPCOMUtils.generateQI([ Ci.nsIProtocolHandler ]) @@ -68,8 +67,7 @@ var testProtocols = [ shouldRegister: true }, ]; -function run_test() -{ +function run_test() { Components.utils.import("resource://testing-common/AppInfo.jsm", this); let XULAppInfo = newAppInfo({ name: "XPCShell", @@ -85,7 +83,7 @@ function run_test() CID: uuidGenerator.generateUUID(), scheme: "XULAppInfo", contractID: "@mozilla.org/xre/app-info;1", - createInstance: function (outer, iid) { + createInstance(outer, iid) { if (outer != null) throw Cr.NS_ERROR_NO_AGGREGATION; return XULAppInfo.QueryInterface(iid); @@ -102,8 +100,7 @@ function run_test() flags: testProtocols[i].flags, CID: testProtocols[i].CID, contractID: "@mozilla.org/network/protocol;1?name=" + testProtocols[i].scheme, - createInstance: function(aOuter, aIID) - { + createInstance(aOuter, aIID) { if (aOuter != null) throw Cr.NS_ERROR_NO_AGGREGATION; let handler = new ProtocolHandler(this.scheme, this.flags, this.CID); @@ -132,15 +129,13 @@ function run_test() old_factory.CID = registrar.contractIDToCID(XULAppInfoFactory.contractID); old_factory.factory = Components.manager.getClassObject(Cc[XULAppInfoFactory.contractID], Ci.nsIFactory); registrar.unregisterFactory(old_factory.CID, old_factory.factory); - } - else { + } else { dump(XULAppInfoFactory.scheme + " has never been registered. Registering...") } registrar.registerFactory(XULAppInfoFactory.CID, "test-" + XULAppInfoFactory.scheme, XULAppInfoFactory.contractID, XULAppInfoFactory); - } - else { - do_throw("CID " + XULAppInfoFactory.CID + " has already been registered!"); + } else { + do_throw("CID " + XULAppInfoFactory.CID + " has already been registered!"); } // Check for new chrome @@ -181,7 +176,7 @@ function run_test() case "resource": sourceURI = "resource://" + protocol.scheme + "/"; break; - }; + } try { let ios = Cc["@mozilla.org/network/io-service;1"]. getService(Ci.nsIIOService); @@ -193,22 +188,19 @@ function run_test() QueryInterface(Ci.nsIResProtocolHandler); // this throws for packages that are not registered uri = rph.resolveURI(sourceURI); - } - else { + } else { // this throws for packages that are not registered uri = cr.convertChromeURL(sourceURI).spec; } if (protocol.shouldRegister) { do_check_eq(expectedURI, uri); - } - else { + } else { // Overrides will not throw, so we'll get to here. We want to make // sure that the two strings are not the same in this situation. do_check_neq(expectedURI, uri); } - } - catch (e) { + } catch (e) { if (protocol.shouldRegister) { dump(e + "\n"); do_throw("Should have registered our URI for protocol " + diff --git a/chrome/test/unit/test_resolve_uris.js b/chrome/test/unit/test_resolve_uris.js index ad92e00a9821..282df07368a3 100644 --- a/chrome/test/unit/test_resolve_uris.js +++ b/chrome/test/unit/test_resolve_uris.js @@ -16,8 +16,7 @@ registerManifests(manifests); var ios = Cc["@mozilla.org/network/io-service;1"]. getService(Ci.nsIIOService); -function do_run_test() -{ +function do_run_test() { let cr = Cc["@mozilla.org/chrome/chrome-registry;1"]. getService(Ci.nsIChromeRegistry); @@ -62,7 +61,7 @@ function do_run_test() expectedURI = ios.newFileURI(manifestFile.parent).spec; sourceURI = "resource://foo/"; break; - }; + } try { sourceURI = ios.newURI(sourceURI); let uri; @@ -71,14 +70,12 @@ function do_run_test() let rph = ios.getProtocolHandler("resource"). QueryInterface(Ci.nsIResProtocolHandler); uri = rph.resolveURI(sourceURI); - } - else { + } else { uri = cr.convertChromeURL(sourceURI).spec; } - + do_check_eq(expectedURI, uri); - } - catch (e) { + } catch (e) { dump(e + "\n"); do_throw("Should have registered a handler for type '" + type + "'\n"); @@ -87,6 +84,7 @@ function do_run_test() } if (typeof run_test === "undefined") { + // eslint-disable-next-line no-native-reassign run_test = function() { do_run_test(); }; diff --git a/chrome/test/unit_ipc/test_resolve_uris_ipc.js b/chrome/test/unit_ipc/test_resolve_uris_ipc.js index 8babc23fd931..35eef62d1cee 100644 --- a/chrome/test/unit_ipc/test_resolve_uris_ipc.js +++ b/chrome/test/unit_ipc/test_resolve_uris_ipc.js @@ -1,8 +1,8 @@ // // Run test script in content process instead of chrome (xpcshell's default) // - function run_test() { + /* globals do_run_test */ load("../unit/test_resolve_uris.js"); do_run_test(); run_test_in_child("../unit/test_resolve_uris.js");