michael@0: /** michael@0: * Test for unassigned code points in IDNs (RFC 3454 section 7) michael@0: */ michael@0: michael@0: var idnService; michael@0: michael@0: function expected_pass(inputIDN) michael@0: { michael@0: var isASCII = {}; michael@0: var displayIDN = idnService.convertToDisplayIDN(inputIDN, isASCII); michael@0: do_check_eq(displayIDN, inputIDN); michael@0: } michael@0: michael@0: function expected_fail(inputIDN) michael@0: { michael@0: var isASCII = {}; michael@0: var displayIDN = ""; michael@0: michael@0: try { michael@0: displayIDN = idnService.convertToDisplayIDN(inputIDN, isASCII); michael@0: } michael@0: catch(e) {} michael@0: michael@0: do_check_neq(displayIDN, inputIDN); michael@0: } michael@0: michael@0: function run_test() { michael@0: // add an IDN whitelist pref michael@0: var pbi = Cc["@mozilla.org/preferences-service;1"] michael@0: .getService(Ci.nsIPrefBranch); michael@0: var whitelistPref = "network.IDN.whitelist.com"; michael@0: michael@0: pbi.setBoolPref(whitelistPref, true); michael@0: michael@0: idnService = Cc["@mozilla.org/network/idn-service;1"] michael@0: .getService(Ci.nsIIDNService); michael@0: michael@0: // assigned code point michael@0: expected_pass("foo\u0101bar.com"); michael@0: michael@0: // assigned code point in punycode. Should *fail* because the URL will be michael@0: // converted to Unicode for display michael@0: expected_fail("xn--foobar-5za.com"); michael@0: michael@0: // unassigned code point michael@0: expected_fail("foo\u3040bar.com"); michael@0: michael@0: // unassigned code point in punycode. Should *pass* because the URL will not michael@0: // be converted to Unicode michael@0: expected_pass("xn--foobar-533e.com"); michael@0: michael@0: // code point assigned since Unicode 3.0 michael@0: // XXX This test will unexpectedly pass when we update to IDNAbis michael@0: expected_fail("foo\u0370bar.com"); michael@0: michael@0: // reset the pref michael@0: if (pbi.prefHasUserValue(whitelistPref)) michael@0: pbi.clearUserPref(whitelistPref); michael@0: }