1 /* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
2 /* vim: set ts=8 et sw=4 tw=80: */
7 function CharsetDetectionTests(aTestFile, aExpectedCharset) {
8 gExpectedCharset = aExpectedCharset;
12 var fileURI = gLocalDir + aTestFile;
13 $("testframe").src = fileURI;
15 SimpleTest.waitForExplicitFinish();
18 function InitDetectorTests() {
19 var loader = Services.scriptloader;
20 var ioService = Services.io;
21 loader.loadSubScript("chrome://mochikit/content/chrome-harness.js");
23 $("testframe").onload = DoDetectionTest;
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";
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
34 var jar = getJar(getRootDirectory(window.location.href));
36 ? extractJarToTmp(jar)
37 : getChromeDir(getResolvedURI(window.location.href));
38 gLocalDir = ioService.newFileURI(dir).spec;
41 function DoDetectionTest() {
42 var iframeDoc = $("testframe").contentDocument;
43 var charset = iframeDoc.characterSet;
45 is(charset, gExpectedCharset, "decoded as " + gExpectedCharset);