From 7ed69036358f2c65ca95cc4bbb1e478ff1d00299 Mon Sep 17 00:00:00 2001 From: Syeda Asra Arshia Qadri Date: Wed, 13 Mar 2019 20:50:11 +0000 Subject: [PATCH] Bug 1532941 - Enable ESLint for uriloader (manual changes). r=Standard8,qdot Differential Revision: https://phabricator.services.mozilla.com/D22478 --HG-- extra : moz-landing-system : lando --- .eslintignore | 2 -- uriloader/exthandler/tests/mochitest/.eslintrc.js | 8 ++++++++ .../tests/mochitest/browser_auto_close_window.js | 1 - uriloader/exthandler/tests/mochitest/handlerApps.js | 6 ++---- .../tests/mochitest/unsafeBidi_chromeScript.js | 2 +- uriloader/exthandler/tests/unit/test_badMIMEType.js | 8 +++----- .../test_getTypeFromExtension_ext_to_type_mapping.js | 3 +-- ...est_getTypeFromExtension_with_empty_Content_Type.js | 10 +++++----- uriloader/exthandler/tests/unit/test_handlerService.js | 9 ++------- uriloader/exthandler/tests/unit/test_punycodeURIs.js | 4 +--- 10 files changed, 23 insertions(+), 30 deletions(-) create mode 100644 uriloader/exthandler/tests/mochitest/.eslintrc.js diff --git a/.eslintignore b/.eslintignore index 202542679f64..171db4ff9428 100644 --- a/.eslintignore +++ b/.eslintignore @@ -27,8 +27,6 @@ netwerk/test/browser/** netwerk/test/mochitests/** netwerk/test/unit*/** tools/update-packaging/** -uriloader/exthandler/** -uriloader/exthandler/tests/mochitest/** xpfe/** # We currently have no js files in these directories, so we ignore them by diff --git a/uriloader/exthandler/tests/mochitest/.eslintrc.js b/uriloader/exthandler/tests/mochitest/.eslintrc.js new file mode 100644 index 000000000000..6746617eebd0 --- /dev/null +++ b/uriloader/exthandler/tests/mochitest/.eslintrc.js @@ -0,0 +1,8 @@ +"use strict"; + +module.exports = { + "extends": [ + "plugin:mozilla/browser-test", + "plugin:mozilla/mochitest-test", + ] +}; diff --git a/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js b/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js index edf91abbc32b..223a7dabe6bf 100644 --- a/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js +++ b/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js @@ -60,7 +60,6 @@ add_task(async function simple_navigation() { // opens with target="_blank" (i.e. a new tab) and ensures that we // automatically open and close that tab. async function testNewTab(browser) { - let targetURL = browser.currentURI.spec; let dialogAppeared = promiseHelperAppDialog(); let tabOpened = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabOpen").then((event) => { return [ event.target, BrowserTestUtils.waitForTabClosing(event.target) ]; diff --git a/uriloader/exthandler/tests/mochitest/handlerApps.js b/uriloader/exthandler/tests/mochitest/handlerApps.js index 13e3560cb8bb..1b47e92be9c0 100644 --- a/uriloader/exthandler/tests/mochitest/handlerApps.js +++ b/uriloader/exthandler/tests/mochitest/handlerApps.js @@ -17,8 +17,7 @@ function test() { "handlerApp.xhtml?uri=%s"; // set up the uri to test with - var ioService = Cc["@mozilla.org/network/io-service;1"]. - getService(SpecialPowers.Ci.nsIIOService); + var ioService = Services.io; var uri = ioService.newURI(testURI); // create a window, and launch the handler in it @@ -43,8 +42,7 @@ function test() { localHandler.name = "Test Local Handler App"; // get a local app that we know will be there and do something sane - var osString = Cc["@mozilla.org/xre/app-info;1"]. - getService(SpecialPowers.Ci.nsIXULRuntime).OS; + var osString = Services.appinfo.OS; var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. getService(SpecialPowers.Ci.nsIDirectoryServiceProvider); diff --git a/uriloader/exthandler/tests/mochitest/unsafeBidi_chromeScript.js b/uriloader/exthandler/tests/mochitest/unsafeBidi_chromeScript.js index 56d29a5eb6f3..48d690bcfda1 100644 --- a/uriloader/exthandler/tests/mochitest/unsafeBidi_chromeScript.js +++ b/uriloader/exthandler/tests/mochitest/unsafeBidi_chromeScript.js @@ -6,7 +6,7 @@ const HELPERAPP_DIALOG_CID = const FAKE_CID = Cc["@mozilla.org/uuid-generator;1"]. getService(Ci.nsIUUIDGenerator).generateUUID(); - +/* eslint-env mozilla/frame-script */ function HelperAppLauncherDialog() {} HelperAppLauncherDialog.prototype = { show(aLauncher, aWindowContext, aReason) { diff --git a/uriloader/exthandler/tests/unit/test_badMIMEType.js b/uriloader/exthandler/tests/unit/test_badMIMEType.js index 61cf0a806ede..8a4b71768fac 100644 --- a/uriloader/exthandler/tests/unit/test_badMIMEType.js +++ b/uriloader/exthandler/tests/unit/test_badMIMEType.js @@ -11,18 +11,16 @@ function run_test() { // its length to make sure this hasn't happened. var badMimeType = "text/plainÿ"; Assert.equal(badMimeType.length, 11); - try { - var type = Cc["@mozilla.org/mime;1"]. - getService(Ci.nsIMIMEService). - getFromTypeAndExtension(badMimeType, "txt"); + Cc["@mozilla.org/mime;1"]. + getService(Ci.nsIMIMEService). + getFromTypeAndExtension(badMimeType, "txt"); } catch (e) { if (!(e instanceof Ci.nsIException) || e.result != Cr.NS_ERROR_NOT_AVAILABLE) { throw e; } // This is an expected exception, thrown if the type can't be determined - } finally { } // Not crashing is good enough Assert.equal(true, true); diff --git a/uriloader/exthandler/tests/unit/test_getTypeFromExtension_ext_to_type_mapping.js b/uriloader/exthandler/tests/unit/test_getTypeFromExtension_ext_to_type_mapping.js index 3c6c90491bdf..ab0f961b82f3 100644 --- a/uriloader/exthandler/tests/unit/test_getTypeFromExtension_ext_to_type_mapping.js +++ b/uriloader/exthandler/tests/unit/test_getTypeFromExtension_ext_to_type_mapping.js @@ -14,8 +14,7 @@ function run_test() { const mimeService = Cc["@mozilla.org/mime;1"]. getService(Ci.nsIMIMEService); - const categoryManager = Cc["@mozilla.org/categorymanager;1"]. - getService(Ci.nsICategoryManager); + const categoryManager = Services.catMan; // --- Test procedure --- diff --git a/uriloader/exthandler/tests/unit/test_getTypeFromExtension_with_empty_Content_Type.js b/uriloader/exthandler/tests/unit/test_getTypeFromExtension_with_empty_Content_Type.js index ed3e4223aa1e..8973c021ae77 100644 --- a/uriloader/exthandler/tests/unit/test_getTypeFromExtension_with_empty_Content_Type.js +++ b/uriloader/exthandler/tests/unit/test_getTypeFromExtension_with_empty_Content_Type.js @@ -121,14 +121,14 @@ function run_test() { const kMockCID = Components.ID("{9b23dfe9-296b-4740-ba1c-d39c9a16e55e}"); const kWindowsRegKeyContractID = "@mozilla.org/windows-registry-key;1"; - const kWindowsRegKeyClassName = "nsWindowsRegKey"; function registerMockWindowsRegKeyFactory() { mockWindowsRegKeyFactory = { createInstance(aOuter, aIid) { if (aOuter != null) throw Cr.NS_ERROR_NO_AGGREGATION; - + // XXX Bug 1533719 - originalWindowsRegKeyFactory is undefined. + // eslint-disable-next-line no-undef var innerKey = originalWindowsRegKeyFactory.createInstance(null, aIid); var key = new MockWindowsRegKey(innerKey); @@ -171,9 +171,9 @@ function run_test() { try { // Try and get the MIME type associated with the extension. If this // operation does not throw an unexpected exception, the test succeeds. - var type = Cc["@mozilla.org/mime;1"]. - getService(Ci.nsIMIMEService). - getTypeFromExtension(".txt"); + Cc["@mozilla.org/mime;1"]. + getService(Ci.nsIMIMEService). + getTypeFromExtension(".txt"); } catch (e) { if (!(e instanceof Ci.nsIException) || e.result != Cr.NS_ERROR_NOT_AVAILABLE) { diff --git a/uriloader/exthandler/tests/unit/test_handlerService.js b/uriloader/exthandler/tests/unit/test_handlerService.js index 83b21cdcc51a..bbc94a4c3d1f 100644 --- a/uriloader/exthandler/tests/unit/test_handlerService.js +++ b/uriloader/exthandler/tests/unit/test_handlerService.js @@ -15,11 +15,7 @@ function run_test() { const protoSvc = Cc["@mozilla.org/uriloader/external-protocol-service;1"]. getService(Ci.nsIExternalProtocolService); - const prefSvc = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService); - - const ioService = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); + const prefSvc = Services.prefs; const env = Cc["@mozilla.org/process/environment;1"]. getService(Ci.nsIEnvironment); @@ -243,10 +239,9 @@ function run_test() { handlerTypes.splice(handlerTypes.indexOf(handler.type), 1); } Assert.equal(handlerTypes.length, 0); - // Make sure the handler service's remove method removes a handler record. handlerSvc.remove(handlerInfo2); - handlers = handlerSvc.enumerate(); + let handlers = handlerSvc.enumerate(); while (handlers.hasMoreElements()) Assert.notEqual(handlers.getNext().QueryInterface(Ci.nsIHandlerInfo).type, handlerInfo2.type); diff --git a/uriloader/exthandler/tests/unit/test_punycodeURIs.js b/uriloader/exthandler/tests/unit/test_punycodeURIs.js index f0da16dca534..89d79b02f34c 100644 --- a/uriloader/exthandler/tests/unit/test_punycodeURIs.js +++ b/uriloader/exthandler/tests/unit/test_punycodeURIs.js @@ -68,9 +68,7 @@ function run_test() { } // set up the uri to test with - var ioService = - Cc["@mozilla.org/network/io-service;1"] - .getService(Ci.nsIIOService); + var ioService = Services.io; // set up the local handler object var localHandler =