Bug 1614846 - Add some more unit tests for nsIMsgAccountManager. draft
authorBen Campbell <benc@thunderbird.net>
Fri, 27 Mar 2020 16:41:57 +1300
changeset 86395 09b34423d61cd1d3ec367800825934552e1fbd50
parent 86389 14fc66cf01c92b40f1fc2b518ba71fcadc5c8bb2
child 86396 91a56fdd59b1f4edc811161df858939668cf1a4d
push id10718
push userbenc@thunderbird.net
push dateFri, 27 Mar 2020 04:34:11 +0000
treeherdertry-comm-central@05424fbb64ac [default view] [failures only]
bugs1614846
Bug 1614846 - Add some more unit tests for nsIMsgAccountManager.
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,60 @@
+/* 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 allIdentities = [...fixIterator(mgr.allIdentities, Ci.nsIMsgIdentity)];
+  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(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]