summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/addrbook/test/unit/test_mailList1.js
blob: 0889257da63792bf77b40b772eac7797be92c398 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 * Test suite for mailing list functions.
 *
 * This suite relies on abLists1.mab. checkLists requires that the mailing list
 * name be "TestList<n>" where <n> is the number of the list that also matches
 * the <n> in the uri: moz-ab???directory://path/MailList<n>
 */

function checkLists(childNodes, number) {
  let count = 0;
  // See comment above for matching requirements
  for (let list of childNodes) {
    if (list.isMailList && list.dirName.startsWith("TestList")) {
      Assert.equal(list.URI, `${kPABData.URI}/${list.UID}`);
      count++;
    }
  }

  Assert.equal(count, number);
}

function run_test() {
  loadABFile("../../../data/abLists1", kPABData.fileName);

  // Test - Get the directory.

  // XXX Getting all directories ensures we create all ABs because mailing
  // lists need help initialising themselves
  MailServices.ab.directories;

  let AB = MailServices.ab.getDirectory(kPABData.URI);

  // Test - Check all the expected mailing lists exist.

  // There are three lists in abLists.mab by default.
  checkLists(AB.childNodes, 3);

  // Test - Add a new list.

  var mailList = Cc[
    "@mozilla.org/addressbook/directoryproperty;1"
  ].createInstance(Ci.nsIAbDirectory);

  mailList.isMailList = true;
  mailList.dirName = "TestList4";
  mailList.listNickName = "test4";
  mailList.description = "test4description";

  AB.addMailList(mailList);

  // check them
  checkLists(AB.childNodes, 4);

  // Test - Remove a list.

  mailList = MailServices.ab.getDirectory(
    kPABData.URI + "/46cf4cbf-5945-43e4-a822-30c2f2969db9"
  );

  AB.deleteDirectory(mailList);

  // check them
  checkLists(AB.childNodes, 3);
}