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

114 lines
4.3 KiB
HTML

<html>
<head>
<title>Testing Mixed Up Microformat APIs</title>
<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 id="contentbody">
<div id="testhere">
<!-- Frames -->
<frameset>
<frame id="frame1">
<div>
<span class="notAMicroformat" id="notme">
<abbr> class="foo">I am not a microformat</abbr>
<abbr> class="title">Foolish title, not a format</abbr>
</span>
</div>
</frame>
<frame id="frame2">
<div class="vcalendar">
<span class="vevent" id="15-calendar-xml-lang">
<a class="url" href="http://www.web2con.com/">
<span class="summary">Web 2.0 Conference</span>:
<abbr class="dtend" title="2005-10-08">7</abbr>,
at the <span class="location">Argent Hotel, San Francisco, CA</span>
</a>
</span>
</div>
</frame>
</frameset>
</div>
<div id="content">
<!-- some really messed up markup-->
<p class="vcard" id="23-abbr-title-everything">
<div id="random div no ending div either">
<abbr class="fn" title="John Doe">foo</abbr>
<span class="n"/>
<abbr class="foo" title="JJ">jj</abbr>
<abbr class="free" title="2006-04-04">April 4, 2006</abbr>
<span class="adr">
<abbr class="invalid" title="Box 1234">B. 1234</abbr>
<abbr class="extended-address" title="Suite 100">Ste. 100</abbr>
<abbr class="street-address" title="123 Fake Street"/>
<abbr class="locality" title="San Francisco">San Fran</abbr>
<abbr class="region" title="California">CA</abbr>
<abbr class="postal-code" title="12345-6789">12345</abbr>
<abbr class="country-name" title="United States of America">USA</abbr>
<abbr class="typo" titl="work">workplace</abbr>
</span>
<span class="org">
<abbr class="organization-name" title="Intellicorp">foo</abbr>
<abbr class="organization-unit" title="Intelligence">bar</abbr>
<!-- <abbr class="category" title=""></abbr> -->
<abbr class="note" title="this is a note">this is not a note</abbr>
<!-- <abbr class="rev" title=""></abbr> (revision datetime) -->
<!-- <abbr class="sort-string" title=""></abbr> -->
<abbr class="uid" title="abcdefghijklmnopqrstuvwxyz">alpha</abbr>
<abbr class="class" title="public">pub</abbr>
<!-- <abbr class="key" title=""></abbr> -->
</span>
<!-- Ok, the test, here we go -->
<pre id="test">
<script class="testbody" type="text/javascript">
test_MicroformatsAPI();
function test_MicroformatsAPI() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
Components.utils.import("resource://gre/modules/Microformats.js");
// Test to see if we can get the invalid vcard
var mfs = Microformats.get("hCard",
document.getElementById("content"),
{ });
is(mfs.length, 0, "Check that we can't get invalid vcard");
// Invalid hCalendar - doesn't have a dtstart
mfs = Microformats.get("hCalendar",
document.getElementById("testhere"),
{recurseExternalFrames: true});
is(mfs.length, 0, "Check that we don't pick up invalid MFs.");
mfs = Microformats.get("notAMicroformat",
document.getElementById("testhere"),
{recurseExternalFrames: true});
is(mfs, null, "No microformat called notAMicroformat");
// What if we try another way?
is(Microformats.isMicroformat(document.getElementById("notme")), false,
"Check that the NotAMicroformat is still not a microformat");
// Attempt to physically add one to the object
try {
Microformats.push("notAMicroformat");
} catch (ex) {
ok(true, "Check thrown exception when adding to microformats object");
}
// Attempt to delete one from the object
try {
Microformats.pop();
} catch (ex) {
ok(true, "Check that exception thrown when removing items from Microformats");
}
}
</script>
</body>
</html>