| <html> |
| <head> |
| <link rel="stylesheet" href="../js/resources/js-test-style.css"> |
| <script src="../js/resources/js-test-pre.js"></script> |
| <script src="../js/resources/js-test-post-function.js"></script> |
| </head> |
| <body> |
| <p id="description"></p> |
| <div id="console"></div> |
| <form id="form" target="subframe"><input type="text" id="text" name="text"></form> |
| <iframe id="subframe" name="subframe"></iframe> |
| <script> |
| |
| |
| var charsets = new Array; |
| var unicodes = new Array; |
| var expectedResults = new Array; |
| |
| var results = new Object; |
| |
| var i = 0; |
| |
| function encode(charset, unicode) |
| { |
| // Returns a value already encoded, since we can't do it synchronously. |
| return results[charset][unicode]; |
| } |
| |
| function testsDone() |
| { |
| var form = document.getElementById('form'); |
| var subframe = document.getElementById('subframe'); |
| |
| form.parentNode.removeChild(form); |
| subframe.parentNode.removeChild(subframe); |
| |
| description("This tests encoding characters in various character sets."); |
| |
| for (i = 0; i < charsets.length; ++i) { |
| shouldBe("encode('" + charsets[i] + "', '" + unicodes[i] + "')", "'" + expectedResults[i] + "'"); |
| } |
| |
| isSuccessfullyParsed(); |
| |
| if (window.layoutTestController) |
| layoutTestController.notifyDone(); |
| } |
| |
| var timeout = null; |
| |
| function processResult(result) |
| { |
| var charsetResults = results[charsets[i]]; |
| if (!charsetResults) { |
| charsetResults = new Object; |
| results[charsets[i]] = charsetResults; |
| } |
| charsetResults[unicodes[i]] = result; |
| } |
| |
| function subframeLoaded() |
| { |
| clearTimeout(timeout); |
| timeout = null; |
| var URL = "" + document.getElementById('subframe').contentWindow.location; |
| processResult(URL.substr(URL.indexOf('=') + 1)); |
| ++i; |
| runTest(); |
| } |
| |
| // Workaround for rdar://problem/5114296 need to allow for |
| // download occuring, and thus not triggering subframeLoaded() |
| function loadTimedOut() |
| { |
| timeout = null; |
| processResult("FAILED"); |
| ++i; |
| runTest(); |
| } |
| |
| function runTest() |
| { |
| if (i >= charsets.length) { |
| testsDone(); |
| return; |
| } |
| |
| var form = document.getElementById('form'); |
| var text = document.getElementById('text'); |
| var subframe = document.getElementById('subframe'); |
| |
| form.acceptCharset = charsets[i]; |
| form.action = "data:text/plain,x"; |
| subframe.onload = subframeLoaded; |
| text.value = String.fromCharCode(unicodes[i].replace('U+', '0x')); |
| |
| // Workaround for rdar://problem/5114296 |
| // 500 millisecond timeout. This will cause a significant slowdown on failures, |
| // but should guarantee we don't fire prematurely |
| timeout = setTimeout(loadTimedOut, 500); |
| form.submit(); |
| } |
| |
| function testEncode(charsetName, unicode, characterSequence) |
| { |
| charsets.push(charsetName); |
| unicodes.push(unicode); |
| expectedResults.push(characterSequence); |
| } |
| |
| testEncode("UTF-8", "U+00A0", "%C2%A0"); |
| testEncode('macintosh', 'U+221A', '%C3'); |
| testEncode('MacRoman', 'U+221A', '%C3'); |
| //Yen symbol in gbk |
| testEncode('GBK', 'U+00A5', '%A3%A4'); |
| testEncode('gb2312', 'U+00A5', '%A3%A4'); |
| testEncode('GB-2312-80', 'U+00A5', '%A3%A4'); |
| testEncode('EUC-CN', 'U+00A5', '%A3%A4'); |
| //Euro symbol in gbk |
| testEncode('GBK', 'U+20AC', '%80'); |
| testEncode('gb2312', 'U+20AC', '%80'); |
| testEncode('GB-2312-80', 'U+20AC', '%80'); |
| testEncode('EUC-CN', 'U+20AC', '%80'); |
| //Misc symbols from TEC specific GBK translation |
| testEncode('GBK', 'U+01F9', '%A8%BF'); |
| testEncode('GBK', 'U+1E3F', '%A8%BC'); |
| testEncode('GBK', 'U+22EF', '%A1%AD'); |
| testEncode('GBK', 'U+301C', '%A1%AB'); |
| |
| // Turning on this test causes a download to occur. FIXME: A bug? |
| //testEncode('UTF-8', 'U+221A', '%E2%88%9A'); |
| |
| if (window.layoutTestController) |
| layoutTestController.waitUntilDone(); |
| runTest(); |
| |
| successfullyParsed = true; |
| |
| </script> |
| </body> |
| </html> |