Make tests that use non-UTF-8 content use file URLs instead of chrome URLs. Bug 644209, r=emk

This commit is contained in:
Simon Montagu 2012-05-24 22:41:38 +03:00
Родитель 7a28af47db
Коммит e3f832b63f
2 изменённых файлов: 38 добавлений и 13 удалений

Просмотреть файл

@ -1,3 +1,7 @@
/* The test text as octets for reference
* %83%86%83%6a%83%52%81%5b%83%68%82%cd%81%41%82%b7%82%d7%82%c4%82%cc%95%b6%8e%9a%82%c9%8c%c5%97%4c%82%cc%94%d4%8d%86%82%f0%95%74%97%5e%82%b5%82%dc%82%b7
*/
/* The test text decoded correctly as Shift_JIS */
const rightText="\u30E6\u30CB\u30B3\u30FC\u30C9\u306F\u3001\u3059\u3079\u3066\u306E\u6587\u5B57\u306B\u56FA\u6709\u306E\u756A\u53F7\u3092\u4ED8\u4E0E\u3057\u307E\u3059";
@ -37,7 +41,13 @@ function afterChangeCharset() {
function test() {
waitForExplicitFinish();
var rootDir = getRootDirectory(gTestPath);
var jar = getJar(getRootDirectory(gTestPath));
var dir = jar ?
extractJarToTmp(jar) :
getChromeDir(getResolvedURI(gTestPath));
var rootDir = Services.io.newFileURI(dir).spec;
gBrowser.selectedTab = gBrowser.addTab(rootDir + "test-form_sjis.html");
gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
}

Просмотреть файл

@ -4,6 +4,8 @@ var gExpectedCharset;
var gOldPref;
var gDetectorList;
var gTestIndex;
const Cc = Components.classes;
const Ci = Components.interfaces;
function CharsetDetectionTests(aTestFile, aExpectedCharset, aDetectorList)
{
@ -12,22 +14,35 @@ function CharsetDetectionTests(aTestFile, aExpectedCharset, aDetectorList)
InitDetectorTests();
$("testframe").src = aTestFile;
// 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;
SimpleTest.waitForExplicitFinish();
}
function InitDetectorTests()
{
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var str = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
var prefService = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch);
var str = Cc["@mozilla.org/supports-string;1"]
.createInstance(Ci.nsISupportsString);
try {
gOldPref = prefService
.getComplexValue("intl.charset.detector",
Components.interfaces.nsIPrefLocalizedString).data;
Ci.nsIPrefLocalizedString).data;
} catch (e) {
gOldPref = "";
}
@ -39,7 +54,7 @@ function InitDetectorTests()
try {
gExpectedCharset = prefService
.getComplexValue("intl.charset.default",
Components.interfaces.nsIPrefLocalizedString)
Ci.nsIPrefLocalizedString)
.data;
} catch (e) {
gExpectedCharset = "ISO-8859-8";
@ -49,13 +64,13 @@ function InitDetectorTests()
function SetDetectorPref(aPrefValue)
{
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var str = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
var prefService = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch);
var str = Cc["@mozilla.org/supports-string;1"]
.createInstance(Ci.nsISupportsString);
str.data = aPrefValue;
prefService.setComplexValue("intl.charset.detector",
Components.interfaces.nsISupportsString, str);
Ci.nsISupportsString, str);
gCurrentDetector = aPrefValue;
}