зеркало из https://github.com/mozilla/pjs.git
Mochitests for charset autodetection
This commit is contained in:
Родитель
946fb09625
Коммит
61cc087900
|
@ -0,0 +1,70 @@
|
|||
var gExpectedCharset;
|
||||
var gOldPref;
|
||||
var gDetectorList;
|
||||
var gTestIndex;
|
||||
|
||||
function CharsetDetectionTests(aTestFile, aExpectedCharset, aDetectorList)
|
||||
{
|
||||
gExpectedCharset = aExpectedCharset;
|
||||
gDetectorList = aDetectorList;
|
||||
|
||||
InitDetectorTests();
|
||||
|
||||
$("testframe").src = aTestFile;
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
}
|
||||
|
||||
function InitDetectorTests()
|
||||
{
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
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);
|
||||
|
||||
try {
|
||||
gOldPref = prefService
|
||||
.getComplexValue("intl.charset.detector",
|
||||
Components.interfaces.nsIPrefLocalizedString).data;
|
||||
} catch (e) {
|
||||
gOldPref = "";
|
||||
}
|
||||
SetDetectorPref(gDetectorList[0]);
|
||||
gTestIndex = 0;
|
||||
$("testframe").onload = DoDetectionTest;
|
||||
}
|
||||
|
||||
function SetDetectorPref(aPrefValue)
|
||||
{
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
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);
|
||||
str.data = aPrefValue;
|
||||
prefService.setComplexValue("intl.charset.detector",
|
||||
Components.interfaces.nsISupportsString, str);
|
||||
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) {
|
||||
SetDetectorPref(gDetectorList[gTestIndex]);
|
||||
iframeDoc.location.reload();
|
||||
} else {
|
||||
CleanUpDetectionTests();
|
||||
}
|
||||
}
|
||||
|
||||
function CleanUpDetectionTests() {
|
||||
SetDetectorPref(gOldPref);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
|
@ -71,10 +71,17 @@ ifdef MOZ_MOCHITEST
|
|||
relativesrcdir = extensions/universalchardet/tests
|
||||
|
||||
_TEST_FILES = \
|
||||
test_bug426271-euc-jp.html \
|
||||
CharsetDetectionTests.js \
|
||||
bug171813_text.html \
|
||||
test_bug171813.html \
|
||||
bug306272_text.html \
|
||||
test_bug306272.html \
|
||||
bug421271_text.html \
|
||||
test_bug421271.html \
|
||||
bug426271_text-euc-jp.html \
|
||||
test_bug426271-utf-8.html \
|
||||
test_bug426271-euc-jp.html \
|
||||
bug426271_text-utf-8.html \
|
||||
test_bug426271-utf-8.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<body leftmargin="0" topmargin="0" bgcolor="#fffeeb">
|
||||
<table border=0 cellpadding=0 cellspacing=0 height=22 width=160>
|
||||
<tbody>
|
||||
<tr bgcolor=C40001>
|
||||
<td align=middle class=cn
|
||||
height=22 >
|
||||
<div align="center"><a href="http://www.sol.sohu.com" class="white" target="_blank"><font color="#ffffff"><b>搜狐在线</b></font></a></div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table border=0 cellpadding=0 cellspacing=2 width=160>
|
||||
<tr>
|
||||
<td class=sca valign=top>
|
||||
<div align="center">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class=sca valign=top>
|
||||
<div align="center"><a href="http://www.sol.sohu.com/promote/nd.htm" target="_blank">搜狐在线国庆免费大酬宾</a></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class=sca valign=top>
|
||||
<p align="center"><a href="http://www.sol.sohu.com/game/crossgate/"><font color="red">拨95933上网魔力宝贝免费玩</font></a></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class=sca valign=top>
|
||||
<div align="center"><a href="http://www.sol.sohu.com/promote/95933/" target="_blank">95933网费天天最低6毛/小时</a></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tbody> </tbody>
|
||||
</table>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html><head>
|
||||
|
||||
<title>306272</title>
|
||||
|
||||
|
||||
</head><body>
|
||||
<a href="mailto:Antti.Nayha@somewhere.fi">Antti Näyhä <Antti.Nayha@somewhere.fi></a>
|
||||
</body></html>
|
|
@ -0,0 +1,5 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html"><title>BBC - 606 - A Forum Conversation</title>
|
||||
</head>
|
||||
<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0"><p class="posted">posted 5 Weeks Ago</p><p>if rangers draw and marseille and benfica win i stand to lift £825. not bad for a £2 bet.<br>50p on 3 homes<br>Man Utd/Marseille/Benfica<br>50p on 3 Draws<br>Rangers/Halifax/Bristol City<br>50p on 3 Aways<br>Doncaster/Stranraer/Rushden & Diamonds<br>and 50p on all nine results.<br>GET IN THERE.</p></body></html>
|
|
@ -4,7 +4,7 @@
|
|||
<title>日本語エンコードテスト</title>
|
||||
</head>
|
||||
<body>
|
||||
<span id="testtext">これはEUC-JPです昔々、</span>ある所に子供のいない老夫婦が住んでいた。ある日、お婆さんが川で洗濯をしていると、大きな桃が流れて来たので、お爺さんと食べようと持ち帰った。二人で桃を割ると中から男の子が生まれたので、「桃太郎」と名付けて大事に育てた。
|
||||
これはEUC-JPです昔々、ある所に子供のいない老夫婦が住んでいた。ある日、お婆さんが川で洗濯をしていると、大きな桃が流れて来たので、お爺さんと食べようと持ち帰った。二人で桃を割ると中から男の子が生まれたので、「桃太郎」と名付けて大事に育てた。
|
||||
|
||||
成長した桃太郎は、鬼ヶ島の鬼が人々を苦しめていることを知り、鬼退治を決意する。両親から黍団子を餞別に貰い、道中にそれを分け与えてイヌ、サル、キジを家来に従える。鬼ヶ島で鬼と戦い、見事に勝利を収め、鬼が方々から奪っていった財宝を持ち帰り、お爺さん・お婆さんの元に返り、幸せに暮らしたという。出典: フリー百科事典『ウィキペディア(Wikipedia)』
|
||||
</body>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<title>日本語エンコードテスト</title>
|
||||
</head>
|
||||
<body>
|
||||
<span id="testtext">これはUTF-8です昔々、</span>ある所に子供のいない老夫婦が住んでいた。ある日、お婆さんが川で洗濯をしていると、大きな桃が流れて来たので、お爺さんと食べようと持ち帰った。二人で桃を割ると中から男の子が生まれたので、「桃太郎」と名付けて大事に育てた。
|
||||
これはUTF-8です昔々、ある所に子供のいない老夫婦が住んでいた。ある日、お婆さんが川で洗濯をしていると、大きな桃が流れて来たので、お爺さんと食べようと持ち帰った。二人で桃を割ると中から男の子が生まれたので、「桃太郎」と名付けて大事に育てた。
|
||||
|
||||
成長した桃太郎は、鬼ヶ島の鬼が人々を苦しめていることを知り、鬼退治を決意する。両親から黍団子を餞別に貰い、道中にそれを分け与えてイヌ、サル、キジを家来に従える。鬼ヶ島で鬼と戦い、見事に勝利を収め、鬼が方々から奪っていった財宝を持ち帰り、お爺さん・お婆さんの元に返り、幸せに暮らしたという。出典: フリー百科事典『ウィキペディア(Wikipedia)』
|
||||
</body>
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=171813
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 171813</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="CharsetDetectionTests.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=171813">Mozilla Bug 171813</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<iframe id="testframe"></iframe>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
/** Test for Bug 171813 **/
|
||||
CharsetDetectionTests("bug171813_text.html",
|
||||
"gb18030",
|
||||
new Array("zh_parallel_state_machine",
|
||||
"zhcn_parallel_state_machine",
|
||||
"cjk_parallel_state_machine",
|
||||
"universal_charset_detector"));
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=306272
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 306272</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="CharsetDetectionTests.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=306272">Mozilla Bug 306272</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<iframe id="testframe"></iframe>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
/** Test for Bug 306272 **/
|
||||
CharsetDetectionTests("bug306272_text.html",
|
||||
"UTF-8",
|
||||
new Array("ja_parallel_state_machine",
|
||||
"ko_parallel_state_machine",
|
||||
"zh_parallel_state_machine",
|
||||
"zhtw_parallel_state_machine",
|
||||
"zhcn_parallel_state_machine",
|
||||
"cjk_parallel_state_machine",
|
||||
"universal_charset_detector"));
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=421271
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 421271</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="CharsetDetectionTests.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=421271">Mozilla Bug 421271</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<iframe id="testframe"></iframe>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
/** Test for Bug 421271 **/
|
||||
CharsetDetectionTests("bug421271_text.html",
|
||||
"windows-1252",
|
||||
new Array("ja_parallel_state_machine",
|
||||
"ko_parallel_state_machine",
|
||||
"zh_parallel_state_machine",
|
||||
"zhtw_parallel_state_machine",
|
||||
"zhcn_parallel_state_machine",
|
||||
"cjk_parallel_state_machine",
|
||||
"universal_charset_detector"));
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -7,6 +7,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=426271
|
|||
<title>Test for Bug 426271</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="CharsetDetectionTests.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
@ -18,46 +19,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=426271
|
|||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
/** Test for Bug 426271 **/
|
||||
const expectedText = "\u3053\u308C\u306FEUC-JP\u3067\u3059\u6614\u3005\u3001";
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
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 oldPref;
|
||||
|
||||
try {
|
||||
oldPref = prefService
|
||||
.getComplexValue("intl.charset.detector",
|
||||
Components.interfaces.nsIPrefLocalizedString).data;
|
||||
} catch (e) {
|
||||
oldPref = "";
|
||||
}
|
||||
str.data = "ja_parallel_state_machine";
|
||||
prefService.setComplexValue("intl.charset.detector",
|
||||
Components.interfaces.nsISupportsString, str);
|
||||
|
||||
function afterLoad() {
|
||||
var iframeDoc = $("testframe").contentDocument;
|
||||
|
||||
is(iframeDoc.getElementById("testtext").innerHTML, expectedText,
|
||||
"decoded as EUC-JP");
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
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);
|
||||
str.data = oldPref;
|
||||
prefService.setComplexValue("intl.charset.detector",
|
||||
Components.interfaces.nsISupportsString, str);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
$("testframe").onload= afterLoad;
|
||||
$("testframe").src="bug426271_text-euc-jp.html";
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
CharsetDetectionTests("bug426271_text-euc-jp.html",
|
||||
"EUC-JP",
|
||||
new Array("ja_parallel_state_machine",
|
||||
"cjk_parallel_state_machine",
|
||||
"universal_charset_detector"));
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
|
|
|
@ -7,6 +7,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=426271
|
|||
<title>Test for Bug 426271</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="CharsetDetectionTests.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
@ -18,46 +19,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=426271
|
|||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
/** Test for Bug 426271 **/
|
||||
const expectedText = "\u3053\u308C\u306FUTF-8\u3067\u3059\u6614\u3005\u3001";
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
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 oldPref;
|
||||
|
||||
try {
|
||||
oldPref = prefService
|
||||
.getComplexValue("intl.charset.detector",
|
||||
Components.interfaces.nsIPrefLocalizedString).data;
|
||||
} catch (e) {
|
||||
oldPref = "";
|
||||
}
|
||||
str.data = "ja_parallel_state_machine";
|
||||
prefService.setComplexValue("intl.charset.detector",
|
||||
Components.interfaces.nsISupportsString, str);
|
||||
|
||||
function afterLoad() {
|
||||
var iframeDoc = $("testframe").contentDocument;
|
||||
|
||||
is(iframeDoc.getElementById("testtext").innerHTML, expectedText,
|
||||
"decoded as UTF-8");
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
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);
|
||||
str.data = oldPref;
|
||||
prefService.setComplexValue("intl.charset.detector",
|
||||
Components.interfaces.nsISupportsString, str);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
$("testframe").onload= afterLoad;
|
||||
$("testframe").src="bug426271_text-utf-8.html";
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
CharsetDetectionTests("bug426271_text-utf-8.html",
|
||||
"UTF-8",
|
||||
new Array("ja_parallel_state_machine",
|
||||
"zhtw_parallel_state_machine",
|
||||
"zhcn_parallel_state_machine",
|
||||
"zh_parallel_state_machine",
|
||||
"cjk_parallel_state_machine",
|
||||
"universal_charset_detector"));
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
|
|
Загрузка…
Ссылка в новой задаче