summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/local/test/unit/test_pop3Proxy.js
blob: 248bbaf92b561d96e842db2477bc832d68c36c56 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that POP3 over a proxy works.

const { NetworkTestUtils } = ChromeUtils.import(
  "resource://testing-common/mailnews/NetworkTestUtils.jsm"
);
const { PromiseTestUtils } = ChromeUtils.import(
  "resource://testing-common/mailnews/PromiseTestUtils.jsm"
);

const PORT = 110;

var server, daemon, incomingServer;

add_setup(async function () {
  // Disable new mail notifications
  Services.prefs.setBoolPref("mail.biff.play_sound", false);
  Services.prefs.setBoolPref("mail.biff.show_alert", false);
  Services.prefs.setBoolPref("mail.biff.show_tray_icon", false);
  Services.prefs.setBoolPref("mail.biff.animate_dock_icon", false);

  [daemon, server] = setupServerDaemon();
  server.start();
  NetworkTestUtils.configureProxy("pop.tinderbox.invalid", PORT, server.port);

  // Set up the basic accounts and folders
  incomingServer = createPop3ServerAndLocalFolders(
    PORT,
    "pop.tinderbox.invalid"
  );

  // Add a message to download
  daemon.setMessages(["message1.eml"]);
});

add_task(async function downloadEmail() {
  // Check that we haven't got any messages in the folder, if we have its a test
  // setup issue.
  equal(localAccountUtils.inboxFolder.getTotalMessages(false), 0);

  // Now get the mail
  let urlListener = new PromiseTestUtils.PromiseUrlListener();
  MailServices.pop3.GetNewMail(
    null,
    urlListener,
    localAccountUtils.inboxFolder,
    incomingServer
  );
  await urlListener.promise;

  // We downloaded a message, so it works!
  equal(localAccountUtils.inboxFolder.getTotalMessages(false), 1);
});

add_task(async function cleanUp() {
  NetworkTestUtils.shutdownServers();
  incomingServer.closeCachedConnections();
  server.stop();
});