diff --git a/chat/components/src/imCore.sys.mjs b/chat/components/src/imCore.sys.mjs index 786274a2d7..ec1f01a229 100644 --- a/chat/components/src/imCore.sys.mjs +++ b/chat/components/src/imCore.sys.mjs @@ -409,25 +409,20 @@ class CoreService { throw Components.Exception("", Cr.NS_ERROR_NOT_INITIALIZED); } - const protocols = []; - for (const id of Object.keys(protocols)) { - // If the preference is set to disable this prpl, don't show it in the - // full list of protocols. - const pref = "chat.prpls." + id + ".disable"; - if ( - Services.prefs.getPrefType(pref) == Services.prefs.PREF_BOOL && - Services.prefs.getBoolPref(pref) - ) { - this.LOG("Disabling prpl: " + id); - continue; - } - - const proto = this.getProtocolById(id); - if (proto) { - protocols.push(proto); - } - } - return protocols; + return ( + Object.keys(protocols) + // If the preference is set to disable this prpl, don't show it in the + // full list of protocols. + .filter(protocolId => { + const pref = `chat.prpls.${protocolId}.disable`; + return ( + Services.prefs.getPrefType(pref) != Services.prefs.PREF_BOOL || + !Services.prefs.getBoolPref(pref) + ); + }) + .map(protocolId => this.getProtocolById(protocolId)) + .filter(Boolean) + ); } /** diff --git a/chat/components/src/test/test_accounts.js b/chat/components/src/test/test_accounts.js index 724bdbe888..75b85e854c 100644 --- a/chat/components/src/test/test_accounts.js +++ b/chat/components/src/test/test_accounts.js @@ -5,9 +5,6 @@ var { IMServices } = ChromeUtils.importESModule( "resource:///modules/IMServices.sys.mjs" ); -const { updateAppInfo } = ChromeUtils.importESModule( - "resource://testing-common/AppInfo.sys.mjs" -); function run_test() { do_get_profile(); @@ -25,9 +22,6 @@ function run_test() { Services.prefs.setCharPref("mail.server.server1.userName", kAccountName); Services.prefs.setCharPref("mail.server.server1.hostname", kPrplId); try { - // Having an implementation of nsIXULAppInfo is required for - // IMServices.core.init to work. - updateAppInfo(); IMServices.core.init(); const account = IMServices.accounts.getAccountByNumericId(1); diff --git a/chat/components/src/test/test_core.js b/chat/components/src/test/test_core.js new file mode 100644 index 0000000000..5c445da482 --- /dev/null +++ b/chat/components/src/test/test_core.js @@ -0,0 +1,36 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +var { IMServices } = ChromeUtils.importESModule( + "resource:///modules/IMServices.sys.mjs" +); + +const DISABLED_PROTOCOLS = [ + "prpl-facebook", + "prpl-gtalk", + "prpl-twitter", + "prpl-yahoo", +]; + +add_setup(() => { + do_get_profile(); + IMServices.core.init(); +}); + +add_task(function test_getProtocols() { + const protocols = IMServices.core.getProtocols(); + + Assert.ok(Array.isArray(protocols), "Protocols are returned as array"); + Assert.greaterOrEqual( + protocols.length, + 4, + "At least 4 active protocols are returned" + ); + for (const protocol of protocols) { + Assert.ok( + !DISABLED_PROTOCOLS.includes(protocol.id), + `${protocol.id} is not one of the disabled protocols` + ); + } +}); diff --git a/chat/components/src/test/xpcshell.ini b/chat/components/src/test/xpcshell.ini index 63cce6e7e1..c5a1ac36e4 100644 --- a/chat/components/src/test/xpcshell.ini +++ b/chat/components/src/test/xpcshell.ini @@ -1,9 +1,10 @@ [DEFAULT] -head = -tail = +head = +tail = [test_accounts.js] [test_commands.js] [test_conversations.js] +[test_core.js] [test_init.js] [test_logger.js]