WIP - more unit testing for accountmanager draft
authorBen Campbell <benc@thunderbird.net>
Fri, 27 Mar 2020 14:50:38 +1300
changeset 86392 589325a63a5ce0cde7da901eaf9690bf0b860a01
parent 86391 1b697d809c94ca689045a229853787313071012c
child 86393 60e86006beda120f758d52819c434c13a580b262
push id10717
push userbenc@thunderbird.net
push dateFri, 27 Mar 2020 02:13:08 +0000
treeherdertry-comm-central@f505e51d8741 [default view] [failures only]
WIP - more unit testing for accountmanager
mailnews/base/src/nsMsgAccountManager.cpp
mailnews/base/test/unit/test_accountMgr2.js
mailnews/base/test/unit/xpcshell.ini
--- a/mailnews/base/src/nsMsgAccountManager.cpp
+++ b/mailnews/base/src/nsMsgAccountManager.cpp
@@ -866,16 +866,17 @@ nsMsgAccountManager::GetAllIdentities(
     uint32_t idCount;
     rv = identities->GetLength(&idCount);
     if (NS_FAILED(rv)) continue;
 
     for (uint32_t j = 0; j < idCount; ++j) {
       nsCOMPtr<nsIMsgIdentity> identity(do_QueryElementAt(identities, j, &rv));
       if (NS_FAILED(rv)) continue;
 
+      // Have we already got this identity?
       nsAutoCString key;
       rv = identity->GetKey(key);
       if (NS_FAILED(rv)) continue;
 
       bool found = false;
       for (auto thisIdentity : result) {
         nsAutoCString thisKey;
         rv = thisIdentity->GetKey(thisKey);
new file mode 100644
--- /dev/null
+++ b/mailnews/base/test/unit/test_accountMgr2.js
@@ -0,0 +1,64 @@
+/* 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();
+
+  dump("XYZZY========================\n");
+  dump(mgr.allIdentities);
+  dump("\nXYZZY========================\n");
+  dump(mgr.accounts);
+
+
+  dump("\nXYZZY========================\n");
+  let allServers = [...fixIterator(mgr.allServers, Ci.nsIMsgIncomingServer)];
+  dump(allServers);
+  dump("\nXYZZY========================\n");
+  for (let srv of allServers) {
+    dump(`${srv.type}\n`);
+  }
+  dump("\nXYZZY========================\n");
+
+  // 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]