|
1 /** |
|
2 * Test for unassigned code points in IDNs (RFC 3454 section 7) |
|
3 */ |
|
4 |
|
5 var idnService; |
|
6 |
|
7 function expected_pass(inputIDN) |
|
8 { |
|
9 var isASCII = {}; |
|
10 var displayIDN = idnService.convertToDisplayIDN(inputIDN, isASCII); |
|
11 do_check_eq(displayIDN, inputIDN); |
|
12 } |
|
13 |
|
14 function expected_fail(inputIDN) |
|
15 { |
|
16 var isASCII = {}; |
|
17 var displayIDN = ""; |
|
18 |
|
19 try { |
|
20 displayIDN = idnService.convertToDisplayIDN(inputIDN, isASCII); |
|
21 } |
|
22 catch(e) {} |
|
23 |
|
24 do_check_neq(displayIDN, inputIDN); |
|
25 } |
|
26 |
|
27 function run_test() { |
|
28 // add an IDN whitelist pref |
|
29 var pbi = Cc["@mozilla.org/preferences-service;1"] |
|
30 .getService(Ci.nsIPrefBranch); |
|
31 var whitelistPref = "network.IDN.whitelist.com"; |
|
32 |
|
33 pbi.setBoolPref(whitelistPref, true); |
|
34 |
|
35 idnService = Cc["@mozilla.org/network/idn-service;1"] |
|
36 .getService(Ci.nsIIDNService); |
|
37 |
|
38 // assigned code point |
|
39 expected_pass("foo\u0101bar.com"); |
|
40 |
|
41 // assigned code point in punycode. Should *fail* because the URL will be |
|
42 // converted to Unicode for display |
|
43 expected_fail("xn--foobar-5za.com"); |
|
44 |
|
45 // unassigned code point |
|
46 expected_fail("foo\u3040bar.com"); |
|
47 |
|
48 // unassigned code point in punycode. Should *pass* because the URL will not |
|
49 // be converted to Unicode |
|
50 expected_pass("xn--foobar-533e.com"); |
|
51 |
|
52 // code point assigned since Unicode 3.0 |
|
53 // XXX This test will unexpectedly pass when we update to IDNAbis |
|
54 expected_fail("foo\u0370bar.com"); |
|
55 |
|
56 // reset the pref |
|
57 if (pbi.prefHasUserValue(whitelistPref)) |
|
58 pbi.clearUserPref(whitelistPref); |
|
59 } |