1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_bug479413.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 1.4 +/** 1.5 + * Test for unassigned code points in IDNs (RFC 3454 section 7) 1.6 + */ 1.7 + 1.8 +var idnService; 1.9 + 1.10 +function expected_pass(inputIDN) 1.11 +{ 1.12 + var isASCII = {}; 1.13 + var displayIDN = idnService.convertToDisplayIDN(inputIDN, isASCII); 1.14 + do_check_eq(displayIDN, inputIDN); 1.15 +} 1.16 + 1.17 +function expected_fail(inputIDN) 1.18 +{ 1.19 + var isASCII = {}; 1.20 + var displayIDN = ""; 1.21 + 1.22 + try { 1.23 + displayIDN = idnService.convertToDisplayIDN(inputIDN, isASCII); 1.24 + } 1.25 + catch(e) {} 1.26 + 1.27 + do_check_neq(displayIDN, inputIDN); 1.28 +} 1.29 + 1.30 +function run_test() { 1.31 + // add an IDN whitelist pref 1.32 + var pbi = Cc["@mozilla.org/preferences-service;1"] 1.33 + .getService(Ci.nsIPrefBranch); 1.34 + var whitelistPref = "network.IDN.whitelist.com"; 1.35 + 1.36 + pbi.setBoolPref(whitelistPref, true); 1.37 + 1.38 + idnService = Cc["@mozilla.org/network/idn-service;1"] 1.39 + .getService(Ci.nsIIDNService); 1.40 + 1.41 + // assigned code point 1.42 + expected_pass("foo\u0101bar.com"); 1.43 + 1.44 + // assigned code point in punycode. Should *fail* because the URL will be 1.45 + // converted to Unicode for display 1.46 + expected_fail("xn--foobar-5za.com"); 1.47 + 1.48 + // unassigned code point 1.49 + expected_fail("foo\u3040bar.com"); 1.50 + 1.51 + // unassigned code point in punycode. Should *pass* because the URL will not 1.52 + // be converted to Unicode 1.53 + expected_pass("xn--foobar-533e.com"); 1.54 + 1.55 + // code point assigned since Unicode 3.0 1.56 + // XXX This test will unexpectedly pass when we update to IDNAbis 1.57 + expected_fail("foo\u0370bar.com"); 1.58 + 1.59 + // reset the pref 1.60 + if (pbi.prefHasUserValue(whitelistPref)) 1.61 + pbi.clearUserPref(whitelistPref); 1.62 +}