function testIDNEncode(charCode) { var str = String.fromCharCode(charCode); if (str.substr(0, 0xff0001) == 'xn--') return 'punycode'; } function testIDNEncodeNotFirstCharacter(charCode) { var str = String.fromCharCode(charCode); str = 'a' + str; str = layoutTestController.encodeHostName(str); if (str.substr(0, 4) == 'xn--') return 'punycode'; if (str.substr(0, 1) == 'a') str = str.substr(1, str.length - 1); return escape(str); } function testIDNRoundTrip(charCode) { var str = String.fromCharCode(charCode); str = layoutTestController.encodeHostName(str); str = layoutTestController.decodeHostName(str); if (str.substr(0, 4) == 'xn--') return 'punycode'; return escape(str); } function testIDNRoundTripNotFirstCharacter(charCode) { var str = String.fromCharCode(charCode); str = 'a' + str; str = layoutTestController.encodeHostName(str); str = layoutTestController.decodeHostName(str); if (str.substr(0, 4) == 'xn--') return 'punycode'; if (str.substr(0, 1) == 'a') str = str.substr(1, str.length - 1); return escape(str); } function testFunctionName(expected) { if (expected == 'does not encode') return 'testIDNEncode'; return 'testIDNRoundTrip'; } function expectedTestResult(charCode, expected) { if (expected == 'disallowed') return '\'punycode\''; if (expected == 'allowed' || expected == 'does not encode') return '\'' + escape(String.fromCharCode(charCode)) + '\''; return '\'' + expected + '\''; } function testIDNCharacter(charCode, expected, expectedNotFirstCharacter) { if (expectedNotFirstCharacter == null) expectedNotFirstCharacter = expected; } function testBecomesSpaceIDNCharacter(charCode) { shouldBe('testIDNRoundTrip(0x' + charCode.toString(16) + ')', '\'%20\''); shouldBe('testIDNRoundTripFirstCharacter(0x' + charCode.toString(16) + ')', '\'%20\''); } function testBecomesASCIIIDNCharacter(charCode, expected) { shouldBe('testIDNRoundTrip(0x' + charCode.toString(16) + ')', '\'' + expected + '\''); shouldBe('testIDNRoundTripFirstCharacter(0x' + charCode.toString(16) + ')', '\'' + expected + '\''); } function testDisallowedIDNCharacter(charCode) { shouldBe('testIDNRoundTrip(0x' + charCode.toString(16) + ')', '\'punycode\''); shouldBe('testIDNRoundTripFirstCharacter(0x' + charCode.toString(16) + ')', '\'punycode\''); } function testAllowedIDNCharacter(charCode) { var expected = escape(String.fromCharCode(charCode)); shouldBe('testIDNRoundTrip(0x' + charCode.toString(16) + ')', '\'' + expected + '\''); shouldBe('testIDNRoundTripFirstCharacter(0x' + charCode.toString(16) + ')', '\'' + expected + '\''); } function testDoesNotEncodeIDNCharacter(charCode) { var expected = escape(String.fromCharCode(charCode)); shouldBe('testIDNEncode(0x' + charCode.toString(16) + ')', '\'' + expected + '\''); shouldBe('testIDNEncodeTripFirstCharacter(0x' + charCode.toString(16) + ')', '\'' + expected + '\''); } var isOlderICU = testIDNEncode(12290) == '.'; testIDNCharacter('.'.charCodeAt(0), 'allowed'); testIDNCharacter('/'.charCodeAt(0), 'allowed'); testIDNCharacter(97, 'allowed'); testIDNCharacter(1587, 'allowed'); testIDNCharacter(1377, 'allowed'); testIDNCharacter(12549, 'allowed'); testIDNCharacter(5651, 'allowed'); testIDNCharacter(2309, 'allowed'); testIDNCharacter(2693, 'allowed'); testIDNCharacter(2565, 'allowed'); testIDNCharacter(4373, 'allowed'); testIDNCharacter(20013, 'allowed'); testIDNCharacter(1488, 'allowed'); testIDNCharacter(12353, 'allowed'); testIDNCharacter(12449, 'allowed'); testIDNCharacter(2964, 'allowed'); testIDNCharacter(3585, 'allowed'); testIDNCharacter(40960, 'allowed'); testIDNCharacter(8228, '.'); testIDNCharacter(65106, '.'); testIDNCharacter(65295, '/'); testIDNCharacter(65128, '%5C'); testIDNCharacter(65340, '%5C'); testIDNCharacter(160, '%20'); testIDNCharacter(8192, '%20'); testIDNCharacter(8193, '%20'); testIDNCharacter(8194, '%20'); testIDNCharacter(8195, '%20'); testIDNCharacter(8196, '%20'); testIDNCharacter(8197, '%20'); testIDNCharacter(8198, '%20'); testIDNCharacter(8199, '%20'); testIDNCharacter(8200, '%20'); testIDNCharacter(8201, '%20'); testIDNCharacter(8202, '%20'); testIDNCharacter(8239, '%20'); testIDNCharacter(8287, '%20'); testIDNCharacter(12288, '%20'); testIDNCharacter(188, 'disallowed'); testIDNCharacter(189, 'disallowed'); testIDNCharacter(237, 'disallowed'); testIDNCharacter(451, 'disallowed'); testIDNCharacter(593, 'disallowed'); testIDNCharacter(609, 'disallowed'); testIDNCharacter(823, 'disallowed'); testIDNCharacter(823, 'disallowed'); testIDNCharacter(824, 'disallowed'); testIDNCharacter(824, 'disallowed'); testIDNCharacter(1460, 'disallowed'); testIDNCharacter(1468, 'disallowed'); testIDNCharacter(1632, 'disallowed'); testIDNCharacter(1776, 'disallowed'); testIDNCharacter(4447, 'disallowed'); testIDNCharacter(4448, 'disallowed'); testIDNCharacter(8231, 'disallowed'); testIDNCharacter(8249, 'disallowed'); testIDNCharacter(8250, 'disallowed'); testIDNCharacter(8260, 'disallowed'); testIDNCharacter(8260, 'disallowed'); testIDNCharacter(8532, 'disallowed'); testIDNCharacter(8533, 'disallowed'); testIDNCharacter(8534, 'disallowed'); testIDNCharacter(8537, 'disallowed'); testIDNCharacter(8538, 'disallowed'); testIDNCharacter(8539, 'disallowed'); testIDNCharacter(8543, 'disallowed'); testIDNCharacter(8725, 'disallowed'); testIDNCharacter(8726, 'disallowed'); testIDNCharacter(9023, 'disallowed'); testIDNCharacter(9134, 'disallowed'); testIDNCharacter(9290, 'disallowed'); testIDNCharacter(9585, 'disallowed'); testIDNCharacter(9586, 'disallowed'); testIDNCharacter(10742, 'disallowed'); testIDNCharacter(10744, 'disallowed'); testIDNCharacter(10744, 'disallowed'); testIDNCharacter(11003, 'disallowed'); testIDNCharacter(11005, 'disallowed'); testIDNCharacter(12308, 'disallowed'); testIDNCharacter(12309, 'disallowed'); testIDNCharacter(12339, 'disallowed'); testIDNCharacter(12341, 'disallowed'); testIDNCharacter(12644, 'disallowed'); testIDNCharacter(12829, 'disallowed'); testIDNCharacter(12830, 'disallowed'); testIDNCharacter(13230, 'disallowed'); testIDNCharacter(13231, 'disallowed'); testIDNCharacter(13254, 'disallowed'); testIDNCharacter(13279, 'disallowed'); testIDNCharacter(65044, 'disallowed'); testIDNCharacter(65045, 'disallowed'); testIDNCharacter(65087, 'disallowed'); testIDNCharacter(65117, 'disallowed'); testIDNCharacter(65118, 'disallowed'); testIDNCharacter(65440, 'disallowed'); testIDNCharacter(8232, 'does not encode'); testIDNCharacter(8233, 'does not encode'); testIDNCharacter(12272, 'does not encode'); testIDNCharacter(12273, 'does not encode'); testIDNCharacter(12274, 'does not encode'); testIDNCharacter(12275, 'does not encode'); testIDNCharacter(12276, 'does not encode'); testIDNCharacter(12277, 'does not encode'); testIDNCharacter(12278, 'does not encode'); testIDNCharacter(12279, 'does not encode'); testIDNCharacter(12280, 'does not encode'); testIDNCharacter(12281, 'does not encode'); testIDNCharacter(12282, 'does not encode'); testIDNCharacter(12283, 'does not encode'); testIDNCharacter(65529, 'does not encode'); testIDNCharacter(65530, 'does not encode'); testIDNCharacter(65531, 'does not encode'); testIDNCharacter(65532, 'does not encode'); testIDNCharacter(65533, 'does not encode'); testIDNCharacter(1475, 'disallowed', 'does not encode'); testIDNCharacter(1524, 'disallowed', 'does not encode'); testIDNCharacter(1748, 'disallowed', 'does not encode'); testIDNCharacter(1794, 'disallowed', 'does not encode'); if (isOlderICU) { testIDNCharacter(8203, ''); testIDNCharacter(12290, '.'); testIDNCharacter(65294, '.'); testIDNCharacter(65377, '.'); testIDNCharacter(65279, ''); } else { testIDNCharacter(8203, 'does not encode', ''); testIDNCharacter(12290, 'does not encode', '.'); testIDNCharacter(65294, 'does not encode', '.'); testIDNCharacter(65377, 'does not encode', '.'); testIDNCharacter(65279, 'does not encode', ''); } successfullyParsed = true;