Bug 1614846 - Add some more unit tests for nsIMsgAccountManager. r=mkmelin
authorBen Campbell <benc@thunderbird.net>
Mon, 30 Mar 2020 13:56:37 +0300
changeset 38624 40b4770d124eb592eb2e4e4c9410ef50cd60baa0
parent 38623 8d219926818378dda077442385c0d59650cc3ab6
child 38625 3c0f617d39f6181ff23253053a36111786a15fb9
push id400
push userclokep@gmail.com
push dateMon, 04 May 2020 18:56:09 +0000
reviewersmkmelin
bugs1614846
Bug 1614846 - Add some more unit tests for nsIMsgAccountManager. r=mkmelin
mailnews/base/test/unit/test_accountMgr2.js
mailnews/base/test/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/mailnews/base/test/unit/test_accountMgr2.js
@@ -0,0 +1,59 @@
+/* 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/. */
+
+/**
+ * This tests various methods and attributes on nsIMsgAccountManager.
+ */
+var { MailServices } = ChromeUtils.import(
+  "resource:///modules/MailServices.jsm"
+);
+
+const { fixIterator } = ChromeUtils.import(
+  "resource:///modules/iteratorUtils.jsm"
+);
+
+add_task(async function() {
+  let mgr = MailServices.accounts;
+
+  // Create a couple of test accounts.
+  let acc1 = mgr.createAccount();
+  acc1.incomingServer = mgr.createIncomingServer(
+    "bob_imap",
+    "imap.example.com",
+    "imap"
+  );
+  let id1 = mgr.createIdentity();
+  id1.email = "bob_imap@example.com";
+  acc1.addIdentity(id1);
+
+  let acc2 = mgr.createAccount();
+  acc2.incomingServer = mgr.createIncomingServer(
+    "bob_pop3",
+    "pop3.example.com",
+    "pop3"
+  );
+  let id2 = mgr.createIdentity();
+  id2.email = "bob_pop3@example.com";
+  acc2.addIdentity(id2);
+
+  // Add an identity shared by both accounts.
+  let id3 = mgr.createIdentity();
+  id3.email = "bob_common@example.com";
+  acc1.addIdentity(id3);
+  acc2.addIdentity(id3);
+
+  // The special "Local Folders" account and server (server type is "none").
+  mgr.createLocalMailAccount();
+
+  // Setup done. Now check that things are as we expect.
+
+  let allServers = [...fixIterator(mgr.allServers, Ci.nsIMsgIncomingServer)];
+
+  // At this point we should have 3 accounts and servers (imap, pop, local).
+  Assert.equal(mgr.accounts.length, 3);
+  Assert.equal(allServers.length, 3);
+
+  // The identities we explicitly created.
+  Assert.equal(mgr.allIdentities.length, 3);
+});
--- a/mailnews/base/test/unit/xpcshell.ini
+++ b/mailnews/base/test/unit/xpcshell.ini
@@ -1,14 +1,15 @@
 [DEFAULT]
 head = head_mailbase.js
 tail =
 support-files = nodelist_test.xml data/*
 
 [test_accountMgr.js]
+[test_accountMgr2.js]
 [test_accountMgrCustomTypes.js]
 [test_accountMigration.js]
 [test_acctRepair.js]
 [test_bccInDatabase.js]
 [test_bug366491.js]
 [test_bug404489.js]
 [test_bug428427.js]
 [test_bug434810.js]