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

172 lines
6.7 KiB
HTML

<html>
<head>
<title>Testing Microformats.js</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="/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">
<div id="test_1">
<div class="vcard" id="vcard1_node">
<a class="url fn" href="http://tantek.com/">Tantek Çelik</a>
<div id="vcard1_org" class="org">Technorati</div>
</div>
<div class="vcard" id="vcard2_node">
<a class="url" href="http://tantek.com/">Tantek Çelik</a>
<div id="vcard2_org" class="org">Technorati</div>
</div>
</div>
<div class="vcard" id="outer_vcard">
<div class="vcard" id="middle_vcard">
<div class="vcard" id="inner_vcard">
<span class="fn">Inner User</span>
</div>
<span class="fn">Middle User</span>
</div>
<span class="fn">Outer User</span>
</div>
<div class="vcard" id="outer_vcard2">
<div class="vevent" id="middle_vevent2">
<div class="vcard" id="inner_vcard2">
<span class="fn">Inner User</span>
</div>
<span class="summary">Middle Event</span>
</div>
<span class="fn">Outer User</span>
</div>
<div class="vevent" id="outer_vevent3">
<div class="vcard" id="middle_vcard3">
<div class="vevent" id="inner_vevent3">
<span class="summary">Inner Event</span>
</div>
<span class="fn">Middle User</span>
</div>
<span class="summary">Outer Event</span>
</div>
<div class="vevent" id="outer_vevent4">
<a rel="tag" id="inner_tag4" href="http://www.example.com/inner_tag">
Inner tag
</a>
<span class="summary">Outer Event</span>
</div>
<a rel="tag" id="outer_tag5" href="http://www.example.com/outer_tag">
<div class="vevent" id="inner_vevent5">
<span class="summary">Inner Event</span>
</div>
</a>
<div class="vcard" id="value_test">
<span class="fn">
<span class="value">John</span>
<span><span class="value">Middle</span></span>
<span class="value">Doe</span>
</span>
</span>
<div class="vcard" id="nested_vcard1">
<div class="agent vcard" id="nested_vcard2">
<div class="agent vcard" id="nested_vcard3">
<span class="fn">Bob Smith</span>
<span class="title">Office Assistant</span>
</div>
<span class="fn">Jack Jones</span>
<span class="title">Executive Assistant</span>
</div>
<span class="fn">John Doe</span>
<span class="title">CEO</span>
</div>
<div class="vevent" id="date_vcal">
<span class="description">Mozilla's Birthday</span>
<span class="dtstart">1998-01-22</span>
</div>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
test_Microformats();
test_hCard();
function test_Microformats() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
Components.utils.import("resource://gre/modules/Microformats.js");
ok(Microformats, "Check global access to Microformats");
var hCards = Microformats.get("hCard", document.getElementById("test_1"), {showHidden: true});
is(hCards.length, 1, "Check Microformats.get");
is(Microformats.count("hCard", document.getElementById("test_1"), {showHidden: true}), 1, "Check Microformats.count");
is(Microformats.count("hCard", document.getElementById("test_1"), {showHidden: true, debug: true}), 2, "Check Microformats.count (debug)");
ok(Microformats.isMicroformat(document.getElementById("vcard1_node")), "Check isMicroformat");
is(Microformats.getParent(document.getElementById("vcard1_org")), document.getElementById("vcard1_node"), "Check getParent");
is(Microformats.getNamesFromNode(document.getElementById("vcard1_node")), "hCard", "Check getNamesFromNode");
var hCardArray1 = Microformats.get("hCard", document.getElementById("test_1"), {showHidden: true});
is(hCardArray1.length, 1, "Check showHidden=true");
var hCardArray2 = Microformats.get("hCard", document.getElementById("test_1"), {showHidden: false});
is(hCardArray2.length, 0, "Check showHidden=false");
var inner_parent = Microformats.getParent(document.getElementById("inner_vcard"));
is(inner_parent.id, "middle_vcard", "GetParent gets correct ancestor 1");
var inner_parent = Microformats.getParent(document.getElementById("inner_vcard2"));
is(inner_parent.id, "middle_vevent2", "GetParent gets correct ancestor 2");
var inner_parent = Microformats.getParent(document.getElementById("middle_vevent2"));
is(inner_parent.id, "outer_vcard2", "GetParent gets correct ancestor 2a");
var inner_parent = Microformats.getParent(document.getElementById("inner_vevent3"));
is(inner_parent.id, "middle_vcard3", "GetParent gets correct ancestor 3");
var inner_parent = Microformats.getParent(document.getElementById("middle_vcard3"));
is(inner_parent.id, "outer_vevent3", "GetParent gets correct ancestor 3a");
var inner_parent = Microformats.getParent(document.getElementById("inner_tag4"));
is(inner_parent.id, "outer_vevent4", "GetParent gets correct ancestor 4");
var inner_parent = Microformats.getParent(document.getElementById("inner_vevent5"));
is(inner_parent.id, "outer_tag5", "GetParent gets correct ancestor 5");
var valueCard = new hCard(document.getElementById("value_test"));
is(valueCard.fn, "JohnDoe", "value_test");
var nestCard1 = new hCard(document.getElementById("nested_vcard1"));
var nestCard2 = new hCard(document.getElementById("nested_vcard2"));
var nestCard3 = new hCard(document.getElementById("nested_vcard3"));
is(nestCard1.fn, "John Doe", "nesting (fn) 1");
is(nestCard1.title, "CEO", "nesting (title) 1");
is(nestCard2.fn, "Jack Jones", "nesting (fn) 2");
is(nestCard2.title, "Executive Assistant", "nesting (title) 2");
is(nestCard3.fn, "Bob Smith", "nesting (fn) 3");
is(nestCard3.title, "Office Assistant", "nesting (title) 3");
is(nestCard1.agent[0].agent[0].fn, "Bob Smith", "nesting all");
var dateCal = new hCalendar(document.getElementById("date_vcal"));
jsdate = Microformats.dateFromISO8601(dateCal.dtstart);
origdate = Microformats.iso8601FromDate(jsdate, true);
is(dateCal.dtstart, origdate, "date round trip");
}
function test_hCard() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
Components.utils.import("resource://gre/modules/Microformats.js");
var hCards = Microformats.get("hCard", document.getElementById("test_1"), {showHidden: true});
is(hCards[0].fn, "Tantek Çelik", "Check for fn on test vcard");
is(hCards[0].url, "http://tantek.com/", "Check for url on test vcard");
}
</script>
</pre>
</body>
</html>