netwerk/test/unit/test_bug479413.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial