gecko/toolkit/components/microformats/tests/test_Microformats_geo.html

224 lines
7.4 KiB
HTML
Raw Normal View History

<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Testing Microformats.js (geo)</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"></link>
</head>
<body>
<div id="content" style="display: none">
<span class="geo" id="01-geo-basic">
<span class="latitude">37.77</span>
<span class="longitude">-122.411</span>
</span>
<span class="geo" id="01-geo-abbr-latlong" >
<abbr class="latitude" title="37.77">Northern</abbr>
<abbr class="longitude" title="-122.41">California</abbr>
</span>
<abbr class="geo" id="01-geo-abbr" title="30.267991;-97.739568">Paradise</abbr>
<span class="vcard">
<span class="fn org">John Doe</span>
<abbr class="geo" id="02-geo-vcard-01" title="37.77;-122.41"></abbr>
</span>
<span class="vcard">
<span class="fn org">John Doe</span>
<abbr class="geo" id="02-geo-vcard-02" title="37.77;-122.41">Northern California</abbr>
</span>
<span class="vevent">
<span class="summary">SXSW Interactive (South by Southwest)</span>
<ABBR title="20080307" class="dtstart">Friday, March 7, 2008</ABBR>
-
<ABBR title="20080311" class="dtend">Tuesday, March 11, 2008</ABBR>
<abbr class="geo" id="02-geo-vevent-01" title="30.2622;-97.7399"></abbr>
</span>
<span class="vevent">
<span class="summary">SXSW Interactive (South by Southwest)</span>
<ABBR title="20080307" class="dtstart">Friday, March 7, 2008</ABBR>
-
<ABBR title="20080311" class="dtend">Tuesday, March 11, 2008</ABBR>
<abbr class="geo" id="02-geo-vevent-02" title="30.2622;-97.7399">Convention Center</abbr>
</span>
<h3>Legal geos</h3>
<ul>
<li><span class="geo" id="legal_geo1"><span class="latitude">0</span>,<span class="longitude">0</span></span></li>
<li><span class="geo" id="legal_geo2"><span class="latitude">0.0</span>,<span class="longitude">0.0</span></span></li>
<li><span class="geo" id="legal_geo3"><span class="latitude">0.</span>,<span class="longitude">0.</span></span></li>
</ul>
<h3>Illegal geos</h3>
<ul>
<li><span class="geo" id="ill_geo1"><span class="latitude">abc</span>,<span class="longitude">def</span></span></li>
<li><span class="geo" id="ill_geo2"><span class="latitude">12.s2</span>,<span class="longitude">1d.23</span></span></li>
<li><span class="geo" id="ill_geo3"><span class="latitude">999.99</span>,<span class="longitude">999</span></span></li>
<li><span class="geo" id="ill_geo4"><span class="latitude">-181</span>,<span class="longitude">-361</span></span></li>
<li><span class="geo" id="ill_geo5">abc;def</span></li>
<li><span class="geo" id="ill_geo6">12.s2;1d.23</span></li>
<li><span class="geo" id="ill_geo7">999.99;999</span></li>
<li><span class="geo" id="ill_geo8">-181;-361</span></li>
<li><span class="geo" id="ill_geo9">-18;;-31</span></li>
<li><ABBR title="+23.70000;+90.30000" class="extra_geo">Dhaka, Bangladesh</ABBR></li>
<li><span class="geo" id="zero_geo">0;0</span></li>
</ul>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
test_Microformats();
test_geo();
function test_Microformats() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
Components.utils.import("resource://gre/modules/Microformats.js");
ok(Microformats, "Check global access to Microformats");
};
function test_geo() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
Components.utils.import("resource://gre/modules/Microformats.js");
var Geo;
Geo = new geo(document.getElementById("01-geo-basic"));
is(Geo.latitude, "37.77", "01-geo-basic - latitude");
is(Geo.longitude, "-122.411", "01-geo-basic - longitude");
Geo = new geo(document.getElementById("01-geo-abbr-latlong"));
is(Geo.latitude, "37.77", "02-geo-abbr-latlong - latitude");
is(Geo.longitude, "-122.41", "02-geo-abbr-latlong - longitude");
Geo = new geo(document.getElementById("01-geo-abbr"));
is(Geo.latitude, "30.267991", "01-geo-abbr - latitude");
is(Geo.longitude, "-97.739568", "01-geo-abbr - longitude");
Geo = new geo(document.getElementById("02-geo-vcard-01"));
is(Geo.toString(), "John Doe", "02-geo-vcard-01");
Geo = new geo(document.getElementById("02-geo-vcard-02"));
is(Geo.toString(), "Northern California", "02-geo-vcard-02");
Geo = new geo(document.getElementById("02-geo-vevent-01"));
is(Geo.toString(), "SXSW Interactive (South by Southwest)", "02-geo-vevent-01");
Geo = new geo(document.getElementById("02-geo-vevent-02"));
is(Geo.toString(), "Convention Center", "02-geo-vevent-02");
Geo = new geo(document.getElementById("legal_geo1"));
is(Geo.latitude, 0, "legal_geo1 - lat");
is(Geo.longitude, 0, "legal_geo1 - long");
Geo = new geo(document.getElementById("legal_geo2"));
is(Geo.latitude, 0, "legal_geo2 - lat");
is(Geo.longitude, 0, "legal_geo2 - long");
Geo = new geo(document.getElementById("legal_geo3"));
is(Geo.latitude, 0, "legal_geo3 - lat");
is(Geo.longitude, 0, "legal_geo3 - long");
try {
Geo = new geo(document.getElementById("ill_geo1"), true);
ok(0, "ill_geo1 - should have been caught as invalid geo");
} catch (ex) {
ok(1, "ill_geo1 - caught invalid geo");
}
try {
Geo = new geo(document.getElementById("ill_geo2"), true);
ok(0, "ill_geo2 - should have been caught as invalid geo");
} catch (ex) {
ok(1, "ill_geo2 - caught invalid geo");
}
try {
Geo = new geo(document.getElementById("ill_geo3"), true);
ok(0, "ill_geo3 - should have been caught as invalid geo");
} catch (ex) {
ok(1, "ill_geo3 - caught invalid geo");
}
try {
Geo = new geo(document.getElementById("ill_geo4"), true);
ok(0, "ill_geo4 - should have been caught as invalid geo");
} catch (ex) {
ok(1, "ill_geo4 - caught invalid geo");
}
try {
Geo = new geo(document.getElementById("ill_geo5"), true);
ok(0, "ill_geo5 - should have been caught as invalid geo");
} catch (ex) {
ok(1, "ill_geo5 - caught invalid geo");
}
try {
Geo = new geo(document.getElementById("ill_geo6"), true);
ok(0, "ill_geo6 - should have been caught as invalid geo");
} catch (ex) {
ok(1, "ill_geo6 - caught invalid geo");
}
try {
Geo = new geo(document.getElementById("ill_geo7"), true);
ok(0, "ill_geo7 - should have been caught as invalid geo");
} catch (ex) {
ok(1, "ill_geo7 - caught invalid geo");
}
try {
Geo = new geo(document.getElementById("ill_geo8"), true);
ok(0, "ill_geo8 - should have been caught as invalid geo");
} catch (ex) {
ok(1, "ill_geo8 - caught invalid geo");
}
try {
Geo = new geo(document.getElementById("ill_geo9"), true);
ok(0, "ill_geo9 - should have been caught as invalid geo");
} catch (ex) {
ok(1, "ill_geo9 - caught invalid geo");
}
try {
Geo = new geo(document.getElementById("zero_geo"), true);
ok(1, "zero_geo - creation succeeded");
} catch (ex) {
ok(0, "zero_geo - creation failed");
}
try {
Geo = new geo(document.getElementById("extra_geo"), true);
ok(1, "extra_geo - creation succeeded");
} catch (ex) {
ok(0, "extra_geo - creation failed");
}
}
</script>
</pre>
</body>
</html>