From afb5dbbfbb1d1f497311cb4aa71e2bfba26f4d05 Mon Sep 17 00:00:00 2001 From: Victor Porof Date: Fri, 5 Jul 2019 11:18:48 +0200 Subject: [PATCH] Bug 1561435 - Format uriloader/, a=automatic-formatting # ignore-this-changeset Differential Revision: https://phabricator.services.mozilla.com/D35942 --HG-- extra : source : 5dea4c57938db29579b142d06cec98f03eb5397d --- .eslintrc.js | 1 - .prettierignore | 1 - uriloader/exthandler/HandlerService.js | 200 +++++++---- uriloader/exthandler/WebHandlerApp.jsm | 79 +++-- .../tests/HandlerServiceTestUtils.jsm | 87 +++-- .../mochitest/browser_auto_close_window.js | 95 ++++-- ...owser_download_always_ask_preferred_app.js | 12 +- .../browser_download_privatebrowsing.js | 6 +- .../browser_remember_download_option.js | 33 +- .../browser_web_protocol_handlers.js | 71 ++-- .../exthandler/tests/mochitest/handlerApps.js | 55 +-- uriloader/exthandler/tests/mochitest/head.js | 59 ++-- .../mochitest/unsafeBidi_chromeScript.js | 30 +- uriloader/exthandler/tests/unit/head.js | 34 +- .../exthandler/tests/unit/test_badMIMEType.js | 12 +- ...etTypeFromExtension_ext_to_type_mapping.js | 28 +- ...peFromExtension_with_empty_Content_Type.js | 50 +-- .../tests/unit/test_handlerService.js | 177 ++++++---- .../tests/unit/test_handlerService_store.js | 321 ++++++++++-------- .../tests/unit/test_punycodeURIs.js | 39 ++- 20 files changed, 869 insertions(+), 521 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c9a4ef644e12..8b11b3c233bd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -45,7 +45,6 @@ module.exports = { "overrides": [{ "files": [ "devtools/**", - "uriloader/**", "view/**", "widget/**", "xpcom/**", diff --git a/.prettierignore b/.prettierignore index c154ce3aa5aa..8edf2d9d6d80 100644 --- a/.prettierignore +++ b/.prettierignore @@ -40,7 +40,6 @@ toolkit/components/telemetry/datareporting-prefs.js toolkit/components/telemetry/healthreport-prefs.js # Ignore all top-level directories for now. -uriloader/** view/** widget/** xpcom/** diff --git a/uriloader/exthandler/HandlerService.js b/uriloader/exthandler/HandlerService.js index 9f6cbc47d546..b5a28f56857f 100644 --- a/uriloader/exthandler/HandlerService.js +++ b/uriloader/exthandler/HandlerService.js @@ -2,21 +2,35 @@ * 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/. */ -const {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm"); -const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); -const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); +const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm"); +const { XPCOMUtils } = ChromeUtils.import( + "resource://gre/modules/XPCOMUtils.jsm" +); +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); -ChromeUtils.defineModuleGetter(this, "FileUtils", - "resource://gre/modules/FileUtils.jsm"); -ChromeUtils.defineModuleGetter(this, "JSONFile", - "resource://gre/modules/JSONFile.jsm"); +ChromeUtils.defineModuleGetter( + this, + "FileUtils", + "resource://gre/modules/FileUtils.jsm" +); +ChromeUtils.defineModuleGetter( + this, + "JSONFile", + "resource://gre/modules/JSONFile.jsm" +); -XPCOMUtils.defineLazyServiceGetter(this, "gExternalProtocolService", - "@mozilla.org/uriloader/external-protocol-service;1", - "nsIExternalProtocolService"); -XPCOMUtils.defineLazyServiceGetter(this, "gMIMEService", - "@mozilla.org/mime;1", - "nsIMIMEService"); +XPCOMUtils.defineLazyServiceGetter( + this, + "gExternalProtocolService", + "@mozilla.org/uriloader/external-protocol-service;1", + "nsIExternalProtocolService" +); +XPCOMUtils.defineLazyServiceGetter( + this, + "gMIMEService", + "@mozilla.org/mime;1", + "nsIMIMEService" +); function HandlerService() { // Observe handlersvc-json-replace so we can switch to the datasource @@ -24,7 +38,6 @@ function HandlerService() { } HandlerService.prototype = { - classID: Components.ID("{220cc253-b60f-41f6-b9cf-fdcb325f970f}"), QueryInterface: ChromeUtils.generateQI([ Ci.nsISupportsWeakReference, @@ -61,11 +74,13 @@ HandlerService.prototype = { }, _dataPostProcessor(data) { - return data.defaultHandlersVersion ? data : { - defaultHandlersVersion: {}, - mimeTypes: {}, - schemes: {}, - }; + return data.defaultHandlersVersion + ? data + : { + defaultHandlersVersion: {}, + mimeTypes: {}, + schemes: {}, + }; }, /** @@ -77,10 +92,13 @@ HandlerService.prototype = { try { prefsDefaultHandlersVersion = Services.prefs.getComplexValue( "gecko.handlerService.defaultHandlersVersion", - Ci.nsIPrefLocalizedString); + Ci.nsIPrefLocalizedString + ); } catch (ex) { - if (ex instanceof Components.Exception && - ex.result == Cr.NS_ERROR_UNEXPECTED) { + if ( + ex instanceof Components.Exception && + ex.result == Cr.NS_ERROR_UNEXPECTED + ) { // This platform does not have any default protocol handlers configured. return; } @@ -92,11 +110,12 @@ HandlerService.prototype = { let locale = Services.locale.appLocaleAsLangTag; let defaultHandlersVersion = - this._store.data.defaultHandlersVersion[locale] || 0; + this._store.data.defaultHandlersVersion[locale] || 0; if (defaultHandlersVersion < prefsDefaultHandlersVersion) { this._injectDefaultProtocolHandlers(); - this._store.data.defaultHandlersVersion[locale] = - prefsDefaultHandlersVersion; + this._store.data.defaultHandlersVersion[ + locale + ] = prefsDefaultHandlersVersion; } } catch (ex) { Cu.reportError(ex); @@ -104,7 +123,9 @@ HandlerService.prototype = { }, _injectDefaultProtocolHandlers() { - let schemesPrefBranch = Services.prefs.getBranch("gecko.handlerService.schemes."); + let schemesPrefBranch = Services.prefs.getBranch( + "gecko.handlerService.schemes." + ); let schemePrefList = schemesPrefBranch.getChildList(""); let schemes = {}; @@ -114,9 +135,10 @@ HandlerService.prototype = { let [scheme, handlerNumber, attribute] = schemePrefName.split("."); try { - let attrData = - schemesPrefBranch.getComplexValue(schemePrefName, - Ci.nsIPrefLocalizedString).data; + let attrData = schemesPrefBranch.getComplexValue( + schemePrefName, + Ci.nsIPrefLocalizedString + ).data; if (!(scheme in schemes)) { schemes[scheme] = {}; } @@ -136,7 +158,9 @@ HandlerService.prototype = { let possibleHandlers = protoInfo.possibleApplicationHandlers; for (let handlerNumber of Object.keys(schemes[scheme])) { - let handlerApp = this.handlerAppFromSerializable(schemes[scheme][handlerNumber]); + 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); @@ -160,7 +184,9 @@ HandlerService.prototype = { const kMigrations = { "30boxes": () => { const k30BoxesRegex = /^https?:\/\/(?:www\.)?30boxes.com\/external\/widget/i; - let webcalHandler = gExternalProtocolService.getProtocolHandlerInfo("webcal"); + let webcalHandler = gExternalProtocolService.getProtocolHandlerInfo( + "webcal" + ); if (this.exists(webcalHandler)) { this.fillHandlerInfo(webcalHandler, ""); let shouldStore = false; @@ -168,8 +194,10 @@ HandlerService.prototype = { let handlers = webcalHandler.possibleApplicationHandlers; for (let i = handlers.length - 1; i >= 0; i--) { let app = handlers.queryElementAt(i, Ci.nsIHandlerApp); - if (app instanceof Ci.nsIWebHandlerApp && - k30BoxesRegex.test(app.uriTemplate)) { + if ( + app instanceof Ci.nsIWebHandlerApp && + k30BoxesRegex.test(app.uriTemplate) + ) { shouldStore = true; handlers.removeElementAt(i); } @@ -177,8 +205,10 @@ HandlerService.prototype = { // Then remove as a preferred handler. if (webcalHandler.preferredApplicationHandler) { let app = webcalHandler.preferredApplicationHandler; - if (app instanceof Ci.nsIWebHandlerApp && - k30BoxesRegex.test(app.uriTemplate)) { + if ( + app instanceof Ci.nsIWebHandlerApp && + k30BoxesRegex.test(app.uriTemplate) + ) { webcalHandler.preferredApplicationHandler = null; shouldStore = true; } @@ -190,7 +220,10 @@ HandlerService.prototype = { } }, }; - let migrationsToRun = Services.prefs.getCharPref("browser.handlers.migrations", ""); + let migrationsToRun = Services.prefs.getCharPref( + "browser.handlers.migrations", + "" + ); migrationsToRun = migrationsToRun ? migrationsToRun.split(",") : []; for (let migration of migrationsToRun) { migration.trim(); @@ -234,19 +267,23 @@ HandlerService.prototype = { path: OS.Path.join(OS.Constants.Path.profileDir, "handlers.json"), dataPostProcessor: this._dataPostProcessor.bind(this), }); - this.__store.load().then(() => { - // __store can be null if we called _onDBChange in the mean time. - if (this.__store) { - this._ensureStoreInitialized(); - } - }).catch(Cu.reportError); + this.__store + .load() + .then(() => { + // __store can be null if we called _onDBChange in the mean time. + if (this.__store) { + this._ensureStoreInitialized(); + } + }) + .catch(Cu.reportError); } }, // nsIHandlerService enumerate() { - let handlers = Cc["@mozilla.org/array;1"] - .createInstance(Ci.nsIMutableArray); + let handlers = Cc["@mozilla.org/array;1"].createInstance( + Ci.nsIMutableArray + ); for (let type of Object.keys(this._store.data.mimeTypes)) { let handler = gMIMEService.getFromTypeAndExtension(type, null); handlers.appendElement(handler); @@ -266,7 +303,9 @@ HandlerService.prototype = { type, get _handlerInfo() { delete this._handlerInfo; - return this._handlerInfo = gExternalProtocolService.getProtocolHandlerInfo(type); + return (this._handlerInfo = gExternalProtocolService.getProtocolHandlerInfo( + type + )); }, }, { @@ -276,7 +315,7 @@ HandlerService.prototype = { set(target, name, value) { target._handlerInfo[name] = value; }, - }, + } ); handlers.appendElement(handler); } @@ -296,9 +335,11 @@ HandlerService.prototype = { } // Only a limited number of preferredAction values is allowed. - if (handlerInfo.preferredAction == Ci.nsIHandlerInfo.saveToDisk || - handlerInfo.preferredAction == Ci.nsIHandlerInfo.useSystemDefault || - handlerInfo.preferredAction == Ci.nsIHandlerInfo.handleInternally) { + if ( + handlerInfo.preferredAction == Ci.nsIHandlerInfo.saveToDisk || + handlerInfo.preferredAction == Ci.nsIHandlerInfo.useSystemDefault || + handlerInfo.preferredAction == Ci.nsIHandlerInfo.handleInternally + ) { storedHandlerInfo.action = handlerInfo.preferredAction; } else { storedHandlerInfo.action = Ci.nsIHandlerInfo.useHelperApp; @@ -315,7 +356,9 @@ HandlerService.prototype = { if (handlerInfo.preferredApplicationHandler) { handlers.push(handlerInfo.preferredApplicationHandler); } - for (let handler of handlerInfo.possibleApplicationHandlers.enumerate(Ci.nsIHandlerApp)) { + for (let handler of handlerInfo.possibleApplicationHandlers.enumerate( + Ci.nsIHandlerApp + )) { // If the caller stored duplicate handlers, we save them only once. if (!handlers.some(h => h.equals(handler))) { handlers.push(handler); @@ -325,8 +368,9 @@ HandlerService.prototype = { // If any of the nsIHandlerInfo instances cannot be serialized, it is not // included in the final list. The first element is always the preferred // handler, or null if there is none. - let serializableHandlers = - handlers.map(h => this.handlerAppToSerializable(h)).filter(h => h); + let serializableHandlers = handlers + .map(h => this.handlerAppToSerializable(h)) + .filter(h => h); if (serializableHandlers.length) { if (!handlerInfo.preferredApplicationHandler) { serializableHandlers.unshift(null); @@ -358,10 +402,14 @@ HandlerService.prototype = { // nsIHandlerService fillHandlerInfo(handlerInfo, overrideType) { let type = overrideType || handlerInfo.type; - let storedHandlerInfo = this._getHandlerListByHandlerInfoType(handlerInfo)[type]; + let storedHandlerInfo = this._getHandlerListByHandlerInfoType(handlerInfo)[ + type + ]; if (!storedHandlerInfo) { - throw new Components.Exception("handlerSvc fillHandlerInfo: don't know this type", - Cr.NS_ERROR_NOT_AVAILABLE); + throw new Components.Exception( + "handlerSvc fillHandlerInfo: don't know this type", + Cr.NS_ERROR_NOT_AVAILABLE + ); } handlerInfo.preferredAction = storedHandlerInfo.action; @@ -436,29 +484,31 @@ HandlerService.prototype = { if (!file.exists()) { return null; } - handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"] - .createInstance(Ci.nsILocalHandlerApp); + handlerApp = Cc[ + "@mozilla.org/uriloader/local-handler-app;1" + ].createInstance(Ci.nsILocalHandlerApp); handlerApp.executable = file; } catch (ex) { return null; } } else if ("uriTemplate" in handlerObj) { - handlerApp = Cc["@mozilla.org/uriloader/web-handler-app;1"] - .createInstance(Ci.nsIWebHandlerApp); + handlerApp = Cc[ + "@mozilla.org/uriloader/web-handler-app;1" + ].createInstance(Ci.nsIWebHandlerApp); handlerApp.uriTemplate = handlerObj.uriTemplate; } else if ("service" in handlerObj) { - handlerApp = Cc["@mozilla.org/uriloader/dbus-handler-app;1"] - .createInstance(Ci.nsIDBusHandlerApp); + handlerApp = Cc[ + "@mozilla.org/uriloader/dbus-handler-app;1" + ].createInstance(Ci.nsIDBusHandlerApp); handlerApp.service = handlerObj.service; handlerApp.method = handlerObj.method; handlerApp.objectPath = handlerObj.objectPath; handlerApp.dBusInterface = handlerObj.dBusInterface; - } else if ("command" in handlerObj && - "@mozilla.org/gio-service;1" in Cc) { + } else if ("command" in handlerObj && "@mozilla.org/gio-service;1" in Cc) { try { handlerApp = Cc["@mozilla.org/gio-service;1"] - .getService(Ci.nsIGIOService) - .createAppFromCommand(handlerObj.command, handlerObj.name); + .getService(Ci.nsIGIOService) + .createAppFromCommand(handlerObj.command, handlerObj.name); } catch (ex) { return null; } @@ -475,8 +525,9 @@ HandlerService.prototype = { * based on which type of handlerInfo is provided. */ _getHandlerListByHandlerInfoType(handlerInfo) { - return this._isMIMEInfo(handlerInfo) ? this._store.data.mimeTypes - : this._store.data.schemes; + return this._isMIMEInfo(handlerInfo) + ? this._store.data.mimeTypes + : this._store.data.schemes; }, /** @@ -486,13 +537,16 @@ HandlerService.prototype = { // We cannot rely only on the instanceof check because on Android both MIME // types and protocols are instances of nsIMIMEInfo. We still do the check // so that properties of nsIMIMEInfo become available to the callers. - return handlerInfo instanceof Ci.nsIMIMEInfo && - handlerInfo.type.includes("/"); + return ( + handlerInfo instanceof Ci.nsIMIMEInfo && handlerInfo.type.includes("/") + ); }, // nsIHandlerService exists(handlerInfo) { - return handlerInfo.type in this._getHandlerListByHandlerInfoType(handlerInfo); + return ( + handlerInfo.type in this._getHandlerListByHandlerInfoType(handlerInfo) + ); }, // nsIHandlerService @@ -506,8 +560,10 @@ HandlerService.prototype = { let extension = fileExtension.toLowerCase(); let mimeTypes = this._store.data.mimeTypes; for (let type of Object.keys(mimeTypes)) { - if (mimeTypes[type].extensions && - mimeTypes[type].extensions.includes(extension)) { + if ( + mimeTypes[type].extensions && + mimeTypes[type].extensions.includes(extension) + ) { return type; } } diff --git a/uriloader/exthandler/WebHandlerApp.jsm b/uriloader/exthandler/WebHandlerApp.jsm index 7aaf0aeede0c..11f073ee4032 100644 --- a/uriloader/exthandler/WebHandlerApp.jsm +++ b/uriloader/exthandler/WebHandlerApp.jsm @@ -2,10 +2,14 @@ * 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/. */ -const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); -const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); +const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); -ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils", "resource://gre/modules/PrivateBrowsingUtils.jsm"); +ChromeUtils.defineModuleGetter( + this, + "PrivateBrowsingUtils", + "resource://gre/modules/PrivateBrowsingUtils.jsm" +); function nsWebHandlerApp() {} @@ -13,7 +17,10 @@ nsWebHandlerApp.prototype = { classDescription: "A web handler for protocols and content", classID: Components.ID("8b1ae382-51a9-4972-b930-56977a57919d"), contractID: "@mozilla.org/uriloader/web-handler-app;1", - QueryInterface: ChromeUtils.generateQI([Ci.nsIWebHandlerApp, Ci.nsIHandlerApp]), + QueryInterface: ChromeUtils.generateQI([ + Ci.nsIWebHandlerApp, + Ci.nsIHandlerApp, + ]), _name: null, _detailedDescription: null, @@ -42,10 +49,12 @@ nsWebHandlerApp.prototype = { throw Cr.NS_ERROR_NULL_POINTER; } - if (aHandlerApp instanceof Ci.nsIWebHandlerApp && - aHandlerApp.uriTemplate && - this.uriTemplate && - aHandlerApp.uriTemplate == this.uriTemplate) { + if ( + aHandlerApp instanceof Ci.nsIWebHandlerApp && + aHandlerApp.uriTemplate && + this.uriTemplate && + aHandlerApp.uriTemplate == this.uriTemplate + ) { return true; } return false; @@ -70,10 +79,14 @@ nsWebHandlerApp.prototype = { // if we have a window context, use the URI loader to load there if (aWindowContext) { try { - let remoteWindow = aWindowContext.getInterface(Ci.nsIRemoteWindowContext); + let remoteWindow = aWindowContext.getInterface( + Ci.nsIRemoteWindowContext + ); if (remoteWindow.usePrivateBrowsing && !privateAllowed) { - throw Components.Exception("Extension not allowed in private windows.", - Cr.NS_ERROR_FILE_NOT_FOUND); + throw Components.Exception( + "Extension not allowed in private windows.", + Cr.NS_ERROR_FILE_NOT_FOUND + ); } // getInterface throws if the object doesn't implement the given // interface, so this try/catch statement is more of an if. @@ -88,12 +101,14 @@ nsWebHandlerApp.prototype = { } try { - let isPrivate = aWindowContext.getInterface(Ci.nsIDocShell) - .QueryInterface(Ci.nsILoadContext) - .usePrivateBrowsing; + let isPrivate = aWindowContext + .getInterface(Ci.nsIDocShell) + .QueryInterface(Ci.nsILoadContext).usePrivateBrowsing; if (isPrivate && !privateAllowed) { - throw Components.Exception("Extension not allowed in private windows.", - Cr.NS_ERROR_FILE_NOT_FOUND); + throw Components.Exception( + "Extension not allowed in private windows.", + Cr.NS_ERROR_FILE_NOT_FOUND + ); } } catch (e) { if (e.result != Cr.NS_NOINTERFACE) { @@ -109,25 +124,31 @@ nsWebHandlerApp.prototype = { channel.loadFlags = Ci.nsIChannel.LOAD_DOCUMENT_URI; // load the channel - var uriLoader = Cc["@mozilla.org/uriloader;1"].getService(Ci.nsIURILoader); + var uriLoader = Cc["@mozilla.org/uriloader;1"].getService( + Ci.nsIURILoader + ); // XXX ideally, whether to pass the IS_CONTENT_PREFERRED flag should be // passed in from above. Practically, the flag is probably a reasonable // default since browsers don't care much, and link click is likely to be // the more interesting case for non-browser apps. See // for details. - uriLoader.openURI(channel, Ci.nsIURILoader.IS_CONTENT_PREFERRED, - aWindowContext); + uriLoader.openURI( + channel, + Ci.nsIURILoader.IS_CONTENT_PREFERRED, + aWindowContext + ); return; } let win = Services.wm.getMostRecentWindow("navigator:browser"); // If this is an extension handler, check private browsing access. - if (!privateAllowed && - PrivateBrowsingUtils.isContentWindowPrivate(win)) { - throw Components.Exception("Extension not allowed in private windows.", - Cr.NS_ERROR_FILE_NOT_FOUND); + if (!privateAllowed && PrivateBrowsingUtils.isContentWindowPrivate(win)) { + throw Components.Exception( + "Extension not allowed in private windows.", + Cr.NS_ERROR_FILE_NOT_FOUND + ); } // If we get an exception, there are several possible reasons why: @@ -147,11 +168,13 @@ nsWebHandlerApp.prototype = { // above, so for now we don't catch the exception. // openURI - win.browserDOMWindow.openURI(uriToSend, - null, // no window.opener - Ci.nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW, - Ci.nsIBrowserDOMWindow.OPEN_NEW, - Services.scriptSecurityManager.getSystemPrincipal()); + win.browserDOMWindow.openURI( + uriToSend, + null, // no window.opener + Ci.nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW, + Ci.nsIBrowserDOMWindow.OPEN_NEW, + Services.scriptSecurityManager.getSystemPrincipal() + ); }, // nsIWebHandlerApp diff --git a/uriloader/exthandler/tests/HandlerServiceTestUtils.jsm b/uriloader/exthandler/tests/HandlerServiceTestUtils.jsm index 5f22c57627bf..72c551d65419 100644 --- a/uriloader/exthandler/tests/HandlerServiceTestUtils.jsm +++ b/uriloader/exthandler/tests/HandlerServiceTestUtils.jsm @@ -7,23 +7,34 @@ "use strict"; -var EXPORTED_SYMBOLS = [ - "HandlerServiceTestUtils", -]; +var EXPORTED_SYMBOLS = ["HandlerServiceTestUtils"]; -const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm"); -const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); -const {Assert} = ChromeUtils.import("resource://testing-common/Assert.jsm"); +const { AppConstants } = ChromeUtils.import( + "resource://gre/modules/AppConstants.jsm" +); +const { XPCOMUtils } = ChromeUtils.import( + "resource://gre/modules/XPCOMUtils.jsm" +); +const { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm"); -XPCOMUtils.defineLazyServiceGetter(this, "gExternalProtocolService", - "@mozilla.org/uriloader/external-protocol-service;1", - "nsIExternalProtocolService"); -XPCOMUtils.defineLazyServiceGetter(this, "gMIMEService", - "@mozilla.org/mime;1", - "nsIMIMEService"); -XPCOMUtils.defineLazyServiceGetter(this, "gHandlerService", - "@mozilla.org/uriloader/handler-service;1", - "nsIHandlerService"); +XPCOMUtils.defineLazyServiceGetter( + this, + "gExternalProtocolService", + "@mozilla.org/uriloader/external-protocol-service;1", + "nsIExternalProtocolService" +); +XPCOMUtils.defineLazyServiceGetter( + this, + "gMIMEService", + "@mozilla.org/mime;1", + "nsIMIMEService" +); +XPCOMUtils.defineLazyServiceGetter( + this, + "gHandlerService", + "@mozilla.org/uriloader/handler-service;1", + "nsIHandlerService" +); var HandlerServiceTestUtils = { /** @@ -34,9 +45,7 @@ var HandlerServiceTestUtils = { * alphabetically regardless of category. */ getAllHandlerInfoTypes() { - return Array.from(gHandlerService.enumerate(), - info => info.type) - .sort(); + return Array.from(gHandlerService.enumerate(), info => info.type).sort(); }, /** @@ -97,12 +106,16 @@ var HandlerServiceTestUtils = { // method does on the default nsIHandlerService instance. let osDefaultHandlerFound = {}; let handlerInfo = gExternalProtocolService.getProtocolHandlerInfoFromOS( - type, osDefaultHandlerFound); + type, + osDefaultHandlerFound + ); if (gHandlerService.exists(handlerInfo)) { gHandlerService.fillHandlerInfo(handlerInfo, ""); } else { gExternalProtocolService.setProtocolHandlerDefaults( - handlerInfo, osDefaultHandlerFound.value); + handlerInfo, + osDefaultHandlerFound.value + ); } return handlerInfo; }, @@ -130,8 +143,8 @@ var HandlerServiceTestUtils = { // handler existed, and as such we initialize them to useSystemDefault. // This is because the AndroidBridge is not available in xpcshell tests. preferredAction = type.includes("/") - ? Ci.nsIHandlerInfo.useHelperApp - : Ci.nsIHandlerInfo.useSystemDefault; + ? Ci.nsIHandlerInfo.useHelperApp + : Ci.nsIHandlerInfo.useSystemDefault; // On Android, the default handler application is always the internal one. preferredApplicationHandler = { name: "Android chooser", @@ -140,8 +153,8 @@ var HandlerServiceTestUtils = { // On Desktop, the default preferredAction for MIME types is saveToDisk, // while for protocols it is alwaysAsk. preferredAction = type.includes("/") - ? Ci.nsIHandlerInfo.saveToDisk - : Ci.nsIHandlerInfo.alwaysAsk; + ? Ci.nsIHandlerInfo.saveToDisk + : Ci.nsIHandlerInfo.alwaysAsk; preferredApplicationHandler = null; } @@ -158,15 +171,18 @@ var HandlerServiceTestUtils = { * Checks whether an nsIHandlerInfo instance matches the provided object. */ assertHandlerInfoMatches(handlerInfo, expected) { - let expectedInterface = expected.type.includes("/") ? Ci.nsIMIMEInfo - : Ci.nsIHandlerInfo; + let expectedInterface = expected.type.includes("/") + ? Ci.nsIMIMEInfo + : Ci.nsIHandlerInfo; Assert.ok(handlerInfo instanceof expectedInterface); Assert.equal(handlerInfo.type, expected.type); if (!expected.preferredActionOSDependent) { Assert.equal(handlerInfo.preferredAction, expected.preferredAction); - Assert.equal(handlerInfo.alwaysAskBeforeHandling, - expected.alwaysAskBeforeHandling); + Assert.equal( + handlerInfo.alwaysAskBeforeHandling, + expected.alwaysAskBeforeHandling + ); } if (expectedInterface == Ci.nsIMIMEInfo) { @@ -178,14 +194,15 @@ var HandlerServiceTestUtils = { } if (expected.preferredApplicationHandler) { - this.assertHandlerAppMatches(handlerInfo.preferredApplicationHandler, - expected.preferredApplicationHandler); + this.assertHandlerAppMatches( + handlerInfo.preferredApplicationHandler, + expected.preferredApplicationHandler + ); } else { Assert.equal(handlerInfo.preferredApplicationHandler, null); } - let handlerAppsArrayEnumerator = - handlerInfo.possibleApplicationHandlers.enumerate(); + let handlerAppsArrayEnumerator = handlerInfo.possibleApplicationHandlers.enumerate(); if (AppConstants.platform == "android") { // On Android, the first handler application is always the internal one. this.assertHandlerAppMatches(handlerAppsArrayEnumerator.getNext(), { @@ -193,8 +210,10 @@ var HandlerServiceTestUtils = { }); } for (let expectedHandlerApp of expected.possibleApplicationHandlers || []) { - this.assertHandlerAppMatches(handlerAppsArrayEnumerator.getNext(), - expectedHandlerApp); + this.assertHandlerAppMatches( + handlerAppsArrayEnumerator.getNext(), + expectedHandlerApp + ); } Assert.ok(!handlerAppsArrayEnumerator.hasMoreElements()); }, diff --git a/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js b/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js index 223a7dabe6bf..28c371ac4779 100644 --- a/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js +++ b/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js @@ -1,35 +1,39 @@ /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ -const ROOT = getRootDirectory(gTestPath).replace("chrome://mochitests/content", - "https://example.com"); +const ROOT = getRootDirectory(gTestPath).replace( + "chrome://mochitests/content", + "https://example.com" +); const PAGE_URL = ROOT + "download_page.html"; const SJS_URL = ROOT + "download.sjs"; const HELPERAPP_DIALOG_CONTRACT_ID = "@mozilla.org/helperapplauncherdialog;1"; -const HELPERAPP_DIALOG_CID = - Components.ID(Cc[HELPERAPP_DIALOG_CONTRACT_ID].number); -const MOCK_HELPERAPP_DIALOG_CID = - Components.ID("{2f372b6f-56c9-46d5-af0d-9f09bb69860c}"); +const HELPERAPP_DIALOG_CID = Components.ID( + Cc[HELPERAPP_DIALOG_CONTRACT_ID].number +); +const MOCK_HELPERAPP_DIALOG_CID = Components.ID( + "{2f372b6f-56c9-46d5-af0d-9f09bb69860c}" +); -let registrar = Components.manager - .QueryInterface(Ci.nsIComponentRegistrar); +let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); let curDialogResolve = null; -function HelperAppLauncherDialog() { -} +function HelperAppLauncherDialog() {} HelperAppLauncherDialog.prototype = { show(aLauncher, aWindowContext, aReason) { ok(true, "Showing the helper app dialog"); curDialogResolve(aWindowContext); - executeSoon(() => { aLauncher.cancel(Cr.NS_ERROR_ABORT); }); + executeSoon(() => { + aLauncher.cancel(Cr.NS_ERROR_ABORT); + }); }, QueryInterface: ChromeUtils.generateQI([Ci.nsIHelperAppLauncherDialog]), }; function promiseHelperAppDialog() { - return new Promise((resolve) => { + return new Promise(resolve => { curDialogResolve = resolve; }); } @@ -39,17 +43,26 @@ let mockHelperAppService; add_task(async function setup() { // Replace the real helper app dialog with our own. mockHelperAppService = XPCOMUtils._getFactory(HelperAppLauncherDialog); - registrar.registerFactory(MOCK_HELPERAPP_DIALOG_CID, "", - HELPERAPP_DIALOG_CONTRACT_ID, - mockHelperAppService); + registrar.registerFactory( + MOCK_HELPERAPP_DIALOG_CID, + "", + HELPERAPP_DIALOG_CONTRACT_ID, + mockHelperAppService + ); }); add_task(async function simple_navigation() { // Tests that simple navigation gives us the right windowContext (that is, // the window that we're using). - await BrowserTestUtils.withNewTab({ gBrowser, url: PAGE_URL }, async function(browser) { + await BrowserTestUtils.withNewTab({ gBrowser, url: PAGE_URL }, async function( + browser + ) { let dialogAppeared = promiseHelperAppDialog(); - await BrowserTestUtils.synthesizeMouseAtCenter("#regular_load", {}, browser); + await BrowserTestUtils.synthesizeMouseAtCenter( + "#regular_load", + {}, + browser + ); let windowContext = await dialogAppeared; is(windowContext, browser.ownerGlobal, "got the right windowContext"); @@ -61,15 +74,18 @@ add_task(async function simple_navigation() { // automatically open and close that tab. async function testNewTab(browser) { let dialogAppeared = promiseHelperAppDialog(); - let tabOpened = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabOpen").then((event) => { - return [ event.target, BrowserTestUtils.waitForTabClosing(event.target) ]; + let tabOpened = BrowserTestUtils.waitForEvent( + gBrowser.tabContainer, + "TabOpen" + ).then(event => { + return [event.target, BrowserTestUtils.waitForTabClosing(event.target)]; }); await BrowserTestUtils.synthesizeMouseAtCenter("#target_blank", {}, browser); let windowContext = await dialogAppeared; is(windowContext, browser.ownerGlobal, "got the right windowContext"); - let [ tab, closingPromise ] = await tabOpened; + let [tab, closingPromise] = await tabOpened; await closingPromise; is(tab.linkedBrowser, null, "tab was opened and closed"); } @@ -77,7 +93,9 @@ async function testNewTab(browser) { add_task(async function target_blank() { // Tests that a link with target=_blank opens a new tab and closes it, // returning the window that we're using for navigation. - await BrowserTestUtils.withNewTab({ gBrowser, url: PAGE_URL }, async function(browser) { + await BrowserTestUtils.withNewTab({ gBrowser, url: PAGE_URL }, async function( + browser + ) { await testNewTab(browser); }); }); @@ -87,7 +105,9 @@ add_task(async function new_window() { // width and a height in window.open) opens a new window for the load, // realizes that we need to close that window and returns the *original* // window as the window context. - await BrowserTestUtils.withNewTab({ gBrowser, url: PAGE_URL }, async function(browser) { + await BrowserTestUtils.withNewTab({ gBrowser, url: PAGE_URL }, async function( + browser + ) { let dialogAppeared = promiseHelperAppDialog(); let windowOpened = BrowserTestUtils.waitForNewWindow(); @@ -96,7 +116,6 @@ add_task(async function new_window() { // Now allow request to complete: fetch(SJS_URL + "?finish"); - let windowContext = await dialogAppeared; is(windowContext, browser.ownerGlobal, "got the right windowContext"); @@ -109,9 +128,19 @@ add_task(async function new_window() { add_task(async function nested_window_opens() { // Tests that the window auto-closing feature works if the download is // initiated by a window that, itself, has an opener (see bug 1373109). - await BrowserTestUtils.withNewTab({ gBrowser, url: PAGE_URL }, async function(outerBrowser) { - let secondTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, `${PAGE_URL}?newwin`, true); - BrowserTestUtils.synthesizeMouseAtCenter("#open_in_new_tab", {}, outerBrowser); + await BrowserTestUtils.withNewTab({ gBrowser, url: PAGE_URL }, async function( + outerBrowser + ) { + let secondTabPromise = BrowserTestUtils.waitForNewTab( + gBrowser, + `${PAGE_URL}?newwin`, + true + ); + BrowserTestUtils.synthesizeMouseAtCenter( + "#open_in_new_tab", + {}, + outerBrowser + ); let secondTab = await secondTabPromise; let nestedBrowser = secondTab.linkedBrowser; @@ -121,7 +150,11 @@ add_task(async function nested_window_opens() { await testNewTab(nestedBrowser); - isnot(secondTab.linkedBrowser, null, "the page that triggered the download is still open"); + isnot( + secondTab.linkedBrowser, + null, + "the page that triggered the download is still open" + ); BrowserTestUtils.removeTab(secondTab); }); }); @@ -129,6 +162,10 @@ add_task(async function nested_window_opens() { add_task(async function cleanup() { // Unregister our factory from XPCOM and restore the original CID. registrar.unregisterFactory(MOCK_HELPERAPP_DIALOG_CID, mockHelperAppService); - registrar.registerFactory(HELPERAPP_DIALOG_CID, "", - HELPERAPP_DIALOG_CONTRACT_ID, null); + registrar.registerFactory( + HELPERAPP_DIALOG_CID, + "", + HELPERAPP_DIALOG_CONTRACT_ID, + null + ); }); diff --git a/uriloader/exthandler/tests/mochitest/browser_download_always_ask_preferred_app.js b/uriloader/exthandler/tests/mochitest/browser_download_always_ask_preferred_app.js index aa24b166e563..54dbae582636 100644 --- a/uriloader/exthandler/tests/mochitest/browser_download_always_ask_preferred_app.js +++ b/uriloader/exthandler/tests/mochitest/browser_download_always_ask_preferred_app.js @@ -10,9 +10,15 @@ add_task(async function() { info("Waiting for dialog to be populated."); await BrowserTestUtils.waitForAttribute("value", location, expectedValue); } - is(doc.getElementById("mode").selectedItem.id, "open", "Should be opening the file."); - ok(!dlg.document.getElementById("openHandler").selectedItem.hidden, - "Should not have selected a hidden item."); + is( + doc.getElementById("mode").selectedItem.id, + "open", + "Should be opening the file." + ); + ok( + !dlg.document.getElementById("openHandler").selectedItem.hidden, + "Should not have selected a hidden item." + ); let helperAppDialogHiddenPromise = BrowserTestUtils.windowClosed(dlg); doc.documentElement.cancelDialog(); await helperAppDialogHiddenPromise; diff --git a/uriloader/exthandler/tests/mochitest/browser_download_privatebrowsing.js b/uriloader/exthandler/tests/mochitest/browser_download_privatebrowsing.js index 36ef68139874..ddb6ba6c4ccc 100644 --- a/uriloader/exthandler/tests/mochitest/browser_download_privatebrowsing.js +++ b/uriloader/exthandler/tests/mochitest/browser_download_privatebrowsing.js @@ -38,8 +38,10 @@ add_task(async function test_download_privatebrowsing() { let win = await BrowserTestUtils.openNewBrowserWindow({ private: true }); try { - let tab = await BrowserTestUtils.openNewForegroundTab(win.gBrowser, - `data:text/html,download`); + let tab = await BrowserTestUtils.openNewForegroundTab( + win.gBrowser, + `data:text/html,download` + ); let promiseNextPrivateDownload = new Promise(resolve => { privateList.addView({ diff --git a/uriloader/exthandler/tests/mochitest/browser_remember_download_option.js b/uriloader/exthandler/tests/mochitest/browser_remember_download_option.js index fe7f11d5705d..be8c4eb8049a 100644 --- a/uriloader/exthandler/tests/mochitest/browser_remember_download_option.js +++ b/uriloader/exthandler/tests/mochitest/browser_remember_download_option.js @@ -8,12 +8,17 @@ add_task(async function() { let doc = dlg.document; // Set remember choice - ok(!doc.getElementById("rememberChoice").checked, - "Remember choice checkbox should be not checked."); + ok( + !doc.getElementById("rememberChoice").checked, + "Remember choice checkbox should be not checked." + ); doc.getElementById("rememberChoice").checked = true; // Make sure the mock handler information is not in nsIHandlerService - ok(!gHandlerSvc.exists(launcher.MIMEInfo), "Should not be in nsIHandlerService."); + ok( + !gHandlerSvc.exists(launcher.MIMEInfo), + "Should not be in nsIHandlerService." + ); // close the dialog by pushing the ok button. let dialogClosedPromise = BrowserTestUtils.windowClosed(dlg); @@ -32,15 +37,23 @@ add_task(async function() { for (let handlerInfo of gHandlerSvc.enumerate()) { if (handlerInfo.type == launcher.MIMEInfo.type) { // check the alwaysAskBeforeHandling - ok(!handlerInfo.alwaysAskBeforeHandling, - "Should turn off the always ask."); + ok( + !handlerInfo.alwaysAskBeforeHandling, + "Should turn off the always ask." + ); // check the preferredApplicationHandler - ok(handlerInfo.preferredApplicationHandler.equals( - launcher.MIMEInfo.preferredApplicationHandler), - "Should be equal to the mockedHandlerApp."); + ok( + handlerInfo.preferredApplicationHandler.equals( + launcher.MIMEInfo.preferredApplicationHandler + ), + "Should be equal to the mockedHandlerApp." + ); // check the perferredAction - is(handlerInfo.preferredAction, launcher.MIMEInfo.preferredAction, - "Should be equal to Ci.nsIHandlerInfo.useHelperApp."); + is( + handlerInfo.preferredAction, + launcher.MIMEInfo.preferredAction, + "Should be equal to Ci.nsIHandlerInfo.useHelperApp." + ); break; } } diff --git a/uriloader/exthandler/tests/mochitest/browser_web_protocol_handlers.js b/uriloader/exthandler/tests/mochitest/browser_web_protocol_handlers.js index 06d33ae9ce44..1221c8c12efd 100644 --- a/uriloader/exthandler/tests/mochitest/browser_web_protocol_handlers.js +++ b/uriloader/exthandler/tests/mochitest/browser_web_protocol_handlers.js @@ -1,4 +1,5 @@ -let testURL = "https://example.com/browser/" + +let testURL = + "https://example.com/browser/" + "uriloader/exthandler/tests/mochitest/protocolHandler.html"; add_task(async function() { @@ -18,45 +19,66 @@ add_task(async function() { button.click(); // Set the new handler as default. - const protoSvc = Cc["@mozilla.org/uriloader/external-protocol-service;1"]. - getService(Ci.nsIExternalProtocolService); + const protoSvc = Cc[ + "@mozilla.org/uriloader/external-protocol-service;1" + ].getService(Ci.nsIExternalProtocolService); let protoInfo = protoSvc.getProtocolHandlerInfo("web+testprotocol"); - is(protoInfo.preferredAction, protoInfo.useHelperApp, - "using a helper application is the preferred action"); + is( + protoInfo.preferredAction, + protoInfo.useHelperApp, + "using a helper application is the preferred action" + ); ok(!protoInfo.preferredApplicationHandler, "no preferred handler is set"); let handlers = protoInfo.possibleApplicationHandlers; is(1, handlers.length, "only one handler registered for web+testprotocol"); 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"); + is( + handler.uriTemplate, + "https://example.com/foobar?uri=%s", + "correct url template" + ); protoInfo.preferredApplicationHandler = handler; protoInfo.alwaysAskBeforeHandling = false; - const handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"]. - getService(Ci.nsIHandlerService); + const handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"].getService( + Ci.nsIHandlerService + ); handlerSvc.store(protoInfo); // Middle-click a testprotocol link and check the new tab is correct let link = "#link"; - const expectedURL = "https://example.com/foobar?uri=web%2Btestprotocol%3Atest"; + const expectedURL = + "https://example.com/foobar?uri=web%2Btestprotocol%3Atest"; - let promiseTabOpened = - BrowserTestUtils.waitForNewTab(gBrowser, expectedURL); - await BrowserTestUtils.synthesizeMouseAtCenter(link, {button: 1}, browser); + let promiseTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, expectedURL); + await BrowserTestUtils.synthesizeMouseAtCenter(link, { button: 1 }, browser); let tab = await promiseTabOpened; gBrowser.selectedTab = tab; - is(gURLBar.value, expectedURL, - "the expected URL is displayed in the location bar"); + is( + gURLBar.value, + expectedURL, + "the expected URL is displayed in the location bar" + ); BrowserTestUtils.removeTab(tab); // Shift-click the testprotocol link and check the new window. - let newWindowPromise = BrowserTestUtils.waitForNewWindow({url: expectedURL}); - await BrowserTestUtils.synthesizeMouseAtCenter(link, {shiftKey: true}, - browser); + let newWindowPromise = BrowserTestUtils.waitForNewWindow({ + url: expectedURL, + }); + await BrowserTestUtils.synthesizeMouseAtCenter( + link, + { shiftKey: true }, + browser + ); let win = await newWindowPromise; - await BrowserTestUtils.waitForCondition(() => win.gBrowser.currentURI.spec == expectedURL); - is(win.gURLBar.value, expectedURL, - "the expected URL is displayed in the location bar"); + await BrowserTestUtils.waitForCondition( + () => win.gBrowser.currentURI.spec == expectedURL + ); + is( + win.gURLBar.value, + expectedURL, + "the expected URL is displayed in the location bar" + ); await BrowserTestUtils.closeWindow(win); // Click the testprotocol link and check the url in the current tab. @@ -64,8 +86,11 @@ add_task(async function() { await BrowserTestUtils.synthesizeMouseAtCenter(link, {}, browser); await loadPromise; await BrowserTestUtils.waitForCondition(() => gURLBar.value != testURL); - is(gURLBar.value, expectedURL, - "the expected URL is displayed in the location bar"); + is( + gURLBar.value, + expectedURL, + "the expected URL is displayed in the location bar" + ); // Cleanup. protoInfo.preferredApplicationHandler = null; diff --git a/uriloader/exthandler/tests/mochitest/handlerApps.js b/uriloader/exthandler/tests/mochitest/handlerApps.js index 065c35780c2d..aa841f13be62 100644 --- a/uriloader/exthandler/tests/mochitest/handlerApps.js +++ b/uriloader/exthandler/tests/mochitest/handlerApps.js @@ -9,18 +9,20 @@ const Cc = SpecialPowers.Cc; function test() { // set up the web handler object - var webHandler = Cc["@mozilla.org/uriloader/web-handler-app;1"]. - createInstance(SpecialPowers.Ci.nsIWebHandlerApp); + var webHandler = Cc[ + "@mozilla.org/uriloader/web-handler-app;1" + ].createInstance(SpecialPowers.Ci.nsIWebHandlerApp); webHandler.name = "Test Web Handler App"; webHandler.uriTemplate = - "https://example.com/tests/uriloader/exthandler/tests/mochitest/" + - "handlerApp.xhtml?uri=%s"; + "https://example.com/tests/uriloader/exthandler/tests/mochitest/" + + "handlerApp.xhtml?uri=%s"; // set up the uri to test with /* eslint-disable mozilla/use-services */ - var ioService = Cc["@mozilla.org/network/io-service;1"]. - getService(SpecialPowers.Ci.nsIIOService); + var ioService = Cc["@mozilla.org/network/io-service;1"].getService( + SpecialPowers.Ci.nsIIOService + ); var uri = ioService.newURI(testURI); @@ -41,18 +43,21 @@ function test() { ok(true, "webHandler launchWithURI (new window/tab) test started"); // set up the local handler object - var localHandler = Cc["@mozilla.org/uriloader/local-handler-app;1"]. - createInstance(SpecialPowers.Ci.nsILocalHandlerApp); + var localHandler = Cc[ + "@mozilla.org/uriloader/local-handler-app;1" + ].createInstance(SpecialPowers.Ci.nsILocalHandlerApp); localHandler.name = "Test Local Handler App"; // get a local app that we know will be there and do something sane /* eslint-disable mozilla/use-services */ - var osString = Cc["@mozilla.org/xre/app-info;1"]. - getService(SpecialPowers.Ci.nsIXULRuntime).OS; + var osString = Cc["@mozilla.org/xre/app-info;1"].getService( + SpecialPowers.Ci.nsIXULRuntime + ).OS; - var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. - getService(SpecialPowers.Ci.nsIDirectoryServiceProvider); + var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService( + SpecialPowers.Ci.nsIDirectoryServiceProvider + ); if (osString == "WINNT") { var windowsDir = dirSvc.getFile("WinD", {}); var exe = windowsDir.clone().QueryInterface(SpecialPowers.Ci.nsIFile); @@ -61,9 +66,9 @@ function test() { var localAppsDir = dirSvc.getFile("LocApp", {}); exe = localAppsDir.clone(); exe.append("iCal.app"); // lingers after the tests finish, but this seems - // seems better than explicitly killing it, since - // developers who run the tests locally may well - // information in their running copy of iCal + // seems better than explicitly killing it, since + // developers who run the tests locally may well + // information in their running copy of iCal if (navigator.userAgent.match(/ SeaMonkey\//)) { // SeaMonkey tinderboxes don't like to have iCal lingering (and focused) @@ -71,14 +76,16 @@ function test() { todo(false, "On SeaMonkey, testing OS X as generic Unix. (Bug 749872)"); // assume a generic UNIX variant - exe = Cc["@mozilla.org/file/local;1"]. - createInstance(SpecialPowers.Ci.nsIFile); + exe = Cc["@mozilla.org/file/local;1"].createInstance( + SpecialPowers.Ci.nsIFile + ); exe.initWithPath("/bin/echo"); } } else { // assume a generic UNIX variant - exe = Cc["@mozilla.org/file/local;1"]. - createInstance(SpecialPowers.Ci.nsIFile); + exe = Cc["@mozilla.org/file/local;1"].createInstance( + SpecialPowers.Ci.nsIFile + ); exe.initWithPath("/bin/echo"); } @@ -91,12 +98,14 @@ function test() { // if we ever decide that killing iCal is the right thing to do, change // the if statement below from "NOTDarwin" to "Darwin" if (osString == "NOTDarwin") { - var killall = Cc["@mozilla.org/file/local;1"]. - createInstance(SpecialPowers.Ci.nsIFile); + var killall = Cc["@mozilla.org/file/local;1"].createInstance( + SpecialPowers.Ci.nsIFile + ); killall.initWithPath("/usr/bin/killall"); - var process = Cc["@mozilla.org/process/util;1"]. - createInstance(SpecialPowers.Ci.nsIProcess); + var process = Cc["@mozilla.org/process/util;1"].createInstance( + SpecialPowers.Ci.nsIProcess + ); process.init(killall); var args = ["iCal"]; diff --git a/uriloader/exthandler/tests/mochitest/head.js b/uriloader/exthandler/tests/mochitest/head.js index 04b42858adce..950c7da2fc8a 100644 --- a/uriloader/exthandler/tests/mochitest/head.js +++ b/uriloader/exthandler/tests/mochitest/head.js @@ -1,7 +1,9 @@ -var {FileUtils} = ChromeUtils.import("resource://gre/modules/FileUtils.jsm"); +var { FileUtils } = ChromeUtils.import("resource://gre/modules/FileUtils.jsm"); var gMimeSvc = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService); -var gHandlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService); +var gHandlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"].getService( + Ci.nsIHandlerService +); function createMockedHandlerApp() { // Mock the executable @@ -11,8 +13,9 @@ function createMockedHandlerApp() { } // Mock the handler app - let mockedHandlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"] - .createInstance(Ci.nsILocalHandlerApp); + let mockedHandlerApp = Cc[ + "@mozilla.org/uriloader/local-handler-app;1" + ].createInstance(Ci.nsILocalHandlerApp); mockedHandlerApp.executable = mockedExecutable; mockedHandlerApp.detailedDescription = "Mocked handler app"; @@ -28,14 +31,19 @@ function createMockedHandlerApp() { function createMockedObjects(createHandlerApp) { // Mock the mime info - let internalMockedMIME = gMimeSvc.getFromTypeAndExtension("text/x-test-handler", null); + let internalMockedMIME = gMimeSvc.getFromTypeAndExtension( + "text/x-test-handler", + null + ); internalMockedMIME.alwaysAskBeforeHandling = true; internalMockedMIME.preferredAction = Ci.nsIHandlerInfo.useHelperApp; internalMockedMIME.appendExtension("abc"); if (createHandlerApp) { let mockedHandlerApp = createMockedHandlerApp(); internalMockedMIME.description = mockedHandlerApp.detailedDescription; - internalMockedMIME.possibleApplicationHandlers.appendElement(mockedHandlerApp); + internalMockedMIME.possibleApplicationHandlers.appendElement( + mockedHandlerApp + ); internalMockedMIME.preferredApplicationHandler = mockedHandlerApp; } @@ -43,12 +51,12 @@ function createMockedObjects(createHandlerApp) { let mockedMIME = new Proxy(internalMockedMIME, { get(target, property) { switch (property) { - case "hasDefaultHandler": - return true; - case "defaultDescription": - return "Default description"; - default: - return target[property]; + case "hasDefaultHandler": + return true; + case "defaultDescription": + return "Default description"; + default: + return target[property]; } }, }); @@ -68,12 +76,18 @@ function createMockedObjects(createHandlerApp) { targetFile: null, // never read // PRTime is microseconds since epoch, Date.now() returns milliseconds: timeDownloadStarted: Date.now() * 1000, - QueryInterface: ChromeUtils.generateQI([Ci.nsICancelable, Ci.nsIHelperAppLauncher]), + QueryInterface: ChromeUtils.generateQI([ + Ci.nsICancelable, + Ci.nsIHelperAppLauncher, + ]), }; registerCleanupFunction(function() { // remove the mocked mime info from database. - let mockHandlerInfo = gMimeSvc.getFromTypeAndExtension("text/x-test-handler", null); + let mockHandlerInfo = gMimeSvc.getFromTypeAndExtension( + "text/x-test-handler", + null + ); if (gHandlerSvc.exists(mockHandlerInfo)) { gHandlerSvc.remove(mockHandlerInfo); } @@ -83,22 +97,29 @@ function createMockedObjects(createHandlerApp) { } async function openHelperAppDialog(launcher) { - let helperAppDialog = Cc["@mozilla.org/helperapplauncherdialog;1"]. - createInstance(Ci.nsIHelperAppLauncherDialog); + let helperAppDialog = Cc[ + "@mozilla.org/helperapplauncherdialog;1" + ].createInstance(Ci.nsIHelperAppLauncherDialog); let helperAppDialogShownPromise = BrowserTestUtils.domWindowOpened(); try { helperAppDialog.show(launcher, window, "foopy"); } catch (ex) { - ok(false, "Trying to show unknownContentType.xul failed with exception: " + ex); + ok( + false, + "Trying to show unknownContentType.xul failed with exception: " + ex + ); Cu.reportError(ex); } let dlg = await helperAppDialogShownPromise; await BrowserTestUtils.waitForEvent(dlg, "load", false); - is(dlg.location.href, "chrome://mozapps/content/downloads/unknownContentType.xul", - "Got correct dialog"); + is( + dlg.location.href, + "chrome://mozapps/content/downloads/unknownContentType.xul", + "Got correct dialog" + ); return dlg; } diff --git a/uriloader/exthandler/tests/mochitest/unsafeBidi_chromeScript.js b/uriloader/exthandler/tests/mochitest/unsafeBidi_chromeScript.js index 48d690bcfda1..708d1c5837ef 100644 --- a/uriloader/exthandler/tests/mochitest/unsafeBidi_chromeScript.js +++ b/uriloader/exthandler/tests/mochitest/unsafeBidi_chromeScript.js @@ -1,11 +1,15 @@ -const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); +const { XPCOMUtils } = ChromeUtils.import( + "resource://gre/modules/XPCOMUtils.jsm" +); const HELPERAPP_DIALOG_CONTRACT = "@mozilla.org/helperapplauncherdialog;1"; -const HELPERAPP_DIALOG_CID = - Components.ID(Cc[HELPERAPP_DIALOG_CONTRACT].number); +const HELPERAPP_DIALOG_CID = Components.ID( + Cc[HELPERAPP_DIALOG_CONTRACT].number +); -const FAKE_CID = Cc["@mozilla.org/uuid-generator;1"]. - getService(Ci.nsIUUIDGenerator).generateUUID(); +const FAKE_CID = Cc["@mozilla.org/uuid-generator;1"] + .getService(Ci.nsIUUIDGenerator) + .generateUUID(); /* eslint-env mozilla/frame-script */ function HelperAppLauncherDialog() {} HelperAppLauncherDialog.prototype = { @@ -16,11 +20,19 @@ HelperAppLauncherDialog.prototype = { }; var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); -registrar.registerFactory(FAKE_CID, "", HELPERAPP_DIALOG_CONTRACT, - XPCOMUtils._getFactory(HelperAppLauncherDialog)); +registrar.registerFactory( + FAKE_CID, + "", + HELPERAPP_DIALOG_CONTRACT, + XPCOMUtils._getFactory(HelperAppLauncherDialog) +); addMessageListener("unregister", function() { - registrar.registerFactory(HELPERAPP_DIALOG_CID, "", - HELPERAPP_DIALOG_CONTRACT, null); + registrar.registerFactory( + HELPERAPP_DIALOG_CID, + "", + HELPERAPP_DIALOG_CONTRACT, + null + ); sendAsyncMessage("unregistered"); }); diff --git a/uriloader/exthandler/tests/unit/head.js b/uriloader/exthandler/tests/unit/head.js index 41a26da0bbb0..3330a309be8c 100644 --- a/uriloader/exthandler/tests/unit/head.js +++ b/uriloader/exthandler/tests/unit/head.js @@ -8,19 +8,31 @@ "use strict"; -var {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm"); -var {FileUtils} = ChromeUtils.import("resource://gre/modules/FileUtils.jsm"); -var {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); -var {OS, require} = ChromeUtils.import("resource://gre/modules/osfile.jsm"); -var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); -var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); +var { AppConstants } = ChromeUtils.import( + "resource://gre/modules/AppConstants.jsm" +); +var { FileUtils } = ChromeUtils.import("resource://gre/modules/FileUtils.jsm"); +var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); +var { OS, require } = ChromeUtils.import("resource://gre/modules/osfile.jsm"); +var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); +var { XPCOMUtils } = ChromeUtils.import( + "resource://gre/modules/XPCOMUtils.jsm" +); -ChromeUtils.import("resource://testing-common/HandlerServiceTestUtils.jsm", this); -var {TestUtils} = ChromeUtils.import("resource://testing-common/TestUtils.jsm"); +ChromeUtils.import( + "resource://testing-common/HandlerServiceTestUtils.jsm", + this +); +var { TestUtils } = ChromeUtils.import( + "resource://testing-common/TestUtils.jsm" +); -XPCOMUtils.defineLazyServiceGetter(this, "gHandlerService", - "@mozilla.org/uriloader/handler-service;1", - "nsIHandlerService"); +XPCOMUtils.defineLazyServiceGetter( + this, + "gHandlerService", + "@mozilla.org/uriloader/handler-service;1", + "nsIHandlerService" +); do_get_profile(); diff --git a/uriloader/exthandler/tests/unit/test_badMIMEType.js b/uriloader/exthandler/tests/unit/test_badMIMEType.js index 8a4b71768fac..49c5e8d84863 100644 --- a/uriloader/exthandler/tests/unit/test_badMIMEType.js +++ b/uriloader/exthandler/tests/unit/test_badMIMEType.js @@ -12,12 +12,14 @@ function run_test() { var badMimeType = "text/plainÿ"; Assert.equal(badMimeType.length, 11); try { - 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) { + 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 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..7202db58dee7 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 @@ -11,16 +11,15 @@ function run_test() { // --- Common services --- - const mimeService = Cc["@mozilla.org/mime;1"]. - getService(Ci.nsIMIMEService); + const mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService); const categoryManager = Services.catMan; // --- Test procedure --- - const kTestExtension = "testextension"; + const kTestExtension = "testextension"; const kTestExtensionMixedCase = "testExtensIon"; - const kTestMimeType = "application/x-testextension"; + const kTestMimeType = "application/x-testextension"; // Ensure that the test extension is not initially recognized by the operating // system or the "ext-to-type-mapping" category. @@ -30,8 +29,10 @@ function run_test() { // The line above should have thrown an exception. do_throw("nsIMIMEService.getTypeFromExtension succeeded unexpectedly"); } catch (e) { - if (!(e instanceof Ci.nsIException) || - e.result != Cr.NS_ERROR_NOT_AVAILABLE) { + 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. @@ -39,8 +40,13 @@ function run_test() { } // Add a temporary category entry mapping the extension to the MIME type. - categoryManager.addCategoryEntry("ext-to-type-mapping", kTestExtension, - kTestMimeType, false, true); + categoryManager.addCategoryEntry( + "ext-to-type-mapping", + kTestExtension, + kTestMimeType, + false, + true + ); // Check that the mapping is recognized in the simple case. var type = mimeService.getTypeFromExtension(kTestExtension); @@ -51,5 +57,9 @@ function run_test() { Assert.equal(type, kTestMimeType); // Clean up after ourselves. - categoryManager.deleteCategoryEntry("ext-to-type-mapping", kTestExtension, false); + categoryManager.deleteCategoryEntry( + "ext-to-type-mapping", + kTestExtension, + false + ); } 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 4310ca275ca9..9ed0579ccca4 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 @@ -21,21 +21,33 @@ function run_test() { registerMockWindowsRegKeyFactory(); // Check the mock has been properly activated. - let regKey = Cc["@mozilla.org/windows-registry-key;1"] - .createInstance(Ci.nsIWindowsRegKey); - regKey.open(Ci.nsIWindowsRegKey.ROOT_KEY_CLASSES_ROOT, FILE_EXTENSION, - Ci.nsIWindowsRegKey.ACCESS_QUERY_VALUE); - Assert.equal(regKey.readStringValue("content type"), "", - "Check the mock replied as expected."); + let regKey = Cc["@mozilla.org/windows-registry-key;1"].createInstance( + Ci.nsIWindowsRegKey + ); + regKey.open( + Ci.nsIWindowsRegKey.ROOT_KEY_CLASSES_ROOT, + FILE_EXTENSION, + Ci.nsIWindowsRegKey.ACCESS_QUERY_VALUE + ); + Assert.equal( + regKey.readStringValue("content type"), + "", + "Check the mock replied as expected." + ); Assert.ok(gTestUsedOurMock, "The test properly used the mock registry"); // Reset gTestUsedOurMock, because we just used it. gTestUsedOurMock = false; // Try and get the MIME type associated with the extension. If this // operation does not throw an unexpected exception, the test succeeds. - Assert.throws(() => { - Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService) - .getTypeFromExtension(FILE_EXTENSION); - }, /NS_ERROR_NOT_AVAILABLE/, "Should throw a NOT_AVAILABLE exception"); + Assert.throws( + () => { + Cc["@mozilla.org/mime;1"] + .getService(Ci.nsIMIMEService) + .getTypeFromExtension(FILE_EXTENSION); + }, + /NS_ERROR_NOT_AVAILABLE/, + "Should throw a NOT_AVAILABLE exception" + ); Assert.ok(gTestUsedOurMock, "The test properly used the mock registry"); } @@ -122,9 +134,11 @@ MockWindowsRegKey.prototype = { readStringValue(aName) { // If this is the key under test, return a fake value - if (this._rootKey == Ci.nsIWindowsRegKey.ROOT_KEY_CLASSES_ROOT && - this._relPath.toLowerCase() == FILE_EXTENSION && - aName.toLowerCase() == "content type") { + if ( + this._rootKey == Ci.nsIWindowsRegKey.ROOT_KEY_CLASSES_ROOT && + this._relPath.toLowerCase() == FILE_EXTENSION && + aName.toLowerCase() == "content type" + ) { gTestUsedOurMock = true; return ""; } @@ -140,8 +154,9 @@ function registerMockWindowsRegKeyFactory() { let originalWindowsRegKeyCID = Cc[kWindowsRegKeyContractID].number; info("Create a mock RegKey factory"); - let originalRegKey = Cc["@mozilla.org/windows-registry-key;1"] - .createInstance(Ci.nsIWindowsRegKey); + let originalRegKey = Cc["@mozilla.org/windows-registry-key;1"].createInstance( + Ci.nsIWindowsRegKey + ); let mockWindowsRegKeyFactory = { createInstance(outer, iid) { if (outer != null) { @@ -163,10 +178,7 @@ function registerMockWindowsRegKeyFactory() { registerCleanupFunction(() => { // Free references to the mock factory - registrar.unregisterFactory( - kMockCID, - mockWindowsRegKeyFactory - ); + registrar.unregisterFactory(kMockCID, mockWindowsRegKeyFactory); // Restore the original factory registrar.registerFactory( Components.ID(originalWindowsRegKeyCID), diff --git a/uriloader/exthandler/tests/unit/test_handlerService.js b/uriloader/exthandler/tests/unit/test_handlerService.js index bbc94a4c3d1f..d518d31f6ef1 100644 --- a/uriloader/exthandler/tests/unit/test_handlerService.js +++ b/uriloader/exthandler/tests/unit/test_handlerService.js @@ -6,19 +6,21 @@ function run_test() { //* *************************************************************************// // Constants - const handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"]. - getService(Ci.nsIHandlerService); + const handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"].getService( + Ci.nsIHandlerService + ); - const mimeSvc = Cc["@mozilla.org/mime;1"]. - getService(Ci.nsIMIMEService); + const mimeSvc = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService); - const protoSvc = Cc["@mozilla.org/uriloader/external-protocol-service;1"]. - getService(Ci.nsIExternalProtocolService); + const protoSvc = Cc[ + "@mozilla.org/uriloader/external-protocol-service;1" + ].getService(Ci.nsIExternalProtocolService); const prefSvc = Services.prefs; - const env = Cc["@mozilla.org/process/environment;1"]. - getService(Ci.nsIEnvironment); + const env = Cc["@mozilla.org/process/environment;1"].getService( + Ci.nsIEnvironment + ); const rootPrefBranch = prefSvc.getBranch(""); @@ -26,12 +28,11 @@ function run_test() { if (mozinfo.os == "win") { // Check mailto handler from registry. // If registry entry is nothing, no mailto handler - let regSvc = Cc["@mozilla.org/windows-registry-key;1"]. - createInstance(Ci.nsIWindowsRegKey); + let regSvc = Cc["@mozilla.org/windows-registry-key;1"].createInstance( + Ci.nsIWindowsRegKey + ); try { - regSvc.open(regSvc.ROOT_KEY_CLASSES_ROOT, - "mailto", - regSvc.ACCESS_READ); + regSvc.open(regSvc.ROOT_KEY_CLASSES_ROOT, "mailto", regSvc.ACCESS_READ); noMailto = false; } catch (ex) { noMailto = true; @@ -42,8 +43,9 @@ function run_test() { if (mozinfo.os == "linux") { // Check mailto handler from GIO // If there isn't one, then we have no mailto handler - let gIOSvc = Cc["@mozilla.org/gio-service;1"]. - createInstance(Ci.nsIGIOService); + let gIOSvc = Cc["@mozilla.org/gio-service;1"].createInstance( + Ci.nsIGIOService + ); try { gIOSvc.getAppForURIScheme("mailto"); noMailto = false; @@ -66,13 +68,15 @@ function run_test() { // if (!executable.exists()) // executable.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o755); - var localHandler = Cc["@mozilla.org/uriloader/local-handler-app;1"]. - createInstance(Ci.nsILocalHandlerApp); + var localHandler = Cc[ + "@mozilla.org/uriloader/local-handler-app;1" + ].createInstance(Ci.nsILocalHandlerApp); localHandler.name = "Local Handler"; localHandler.executable = executable; - var webHandler = Cc["@mozilla.org/uriloader/web-handler-app;1"]. - createInstance(Ci.nsIWebHandlerApp); + var webHandler = Cc[ + "@mozilla.org/uriloader/web-handler-app;1" + ].createInstance(Ci.nsIWebHandlerApp); webHandler.name = "Web Handler"; webHandler.uriTemplate = "http://www.example.com/?%s"; @@ -80,7 +84,6 @@ function run_test() { // make sense to move each test into its own scope so we don't run the risk // of one test stomping on another's data. - //* *************************************************************************// // Test Default Properties @@ -154,16 +157,18 @@ function run_test() { // OS default exists, injected default exists, explicit warning pref: false prefSvc.setBoolPref(kExternalWarningPrefPrefix + "mailto", false); protoInfo = protoSvc.getProtocolHandlerInfo("mailto"); - if (haveDefaultHandlersVersion) + if (haveDefaultHandlersVersion) { Assert.equal(2, protoInfo.possibleApplicationHandlers.length); - else + } else { Assert.equal(0, protoInfo.possibleApplicationHandlers.length); + } // Win7+ or Linux's GIO might not have a default mailto: handler - if (noMailto) + if (noMailto) { Assert.ok(protoInfo.alwaysAskBeforeHandling); - else + } else { Assert.ok(!protoInfo.alwaysAskBeforeHandling); + } // OS default exists, injected default exists, explicit warning pref: true prefSvc.setBoolPref(kExternalWarningPrefPrefix + "mailto", true); @@ -175,10 +180,11 @@ function run_test() { // the pref is true, the value in RDF is false. The injected mailto handler // carried over the default pref value, and so when we set the pref above // to true it's ignored. - if (noMailto) + if (noMailto) { Assert.ok(protoInfo.alwaysAskBeforeHandling); - else + } else { Assert.ok(!protoInfo.alwaysAskBeforeHandling); + } } else { Assert.equal(0, protoInfo.possibleApplicationHandlers.length); Assert.ok(protoInfo.alwaysAskBeforeHandling); @@ -196,7 +202,6 @@ function run_test() { Assert.ok(protoInfo.alwaysAskBeforeHandling); } - //* *************************************************************************// // Test Round-Trip Data Integrity @@ -242,46 +247,63 @@ function run_test() { // Make sure the handler service's remove method removes a handler record. handlerSvc.remove(handlerInfo2); let handlers = handlerSvc.enumerate(); - while (handlers.hasMoreElements()) - Assert.notEqual(handlers.getNext().QueryInterface(Ci.nsIHandlerInfo).type, - handlerInfo2.type); + while (handlers.hasMoreElements()) { + Assert.notEqual( + handlers.getNext().QueryInterface(Ci.nsIHandlerInfo).type, + handlerInfo2.type + ); + } // Make sure we can store and retrieve a handler info object with no preferred // handler. - var noPreferredHandlerInfo = - mimeSvc.getFromTypeAndExtension("nonexistent/no-preferred-handler", null); + var noPreferredHandlerInfo = mimeSvc.getFromTypeAndExtension( + "nonexistent/no-preferred-handler", + null + ); handlerSvc.store(noPreferredHandlerInfo); - noPreferredHandlerInfo = - mimeSvc.getFromTypeAndExtension("nonexistent/no-preferred-handler", null); + noPreferredHandlerInfo = mimeSvc.getFromTypeAndExtension( + "nonexistent/no-preferred-handler", + null + ); Assert.equal(noPreferredHandlerInfo.preferredApplicationHandler, null); // Make sure that the handler service removes an existing handler record // if we store a handler info object with no preferred handler. - var removePreferredHandlerInfo = - mimeSvc.getFromTypeAndExtension("nonexistent/rem-preferred-handler", null); + var removePreferredHandlerInfo = mimeSvc.getFromTypeAndExtension( + "nonexistent/rem-preferred-handler", + null + ); removePreferredHandlerInfo.preferredApplicationHandler = localHandler; handlerSvc.store(removePreferredHandlerInfo); - removePreferredHandlerInfo = - mimeSvc.getFromTypeAndExtension("nonexistent/rem-preferred-handler", null); + removePreferredHandlerInfo = mimeSvc.getFromTypeAndExtension( + "nonexistent/rem-preferred-handler", + null + ); removePreferredHandlerInfo.preferredApplicationHandler = null; handlerSvc.store(removePreferredHandlerInfo); - removePreferredHandlerInfo = - mimeSvc.getFromTypeAndExtension("nonexistent/rem-preferred-handler", null); + removePreferredHandlerInfo = mimeSvc.getFromTypeAndExtension( + "nonexistent/rem-preferred-handler", + null + ); Assert.equal(removePreferredHandlerInfo.preferredApplicationHandler, null); // Make sure we can store and retrieve a handler info object with possible // handlers. We test both adding and removing handlers. // Get a handler info and make sure it has no possible handlers. - var possibleHandlersInfo = - mimeSvc.getFromTypeAndExtension("nonexistent/possible-handlers", null); + var possibleHandlersInfo = mimeSvc.getFromTypeAndExtension( + "nonexistent/possible-handlers", + null + ); Assert.equal(possibleHandlersInfo.possibleApplicationHandlers.length, 0); // Store and re-retrieve the handler and make sure it still has no possible // handlers. handlerSvc.store(possibleHandlersInfo); - possibleHandlersInfo = - mimeSvc.getFromTypeAndExtension("nonexistent/possible-handlers", null); + possibleHandlersInfo = mimeSvc.getFromTypeAndExtension( + "nonexistent/possible-handlers", + null + ); Assert.equal(possibleHandlersInfo.possibleApplicationHandlers.length, 0); // Add two handlers, store the object, re-retrieve it, and make sure it has @@ -289,26 +311,37 @@ function run_test() { possibleHandlersInfo.possibleApplicationHandlers.appendElement(localHandler); possibleHandlersInfo.possibleApplicationHandlers.appendElement(webHandler); handlerSvc.store(possibleHandlersInfo); - possibleHandlersInfo = - mimeSvc.getFromTypeAndExtension("nonexistent/possible-handlers", null); + possibleHandlersInfo = mimeSvc.getFromTypeAndExtension( + "nonexistent/possible-handlers", + null + ); Assert.equal(possibleHandlersInfo.possibleApplicationHandlers.length, 2); // Figure out which is the local and which is the web handler and the index // in the array of the local handler, which is the one we're going to remove // to test removal of a handler. - var handler1 = possibleHandlersInfo.possibleApplicationHandlers. - queryElementAt(0, Ci.nsIHandlerApp); - var handler2 = possibleHandlersInfo.possibleApplicationHandlers. - queryElementAt(1, Ci.nsIHandlerApp); + var handler1 = possibleHandlersInfo.possibleApplicationHandlers.queryElementAt( + 0, + Ci.nsIHandlerApp + ); + var handler2 = possibleHandlersInfo.possibleApplicationHandlers.queryElementAt( + 1, + Ci.nsIHandlerApp + ); var localPossibleHandler, webPossibleHandler, localIndex; - if (handler1 instanceof Ci.nsILocalHandlerApp) - [localPossibleHandler, webPossibleHandler, localIndex] = [handler1, - handler2, - 0]; - else - [localPossibleHandler, webPossibleHandler, localIndex] = [handler2, - handler1, - 1]; + if (handler1 instanceof Ci.nsILocalHandlerApp) { + [localPossibleHandler, webPossibleHandler, localIndex] = [ + handler1, + handler2, + 0, + ]; + } else { + [localPossibleHandler, webPossibleHandler, localIndex] = [ + handler2, + handler1, + 1, + ]; + } localPossibleHandler.QueryInterface(Ci.nsILocalHandlerApp); webPossibleHandler.QueryInterface(Ci.nsIWebHandlerApp); @@ -322,20 +355,25 @@ function run_test() { // it only has one handler. possibleHandlersInfo.possibleApplicationHandlers.removeElementAt(localIndex); handlerSvc.store(possibleHandlersInfo); - possibleHandlersInfo = - mimeSvc.getFromTypeAndExtension("nonexistent/possible-handlers", null); + possibleHandlersInfo = mimeSvc.getFromTypeAndExtension( + "nonexistent/possible-handlers", + null + ); Assert.equal(possibleHandlersInfo.possibleApplicationHandlers.length, 1); // Make sure the handler is the one we didn't remove. - webPossibleHandler = possibleHandlersInfo.possibleApplicationHandlers. - queryElementAt(0, Ci.nsIWebHandlerApp); + webPossibleHandler = possibleHandlersInfo.possibleApplicationHandlers.queryElementAt( + 0, + Ci.nsIWebHandlerApp + ); 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); + var localApp = Cc[ + "@mozilla.org/uriloader/local-handler-app;1" + ].createInstance(Ci.nsILocalHandlerApp); var handlerApp = localApp.QueryInterface(Ci.nsIHandlerApp); Assert.ok(handlerApp.equals(localApp)); @@ -353,8 +391,9 @@ function run_test() { localApp.clearParameters(); Assert.equal(0, localApp.parameterCount); - var localApp2 = Cc["@mozilla.org/uriloader/local-handler-app;1"]. - createInstance(Ci.nsILocalHandlerApp); + var localApp2 = Cc[ + "@mozilla.org/uriloader/local-handler-app;1" + ].createInstance(Ci.nsILocalHandlerApp); localApp2.executable = executable; @@ -406,7 +445,6 @@ function run_test() { var lolType = handlerSvc.getTypeFromExtension("lolcat"); Assert.equal(lolType, ""); - // add a handler for the extension var lolHandler = mimeSvc.getFromTypeAndExtension("application/lolcat", null); @@ -429,7 +467,10 @@ function run_test() { if (mozinfo.os != "win" && mozinfo.os != "mac") { 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.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..a543da40142c 100644 --- a/uriloader/exthandler/tests/unit/test_handlerService_store.js +++ b/uriloader/exthandler/tests/unit/test_handlerService_store.js @@ -6,8 +6,9 @@ */ // Set up an nsIWebHandlerApp instance that can be used in multiple tests. -let webHandlerApp = Cc["@mozilla.org/uriloader/web-handler-app;1"] - .createInstance(Ci.nsIWebHandlerApp); +let webHandlerApp = Cc[ + "@mozilla.org/uriloader/web-handler-app;1" +].createInstance(Ci.nsIWebHandlerApp); webHandlerApp.name = "Web Handler"; webHandlerApp.uriTemplate = "https://www.example.com/?url=%s"; let expectedWebHandlerApp = { @@ -18,8 +19,9 @@ let expectedWebHandlerApp = { // Set up an nsILocalHandlerApp instance that can be used in multiple tests. The // executable should exist, but it doesn't need to point to an actual file, so // we simply initialize it to the path of an existing directory. -let localHandlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"] - .createInstance(Ci.nsILocalHandlerApp); +let localHandlerApp = Cc[ + "@mozilla.org/uriloader/local-handler-app;1" +].createInstance(Ci.nsILocalHandlerApp); localHandlerApp.name = "Local Handler"; localHandlerApp.executable = FileUtils.getFile("TmpD", []); let expectedLocalHandlerApp = { @@ -58,9 +60,7 @@ function assertAllHandlerInfosMatchTestData() { type: "example/type.handleinternally", preferredAction: Ci.nsIHandlerInfo.handleInternally, alwaysAskBeforeHandling: false, - fileExtensions: [ - "example_one", - ], + fileExtensions: ["example_one"], }); HandlerServiceTestUtils.assertHandlerInfoMatches(handlerInfos.shift(), { @@ -71,14 +71,13 @@ function assertAllHandlerInfosMatchTestData() { name: "Example Default Handler", uriTemplate: "https://www.example.com/?url=%s", }, - possibleApplicationHandlers: [{ - name: "Example Default Handler", - uriTemplate: "https://www.example.com/?url=%s", - }], - fileExtensions: [ - "example_two", - "example_three", + possibleApplicationHandlers: [ + { + name: "Example Default Handler", + uriTemplate: "https://www.example.com/?url=%s", + }, ], + fileExtensions: ["example_two", "example_three"], }); HandlerServiceTestUtils.assertHandlerInfoMatches(handlerInfos.shift(), { @@ -89,30 +88,33 @@ function assertAllHandlerInfosMatchTestData() { name: "Example Default Handler", uriTemplate: "https://www.example.com/?url=%s", }, - 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", - }], - fileExtensions: [ - "example_two", - "example_three", + 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", + }, ], + fileExtensions: ["example_two", "example_three"], }); HandlerServiceTestUtils.assertHandlerInfoMatches(handlerInfos.shift(), { type: "example/type.usesystemdefault", preferredAction: Ci.nsIHandlerInfo.useSystemDefault, alwaysAskBeforeHandling: false, - possibleApplicationHandlers: [{ - name: "Example Possible Handler", - uriTemplate: "http://www.example.com/?url=%s", - }], + possibleApplicationHandlers: [ + { + name: "Example Possible Handler", + uriTemplate: "http://www.example.com/?url=%s", + }, + ], }); HandlerServiceTestUtils.assertHandlerInfoMatches(handlerInfos.shift(), { @@ -123,26 +125,32 @@ function assertAllHandlerInfosMatchTestData() { name: "Example Default Handler", uriTemplate: "https://www.example.com/?url=%s", }, - 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", - }], + 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", + }, + ], }); HandlerServiceTestUtils.assertHandlerInfoMatches(handlerInfos.shift(), { type: "examplescheme.usesystemdefault", preferredAction: Ci.nsIHandlerInfo.useSystemDefault, alwaysAskBeforeHandling: false, - possibleApplicationHandlers: [{ - name: "Example Possible Handler", - uriTemplate: "http://www.example.com/?url=%s", - }], + possibleApplicationHandlers: [ + { + name: "Example Possible Handler", + uriTemplate: "http://www.example.com/?url=%s", + }, + ], }); Assert.equal(handlerInfos.length, 0); @@ -181,8 +189,10 @@ add_task(async function test_store_fillHandlerInfo_predefined() { */ add_task(async function test_store_remove_exists() { // Test both MIME types and protocols. - for (let type of ["example/type.usehelperapp", - "examplescheme.usehelperapp"]) { + for (let type of [ + "example/type.usehelperapp", + "examplescheme.usehelperapp", + ]) { // Create new nsIHandlerInfo instances before loading the test data. await deleteHandlerStore(); let handlerInfoPresent = HandlerServiceTestUtils.getHandlerInfo(type); @@ -207,7 +217,8 @@ add_task(async function test_store_remove_exists() { Assert.throws( () => gHandlerService.fillHandlerInfo(handlerInfoPresent, ""), - ex => ex.result == Cr.NS_ERROR_NOT_AVAILABLE); + ex => ex.result == Cr.NS_ERROR_NOT_AVAILABLE + ); let actualHandlerInfo = HandlerServiceTestUtils.getHandlerInfo(type + "2"); HandlerServiceTestUtils.assertHandlerInfoMatches(actualHandlerInfo, { @@ -247,8 +258,9 @@ add_task(async function test_store_localHandlerApp_missing() { return; } - let missingHandlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"] - .createInstance(Ci.nsILocalHandlerApp); + let missingHandlerApp = Cc[ + "@mozilla.org/uriloader/local-handler-app;1" + ].createInstance(Ci.nsILocalHandlerApp); missingHandlerApp.name = "Non-existing Handler"; missingHandlerApp.executable = FileUtils.getFile("TmpD", ["nonexisting"]); @@ -281,8 +293,9 @@ add_task(async function test_store_dBusHandlerApp() { } // Set up an nsIDBusHandlerApp instance for testing. - let dBusHandlerApp = Cc["@mozilla.org/uriloader/dbus-handler-app;1"] - .createInstance(Ci.nsIDBusHandlerApp); + let dBusHandlerApp = Cc[ + "@mozilla.org/uriloader/dbus-handler-app;1" + ].createInstance(Ci.nsIDBusHandlerApp); dBusHandlerApp.name = "DBus Handler"; dBusHandlerApp.service = "test.method.server"; dBusHandlerApp.method = "Method"; @@ -320,24 +333,28 @@ add_task(async function test_store_dBusHandlerApp() { * "preferredApplicationHandler" and no "possibleApplicationHandlers", but the * former is always included in the latter list when reloading. */ -add_task(async function test_store_possibleApplicationHandlers_includes_preferred() { - await deleteHandlerStore(); +add_task( + async function test_store_possibleApplicationHandlers_includes_preferred() { + await deleteHandlerStore(); - let handlerInfo = getKnownHandlerInfo("example/new"); - handlerInfo.preferredApplicationHandler = localHandlerApp; - gHandlerService.store(handlerInfo); + let handlerInfo = getKnownHandlerInfo("example/new"); + handlerInfo.preferredApplicationHandler = localHandlerApp; + gHandlerService.store(handlerInfo); - await unloadHandlerStore(); + await unloadHandlerStore(); - let actualHandlerInfo = HandlerServiceTestUtils.getHandlerInfo("example/new"); - HandlerServiceTestUtils.assertHandlerInfoMatches(actualHandlerInfo, { - type: "example/new", - preferredAction: Ci.nsIHandlerInfo.saveToDisk, - alwaysAskBeforeHandling: false, - preferredApplicationHandler: expectedLocalHandlerApp, - possibleApplicationHandlers: [expectedLocalHandlerApp], - }); -}); + let actualHandlerInfo = HandlerServiceTestUtils.getHandlerInfo( + "example/new" + ); + HandlerServiceTestUtils.assertHandlerInfoMatches(actualHandlerInfo, { + type: "example/new", + preferredAction: Ci.nsIHandlerInfo.saveToDisk, + alwaysAskBeforeHandling: false, + preferredApplicationHandler: expectedLocalHandlerApp, + possibleApplicationHandlers: [expectedLocalHandlerApp], + }); + } +); /** * Tests that it is possible to save an nsIHandlerInfo instance with a @@ -345,30 +362,34 @@ add_task(async function test_store_possibleApplicationHandlers_includes_preferre * "possibleApplicationHandlers", but the former is always included as the first * element of the latter list when reloading. */ -add_task(async function test_store_possibleApplicationHandlers_preferred_first() { - await deleteHandlerStore(); +add_task( + async function test_store_possibleApplicationHandlers_preferred_first() { + await deleteHandlerStore(); - let handlerInfo = getKnownHandlerInfo("example/new"); - handlerInfo.preferredApplicationHandler = webHandlerApp; - // The preferred handler is appended after the other one. - handlerInfo.possibleApplicationHandlers.appendElement(localHandlerApp); - handlerInfo.possibleApplicationHandlers.appendElement(webHandlerApp); - gHandlerService.store(handlerInfo); + let handlerInfo = getKnownHandlerInfo("example/new"); + handlerInfo.preferredApplicationHandler = webHandlerApp; + // The preferred handler is appended after the other one. + handlerInfo.possibleApplicationHandlers.appendElement(localHandlerApp); + handlerInfo.possibleApplicationHandlers.appendElement(webHandlerApp); + gHandlerService.store(handlerInfo); - await unloadHandlerStore(); + await unloadHandlerStore(); - let actualHandlerInfo = HandlerServiceTestUtils.getHandlerInfo("example/new"); - HandlerServiceTestUtils.assertHandlerInfoMatches(actualHandlerInfo, { - type: "example/new", - preferredAction: Ci.nsIHandlerInfo.saveToDisk, - alwaysAskBeforeHandling: false, - preferredApplicationHandler: expectedWebHandlerApp, - possibleApplicationHandlers: [ - expectedWebHandlerApp, - expectedLocalHandlerApp, - ], - }); -}); + let actualHandlerInfo = HandlerServiceTestUtils.getHandlerInfo( + "example/new" + ); + HandlerServiceTestUtils.assertHandlerInfoMatches(actualHandlerInfo, { + type: "example/new", + preferredAction: Ci.nsIHandlerInfo.saveToDisk, + alwaysAskBeforeHandling: false, + preferredApplicationHandler: expectedWebHandlerApp, + possibleApplicationHandlers: [ + expectedWebHandlerApp, + expectedLocalHandlerApp, + ], + }); + } +); /** * Tests that it is possible to save an nsIHandlerInfo instance with an @@ -389,10 +410,7 @@ add_task(async function test_store_fileExtensions_lowercase() { type: "example/new", preferredAction: Ci.nsIHandlerInfo.saveToDisk, alwaysAskBeforeHandling: false, - fileExtensions: [ - "extension_test1", - "extension_test2", - ], + fileExtensions: ["extension_test1", "extension_test2"], }); }); @@ -427,10 +445,7 @@ add_task(async function test_store_no_duplicates() { expectedWebHandlerApp, expectedLocalHandlerApp, ], - fileExtensions: [ - "extension_test1", - "extension_test2", - ], + fileExtensions: ["extension_test1", "extension_test2"], }); }); @@ -446,8 +461,9 @@ add_task(async function test_store_deletes_properties_except_extensions() { // Prepare an nsIHandlerInfo instance with all the properties set to values // that will result in deletions. The preferredAction is also set to a defined // value so we can more easily verify it later. - let handlerInfo = - HandlerServiceTestUtils.getBlankHandlerInfo("example/type.savetodisk"); + let handlerInfo = HandlerServiceTestUtils.getBlankHandlerInfo( + "example/type.savetodisk" + ); handlerInfo.preferredAction = Ci.nsIHandlerInfo.saveToDisk; handlerInfo.alwaysAskBeforeHandling = false; @@ -458,16 +474,14 @@ add_task(async function test_store_deletes_properties_except_extensions() { // Now we can reload the data and verify that no extra values have been kept. await unloadHandlerStore(); - let actualHandlerInfo = - HandlerServiceTestUtils.getHandlerInfo("example/type.savetodisk"); + let actualHandlerInfo = HandlerServiceTestUtils.getHandlerInfo( + "example/type.savetodisk" + ); HandlerServiceTestUtils.assertHandlerInfoMatches(actualHandlerInfo, { type: "example/type.savetodisk", preferredAction: Ci.nsIHandlerInfo.saveToDisk, alwaysAskBeforeHandling: false, - fileExtensions: [ - "example_two", - "example_three", - ], + fileExtensions: ["example_two", "example_three"], }); }); @@ -476,8 +490,10 @@ add_task(async function test_store_deletes_properties_except_extensions() { */ add_task(async function test_fillHandlerInfo_overrideType() { // Test both MIME types and protocols. - for (let type of ["example/type.usesystemdefault", - "examplescheme.usesystemdefault"]) { + for (let type of [ + "example/type.usesystemdefault", + "examplescheme.usesystemdefault", + ]) { await deleteHandlerStore(); // Create new nsIHandlerInfo instances before loading the test data. @@ -491,10 +507,12 @@ add_task(async function test_fillHandlerInfo_overrideType() { type: type + "2", preferredAction: Ci.nsIHandlerInfo.useSystemDefault, alwaysAskBeforeHandling: false, - possibleApplicationHandlers: [{ - name: "Example Possible Handler", - uriTemplate: "http://www.example.com/?url=%s", - }], + possibleApplicationHandlers: [ + { + name: "Example Possible Handler", + uriTemplate: "http://www.example.com/?url=%s", + }, + ], }); } }); @@ -507,10 +525,14 @@ add_task(async function test_getTypeFromExtension() { Assert.equal(gHandlerService.getTypeFromExtension(""), ""); Assert.equal(gHandlerService.getTypeFromExtension("example_unknown"), ""); - Assert.equal(gHandlerService.getTypeFromExtension("example_one"), - "example/type.handleinternally"); - Assert.equal(gHandlerService.getTypeFromExtension("EXAMPLE_one"), - "example/type.handleinternally"); + Assert.equal( + gHandlerService.getTypeFromExtension("example_one"), + "example/type.handleinternally" + ); + Assert.equal( + gHandlerService.getTypeFromExtension("EXAMPLE_one"), + "example/type.handleinternally" + ); }); /** @@ -524,23 +546,28 @@ function assertAllHandlerInfosMatchDefaultHandlers() { HandlerServiceTestUtils.assertHandlerInfoMatches(handlerInfos.shift(), { type, preferredActionOSDependent: true, - possibleApplicationHandlers: [{ - name: "Mibbit", - uriTemplate: "https://www.mibbit.com/?url=%s", - }], + possibleApplicationHandlers: [ + { + name: "Mibbit", + uriTemplate: "https://www.mibbit.com/?url=%s", + }, + ], }); } HandlerServiceTestUtils.assertHandlerInfoMatches(handlerInfos.shift(), { type: "mailto", preferredActionOSDependent: true, - possibleApplicationHandlers: [{ - name: "Yahoo! Mail", - uriTemplate: "https://compose.mail.yahoo.com/?To=%s", - }, { - name: "Gmail", - uriTemplate: "https://mail.google.com/mail/?extsrc=mailto&url=%s", - }], + possibleApplicationHandlers: [ + { + name: "Yahoo! Mail", + uriTemplate: "https://compose.mail.yahoo.com/?To=%s", + }, + { + name: "Gmail", + uriTemplate: "https://mail.google.com/mail/?extsrc=mailto&url=%s", + }, + ], }); Assert.equal(handlerInfos.length, 0); @@ -550,7 +577,9 @@ function assertAllHandlerInfosMatchDefaultHandlers() { * Tests the default protocol handlers imported from the locale-specific data. */ add_task(async function test_default_protocol_handlers() { - if (!Services.prefs.getPrefType("gecko.handlerService.defaultHandlersVersion")) { + if ( + !Services.prefs.getPrefType("gecko.handlerService.defaultHandlersVersion") + ) { info("This platform or locale does not have default handlers."); return; } @@ -566,7 +595,9 @@ add_task(async function test_default_protocol_handlers() { * locale-specific data if they already exist. */ add_task(async function test_default_protocol_handlers_no_duplicates() { - if (!Services.prefs.getPrefType("gecko.handlerService.defaultHandlersVersion")) { + if ( + !Services.prefs.getPrefType("gecko.handlerService.defaultHandlersVersion") + ) { info("This platform or locale does not have default handlers."); return; } @@ -579,11 +610,15 @@ add_task(async function test_default_protocol_handlers_no_duplicates() { gHandlerService.remove(ircHandlerInfo); let originalDefaultHandlersVersion = Services.prefs.getComplexValue( - "gecko.handlerService.defaultHandlersVersion", Ci.nsIPrefLocalizedString); + "gecko.handlerService.defaultHandlersVersion", + Ci.nsIPrefLocalizedString + ); // Set the preference to an arbitrarily high number to force injecting again. - Services.prefs.setStringPref("gecko.handlerService.defaultHandlersVersion", - "999"); + Services.prefs.setStringPref( + "gecko.handlerService.defaultHandlersVersion", + "999" + ); await unloadHandlerStore(); @@ -593,8 +628,10 @@ add_task(async function test_default_protocol_handlers_no_duplicates() { // There should be no duplicate handlers in the protocols. await assertAllHandlerInfosMatchDefaultHandlers(); - Services.prefs.setStringPref("gecko.handlerService.defaultHandlersVersion", - originalDefaultHandlersVersion); + Services.prefs.setStringPref( + "gecko.handlerService.defaultHandlersVersion", + originalDefaultHandlersVersion + ); }); /** @@ -604,16 +641,19 @@ add_task(async function test_default_protocol_handlers_no_duplicates() { add_task(async function test_store_keeps_unknown_properties() { // Create a new nsIHandlerInfo instance before loading the test data. await deleteHandlerStore(); - let handlerInfo = - HandlerServiceTestUtils.getHandlerInfo("example/type.handleinternally"); + let handlerInfo = HandlerServiceTestUtils.getHandlerInfo( + "example/type.handleinternally" + ); await copyTestDataToHandlerStore(); gHandlerService.store(handlerInfo); await unloadHandlerStore(); let data = JSON.parse(new TextDecoder().decode(await OS.File.read(jsonPath))); - Assert.equal(data.mimeTypes["example/type.handleinternally"].unknownProperty, - "preserved"); + Assert.equal( + data.mimeTypes["example/type.handleinternally"].unknownProperty, + "preserved" + ); }); /** @@ -665,12 +705,15 @@ add_task(async function test_store_gioHandlerApp() { // Create dummy exec file that following won't fail because file not found error let dummyHandlerFile = FileUtils.getFile("TmpD", ["dummyHandler"]); - dummyHandlerFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("777", 8)); + dummyHandlerFile.createUnique( + Ci.nsIFile.NORMAL_FILE_TYPE, + parseInt("777", 8) + ); // Set up an nsIGIOMimeApp instance for testing. let handlerApp = Cc["@mozilla.org/gio-service;1"] - .getService(Ci.nsIGIOService) - .createAppFromCommand(dummyHandlerFile.path, "Dummy GIO handler"); + .getService(Ci.nsIGIOService) + .createAppFromCommand(dummyHandlerFile.path, "Dummy GIO handler"); let expectedGIOMimeHandlerApp = { name: handlerApp.name, command: handlerApp.command, diff --git a/uriloader/exthandler/tests/unit/test_punycodeURIs.js b/uriloader/exthandler/tests/unit/test_punycodeURIs.js index 89d79b02f34c..638128d11bb7 100644 --- a/uriloader/exthandler/tests/unit/test_punycodeURIs.js +++ b/uriloader/exthandler/tests/unit/test_punycodeURIs.js @@ -20,8 +20,13 @@ function checkFile() { if (!tempFile.exists()) { if (gCheckExistsAttempts >= kMaxCheckExistAttempts) { - do_throw("Expected File " + tempFile.path + " does not exist after " + - kMaxCheckExistAttempts + " seconds"); + do_throw( + "Expected File " + + tempFile.path + + " does not exist after " + + kMaxCheckExistAttempts + + " seconds" + ); } else { ++gCheckExistsAttempts; // Wait a bit longer then try again @@ -31,12 +36,12 @@ function checkFile() { } // Now read it - var fstream = - Cc["@mozilla.org/network/file-input-stream;1"] - .createInstance(Ci.nsIFileInputStream); - var sstream = - Cc["@mozilla.org/scriptableinputstream;1"] - .createInstance(Ci.nsIScriptableInputStream); + var fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance( + Ci.nsIFileInputStream + ); + var sstream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance( + Ci.nsIScriptableInputStream + ); fstream.init(tempFile, -1, 0, 0); sstream.init(fstream); @@ -55,8 +60,9 @@ function checkFile() { // find a way around it. // Additionally the lack of OS detection in xpcshell tests sucks, so we'll // have to check for the argument mac gives us. - if (data.substring(0, 7) != "-psn_0_") + if (data.substring(0, 7) != "-psn_0_") { Assert.equal(data, kExpectedURI); + } do_test_finished(); } @@ -71,9 +77,9 @@ function run_test() { var ioService = Services.io; // set up the local handler object - var localHandler = - Cc["@mozilla.org/uriloader/local-handler-app;1"] - .createInstance(Ci.nsILocalHandlerApp); + var localHandler = Cc[ + "@mozilla.org/uriloader/local-handler-app;1" + ].createInstance(Ci.nsILocalHandlerApp); localHandler.name = "Test Local Handler App"; // WriteArgument will just dump its arguments to a file for us. @@ -84,17 +90,18 @@ function run_test() { if (!exe.exists()) { // Maybe we are on windows exe.leafName = "WriteArgument.exe"; - if (!exe.exists()) + if (!exe.exists()) { do_throw("Could not locate the WriteArgument tests executable\n"); + } } var outFile = tempDir.clone(); outFile.append(kOutputFile); // Set an environment variable for WriteArgument to pick up - var envSvc = - Cc["@mozilla.org/process/environment;1"] - .getService(Ci.nsIEnvironment); + var envSvc = Cc["@mozilla.org/process/environment;1"].getService( + Ci.nsIEnvironment + ); // The Write Argument file needs to know where its libraries are, so // just force the path variable