summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/base/test/unit/test_testsuite_fakeserver_imapd_list-extended.js
blob: 89214b2b51975154b8839087e7d046e16b8e8129 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* 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 that Imapd.jsm fakeserver correctly implements LIST-EXTENDED imap
// extension (RFC 5258 - http://tools.ietf.org/html/rfc5258)

// IMAP pump
var { IMAPPump, setupIMAPPump, teardownIMAPPump } = ChromeUtils.import(
  "resource://testing-common/mailnews/IMAPpump.jsm"
);
var { PromiseTestUtils } = ChromeUtils.import(
  "resource://testing-common/mailnews/PromiseTestUtils.jsm"
);

// Globals

// Dovecot is one of the servers that supports LIST-EXTENDED
setupIMAPPump("Dovecot");
// create our own handler so that we can call imapd functions directly
var handler;

add_setup(function () {
  Services.prefs.setBoolPref(
    "mail.server.server1.autosync_offline_stores",
    false
  );
});

// mbox mailboxes cannot contain both child mailboxes and messages, so this will
// be one test case.
add_setup(async function () {
  IMAPPump.mailbox.flags = ["\\Marked", "\\NoInferiors"];
  IMAPPump.mailbox.subscribed = true;
  IMAPPump.daemon.createMailbox("Fruit", {});
  IMAPPump.daemon.createMailbox("Fruit/Apple", {});
  IMAPPump.daemon.createMailbox("Fruit/Banana", { subscribed: true });
  IMAPPump.daemon.createMailbox("Fruit/Peach", {
    nonExistent: true,
    subscribed: true,
  });
  IMAPPump.daemon.createMailbox("Tofu", {});
  IMAPPump.daemon.createMailbox("Vegetable", { subscribed: true });
  IMAPPump.daemon.createMailbox("Vegetable/Broccoli", { subscribed: true });
  IMAPPump.daemon.createMailbox("Vegetable/Corn", {});

  handler = IMAPPump.server._handlerCreator(IMAPPump.daemon);
  let response = handler.onError("1", "LOGIN user password");
  Assert.ok(response.includes("OK"));
  // wait for imap pump to do it's thing or else we get memory leaks
  let listener = new PromiseTestUtils.PromiseUrlListener();
  IMAPPump.inbox.updateFolderWithListener(null, listener);
  await listener.promise;
});

// test that 'LIST "" "*"' returns the proper responses (standard LIST usage)
add_task(function testList() {
  let response = handler.onError("2", 'LIST "" "*"');

  Assert.ok(response.includes('* LIST (\\Marked \\NoInferiors) "/" "INBOX"'));
  Assert.ok(response.includes('* LIST () "/" "Fruit"'));
  Assert.ok(response.includes('* LIST () "/" "Fruit/Apple"'));
  Assert.ok(response.includes('* LIST () "/" "Fruit/Banana"'));
  Assert.ok(response.includes('* LIST () "/" "Tofu"'));
  Assert.ok(response.includes('* LIST () "/" "Vegetable"'));
  Assert.ok(response.includes('* LIST () "/" "Vegetable/Broccoli"'));
  Assert.ok(response.includes('* LIST () "/" "Vegetable/Corn"'));
  Assert.ok(!response.includes("Peach"));
});

// test that 'LIST (SUBSCRIBED) "" "*"' returns the proper responses
add_task(function testListSelectSubscribed() {
  let response = handler.onError("3", 'LIST (SUBSCRIBED) "" "*"');

  Assert.ok(
    response.includes(
      '* LIST (\\Marked \\NoInferiors \\Subscribed) "/" "INBOX"'
    )
  );
  Assert.ok(response.includes('* LIST (\\Subscribed) "/" "Fruit/Banana"'));
  Assert.ok(
    response.includes('* LIST (\\Subscribed \\NonExistent) "/" "Fruit/Peach"')
  );
  Assert.ok(response.includes('* LIST (\\Subscribed) "/" "Vegetable"'));
  Assert.ok(
    response.includes('* LIST (\\Subscribed) "/" "Vegetable/Broccoli"')
  );
  Assert.ok(!response.includes('"Fruit"'));
  Assert.ok(!response.includes("Apple"));
  Assert.ok(!response.includes("Tofu"));
  Assert.ok(!response.includes("Corn"));
});

// test that 'LIST "" "%" RETURN (CHILDEREN)' returns the proper responses
add_task(function testListReturnChilderen() {
  let response = handler.onError("4", 'LIST "" "%" RETURN (CHILDREN)');

  Assert.ok(response.includes('* LIST (\\Marked \\NoInferiors) "/" "INBOX"'));
  Assert.ok(response.includes('* LIST (\\HasChildren) "/" "Fruit"'));
  Assert.ok(response.includes('* LIST (\\HasNoChildren) "/" "Tofu"'));
  Assert.ok(response.includes('* LIST (\\HasChildren) "/" "Vegetable"'));
  Assert.ok(!response.includes("Apple"));
  Assert.ok(!response.includes("Banana"));
  Assert.ok(!response.includes("Peach"));
  Assert.ok(!response.includes("Broccoli"));
  Assert.ok(!response.includes("Corn"));
});

// test that 'LIST "" "*" RETURN (SUBSCRIBED)' returns the proper responses
add_task(function testListReturnSubscribed() {
  let response = handler.onError("5", 'LIST "" "*" RETURN (SUBSCRIBED)');

  Assert.ok(
    response.includes(
      '* LIST (\\Marked \\NoInferiors \\Subscribed) "/" "INBOX"'
    )
  );
  Assert.ok(response.includes('* LIST () "/" "Fruit"'));
  Assert.ok(response.includes('* LIST () "/" "Fruit/Apple"'));
  Assert.ok(response.includes('* LIST (\\Subscribed) "/" "Fruit/Banana"'));
  Assert.ok(response.includes('* LIST () "/" "Tofu"'));
  Assert.ok(response.includes('* LIST (\\Subscribed) "/" "Vegetable"'));
  Assert.ok(
    response.includes('* LIST (\\Subscribed) "/" "Vegetable/Broccoli"')
  );
  Assert.ok(response.includes('* LIST () "/" "Vegetable/Corn"'));
  Assert.ok(!response.includes("Peach"));
});

// test that 'LIST "" ("INBOX" "Tofu" "Vegetable/%")' returns the proper responses
add_task(function testListSelectMultiple() {
  let response = handler._dispatchCommand("LIST", [
    "",
    '("INBOX" "Tofu" "Vegetable/%")',
  ]);

  Assert.ok(response.includes('* LIST (\\Marked \\NoInferiors) "/" "INBOX"'));
  Assert.ok(response.includes('* LIST () "/" "Tofu"'));
  Assert.ok(response.includes('* LIST () "/" "Vegetable/Broccoli"'));
  Assert.ok(response.includes('* LIST () "/" "Vegetable/Corn"'));
  Assert.ok(!response.includes('"Vegetable"'));
  Assert.ok(!response.includes("Fruit"));
  Assert.ok(!response.includes("Peach"));
});

// Cleanup at end
add_task(function endTest() {
  handler = null;
  teardownIMAPPump();
});