summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/addrbook/test/unit/test_ldap2.js
blob: 2dc39c4a86458efc1b5f8ff2edc0b14c4ba8743d (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
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 * Test suite for bug 532170. LDAP address book named with cyrillic/chinese
 * letters doesn't work.
 */

var kLDAPUriPrefix = "moz-abldapdirectory://";
var kLDAPTestSpec = "ldap://invalidhost//dc=intranet??sub?(objectclass=*)";

function run_test() {
  // If nsIAbLDAPDirectory doesn't exist in our build options, someone has
  // specified --disable-ldap
  if (!("nsIAbLDAPDirectory" in Ci)) {
    return;
  }

  // Test - Create an LDAP directory

  // Use a UTF-8 based directory name
  var abUri = MailServices.ab.newAddressBook(
    "\u041C\u0435\u043B\u0435\u043D\u043A\u0438",
    kLDAPTestSpec,
    Ci.nsIAbManager.LDAP_DIRECTORY_TYPE
  );

  // Test - Check we have the directory.
  let abDir = MailServices.ab
    .getDirectory(kLDAPUriPrefix + abUri)
    .QueryInterface(Ci.nsIAbLDAPDirectory);

  // Test - Check various fields
  Assert.equal(abDir.dirName, "\u041C\u0435\u043B\u0435\u043D\u043A\u0438");
  Assert.equal(abDir.lDAPURL.spec, kLDAPTestSpec);
  Assert.ok(abDir.readOnly);

  // XXX I'd really like a better check than this, to check that searching
  // works correctly. However we haven't got the support for that at the moment
  // and this at least ensures that we get a consistent ascii based preference
  // for the directory.
  Assert.equal(abDir.dirPrefId, "ldap_2.servers._nonascii");
}