Bug 861454 - Fix handling of accounts with the unknown protocol plugin, r=clokep.
authorFlorian Quèze <florian@queze.net>
Sat, 22 Jun 2013 18:00:06 +0200
changeset 15785 a98a8f1574d421a474b39336ca19e2b738ac7cae
parent 15784 5c809c8e2d791df19f53da88c733e47acc1fbe62
child 15786 89ca38497a74fa4e060e24e81e863fd31609520f
push idunknown
push userunknown
push dateunknown
reviewersclokep
bugs861454
Bug 861454 - Fix handling of accounts with the unknown protocol plugin, r=clokep.
chat/components/src/imAccounts.js
chat/components/src/moz.build
chat/components/src/test/test_accounts.js
chat/components/src/test/xpcshell.ini
chat/modules/Makefile.in
chat/modules/test/appInfoUtils.jsm
--- a/chat/components/src/imAccounts.js
+++ b/chat/components/src/imAccounts.js
@@ -100,16 +100,17 @@ UnknownProtocol.prototype = {
 // 2 values should be stored.
 function imAccount(aKey, aName, aPrplId)
 {
   if (!aKey.startsWith(kAccountKeyPrefix))
     throw Cr.NS_ERROR_INVALID_ARG;
 
   this.id = aKey;
   this.numericId = parseInt(aKey.substr(kAccountKeyPrefix.length));
+  gAccountsService._keepAccount(this);
   this.prefBranch = Services.prefs.getBranch(kPrefAccountPrefix + aKey + ".");
 
   if (aName) {
     this.name = aName;
     let str = Cc["@mozilla.org/supports-string;1"]
               .createInstance(Ci.nsISupportsString);
     str.data = aName;
     this.prefBranch.setComplexValue(kPrefAccountName, Ci.nsISupportsString,
@@ -134,18 +135,16 @@ function imAccount(aKey, aName, aPrplId)
     this.protocol = new UnknownProtocol(prplId);
     this._connectionErrorReason = Ci.imIAccount.ERROR_UNKNOWN_PRPL;
     return;
   }
 
   // Ensure the account is correctly stored in blist.sqlite.
   Services.contacts.storeAccount(this.numericId, this.name, prplId);
 
-  gAccountsService._keepAccount(this);
-
   // Get the prplIAccount from the protocol plugin.
   this.prplAccount = this.protocol.getAccount(this);
 
   // Send status change notifications to the account.
   this.observedStatusInfo = null; // (To execute the setter).
 
   // If we have never finished the first connection attempt for this account,
   // mark the account as having caused a crash.
--- a/chat/components/src/moz.build
+++ b/chat/components/src/moz.build
@@ -1,13 +1,15 @@
 # vim: set filetype=python:
 # 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/.
 
+XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell.ini']
+
 EXTRA_COMPONENTS += [
     'imAccounts.js',
     'imAccounts.manifest',
     'imCommands.js',
     'imCommands.manifest',
     'imContacts.js',
     'imContacts.manifest',
     'imConversations.js',
new file mode 100644
--- /dev/null
+++ b/chat/components/src/test/test_accounts.js
@@ -0,0 +1,39 @@
+/* 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/. */
+
+const {interfaces: Ci, utils: Cu} = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource:///modules/imServices.jsm");
+Cu.import("resource://testing-common/appInfoUtils.jsm");
+
+function run_test() {
+  do_get_profile();
+
+  // Test the handling of accounts for unknown protocols.
+  const kAccountName = "Unknown"
+  const kPrplId = "prpl-unknown";
+
+  let prefs = Services.prefs;
+  prefs.setCharPref("messenger.account.account1.name", kAccountName);
+  prefs.setCharPref("messenger.account.account1.prpl", kPrplId);
+  prefs.setCharPref("messenger.accounts", "account1");
+
+  try {
+    // Having an implementation of nsIXULAppInfo is required for
+    // Services.core.init to work.
+    XULAppInfo.init();
+    Services.core.init();
+
+    let account = Services.accounts.getAccountByNumericId(1);
+    do_check_true(account instanceof Ci.imIAccount);
+    do_check_eq(account.name, kAccountName);
+    do_check_eq(account.protocol.id, kPrplId);
+    do_check_eq(account.connectionErrorReason, Ci.imIAccount.ERROR_UNKNOWN_PRPL);
+  } finally {
+    Services.core.quit();
+
+    prefs.deleteBranch("messenger");
+  }
+}
new file mode 100644
--- /dev/null
+++ b/chat/components/src/test/xpcshell.ini
@@ -0,0 +1,9 @@
+; 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/.
+
+[DEFAULT]
+head = 
+tail = 
+
+[test_accounts.js]
--- a/chat/modules/Makefile.in
+++ b/chat/modules/Makefile.in
@@ -10,9 +10,13 @@ relativesrcdir = @relativesrcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 EXTRA_PP_JS_MODULES = \
 	hiddenWindow.jsm \
 	imTextboxUtils.jsm \
 	$(NULL)
 
+ifdef ENABLE_TESTS
+TESTING_JS_MODULES := test/appInfoUtils.jsm
+endif
+
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/chat/modules/test/appInfoUtils.jsm
@@ -0,0 +1,41 @@
+/* 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/. */
+
+const EXPORTED_SYMBOLS = ["XULAppInfo"];
+
+const Ci = Components.interfaces;
+
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+var XULAppInfo = {
+  vendor: "Mozilla",
+  name: "XPCShell",
+  ID: "{39885e5f-f6b4-4e2a-87e5-6259ecf79011}",
+  version: "5",
+  appBuildID: "2007010101",
+  platformVersion: "1.9",
+  platformBuildID: "2007010101",
+  inSafeMode: false,
+  logConsoleErrors: true,
+  OS: "XPCShell",
+  XPCOMABI: "noarch-spidermonkey",
+
+  init: function() {
+    Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
+              .registerFactory(Components.ID("{48a4e946-1f9f-4224-b4b0-9a54183cb81e}"),
+                               "XULAppInfo", "@mozilla.org/xre/app-info;1",
+                               XULAppInfoFactory);
+  },
+
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo, Ci.nsIXULRuntime,
+					 Ci.nsISupports])
+};
+
+var XULAppInfoFactory = {
+  createInstance: function (outer, iid) {
+    if (outer != null)
+      throw Components.results.NS_ERROR_NO_AGGREGATION;
+    return XULAppInfo.QueryInterface(iid);
+  }
+};