4 // The 3rd element indicates whether the second element
6 ["asciihost", "asciihost", false],
7 ["b\u00FCcher", "xn--bcher-kva", true]
11 var idnService = Components.classes["@mozilla.org/network/idn-service;1"]
12 .getService(Components.interfaces.nsIIDNService);
14 for (var i = 0; i < reference.length; ++i) {
15 dump("Testing " + reference[i] + "\n");
16 // We test the following:
17 // - Converting UTF-8 to ACE and back gives us the expected answer
18 // - Converting the ASCII string UTF-8 -> ACE leaves the string unchanged
19 // - isACE returns true when we expect it to (third array elem true)
20 do_check_eq(idnService.convertUTF8toACE(reference[i][0]), reference[i][1]);
21 do_check_eq(idnService.convertUTF8toACE(reference[i][1]), reference[i][1]);
22 do_check_eq(idnService.convertACEtoUTF8(reference[i][1]), reference[i][0]);
23 do_check_eq(idnService.isACE(reference[i][1]), reference[i][2]);
26 // add an IDN whitelist pref
27 var pbi = Components.classes["@mozilla.org/preferences-service;1"]
28 .getService(Components.interfaces.nsIPrefBranch2);
29 pbi.setBoolPref("network.IDN.whitelist.es", true);
31 // check convertToDisplayIDN against the whitelist
33 do_check_eq(idnService.convertToDisplayIDN("b\u00FCcher.es", isASCII), "b\u00FCcher.es");
34 do_check_eq(isASCII.value, false);
35 do_check_eq(idnService.convertToDisplayIDN("xn--bcher-kva.es", isASCII), "b\u00FCcher.es");
36 do_check_eq(isASCII.value, false);
37 do_check_eq(idnService.convertToDisplayIDN("b\u00FCcher.uk", isASCII), "xn--bcher-kva.uk");
38 do_check_eq(isASCII.value, true);
39 do_check_eq(idnService.convertToDisplayIDN("xn--bcher-kva.uk", isASCII), "xn--bcher-kva.uk");
40 do_check_eq(isASCII.value, true);
42 // check ACE TLD's are handled by the whitelist
43 pbi.setBoolPref("network.IDN.whitelist.xn--k-dha", true);
44 do_check_eq(idnService.convertToDisplayIDN("test.\u00FCk", isASCII), "test.\u00FCk");
45 do_check_eq(isASCII.value, false);
46 do_check_eq(idnService.convertToDisplayIDN("test.xn--k-dha", isASCII), "test.\u00FCk");
47 do_check_eq(isASCII.value, false);