68 lines
2.1 KiB
HTML
68 lines
2.1 KiB
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=368998
|
|
-->
|
|
<head>
|
|
<title>Test for Bug 368998</title>
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.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=368998">Mozilla Bug 368998</a>
|
|
<p id="display"></p>
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
<pre id="test">
|
|
<script class="testbody" type="text/javascript">
|
|
<![CDATA[
|
|
|
|
/** Test for Bug 368998 - hostname canonicalization **/
|
|
|
|
// test charmap
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
var Cc = Components.classes;
|
|
var Ci = Components.interfaces;
|
|
var table = Cc["@mozilla.org/url-classifier/table;1?type=url"].createInstance();
|
|
var componentScope = table.wrappedJSObject.__parent__;
|
|
ok(!!componentScope, "unable to get wrapped js object");
|
|
|
|
var PROT_EnchashDecrypter = componentScope.PROT_EnchashDecrypter;
|
|
var enchash = new PROT_EnchashDecrypter();
|
|
|
|
// escapeCharmap_ should be true for non-alphanumeric, non-hyphen, and
|
|
// non-dot chars
|
|
for (var i = 0; i < 256; ++i) {
|
|
var chr = String.fromCharCode(i);
|
|
if ( (chr.toLowerCase() >= 'a' && chr.toLowerCase() <= 'z') ||
|
|
(chr >= '0' && chr <= '9') ||
|
|
'.' == chr || '-' == chr) {
|
|
ok(!enchash.escapeCharmap_.contains(chr), 'failed on ' + i);
|
|
} else {
|
|
ok(enchash.escapeCharmap_.contains(chr), 'failed on ' + i);
|
|
}
|
|
}
|
|
|
|
// Test canonicalizeHost
|
|
var tests = {
|
|
'http://www.mozilla.org/foo': 'www.mozilla.org',
|
|
'http://,=.mozilla.org/foo': '%2c%3d.mozilla.org',
|
|
'http://f00.b4r.mozi=lla.org/': 'f00.b4r.mozi%3dlla.org',
|
|
'http://a-_b.mozilla.org/': 'a-%5fb.mozilla.org',
|
|
'http://z%38bl%61h%%2F.com/': 'z8blah%25%2f.com',
|
|
'http://moZilla.Org/': 'mozilla.org'
|
|
}
|
|
|
|
for (var url in tests) {
|
|
ok(enchash.getCanonicalHost(url) == tests[url],
|
|
'expected ' + tests[url] + ' but got ' + enchash.getCanonicalHost(url));
|
|
}
|
|
|
|
]]>
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|
|
|