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