diff --git a/.eslintignore b/.eslintignore index 171db4ff9428..202542679f64 100644 --- a/.eslintignore +++ b/.eslintignore @@ -27,6 +27,8 @@ 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/HandlerService.js b/uriloader/exthandler/HandlerService.js index 9f6cbc47d546..712ab41150b6 100644 --- a/uriloader/exthandler/HandlerService.js +++ b/uriloader/exthandler/HandlerService.js @@ -29,7 +29,7 @@ HandlerService.prototype = { QueryInterface: ChromeUtils.generateQI([ Ci.nsISupportsWeakReference, Ci.nsIHandlerService, - Ci.nsIObserver, + Ci.nsIObserver ]), __store: null, @@ -111,6 +111,7 @@ HandlerService.prototype = { // read all the scheme prefs into a hash for (let schemePrefName of schemePrefList) { + let [scheme, handlerNumber, attribute] = schemePrefName.split("."); try { @@ -139,7 +140,7 @@ HandlerService.prototype = { let handlerApp = this.handlerAppFromSerializable(schemes[scheme][handlerNumber]); // If there is already a handler registered with the same template // URL, the newly added one will be ignored when saving. - possibleHandlers.appendElement(handlerApp); + possibleHandlers.appendElement(handlerApp, false); } this.store(protoInfo); @@ -263,17 +264,17 @@ HandlerService.prototype = { let handler = new Proxy( { QueryInterface: ChromeUtils.generateQI([Ci.nsIHandlerInfo]), - type, + type: type, get _handlerInfo() { delete this._handlerInfo; return this._handlerInfo = gExternalProtocolService.getProtocolHandlerInfo(type); }, }, { - get(target, name) { + get: function(target, name) { return target[name] || target._handlerInfo[name]; }, - set(target, name, value) { + set: function(target, name, value) { target._handlerInfo[name] = value; }, }, diff --git a/uriloader/exthandler/tests/mochitest/.eslintrc.js b/uriloader/exthandler/tests/mochitest/.eslintrc.js deleted file mode 100644 index 6746617eebd0..000000000000 --- a/uriloader/exthandler/tests/mochitest/.eslintrc.js +++ /dev/null @@ -1,8 +0,0 @@ -"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 223a7dabe6bf..b3c475248a00 100644 --- a/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js +++ b/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js @@ -20,12 +20,12 @@ function HelperAppLauncherDialog() { } HelperAppLauncherDialog.prototype = { - show(aLauncher, aWindowContext, aReason) { + show: function(aLauncher, aWindowContext, aReason) { ok(true, "Showing the helper app dialog"); curDialogResolve(aWindowContext); executeSoon(() => { aLauncher.cancel(Cr.NS_ERROR_ABORT); }); }, - QueryInterface: ChromeUtils.generateQI([Ci.nsIHelperAppLauncherDialog]), + QueryInterface: ChromeUtils.generateQI([Ci.nsIHelperAppLauncherDialog]) }; function promiseHelperAppDialog() { @@ -60,6 +60,7 @@ 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/browser_web_protocol_handlers.js b/uriloader/exthandler/tests/mochitest/browser_web_protocol_handlers.js index 06d33ae9ce44..f3dea57ec9dc 100644 --- a/uriloader/exthandler/tests/mochitest/browser_web_protocol_handlers.js +++ b/uriloader/exthandler/tests/mochitest/browser_web_protocol_handlers.js @@ -29,7 +29,7 @@ add_task(async function() { let handler = handlers.queryElementAt(0, Ci.nsIHandlerApp); ok(handler instanceof Ci.nsIWebHandlerApp, "the handler is a web handler"); is(handler.uriTemplate, "https://example.com/foobar?uri=%s", - "correct url template"); + "correct url template") protoInfo.preferredApplicationHandler = handler; protoInfo.alwaysAskBeforeHandling = false; const handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"]. diff --git a/uriloader/exthandler/tests/mochitest/handlerApp.xhtml b/uriloader/exthandler/tests/mochitest/handlerApp.xhtml index 3fbd72404126..83ba0d1a5490 100644 --- a/uriloader/exthandler/tests/mochitest/handlerApp.xhtml +++ b/uriloader/exthandler/tests/mochitest/handlerApp.xhtml @@ -10,14 +10,15 @@ Pseudo Web Handler App diff --git a/uriloader/exthandler/tests/mochitest/test_unsafeBidiChars.xhtml b/uriloader/exthandler/tests/mochitest/test_unsafeBidiChars.xhtml index 487bc8516ece..1ad96982063f 100644 --- a/uriloader/exthandler/tests/mochitest/test_unsafeBidiChars.xhtml +++ b/uriloader/exthandler/tests/mochitest/test_unsafeBidiChars.xhtml @@ -16,7 +16,7 @@ var unsafeBidiChars = [ "\xe2\x80\xab", // RLE "\xe2\x80\xac", // PDF "\xe2\x80\xad", // LRO - "\xe2\x80\xae", // RLO + "\xe2\x80\xae" // RLO ]; var tests = [ @@ -35,7 +35,7 @@ function replace(name, x) { } function sanitize(name) { - return replace(name, "_"); + return replace(name, '_'); } const INSECURE_REGISTER_PREF = "dom.registerProtocolHandler.insecure.enabled"; diff --git a/uriloader/exthandler/tests/mochitest/test_web_protocol_handlers.html b/uriloader/exthandler/tests/mochitest/test_web_protocol_handlers.html index d7bbaf234f2c..d45ff8f6647b 100644 --- a/uriloader/exthandler/tests/mochitest/test_web_protocol_handlers.html +++ b/uriloader/exthandler/tests/mochitest/test_web_protocol_handlers.html @@ -15,7 +15,7 @@ add_task(async function() { set: [ ["dom.registerContentHandler.enabled", true], ["dom.registerProtocolHandler.insecure.enabled", false], - ], + ] }); let result = "registerProtocolHandler" in navigator; diff --git a/uriloader/exthandler/tests/mochitest/unsafeBidi_chromeScript.js b/uriloader/exthandler/tests/mochitest/unsafeBidi_chromeScript.js index 48d690bcfda1..2b6b4d67d5ba 100644 --- a/uriloader/exthandler/tests/mochitest/unsafeBidi_chromeScript.js +++ b/uriloader/exthandler/tests/mochitest/unsafeBidi_chromeScript.js @@ -6,13 +6,13 @@ 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) { + show: function(aLauncher, aWindowContext, aReason) { sendAsyncMessage("suggestedFileName", aLauncher.suggestedFileName); }, - QueryInterface: ChromeUtils.generateQI([Ci.nsIHelperAppLauncherDialog]), + QueryInterface: ChromeUtils.generateQI([Ci.nsIHelperAppLauncherDialog]) }; var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); diff --git a/uriloader/exthandler/tests/unit/head.js b/uriloader/exthandler/tests/unit/head.js index 41a26da0bbb0..7e9c14fef618 100644 --- a/uriloader/exthandler/tests/unit/head.js +++ b/uriloader/exthandler/tests/unit/head.js @@ -37,7 +37,7 @@ let unloadHandlerStore = async function() { gHandlerService; let promise = TestUtils.topicObserved("handlersvc-json-replace-complete"); - Services.obs.notifyObservers(null, "handlersvc-json-replace"); + Services.obs.notifyObservers(null, "handlersvc-json-replace", null); await promise; }; diff --git a/uriloader/exthandler/tests/unit/test_badMIMEType.js b/uriloader/exthandler/tests/unit/test_badMIMEType.js index 8a4b71768fac..61cf0a806ede 100644 --- a/uriloader/exthandler/tests/unit/test_badMIMEType.js +++ b/uriloader/exthandler/tests/unit/test_badMIMEType.js @@ -11,16 +11,18 @@ function run_test() { // its length to make sure this hasn't happened. var badMimeType = "text/plainÿ"; Assert.equal(badMimeType.length, 11); + try { - Cc["@mozilla.org/mime;1"]. - getService(Ci.nsIMIMEService). - getFromTypeAndExtension(badMimeType, "txt"); + var type = 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 ab0f961b82f3..3c6c90491bdf 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,7 +14,8 @@ function run_test() { const mimeService = Cc["@mozilla.org/mime;1"]. getService(Ci.nsIMIMEService); - const categoryManager = Services.catMan; + const categoryManager = Cc["@mozilla.org/categorymanager;1"]. + getService(Ci.nsICategoryManager); // --- 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 8973c021ae77..edaa276984d0 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 @@ -37,7 +37,7 @@ function run_test() { function makeForwardingFunction(functionName) { return function() { return aWrappedObject[functionName].apply(aWrappedObject, arguments); - }; + } } // Forward all the functions that are not explicitly overridden @@ -59,7 +59,7 @@ function run_test() { // --- Overridden nsIWindowsRegKey interface functions --- - open(aRootKey, aRelPath, aMode) { + open: function(aRootKey, aRelPath, aMode) { // Remember the provided root key and path this._rootKey = aRootKey; this._relPath = aRelPath; @@ -68,7 +68,7 @@ function run_test() { return this._wrappedObject.open(aRootKey, aRelPath, aMode); }, - openChild(aRelPath, aMode) { + openChild: function(aRelPath, aMode) { // Open the child key and wrap it var innerKey = this._wrappedObject.openChild(aRelPath, aMode); var key = new MockWindowsRegKey(innerKey); @@ -79,7 +79,7 @@ function run_test() { return key; }, - createChild(aRelPath, aMode) { + createChild: function(aRelPath, aMode) { // Create the child key and wrap it var innerKey = this._wrappedObject.createChild(aRelPath, aMode); var key = new MockWindowsRegKey(innerKey); @@ -98,7 +98,7 @@ function run_test() { return this._wrappedObject.valueCount; }, - readStringValue(aName) { + readStringValue: function(aName) { // If this is the key under test, return a fake value if (this._rootKey == Ci.nsIWindowsRegKey.ROOT_KEY_CLASSES_ROOT && this._relPath.toLowerCase() == ".txt" && @@ -108,7 +108,7 @@ function run_test() { // Return the real value in the registry return this._wrappedObject.readStringValue(aName); - }, + } }; // --- Mock nsIWindowsRegKey factory --- @@ -121,19 +121,19 @@ 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) { + createInstance: function(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); return key.QueryInterface(aIid); - }, + } }; // Preserve the original factory @@ -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. - Cc["@mozilla.org/mime;1"]. - getService(Ci.nsIMIMEService). - getTypeFromExtension(".txt"); + var type = 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 bbc94a4c3d1f..8fdde0d21791 100644 --- a/uriloader/exthandler/tests/unit/test_handlerService.js +++ b/uriloader/exthandler/tests/unit/test_handlerService.js @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ function run_test() { - //* *************************************************************************// + //**************************************************************************// // Constants const handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"]. @@ -14,14 +14,18 @@ function run_test() { const protoSvc = Cc["@mozilla.org/uriloader/external-protocol-service;1"]. getService(Ci.nsIExternalProtocolService); - - const prefSvc = Services.prefs; + + const prefSvc = Cc["@mozilla.org/preferences-service;1"]. + getService(Ci.nsIPrefService); + + const ioService = Cc["@mozilla.org/network/io-service;1"]. + getService(Ci.nsIIOService); const env = Cc["@mozilla.org/process/environment;1"]. getService(Ci.nsIEnvironment); const rootPrefBranch = prefSvc.getBranch(""); - + let noMailto = false; if (mozinfo.os == "win") { // Check mailto handler from registry. @@ -52,7 +56,7 @@ function run_test() { } } - //* *************************************************************************// + //**************************************************************************// // Sample Data // It doesn't matter whether or not this nsIFile is actually executable, @@ -62,8 +66,8 @@ function run_test() { // from the directory service), we use the temporary directory itself. var executable = Services.dirsvc.get("TmpD", Ci.nsIFile); // XXX We could, of course, create an actual executable in the directory: - // executable.append("localhandler"); - // if (!executable.exists()) + //executable.append("localhandler"); + //if (!executable.exists()) // executable.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o755); var localHandler = Cc["@mozilla.org/uriloader/local-handler-app;1"]. @@ -81,7 +85,7 @@ function run_test() { // of one test stomping on another's data. - //* *************************************************************************// + //**************************************************************************// // Test Default Properties // Get a handler info for a MIME type that neither the application nor @@ -112,7 +116,7 @@ function run_test() { // test some default protocol info properties var haveDefaultHandlersVersion = false; - try { + try { // If we have a defaultHandlersVersion pref, then assume that we're in the // firefox tree and that we'll also have default handlers. // Bug 395131 has been filed to make this test work more generically @@ -122,26 +126,26 @@ function run_test() { haveDefaultHandlersVersion = true; } catch (ex) {} - const kExternalWarningDefault = + const kExternalWarningDefault = "network.protocol-handler.warn-external-default"; prefSvc.setBoolPref(kExternalWarningDefault, true); // XXX add more thorough protocol info property checking - + // no OS default handler exists var protoInfo = protoSvc.getProtocolHandlerInfo("x-moz-rheet"); Assert.equal(protoInfo.preferredAction, protoInfo.alwaysAsk); Assert.ok(protoInfo.alwaysAskBeforeHandling); - - // OS default exists, injected default does not exist, + + // OS default exists, injected default does not exist, // explicit warning pref: false const kExternalWarningPrefPrefix = "network.protocol-handler.warn-external."; prefSvc.setBoolPref(kExternalWarningPrefPrefix + "http", false); protoInfo = protoSvc.getProtocolHandlerInfo("http"); Assert.equal(0, protoInfo.possibleApplicationHandlers.length); Assert.ok(!protoInfo.alwaysAskBeforeHandling); - - // OS default exists, injected default does not exist, + + // OS default exists, injected default does not exist, // explicit warning pref: true prefSvc.setBoolPref(kExternalWarningPrefPrefix + "http", true); protoInfo = protoSvc.getProtocolHandlerInfo("http"); @@ -179,6 +183,7 @@ function run_test() { Assert.ok(protoInfo.alwaysAskBeforeHandling); else Assert.ok(!protoInfo.alwaysAskBeforeHandling); + } else { Assert.equal(0, protoInfo.possibleApplicationHandlers.length); Assert.ok(protoInfo.alwaysAskBeforeHandling); @@ -197,7 +202,7 @@ function run_test() { } - //* *************************************************************************// + //**************************************************************************// // Test Round-Trip Data Integrity // Test round-trip data integrity by setting the properties of the handler @@ -239,9 +244,10 @@ 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); - let handlers = handlerSvc.enumerate(); + handlers = handlerSvc.enumerate(); while (handlers.hasMoreElements()) Assert.notEqual(handlers.getNext().QueryInterface(Ci.nsIHandlerInfo).type, handlerInfo2.type); @@ -332,7 +338,7 @@ function run_test() { Assert.equal(webPossibleHandler.name, webHandler.name); Assert.ok(webPossibleHandler.equals(webHandler)); - // //////////////////////////////////////////////////// + ////////////////////////////////////////////////////// // handler info command line parameters and equality var localApp = Cc["@mozilla.org/uriloader/local-handler-app;1"]. createInstance(Ci.nsILocalHandlerApp); @@ -355,7 +361,7 @@ function run_test() { var localApp2 = Cc["@mozilla.org/uriloader/local-handler-app;1"]. createInstance(Ci.nsILocalHandlerApp); - + localApp2.executable = executable; localApp.clearParameters(); @@ -389,17 +395,17 @@ function run_test() { Assert.ok(!localApp2.equals(localApp)); var str; - str = localApp.getParameter(0); + str = localApp.getParameter(0) Assert.equal(str, "-test1"); - str = localApp.getParameter(1); + str = localApp.getParameter(1) Assert.equal(str, "-test2"); - str = localApp.getParameter(2); + str = localApp.getParameter(2) Assert.equal(str, "-test3"); // FIXME: test round trip integrity for a protocol. // FIXME: test round trip integrity for a handler info with a web handler. - //* *************************************************************************// + //**************************************************************************// // getTypeFromExtension tests // test nonexistent extension @@ -427,7 +433,7 @@ function run_test() { // test mailcap entries with needsterminal are ignored on non-Windows non-Mac. if (mozinfo.os != "win" && mozinfo.os != "mac") { - env.set("PERSONAL_MAILCAP", do_get_file("mailcap").path); + env.set('PERSONAL_MAILCAP', do_get_file('mailcap').path); handlerInfo = mimeSvc.getFromTypeAndExtension("text/plain", null); Assert.equal(handlerInfo.preferredAction, Ci.nsIHandlerInfo.useSystemDefault); Assert.equal(handlerInfo.defaultDescription, "sed"); diff --git a/uriloader/exthandler/tests/unit/test_handlerService_store.js b/uriloader/exthandler/tests/unit/test_handlerService_store.js index 1fc4ef6014dc..d1ab6ee2a880 100644 --- a/uriloader/exthandler/tests/unit/test_handlerService_store.js +++ b/uriloader/exthandler/tests/unit/test_handlerService_store.js @@ -92,10 +92,10 @@ function assertAllHandlerInfosMatchTestData() { possibleApplicationHandlers: [{ name: "Example Default Handler", uriTemplate: "https://www.example.com/?url=%s", - }, { + },{ name: "Example Possible Handler One", uriTemplate: "http://www.example.com/?id=1&url=%s", - }, { + },{ name: "Example Possible Handler Two", uriTemplate: "http://www.example.com/?id=2&url=%s", }], @@ -126,10 +126,10 @@ function assertAllHandlerInfosMatchTestData() { possibleApplicationHandlers: [{ name: "Example Default Handler", uriTemplate: "https://www.example.com/?url=%s", - }, { + },{ name: "Example Possible Handler One", uriTemplate: "http://www.example.com/?id=1&url=%s", - }, { + },{ name: "Example Possible Handler Two", uriTemplate: "http://www.example.com/?id=2&url=%s", }], @@ -466,7 +466,7 @@ add_task(async function test_store_deletes_properties_except_extensions() { alwaysAskBeforeHandling: false, fileExtensions: [ "example_two", - "example_three", + "example_three" ], }); }); @@ -537,7 +537,7 @@ function assertAllHandlerInfosMatchDefaultHandlers() { possibleApplicationHandlers: [{ name: "Yahoo! Mail", uriTemplate: "https://compose.mail.yahoo.com/?To=%s", - }, { + },{ name: "Gmail", uriTemplate: "https://mail.google.com/mail/?extsrc=mailto&url=%s", }], diff --git a/uriloader/exthandler/tests/unit/test_punycodeURIs.js b/uriloader/exthandler/tests/unit/test_punycodeURIs.js index 89d79b02f34c..c66275c11b70 100644 --- a/uriloader/exthandler/tests/unit/test_punycodeURIs.js +++ b/uriloader/exthandler/tests/unit/test_punycodeURIs.js @@ -22,7 +22,8 @@ function checkFile() { if (gCheckExistsAttempts >= kMaxCheckExistAttempts) { do_throw("Expected File " + tempFile.path + " does not exist after " + kMaxCheckExistAttempts + " seconds"); - } else { + } + else { ++gCheckExistsAttempts; // Wait a bit longer then try again do_timeout(1000, checkFile); @@ -63,12 +64,14 @@ function checkFile() { function run_test() { if (mozinfo.os == "mac") { - dump("INFO | test_punycodeURIs.js | Skipping test on mac, bug 599475"); + dump("INFO | test_punycodeURIs.js | Skipping test on mac, bug 599475") return; } // set up the uri to test with - var ioService = Services.io; + var ioService = + Cc["@mozilla.org/network/io-service;1"] + .getService(Ci.nsIIOService); // set up the local handler object var localHandler = @@ -104,7 +107,7 @@ function run_test() { envSvc.set("DYLD_LIBRARY_PATH", greDir.path); // For Linux envSvc.set("LD_LIBRARY_PATH", greDir.path); - // XXX: handle windows + //XXX: handle windows // Now tell it where we want the file. envSvc.set("WRITE_ARGUMENT_FILE", outFile.path);