summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/base/test/unit/test_nsIMsgFolder.js
blob: 9cfb57a07ca5f808bc744bd1488af4577da1a8f1 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 * Test suite for nsIMsgFolder functions.
 */

var { MailServices } = ChromeUtils.import(
  "resource:///modules/MailServices.jsm"
);

function run_test() {
  // Create a local mail account (we need this first)
  MailServices.accounts.createLocalMailAccount();

  // Get the account
  let account = MailServices.accounts.accounts[0];

  // Get the root folder
  var root = account.incomingServer.rootFolder;

  // Add a sub folder to ensure that we have some folders created
  root.createSubfolder("folder1", null);

  // Test - getChildNamed

  var caught = false;
  try {
    root.getChildNamed("folder");
  } catch (e) {
    caught = true;
  }
  Assert.equal(caught, true);

  caught = false;
  try {
    root.getChildNamed("Trash1");
  } catch (e) {
    caught = true;
  }
  Assert.equal(caught, true);

  var folder1 = root.getChildNamed("folder1");

  Assert.notEqual(folder1, folder2);
  Assert.equal(folder1.prettyName, "folder1");

  var folder2 = root.getChildNamed("FOLDER1");

  Assert.equal(folder1, folder2);

  // Check special folders aren't deletable, and that normal folders are.
  if (!root.containsChildNamed("Inbox")) {
    root.createSubfolder("Inbox", null);
  }
  var inbox = root.getChildNamed("Inbox");
  inbox.setFlag(Ci.nsMsgFolderFlags.Inbox);
  Assert.ok(!inbox.deletable);

  if (!root.containsChildNamed("Drafts")) {
    root.createSubfolder("Drafts", null);
  }
  var drafts = root.getChildNamed("Drafts");
  drafts.setFlag(Ci.nsMsgFolderFlags.Drafts);
  Assert.ok(!drafts.deletable);

  if (!root.containsChildNamed("Templates")) {
    root.createSubfolder("Templates", null);
  }
  var templates = root.getChildNamed("Templates");
  templates.setFlag(Ci.nsMsgFolderFlags.Templates);
  Assert.ok(!templates.deletable);

  if (!root.containsChildNamed("Sent")) {
    root.createSubfolder("Sent", null);
  }
  var sent = root.getChildNamed("Sent");
  sent.setFlag(Ci.nsMsgFolderFlags.SentMail);
  Assert.ok(!sent.deletable);

  if (!root.containsChildNamed("Archives")) {
    root.createSubfolder("Archives", null);
  }
  var archives = root.getChildNamed("Archives");
  archives.setFlag(Ci.nsMsgFolderFlags.Archive);
  Assert.ok(!archives.deletable);

  if (!root.containsChildNamed("Trash")) {
    root.createSubfolder("Trash", null);
  }
  var trash = root.getChildNamed("Trash");
  trash.setFlag(Ci.nsMsgFolderFlags.Trash);
  Assert.ok(!trash.deletable);

  if (!root.containsChildNamed("Outbox")) {
    root.createSubfolder("Outbox", null);
  }
  var outbox = root.getChildNamed("Outbox");
  outbox.setFlag(Ci.nsMsgFolderFlags.Queue);
  Assert.ok(!outbox.deletable);

  // test a normal folder is deletable
  Assert.ok(folder1.deletable);
}