summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/base/test/unit/test_fix_deferred_accounts.js
blob: 0fd09a543aac16d3dbc8f2ba619d25a27b48524b (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
/* 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/. */

/**
 * This tests that we cleanup the account prefs when a pop3 account has
 * been deferred to a hidden account.
 */
var { MailServices } = ChromeUtils.import(
  "resource:///modules/MailServices.jsm"
);

function run_test() {
  // Create account prefs with a pop3 account deferred to a hidden account.

  Services.prefs.setCharPref("mail.account.account1.identities", "id1");
  Services.prefs.setCharPref("mail.account.account1.server", "server1");
  Services.prefs.setCharPref("mail.account.account2.server", "server2");
  Services.prefs.setCharPref("mail.account.account4.identities", "id2");
  Services.prefs.setCharPref("mail.account.account4.server", "server4");
  Services.prefs.setCharPref("mail.account.account5.identities", "id3");
  Services.prefs.setCharPref("mail.account.account5.server", "server5");
  Services.prefs.setCharPref("mail.server.server1.hostname", "Local Folders");
  Services.prefs.setCharPref("mail.server.server1.type", "none");
  Services.prefs.setCharPref("mail.server.server2.hostname", "Smart Mailboxes");
  Services.prefs.setCharPref("mail.server.server2.type", "none");
  Services.prefs.setBoolPref("mail.server.server2.hidden", true);
  Services.prefs.setCharPref("mail.server.server4.hostname", "mail.host4.org");
  Services.prefs.setCharPref("mail.server.server4.type", "pop3");
  Services.prefs.setCharPref(
    "mail.server.server4.deferred_to_account",
    "account2"
  );
  Services.prefs.setCharPref("mail.server.server5.hostname", "mail.host5.org");
  Services.prefs.setCharPref("mail.server.server5.type", "pop3");
  Services.prefs.setCharPref(
    "mail.server.server5.deferred_to_account",
    "account2"
  );

  Services.prefs.setCharPref(
    "mail.accountmanager.accounts",
    "account1,account2,account4,account5"
  );
  // Set the default account to one we're going to get rid of. The account manager
  // should recover relatively gracefully.
  Services.prefs.setCharPref("mail.accountmanager.defaultaccount", "account1");

  // This will force the load of the accounts setup above.
  Assert.equal(MailServices.accounts.accounts.length, 3); // hidden account not included
  let server4 = MailServices.accounts
    .getAccount("account4")
    .incomingServer.QueryInterface(Ci.nsIPop3IncomingServer);
  Assert.equal(server4.deferredToAccount, "account1");
  let server5 = MailServices.accounts
    .getAccount("account5")
    .incomingServer.QueryInterface(Ci.nsIPop3IncomingServer);
  Assert.equal(server5.deferredToAccount, "account1");
}