CharsetDetectionTests.js (1403B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */ 2 /* vim: set ts=8 et sw=4 tw=80: */ 3 4 var gExpectedCharset; 5 var gLocalDir; 6 7 function CharsetDetectionTests(aTestFile, aExpectedCharset) { 8 gExpectedCharset = aExpectedCharset; 9 10 InitDetectorTests(); 11 12 var fileURI = gLocalDir + aTestFile; 13 $("testframe").src = fileURI; 14 15 SimpleTest.waitForExplicitFinish(); 16 } 17 18 function InitDetectorTests() { 19 var loader = Services.scriptloader; 20 var ioService = Services.io; 21 loader.loadSubScript("chrome://mochikit/content/chrome-harness.js"); 22 23 $("testframe").onload = DoDetectionTest; 24 25 if (gExpectedCharset == "default") { 26 // No point trying to be generic here, because we have plenty of other 27 // unit tests that fail if run using a non-windows-1252 locale. 28 gExpectedCharset = "windows-1252"; 29 } 30 31 // Get the local directory. This needs to be a file: URI because chrome: 32 // URIs are always UTF-8 (bug 617339) and we are testing decoding from other 33 // charsets. 34 var jar = getJar(getRootDirectory(window.location.href)); 35 var dir = jar 36 ? extractJarToTmp(jar) 37 : getChromeDir(getResolvedURI(window.location.href)); 38 gLocalDir = ioService.newFileURI(dir).spec; 39 } 40 41 function DoDetectionTest() { 42 var iframeDoc = $("testframe").contentDocument; 43 var charset = iframeDoc.characterSet; 44 45 is(charset, gExpectedCharset, "decoded as " + gExpectedCharset); 46 47 SimpleTest.finish(); 48 }