2010-03-06 07:36:05 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=8 et sw=4 tw=80: */
|
2008-04-21 03:50:45 -07:00
|
|
|
var gExpectedCharset;
|
|
|
|
var gOldPref;
|
|
|
|
var gDetectorList;
|
|
|
|
var gTestIndex;
|
2012-05-24 12:41:38 -07:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
2008-04-21 03:50:45 -07:00
|
|
|
|
|
|
|
function CharsetDetectionTests(aTestFile, aExpectedCharset, aDetectorList)
|
|
|
|
{
|
|
|
|
gExpectedCharset = aExpectedCharset;
|
|
|
|
gDetectorList = aDetectorList;
|
|
|
|
|
|
|
|
InitDetectorTests();
|
|
|
|
|
2012-05-24 12:41:38 -07:00
|
|
|
// convert aTestFile to a file:// URI
|
|
|
|
var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
|
|
.getService(Ci.mozIJSSubScriptLoader);
|
|
|
|
var ioService = Cc['@mozilla.org/network/io-service;1']
|
|
|
|
.getService(Ci.nsIIOService);
|
|
|
|
|
|
|
|
loader.loadSubScript("chrome://mochikit/content/chrome-harness.js");
|
|
|
|
var jar = getJar(getRootDirectory(window.location.href));
|
|
|
|
var dir = jar ?
|
|
|
|
extractJarToTmp(jar) :
|
|
|
|
getChromeDir(getResolvedURI(window.location.href));
|
|
|
|
var fileURI = ioService.newFileURI(dir).spec + aTestFile;
|
|
|
|
|
|
|
|
$("testframe").src = fileURI;
|
2008-04-21 03:50:45 -07:00
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
}
|
|
|
|
|
|
|
|
function InitDetectorTests()
|
|
|
|
{
|
2012-05-24 12:41:38 -07:00
|
|
|
var prefService = Cc["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Ci.nsIPrefBranch);
|
|
|
|
var str = Cc["@mozilla.org/supports-string;1"]
|
|
|
|
.createInstance(Ci.nsISupportsString);
|
2008-04-21 03:50:45 -07:00
|
|
|
|
|
|
|
try {
|
2010-03-06 07:36:05 -08:00
|
|
|
gOldPref = prefService
|
|
|
|
.getComplexValue("intl.charset.detector",
|
2012-05-24 12:41:38 -07:00
|
|
|
Ci.nsIPrefLocalizedString).data;
|
2008-04-21 03:50:45 -07:00
|
|
|
} catch (e) {
|
2010-03-06 07:36:05 -08:00
|
|
|
gOldPref = "";
|
2008-04-21 03:50:45 -07:00
|
|
|
}
|
|
|
|
SetDetectorPref(gDetectorList[0]);
|
|
|
|
gTestIndex = 0;
|
|
|
|
$("testframe").onload = DoDetectionTest;
|
2010-02-23 01:46:15 -08:00
|
|
|
|
|
|
|
if (gExpectedCharset == "default") {
|
2010-03-06 07:36:05 -08:00
|
|
|
try {
|
|
|
|
gExpectedCharset = prefService
|
|
|
|
.getComplexValue("intl.charset.default",
|
2012-05-24 12:41:38 -07:00
|
|
|
Ci.nsIPrefLocalizedString)
|
2010-03-06 07:36:05 -08:00
|
|
|
.data;
|
|
|
|
} catch (e) {
|
|
|
|
gExpectedCharset = "ISO-8859-8";
|
|
|
|
}
|
2010-02-23 01:46:15 -08:00
|
|
|
}
|
2008-04-21 03:50:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function SetDetectorPref(aPrefValue)
|
|
|
|
{
|
2012-05-24 12:41:38 -07:00
|
|
|
var prefService = Cc["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Ci.nsIPrefBranch);
|
|
|
|
var str = Cc["@mozilla.org/supports-string;1"]
|
|
|
|
.createInstance(Ci.nsISupportsString);
|
2008-04-21 03:50:45 -07:00
|
|
|
str.data = aPrefValue;
|
|
|
|
prefService.setComplexValue("intl.charset.detector",
|
2012-05-24 12:41:38 -07:00
|
|
|
Ci.nsISupportsString, str);
|
2008-04-21 03:50:45 -07:00
|
|
|
gCurrentDetector = aPrefValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
function DoDetectionTest() {
|
|
|
|
var iframeDoc = $("testframe").contentDocument;
|
|
|
|
var charset = iframeDoc.characterSet;
|
|
|
|
|
|
|
|
is(charset, gExpectedCharset,
|
|
|
|
"decoded as " + gExpectedCharset + " by " + gDetectorList[gTestIndex]);
|
|
|
|
|
|
|
|
if (++gTestIndex < gDetectorList.length) {
|
2010-03-06 07:36:05 -08:00
|
|
|
SetDetectorPref(gDetectorList[gTestIndex]);
|
|
|
|
iframeDoc.location.reload();
|
2008-04-21 03:50:45 -07:00
|
|
|
} else {
|
2010-03-06 07:36:05 -08:00
|
|
|
CleanUpDetectionTests();
|
2008-04-21 03:50:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function CleanUpDetectionTests() {
|
|
|
|
SetDetectorPref(gOldPref);
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|