summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/base/test/unit/test_testsuite_fakeserver_imapd_gmail.js
blob: a9eb9ae2d7609ba82511570737ec5bf755707221 (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
/* 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 emulates GMail server
// That means X-GM-EXT-1 capability and GMail flavor XLIST
// per https://developers.google.com/google-apps/gmail/imap_extensions

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

setupIMAPPump("GMail");
// 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.specialUseFlag = "\\Inbox";
  IMAPPump.daemon.createMailbox("[Gmail]", { flags: ["\\Noselect"] });
  IMAPPump.daemon.createMailbox("[Gmail]/All Mail", {
    specialUseFlag: "\\AllMail",
  });
  IMAPPump.daemon.createMailbox("[Gmail]/Drafts", {
    specialUseFlag: "\\Drafts",
  });
  IMAPPump.daemon.createMailbox("[Gmail]/Sent", { specialUseFlag: "\\Sent" });
  IMAPPump.daemon.createMailbox("[Gmail]/Spam", { specialUseFlag: "\\Spam" });
  IMAPPump.daemon.createMailbox("[Gmail]/Starred", {
    specialUseFlag: "\\Starred",
  });
  IMAPPump.daemon.createMailbox("[Gmail]/Trash", { specialUseFlag: "\\Trash" });
  IMAPPump.daemon.createMailbox("test", {});

  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 its thing or else we get memory leaks
  let listener = new PromiseTestUtils.PromiseUrlListener();
  IMAPPump.inbox.updateFolderWithListener(null, listener);
  await listener.promise;
});

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

  Assert.ok(response.includes('* LIST (\\HasNoChildren \\Inbox) "/" "INBOX"'));
  Assert.ok(
    response.includes('* LIST (\\Noselect \\HasChildren) "/" "[Gmail]"')
  );
  Assert.ok(
    response.includes(
      '* LIST (\\HasNoChildren \\AllMail) "/" "[Gmail]/All Mail"'
    )
  );
  Assert.ok(
    response.includes('* LIST (\\HasNoChildren \\Drafts) "/" "[Gmail]/Drafts"')
  );
  Assert.ok(
    response.includes('* LIST (\\HasNoChildren \\Sent) "/" "[Gmail]/Sent"')
  );
  Assert.ok(
    response.includes('* LIST (\\HasNoChildren \\Spam) "/" "[Gmail]/Spam"')
  );
  Assert.ok(
    response.includes(
      '* LIST (\\HasNoChildren \\Starred) "/" "[Gmail]/Starred"'
    )
  );
  Assert.ok(
    response.includes('* LIST (\\HasNoChildren \\Trash) "/" "[Gmail]/Trash"')
  );
  Assert.ok(response.includes('* LIST (\\HasNoChildren) "/" "test"'));
});

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