1 function encode(charset, unicode) 2 { 3 // Returns a value already encoded, since we can't do it synchronously. 4 return results[charset][unicode]; 5 } 6 7 function testsDone() 8 { 9 var form = document.getElementById('form'); 10 var subframe = document.getElementById('subframe'); 11 12 form.parentNode.removeChild(form); 13 subframe.parentNode.removeChild(subframe); 14 15 description("This tests encoding characters in various character sets."); 16 17 for (i = 0; i < charsets.length; ++i) { 18 shouldBe("encode('" + charsets[i] + "', '" + unicodes[i] + "')", "'" + expectedResults[i] + "'"); 19 } 20 21 isSuccessfullyParsed(); 22 23 if (window.layoutTestController) 24 layoutTestController.notifyDone(); 25 } 26 27 function processResult(result) 28 { 29 var charsetResults = results[charsets[i]]; 30 if (!charsetResults) { 31 charsetResults = new Object; 32 results[charsets[i]] = charsetResults; 33 } 34 charsetResults[unicodes[i]] = result; 35 } 36 37 function subframeLoaded() 38 { 39 var URL = "" + document.getElementById('subframe').contentWindow.location; 40 processResult(URL.substr(URL.indexOf('=') + 1)); 41 ++i; 42 runTest(); 43 } 44 45 function runTest() 46 { 47 if (i >= charsets.length) { 48 testsDone(); 49 return; 50 } 51 52 var form = document.getElementById('form'); 53 var text = document.getElementById('text'); 54 var subframe = document.getElementById('subframe'); 55 56 form.acceptCharset = charsets[i]; 57 form.action = "resources/dummy.html"; 58 subframe.onload = subframeLoaded; 59 text.value = String.fromCharCode(unicodes[i].replace('U+', '0x')); 60 61 form.submit(); 62 } 63 64 function testEncode(charsetName, unicode, characterSequence) 65 { 66 charsets.push(charsetName); 67 unicodes.push(unicode); 68 expectedResults.push(characterSequence); 69 } 70