зеркало из https://github.com/mozilla/gecko-dev.git
bug 427457 - More tests for microformat API, forgot to add the test files r=mkaply
This commit is contained in:
Родитель
582bbfbc22
Коммит
0bdef93232
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<body>
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,237 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Testing Mixed Up Microformat APIs</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 id="contentbody">
|
||||
|
||||
<!-- Parsing tests are well covered, we're going to do some data type stuff
|
||||
here -->
|
||||
<div id="test1">
|
||||
<p class="mftest" id="mftest-version1">
|
||||
<span class="title"><b>Can Really be Anything, even HTML</b></span>
|
||||
<span class="htmlval"><i>foo</i></span>
|
||||
<span class="htmlval">what about just text?</span>
|
||||
<span class="tel">011-23-45-7867-897890</span>
|
||||
<span class="uri">http://www.mozilla.org </span>
|
||||
<span class="email">mailto:joe@nowhere.org</span>
|
||||
<span class="geo">
|
||||
<span class="latitude">0.0</span>
|
||||
<span class="longitude">0.0</span>
|
||||
</span>
|
||||
<span class="date">20080401T235900</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- This one is invalid until we add the new version of the hTest MF -->
|
||||
<div id="test2">
|
||||
<span class="mftest" id="mftest-version2">
|
||||
<abbr class="title" title="<b>Can Really be Anything, even HTML</b>"/>
|
||||
<span class="uri" title="http://www.mozilla.org"/>
|
||||
<abbr class="email" title="joe@nowhere.org">joe's email</ABBR>
|
||||
<span class="geo">
|
||||
<span class="latitude">0.0</span>
|
||||
<span class="longitude">0.0"</span>
|
||||
</span>
|
||||
<!-- Throw a zulu in there! -->
|
||||
<span class="date" title="20080401T235900Z"/>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- This one is invalid in both versions (no title)-->
|
||||
<div id="test3">
|
||||
<div class="mftest">
|
||||
<abbr class="htmlval" title="what about just text?">more values</abbr>
|
||||
<span class="uri">http://foo.com</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Contains an invalid geo -->
|
||||
<div id="test4">
|
||||
<span class="mftest">
|
||||
<abbr class="title" title="<b>Can Really be Anything, even HTML</b>"/>
|
||||
<abbr class="htmlval" title="<html><body>foo</body></html>">
|
||||
An HTML document!
|
||||
</abbr>
|
||||
<abbr class="htmlval" title="what about just text?">more values</abbr>
|
||||
<span class="tel" title="011-23-45-7867-897890"/>
|
||||
<span class="uri" title="http://www.mozilla.org"/>
|
||||
<abbr class="email" title="joe@nowhere.org">joe's email</ABBR>
|
||||
<span class="geo">
|
||||
<span class="latitude">659</span>
|
||||
<span class="longitude">-362.5</span>
|
||||
</span>
|
||||
<span class="date" title="20080401T235900"/>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Contains an invalid date -->
|
||||
<div id="test5">
|
||||
<span class="mftest">
|
||||
<abbr class="title htmlval" title="another test">thehtmlvaltodoescapeme</abbr>
|
||||
<abbr class="date" title="200311T032Z">invalid date</abbr>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Ok, the test, here we go -->
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
function hTest(node, validate) {
|
||||
if (node)
|
||||
Microformats.parser.newMicroformat(this, node, "hTest", validate);
|
||||
}
|
||||
|
||||
hTest.prototype.toString = function () {
|
||||
return("This is a test");
|
||||
}
|
||||
|
||||
// Define a new microformat to add to the Microformats collection
|
||||
var hTest_definition = {
|
||||
mfObject: hTest,
|
||||
className: "mftest",
|
||||
required: ["title", "htmlval"],
|
||||
properties: {
|
||||
"title" : {},
|
||||
"htmlval" : {
|
||||
plural: true,
|
||||
datatype: "HTML"
|
||||
},
|
||||
"tel" : {
|
||||
datatype: "tel",
|
||||
},
|
||||
"uri" : {
|
||||
dataypte: "anyURI"
|
||||
},
|
||||
"email" : {
|
||||
datatype: "email"
|
||||
},
|
||||
"geo" : {
|
||||
datatype: "microformat",
|
||||
microformat: "geo"
|
||||
},
|
||||
"date" : {
|
||||
datatype: "dateTime",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Define another version of this microformat to overwrite it - this one
|
||||
// removes the requirement to have a htmlval and also removes the tel prop.
|
||||
var hTest_definition2 = {
|
||||
mfObject: hTest,
|
||||
className: "mftest",
|
||||
required: ["title"],
|
||||
properties: {
|
||||
"title" : {},
|
||||
"htmlval" : {
|
||||
plural: true,
|
||||
datatype: "HTML"
|
||||
},
|
||||
"uri" : {
|
||||
dataypte: "anyURI"
|
||||
},
|
||||
"email" : {
|
||||
datatype: "email"
|
||||
},
|
||||
"geo" : {
|
||||
datatype: "microformat",
|
||||
microformat: "geo"
|
||||
},
|
||||
"date" : {
|
||||
datatype: "dateTime",
|
||||
}
|
||||
}
|
||||
};
|
||||
test_MicroformatsAPI();
|
||||
|
||||
function doTest3_4_and5() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
ok(Microformats, "Make sure we still have a microformats object");
|
||||
|
||||
var mfs = Microformats.get("hTest",
|
||||
document.getElementById("test3"),
|
||||
{recurseExternalFrames: true});
|
||||
|
||||
is(mfs.length, 0, "Check hTest 3 is invalid");
|
||||
|
||||
mfs = Microformats.get("hTest",
|
||||
document.getElementById("test4"),
|
||||
{recurseExternalFrames: true});
|
||||
|
||||
is(mfs.length, 1, "Check hTest 4 is valid");
|
||||
// Test 4 is a valid hTest, but it's embedded Geo is invalid,
|
||||
// test that assumption
|
||||
ok(!(mfs.geo), "Ensure that the test 4 geo is reporting as invalid");
|
||||
|
||||
mfs = Microformats.get("hTest",
|
||||
document.getElementById("test5"),
|
||||
{recurseExternalFrames: true});
|
||||
is(mfs.length, 1, "Check hTest 5 is valid");
|
||||
|
||||
try {
|
||||
var jsDate = new Date(Microformats.parser.dateFromISO8601(mfs[0].date));
|
||||
ok(false, "Invalid JS Date should throw");
|
||||
} catch (ex) {
|
||||
ok(true, "Check that getting invalid jsdate throws");
|
||||
}
|
||||
}
|
||||
|
||||
function test_MicroformatsAPI() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
Components.utils.import("resource://gre/modules/Microformats.js");
|
||||
|
||||
// Make sure they aren't microformats yet
|
||||
is(Microformats.isMicroformat(document.getElementById("mftest-version1")),
|
||||
false, "Check that the mfTest microformat does not exist yet");
|
||||
|
||||
try {
|
||||
Microformats.add("hTest", hTest_definition);
|
||||
} catch (ex) {
|
||||
ok(false, "Threw while adding hTest definition 1");
|
||||
}
|
||||
|
||||
ok(Microformats.isMicroformat(document.getElementById("mftest-version1")),
|
||||
"Check that the mfTest microformat now exists");
|
||||
|
||||
var mf = Microformats.get("hTest", document.getElementById("test1"),
|
||||
{recurseExternalFrames: true});
|
||||
|
||||
is(mf.length, 1, "Check that test1 is a valid microformat");
|
||||
is(mf[0].title, "Can Really be Anything, even HTML", "Check test1 title");
|
||||
|
||||
is(mf[0].geo.latitude, 0.0, "Check test1 geo");
|
||||
|
||||
// Make sure that our test2 doesn't pass validation until we add
|
||||
// version 2 of the hTest microformat
|
||||
var mf2 = Microformats.get("hTest", document.getElementById("test2"), {});
|
||||
is(mf2.length, 0, "Check that the mfTest microformat version 2 is not a MF");
|
||||
|
||||
doTest3_4_and5(false);
|
||||
|
||||
// Ok, add the version 2 hTest
|
||||
try {
|
||||
Microformats.add("hTest", hTest_definition2);
|
||||
} catch (ex) {
|
||||
ok(false, "Threw while adding hTest definition 2");
|
||||
}
|
||||
|
||||
// The old version's microformat is still valid
|
||||
mf = Microformats.get("hTest", document.getElementById("test1"),
|
||||
{recurseExternalFrames: true});
|
||||
|
||||
ok(mf.length, 1, "Check that test1 is a valid microformat");
|
||||
|
||||
// Verify that the version 2 microformat is now also considered valid
|
||||
var mf2 = Microformats.get("hTest", document.getElementById("test2"), {});
|
||||
|
||||
ok(mf2.length, 1, "Check that the mfTest microformat version 2 is now valid");
|
||||
doTest3_4_and5(true);
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,155 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Testing Mixed Up Microformat APIs</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 id="contentbody">
|
||||
<!-- hCard -->
|
||||
<p class="vcard" id="23-abbr-title-everything">
|
||||
<!-- perhaps the most annoying test ever -->
|
||||
<abbr class="fn" title="John Doe">foo</abbr>
|
||||
<span class="n">
|
||||
<abbr class="honorific-prefix" title="Mister">Mr.</abbr>
|
||||
<abbr class="given-name" title="Jonathan">John</abbr>
|
||||
<abbr class="additional-name" title="John">J</abbr>
|
||||
<abbr class="family-name" title="Doe-Smith">Doe</abbr>
|
||||
<abbr class="honorific-suffix" title="Medical Doctor">M.D</abbr>
|
||||
</span>
|
||||
<abbr class="nickname" title="JJ">jj</abbr>
|
||||
<abbr class="bday" title="2006-04-04">April 4, 2006</abbr>
|
||||
<span class="adr">
|
||||
<abbr class="post-office-box" title="Box 1234">B. 1234</abbr>
|
||||
<abbr class="extended-address" title="Suite 100">Ste. 100</abbr>
|
||||
<abbr class="street-address" title="123 Fake Street">123 Fake St.</abbr>
|
||||
<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="type" title="work">workplace</abbr>
|
||||
</span>
|
||||
<abbr class="tel" title="415.555.1234">1234</abbr>
|
||||
<abbr class="tel-type-value" title="work">workplace</abbr>
|
||||
<!-- mailer -->
|
||||
<abbr class="tz" title="-0700">Pacific Time</abbr>
|
||||
<span class="geo">
|
||||
<abbr class="latitude" title="37.77">Northern</abbr>
|
||||
<abbr class="longitude" title="-122.41">California</abbr>
|
||||
</span>
|
||||
<abbr class="title" title="President">pres.</abbr> and
|
||||
<abbr class="role" title="Chief">cat wrangler</abbr>
|
||||
<!-- <span class="agent"></span> -->
|
||||
<span class="org">
|
||||
<abbr class="organization-name" title="Intellicorp">foo</abbr>
|
||||
<abbr class="organization-unit" title="Intelligence">bar</abbr>
|
||||
</span>
|
||||
<!-- <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> -->
|
||||
</p>
|
||||
|
||||
<!-- hCalendar -->
|
||||
<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="frame3">
|
||||
<span class="geo" id="02-geo-abbr-latlong" >
|
||||
<abbr class="latitude" title="75.77">Far Northern</abbr>
|
||||
<abbr class="longitude" title="-122.41">Canada</abbr>
|
||||
</span>
|
||||
<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="dtstart" title="2005-10-05">October 5</abbr>-
|
||||
<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>
|
||||
|
||||
<!-- Geo Fire the test from here so we know this is loaded at the outset -->
|
||||
<iframe src="geo.html" onload="test_MicroformatsAPI();">
|
||||
</iframe>
|
||||
|
||||
<!-- adr -->
|
||||
<div class="adr" id="01-extended-address">
|
||||
<span class="extended-address">Park Bench</span>
|
||||
</div>
|
||||
<!-- Ok, the test, here we go -->
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
// Called from the onload of the iframe
|
||||
function test_MicroformatsAPI() {
|
||||
// I'm going to try to do this without getting XPConnect priv's, make sure
|
||||
// we throw
|
||||
try {
|
||||
Components.utils.import("resource://gre/modules/Microformats.js");
|
||||
ok(false, "Should not execute this code");
|
||||
} catch(ex) {
|
||||
ok(true, "Expected exception");
|
||||
}
|
||||
|
||||
// Gonna do things the right way
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
Components.utils.import("resource://gre/modules/Microformats.js");
|
||||
|
||||
// Test Microformat frame recursion - start with counting
|
||||
var count = Microformats.count("adr",
|
||||
document.getElementById("contentbody"),
|
||||
{recurseExternalFrames: false}, // do not recurse frames
|
||||
0); // current count
|
||||
is(count, 2, "No frame recursion, finds 2 adr's (none in frames)");
|
||||
|
||||
// Try it with frame recursion
|
||||
count = Microformats.count("adr",
|
||||
document.getElementById("contentbody"),
|
||||
{recurseExternalFrames: true},
|
||||
count);
|
||||
// Should still find 2
|
||||
is(count, 2, "Only 2 adr nodes, even when recursing frames");
|
||||
|
||||
// Since "recurseExternalFrames" only affects the external frames, the microformat
|
||||
// in the <frameset> will always be counted.
|
||||
count = Microformats.count("geo",
|
||||
document.getElementById("contentbody"),
|
||||
{recurseExternalFrames: false},
|
||||
0);
|
||||
is(count, 2, "Should find two geo if we don't recurse external frames");
|
||||
|
||||
count = Microformats.count("geo",
|
||||
document.getElementById("contentbody"),
|
||||
{recurseExternalFrames: true},
|
||||
0);
|
||||
is(count, 3, "Three geos,one outside, one in a frameset, and one in iframe");
|
||||
|
||||
count = Microformats.count("hCalendar",
|
||||
document.getElementById("contentbody"),
|
||||
{recurseExternalFrames: true},
|
||||
0);
|
||||
is(count, 1, "One hCalendar");
|
||||
|
||||
count = Microformats.count("hCard",
|
||||
document.getElementById("contentbody"),
|
||||
{recurseExternalFrames: true});
|
||||
is(count, 1, "One hCard");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,158 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Testing Mixed Up Microformat APIs</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 id="contentbody">
|
||||
<div id="content">
|
||||
<!-- hCard -->
|
||||
<p class="vcard" id="23-abbr-title-everything">
|
||||
<!-- perhaps the most annoying test ever -->
|
||||
<abbr class="fn" title="John Doe">foo</abbr>
|
||||
<span class="n">
|
||||
<abbr class="honorific-prefix" title="Mister">Mr.</abbr>
|
||||
<abbr class="given-name" title="Jonathan">John</abbr>
|
||||
<abbr class="additional-name" title="John">J</abbr>
|
||||
<abbr class="family-name" title="Doe-Smith">Doe</abbr>
|
||||
<abbr class="honorific-suffix" title="Medical Doctor">M.D</abbr>
|
||||
</span>
|
||||
<abbr class="nickname" title="JJ">jj</abbr>
|
||||
<abbr class="bday" title="2006-04-04">April 4, 2006</abbr>
|
||||
<span class="adr">
|
||||
<abbr class="post-office-box" title="Box 1234">B. 1234</abbr>
|
||||
<abbr class="extended-address" title="Suite 100">Ste. 100</abbr>
|
||||
<abbr class="street-address" title="123 Fake Street">123 Fake St.</abbr>
|
||||
<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="type" title="work">workplace</abbr>
|
||||
</span>
|
||||
<abbr class="tel" title="415.555.1234">1234</abbr>
|
||||
<abbr class="tel-type-value" title="work">workplace</abbr>
|
||||
<!-- mailer -->
|
||||
<abbr class="tz" title="-0700">Pacific Time</abbr>
|
||||
<span class="geo">
|
||||
<abbr class="latitude" title="37.77">Northern</abbr>
|
||||
<abbr class="longitude" title="-122.41">California</abbr>
|
||||
</span>
|
||||
<abbr class="title" title="President">pres.</abbr> and
|
||||
<abbr class="role" title="Chief">cat wrangler</abbr>
|
||||
<!-- <span class="agent"></span> -->
|
||||
<span class="org">
|
||||
<abbr class="organization-name" title="Intellicorp">foo</abbr>
|
||||
<abbr class="organization-unit" title="Intelligence">bar</abbr>
|
||||
</span>
|
||||
<!-- <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> -->
|
||||
</p>
|
||||
|
||||
<!-- hCalendar -->
|
||||
<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="frame3">
|
||||
<span class="geo" id="02-geo-abbr-latlong" >
|
||||
<abbr class="latitude" title="75.77">Far Northern</abbr>
|
||||
<abbr class="longitude" title="-122.41">Canada</abbr>
|
||||
</span>
|
||||
<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="dtstart" title="2005-10-05">October 5</abbr>-
|
||||
<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 id="secondnode">
|
||||
<span>some interesting content</span>
|
||||
|
||||
<!-- Geo Fire test once we know this is loaded.-->
|
||||
<iframe src="geo.html" onload="test_MicroformatsAPI();">
|
||||
</iframe>
|
||||
|
||||
<!-- adr -->
|
||||
<div class="adr" id="01-extended-address">
|
||||
<span class="extended-address">Park Bench</span>
|
||||
</div>
|
||||
|
||||
<div class="vcalendar">
|
||||
<span class="vevent" id="16-calendar-xml-lang">
|
||||
<a class="url" href="http://www.foo.com/">
|
||||
<span class="summary">Pseudo Conference</span>:
|
||||
<abbr class="dtstart" title="2008-04-01">April 1</abbr>-
|
||||
<abbr class="dtend" title="2008-04-03">April 3</abbr>,
|
||||
at the <span class="location">Argent Hotel, San Francisco, CA</span>
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Ok, the test, here we go -->
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
// Called from onload in iframe
|
||||
function test_MicroformatsAPI() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
Components.utils.import("resource://gre/modules/Microformats.js");
|
||||
|
||||
// Test that we can get them all
|
||||
var mfs = [];
|
||||
mfs = Microformats.get("adr",
|
||||
document.getElementById("content"),
|
||||
{showHidden: true});
|
||||
|
||||
is(mfs.length, 2, "Two adr's in our array");
|
||||
|
||||
mfs = Microformats.get("geo",
|
||||
document.getElementById("content"),
|
||||
{recurseExternalFrames: true});
|
||||
is(mfs.length, 3, "Three geo's in our array");
|
||||
|
||||
mfs = Microformats.get("hCalendar",
|
||||
document.getElementById("content"),
|
||||
{recurseExternalFrames: false});
|
||||
// Should get the hCalendar whether we recurseExternalFrames or not.
|
||||
is(mfs.length, 2, "Two hCalendar returned not recursing frames");
|
||||
|
||||
mfs = Microformats.get("hCalendar",
|
||||
document.getElementById("content"),
|
||||
{recurseExternalFrames: true});
|
||||
is(mfs.length, 2, "Two hCalendars returned recursing frames");
|
||||
|
||||
mfs = Microformats.get("hCard",
|
||||
document.getElementById("content"),
|
||||
{recurseExternalFrames: true},
|
||||
mfs);
|
||||
is(mfs.length, 3, "Two hCalendars and one hCard");
|
||||
|
||||
mfs = Microformats.get("hCalendar", document.getElementById("secondnode"));
|
||||
|
||||
is(mfs[0].summary, "Pseudo Conference",
|
||||
"Make sure we get the proper hCalendar from the second level node");
|
||||
is(mfs.length, 1, "And we should only get one hCalendar not two from this node.");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,114 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Testing Mixed Up Microformat APIs</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 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>
|
|
@ -0,0 +1,66 @@
|
|||
<!-- Demonstrates that we are always counting MF's in a <frame> tag, and NEVER
|
||||
counting MF's in an <iframe> regardless of what the "frame recursion" bit
|
||||
is set to. -->
|
||||
<html>
|
||||
<head>
|
||||
<title>Testing Mixed Up Microformat APIs</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 id="contentbody">
|
||||
|
||||
<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="frame3">
|
||||
<span class="geo" id="02-geo-abbr-latlong" >
|
||||
<abbr class="latitude" title="75.77">Far Northern</abbr>
|
||||
<abbr class="longitude" title="-122.41">Canada</abbr>
|
||||
</span>
|
||||
</frame>
|
||||
<frame id="frame2">
|
||||
<div class="stuff">
|
||||
<span>Testing is Fun!</span>
|
||||
</div>
|
||||
</frame>
|
||||
</frameset>
|
||||
|
||||
<!-- Geo -->
|
||||
<iframe id="iframe" src="geo.html" onload="onLoad();">
|
||||
</iframe>
|
||||
|
||||
<!-- Ok, the test, here we go -->
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
// Start the test once the iFrame loads
|
||||
function onLoad() {
|
||||
test_MicroformatsAPI();
|
||||
}
|
||||
|
||||
function test_MicroformatsAPI() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
Components.utils.import("resource://gre/modules/Microformats.js");
|
||||
|
||||
count = Microformats.count("geo",
|
||||
document.getElementById("contentbody"),
|
||||
{recurseExternalFrames: false},
|
||||
0);
|
||||
is(count, 1, "Only one geo - we don't count external frames");
|
||||
|
||||
count = Microformats.count("geo",
|
||||
document.getElementById("contentbody"),
|
||||
{recurseExternalFrames: true});
|
||||
is(count, 2, "Two Geo's - one in frame and one in iframe");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче