summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/addrbook/test/unit/test_nsIAbDirectory_getMailListFromName.js
blob: 7d51cecee1067f0b1837babe713fbbe301e2ad40 (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
/* 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/. */

/**
 * Test suite for the getMailListFromName() function.
 */

"use strict";

/**
 * Tests the getMailListFromName function returns the correct nsIAbDirectory,
 * also tests the hasMailListWithName function as it uses the same code.
 */
add_task(function testGetMailListFromName() {
  loadABFile("../../../data/abLists1", kPABData.fileName);

  // Test all top level lists are returned.
  let root = MailServices.ab.getDirectory(kPABData.URI);
  for (let listName of ["TestList1", "TestList2", "TestList3"]) {
    Assert.ok(root.hasMailListWithName(listName), `parent has "${listName}"`);

    let list = root.getMailListFromName(listName);
    Assert.ok(list, `"${listName}" is not null`);
    Assert.equal(
      list.dirName,
      listName,
      `"${listName}" dirName is "${listName}"`
    );
  }

  Assert.ok(
    !root.hasMailListWithName("Non existent"),
    "hasMailListWithName() returns false for non-existent list name"
  );
  Assert.ok(
    !root.getMailListFromName("Non existent"),
    "getMailListFromName() returns null for non-existent list name"
  );
});