toolkit/components/microformats/tests/test_Microformats.html

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 <html>
michael@0 2 <head>
michael@0 3 <title>Testing Microformats.js</title>
michael@0 4 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"></link>
michael@0 7 <style type="text/css">
michael@0 8 /*vcards weee! */
michael@0 9 .floated div {
michael@0 10 float:left;
michael@0 11 }
michael@0 12 </style>
michael@0 13
michael@0 14 </head>
michael@0 15 <body>
michael@0 16 <div id="content" style="display: none">
michael@0 17 <div id="test_1">
michael@0 18 <div class="vcard" id="vcard1_node">
michael@0 19 <a class="url fn" href="http://tantek.com/">Tantek Çelik</a>
michael@0 20 <div id="vcard1_org" class="org">Technorati</div>
michael@0 21 </div>
michael@0 22 <div class="vcard" id="vcard2_node">
michael@0 23 <a class="url" href="http://tantek.com/">Tantek Çelik</a>
michael@0 24 <div id="vcard2_org" class="org">Technorati</div>
michael@0 25 </div>
michael@0 26 </div>
michael@0 27 <div class="vcard" id="outer_vcard">
michael@0 28 <div class="vcard" id="middle_vcard">
michael@0 29 <div class="vcard" id="inner_vcard">
michael@0 30 <span class="fn">Inner User</span>
michael@0 31 </div>
michael@0 32 <span class="fn">Middle User</span>
michael@0 33 </div>
michael@0 34 <span class="fn">Outer User</span>
michael@0 35 </div>
michael@0 36 <div class="vcard" id="outer_vcard2">
michael@0 37 <div class="vevent" id="middle_vevent2">
michael@0 38 <div class="vcard" id="inner_vcard2">
michael@0 39 <span class="fn">Inner User</span>
michael@0 40 </div>
michael@0 41 <span class="summary">Middle Event</span>
michael@0 42 </div>
michael@0 43 <span class="fn">Outer User</span>
michael@0 44 </div>
michael@0 45 <div class="vevent" id="outer_vevent3">
michael@0 46 <div class="vcard" id="middle_vcard3">
michael@0 47 <div class="vevent" id="inner_vevent3">
michael@0 48 <span class="summary">Inner Event</span>
michael@0 49 </div>
michael@0 50 <span class="fn">Middle User</span>
michael@0 51 </div>
michael@0 52 <span class="summary">Outer Event</span>
michael@0 53 </div>
michael@0 54
michael@0 55 <div class="vevent" id="outer_vevent4">
michael@0 56 <a rel="tag" id="inner_tag4" href="http://www.example.com/inner_tag">
michael@0 57 Inner tag
michael@0 58 </a>
michael@0 59 <span class="summary">Outer Event</span>
michael@0 60 </div>
michael@0 61
michael@0 62 <a rel="tag" id="outer_tag5" href="http://www.example.com/outer_tag">
michael@0 63 <div class="vevent" id="inner_vevent5">
michael@0 64 <span class="summary">Inner Event</span>
michael@0 65 </div>
michael@0 66 </a>
michael@0 67
michael@0 68 <div class="vcard" id="value_test">
michael@0 69 <span class="fn">
michael@0 70 <span class="value">John</span>
michael@0 71 <span><span class="value">Middle</span></span>
michael@0 72 <span class="value">Doe</span>
michael@0 73 </span>
michael@0 74 </div>
michael@0 75
michael@0 76 <div class="vcard" id="nested_vcard1">
michael@0 77 <div class="agent vcard" id="nested_vcard2">
michael@0 78 <div class="agent vcard" id="nested_vcard3">
michael@0 79 <span class="fn">Bob Smith</span>
michael@0 80 <span class="title">Office Assistant</span>
michael@0 81 </div>
michael@0 82 <span class="fn">Jack Jones</span>
michael@0 83 <span class="title">Executive Assistant</span>
michael@0 84 </div>
michael@0 85 <span class="fn">John Doe</span>
michael@0 86 <span class="title">CEO</span>
michael@0 87 </div>
michael@0 88
michael@0 89 <div class="vevent" id="date_vcal">
michael@0 90 <span class="description">Mozilla's Birthday</span>
michael@0 91 <span class="dtstart">1998-01-22</span>
michael@0 92 </div>
michael@0 93
michael@0 94 <div class="vevent" id="vcal_vcard">
michael@0 95 <div class="vcard">
michael@0 96 <span class="description">
michael@0 97 <span class="fn org">Mozilla</span>'s Birthday
michael@0 98 </span>
michael@0 99 </div>
michael@0 100 <span class="dtstart">1998-01-22</span>
michael@0 101 </div>
michael@0 102
michael@0 103 <div id="geo_vcard" class="vcard">
michael@0 104 <span class="fn">John Doe</span>
michael@0 105 <span class="geo" id="ill_geo5">abc;def</span>
michael@0 106 </div>
michael@0 107 <div id="loc_vevent" class="vevent">
michael@0 108 <span class="summary">Party</span>
michael@0 109 <span class="location">The White House</span>
michael@0 110 </div>
michael@0 111 <div id="loc_vcard_vevent" class="vevent">
michael@0 112 <span class="summary">Party</span>
michael@0 113 <span class="location vcard"><span class="fn">The White House</span></span>
michael@0 114 </div>
michael@0 115
michael@0 116 <div class="vcard" id="valuespace_1">
michael@0 117 <span class="fn">
michael@0 118 <span class="value">John</span>
michael@0 119 <span class="value"> </span>
michael@0 120 <span class="value">Doe</span>
michael@0 121 </span>
michael@0 122 </div>
michael@0 123 <div class="vcard" id="valuespace_2">
michael@0 124 <span class="fn">
michael@0 125 <span class="value">John</span>
michael@0 126 <span class="value"> </span>
michael@0 127 <span class="value">Doe</span>
michael@0 128 </span>
michael@0 129 </div>
michael@0 130 <div class="vcard" id="valuespace_3">
michael@0 131 <span class="fn">
michael@0 132 <span class="value"> John</span>
michael@0 133 <span class="value"> </span>
michael@0 134 <span class="value">Doe </span>
michael@0 135 </span>
michael@0 136 </div>
michael@0 137 <div class="vcard" id="valuespace_4">
michael@0 138 <span class="fn">
michael@0 139 <span class="value">John </span>
michael@0 140 <span class="value"> Doe</span>
michael@0 141 </span>
michael@0 142 </div>
michael@0 143 <div class="vcard" id="valuespace_5">
michael@0 144 <span class="fn">
michael@0 145 <span class="value"> John</span>
michael@0 146 <span class="value"> Doe </span>
michael@0 147 </span>
michael@0 148 </div>
michael@0 149 <div class="vcard" id="valuespace_6">
michael@0 150 <span class="fn">
michael@0 151 <span class="value">John
michael@0 152 </span>
michael@0 153 <span class="value">
michael@0 154 Doe</span>
michael@0 155 </span>
michael@0 156 </div>
michael@0 157 <div class="vcard" id="valuespace_7">
michael@0 158 <span class="fn">
michael@0 159 <span class="value">John</span>
michael@0 160 <span class="value">Doe</span>
michael@0 161 </span>
michael@0 162 </div>
michael@0 163
michael@0 164 <span id="austin" class="location">Austin - Sixth Street</span>
michael@0 165 <table summary="Timetable">
michael@0 166 <thead>
michael@0 167 <tr>
michael@0 168 <th id="location-1"><a href="#austin" class="include"></a>New York</th>
michael@0 169 </tr>
michael@0 170 </thead>
michael@0 171 <tbody>
michael@0 172 <tr>
michael@0 173 <th id="time-1"><abbr title="2008-01-01" class="dtstart">Jan 1, 2008</abbr></th>
michael@0 174 <td id="nested_header_include" class="vevent" headers="time-1 location-1"><div class="summary">New Years Party</div></td>
michael@0 175 </tr>
michael@0 176 </tbody>
michael@0 177 </table>
michael@0 178
michael@0 179 </div>
michael@0 180
michael@0 181 <div id="float_test">
michael@0 182 <div class="vcard floated" id="one">
michael@0 183 <div class="fn">John Doe</div>
michael@0 184 </div>
michael@0 185 <div class="vcard" id="two">
michael@0 186 <div class="fn">John Smith</div>
michael@0 187 </div>
michael@0 188 </div>
michael@0 189
michael@0 190 <pre id="test">
michael@0 191 <script class="testbody" type="application/javascript;version=1.8">
michael@0 192
michael@0 193 test_Microformats();
michael@0 194 test_hCard();
michael@0 195
michael@0 196 function test_Microformats() {
michael@0 197 let { Microformats, hCard, hCalendar } = SpecialPowers.Cu.import("resource://gre/modules/Microformats.js");
michael@0 198
michael@0 199 ok(Microformats, "Check global access to Microformats");
michael@0 200 var hCards = Microformats.get("hCard", document.getElementById("test_1"), {showHidden: true});
michael@0 201 is(hCards.length, 1, "Check Microformats.get");
michael@0 202 is(Microformats.count("hCard", document.getElementById("test_1"), {showHidden: true}), 1, "Check Microformats.count");
michael@0 203 is(Microformats.count("hCard", document.getElementById("test_1"), {showHidden: true, debug: true}), 2, "Check Microformats.count (debug)");
michael@0 204 ok(Microformats.isMicroformat(document.getElementById("vcard1_node")), "Check isMicroformat");
michael@0 205 is(SpecialPowers.unwrap(Microformats.getParent(document.getElementById("vcard1_org"))), document.getElementById("vcard1_node"), "Check getParent");
michael@0 206 is(Microformats.getNamesFromNode(document.getElementById("vcard1_node")), "hCard", "Check getNamesFromNode");
michael@0 207
michael@0 208 var hCardArray1 = Microformats.get("hCard", document.getElementById("test_1"), {showHidden: true});
michael@0 209 is(hCardArray1.length, 1, "Check showHidden=true");
michael@0 210 var hCardArray2 = Microformats.get("hCard", document.getElementById("test_1"), {showHidden: false});
michael@0 211 is(hCardArray2.length, 0, "Check showHidden=false");
michael@0 212
michael@0 213 var inner_parent = Microformats.getParent(document.getElementById("inner_vcard"));
michael@0 214 is(inner_parent.id, "middle_vcard", "GetParent gets correct ancestor 1");
michael@0 215
michael@0 216 var inner_parent = Microformats.getParent(document.getElementById("inner_vcard2"));
michael@0 217 is(inner_parent.id, "middle_vevent2", "GetParent gets correct ancestor 2");
michael@0 218
michael@0 219 var inner_parent = Microformats.getParent(document.getElementById("middle_vevent2"));
michael@0 220 is(inner_parent.id, "outer_vcard2", "GetParent gets correct ancestor 2a");
michael@0 221
michael@0 222 var inner_parent = Microformats.getParent(document.getElementById("inner_vevent3"));
michael@0 223 is(inner_parent.id, "middle_vcard3", "GetParent gets correct ancestor 3");
michael@0 224
michael@0 225 var inner_parent = Microformats.getParent(document.getElementById("middle_vcard3"));
michael@0 226 is(inner_parent.id, "outer_vevent3", "GetParent gets correct ancestor 3a");
michael@0 227
michael@0 228 var inner_parent = Microformats.getParent(document.getElementById("inner_tag4"));
michael@0 229 is(inner_parent.id, "outer_vevent4", "GetParent gets correct ancestor 4");
michael@0 230
michael@0 231 var inner_parent = Microformats.getParent(document.getElementById("inner_vevent5"));
michael@0 232 is(inner_parent.id, "outer_tag5", "GetParent gets correct ancestor 5");
michael@0 233
michael@0 234 var valueCard = new hCard(document.getElementById("value_test"));
michael@0 235
michael@0 236 is(valueCard.fn, "JohnDoe", "value_test");
michael@0 237
michael@0 238 var nestCard1 = new hCard(document.getElementById("nested_vcard1"));
michael@0 239 var nestCard2 = new hCard(document.getElementById("nested_vcard2"));
michael@0 240 var nestCard3 = new hCard(document.getElementById("nested_vcard3"));
michael@0 241
michael@0 242 is(nestCard1.fn, "John Doe", "nesting (fn) 1");
michael@0 243 is(nestCard1.title, "CEO", "nesting (title) 1");
michael@0 244 is(nestCard2.fn, "Jack Jones", "nesting (fn) 2");
michael@0 245 is(nestCard2.title, "Executive Assistant", "nesting (title) 2");
michael@0 246 is(nestCard3.fn, "Bob Smith", "nesting (fn) 3");
michael@0 247 is(nestCard3.title, "Office Assistant", "nesting (title) 3");
michael@0 248 is(nestCard1.agent[0].agent[0].fn, "Bob Smith", "nesting all");
michael@0 249
michael@0 250 var dateCal = new hCalendar(document.getElementById("date_vcal"));
michael@0 251 jsdate = Microformats.dateFromISO8601(dateCal.dtstart);
michael@0 252 origdate = Microformats.iso8601FromDate(jsdate, true);
michael@0 253 is(dateCal.dtstart, origdate, "date round trip");
michael@0 254
michael@0 255 var dateCal = new hCalendar(document.getElementById("vcal_vcard"));
michael@0 256 is(dateCal.description, "Mozilla's Birthday", "vcard in vcal");
michael@0 257
michael@0 258 is(Microformats.count("hCard", document.getElementById("float_test")), 2, "Check Microformats.count for floated div");
michael@0 259
michael@0 260 var hcard = new hCard(document.getElementById("geo_vcard"));
michael@0 261 ok(!hcard.geo, "Check if invalid geo does not exist");
michael@0 262 var hcal = new hCalendar(document.getElementById("loc_vevent"));
michael@0 263 is(hcal.location, "The White House", "Check if non vcard location works");
michael@0 264 var hcal = new hCalendar(document.getElementById("loc_vcard_vevent"));
michael@0 265 is(hcal.location.fn, "The White House", "Check if vcard location works");
michael@0 266
michael@0 267 var nestedCal = new hCalendar(document.getElementById("nested_header_include"));
michael@0 268 is(nestedCal.dtstart, "2008-01-01", "nested_header_include - dtstart");
michael@0 269 is(nestedCal.location, "Austin - Sixth Street", "nested_header_include - location");
michael@0 270 is(nestedCal.summary, "New Years Party", "nested_header_include - summary");
michael@0 271
michael@0 272 var valueCard = new hCard(document.getElementById("valuespace_1"));
michael@0 273 is(valueCard.fn, "John Doe", "valuespace_1");
michael@0 274 var valueCard = new hCard(document.getElementById("valuespace_2"));
michael@0 275 is(valueCard.fn, "John Doe", "valuespace_2");
michael@0 276 var valueCard = new hCard(document.getElementById("valuespace_3"));
michael@0 277 is(valueCard.fn, "John Doe", "valuespace_3");
michael@0 278 var valueCard = new hCard(document.getElementById("valuespace_4"));
michael@0 279 is(valueCard.fn, "John Doe", "valuespace_4");
michael@0 280 var valueCard = new hCard(document.getElementById("valuespace_5"));
michael@0 281 is(valueCard.fn, "John Doe", "valuespace_5");
michael@0 282 var valueCard = new hCard(document.getElementById("valuespace_6"));
michael@0 283 is(valueCard.fn, "John Doe", "valuespace_6");
michael@0 284 var valueCard = new hCard(document.getElementById("valuespace_7"));
michael@0 285 is(valueCard.fn, "JohnDoe", "valuespace_7");
michael@0 286
michael@0 287 }
michael@0 288
michael@0 289 function test_hCard() {
michael@0 290 var Microformats = SpecialPowers.Cu.import("resource://gre/modules/Microformats.js").Microformats;
michael@0 291
michael@0 292 var hCards = Microformats.get("hCard", document.getElementById("test_1"), {showHidden: true});
michael@0 293
michael@0 294 is(hCards[0].fn, "Tantek Çelik", "Check for fn on test vcard");
michael@0 295 is(hCards[0].url, "http://tantek.com/", "Check for url on test vcard");
michael@0 296 }
michael@0 297
michael@0 298 </script>
michael@0 299 </pre>
michael@0 300 </body>
michael@0 301 </html>

mercurial