|
1 <html> |
|
2 <head> |
|
3 <title>Testing Mixed Up Microformat APIs</title> |
|
4 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
5 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"></link> |
|
7 </head> |
|
8 <body id="contentbody"> |
|
9 <!-- hCard --> |
|
10 <p class="vcard" id="23-abbr-title-everything"> |
|
11 <!-- perhaps the most annoying test ever --> |
|
12 <abbr class="fn" title="John Doe">foo</abbr> |
|
13 <span class="n"> |
|
14 <abbr class="honorific-prefix" title="Mister">Mr.</abbr> |
|
15 <abbr class="given-name" title="Jonathan">John</abbr> |
|
16 <abbr class="additional-name" title="John">J</abbr> |
|
17 <abbr class="family-name" title="Doe-Smith">Doe</abbr> |
|
18 <abbr class="honorific-suffix" title="Medical Doctor">M.D</abbr> |
|
19 </span> |
|
20 <abbr class="nickname" title="JJ">jj</abbr> |
|
21 <abbr class="bday" title="2006-04-04">April 4, 2006</abbr> |
|
22 <span class="adr"> |
|
23 <abbr class="post-office-box" title="Box 1234">B. 1234</abbr> |
|
24 <abbr class="extended-address" title="Suite 100">Ste. 100</abbr> |
|
25 <abbr class="street-address" title="123 Fake Street">123 Fake St.</abbr> |
|
26 <abbr class="locality" title="San Francisco">San Fran</abbr> |
|
27 <abbr class="region" title="California">CA</abbr> |
|
28 <abbr class="postal-code" title="12345-6789">12345</abbr> |
|
29 <abbr class="country-name" title="United States of America">USA</abbr> |
|
30 <abbr class="type" title="work">workplace</abbr> |
|
31 </span> |
|
32 <abbr class="tel" title="415.555.1234">1234</abbr> |
|
33 <abbr class="tel-type-value" title="work">workplace</abbr> |
|
34 <!-- mailer --> |
|
35 <abbr class="tz" title="-0700">Pacific Time</abbr> |
|
36 <span class="geo"> |
|
37 <abbr class="latitude" title="37.77">Northern</abbr> |
|
38 <abbr class="longitude" title="-122.41">California</abbr> |
|
39 </span> |
|
40 <abbr class="title" title="President">pres.</abbr> and |
|
41 <abbr class="role" title="Chief">cat wrangler</abbr> |
|
42 <!-- <span class="agent"></span> --> |
|
43 <span class="org"> |
|
44 <abbr class="organization-name" title="Intellicorp">foo</abbr> |
|
45 <abbr class="organization-unit" title="Intelligence">bar</abbr> |
|
46 </span> |
|
47 <!-- <abbr class="category" title=""></abbr> --> |
|
48 <abbr class="note" title="this is a note">this is not a note</abbr> |
|
49 <!-- <abbr class="rev" title=""></abbr> (revision datetime) --> |
|
50 <!-- <abbr class="sort-string" title=""></abbr> --> |
|
51 <abbr class="uid" title="abcdefghijklmnopqrstuvwxyz">alpha</abbr> |
|
52 <abbr class="class" title="public">pub</abbr> |
|
53 <!-- <abbr class="key" title=""></abbr> --> |
|
54 </p> |
|
55 |
|
56 <!-- hCalendar --> |
|
57 <frameset> |
|
58 <frame id="frame1"> |
|
59 <div> |
|
60 <span class="notAMicroformat" id="notme"> |
|
61 <abbr> class="foo">I am not a microformat</abbr> |
|
62 <abbr> class="title">Foolish title, not a format</abbr> |
|
63 </span> |
|
64 </div> |
|
65 </frame> |
|
66 <frame id="frame3"> |
|
67 <span class="geo" id="02-geo-abbr-latlong" > |
|
68 <abbr class="latitude" title="75.77">Far Northern</abbr> |
|
69 <abbr class="longitude" title="-122.41">Canada</abbr> |
|
70 </span> |
|
71 <frame id="frame2"> |
|
72 <div class="vcalendar"> |
|
73 <span class="vevent" id="15-calendar-xml-lang"> |
|
74 <a class="url" href="http://www.web2con.com/"> |
|
75 <span class="summary">Web 2.0 Conference</span>: |
|
76 <abbr class="dtstart" title="2005-10-05">October 5</abbr>- |
|
77 <abbr class="dtend" title="2005-10-08">7</abbr>, |
|
78 at the <span class="location">Argent Hotel, San Francisco, CA</span> |
|
79 </a> |
|
80 </span> |
|
81 </div> |
|
82 </frame> |
|
83 </frameset> |
|
84 |
|
85 <!-- Put the test code before the iframe just to be |
|
86 extra-sure it's been evaluated before the iframe onload fires --> |
|
87 <script class="testbody" type="text/javascript"> |
|
88 // Called from the onload of the iframe |
|
89 function test_MicroformatsAPI() { |
|
90 // I'm going to try to do this without getting XPConnect priv's, make sure |
|
91 // we throw |
|
92 try { |
|
93 Components.utils.import("resource://gre/modules/Microformats.js"); |
|
94 ok(false, "Should not execute this code"); |
|
95 } catch(ex) { |
|
96 ok(true, "Expected exception"); |
|
97 } |
|
98 |
|
99 // Gonna do things the right way |
|
100 var Microformats = SpecialPowers.Cu.import("resource://gre/modules/Microformats.js").Microformats; |
|
101 |
|
102 // Test Microformat frame recursion - start with counting |
|
103 var count = Microformats.count("adr", |
|
104 document.getElementById("contentbody"), |
|
105 {recurseExternalFrames: false}, // do not recurse frames |
|
106 0); // current count |
|
107 is(count, 2, "No frame recursion, finds 2 adr's (none in frames)"); |
|
108 |
|
109 // Try it with frame recursion |
|
110 count = Microformats.count("adr", |
|
111 document.getElementById("contentbody"), |
|
112 {recurseExternalFrames: true}, |
|
113 count); |
|
114 // Should still find 2 |
|
115 is(count, 2, "Only 2 adr nodes, even when recursing frames"); |
|
116 |
|
117 // Since "recurseExternalFrames" only affects the external frames, the microformat |
|
118 // in the <frameset> will always be counted. |
|
119 count = Microformats.count("geo", |
|
120 document.getElementById("contentbody"), |
|
121 {recurseExternalFrames: false}, |
|
122 0); |
|
123 is(count, 2, "Should find two geo if we don't recurse external frames"); |
|
124 |
|
125 count = Microformats.count("geo", |
|
126 document.getElementById("contentbody"), |
|
127 {recurseExternalFrames: true}, |
|
128 0); |
|
129 is(count, 3, "Three geos,one outside, one in a frameset, and one in iframe"); |
|
130 |
|
131 count = Microformats.count("hCalendar", |
|
132 document.getElementById("contentbody"), |
|
133 {recurseExternalFrames: true}, |
|
134 0); |
|
135 is(count, 1, "One hCalendar"); |
|
136 |
|
137 count = Microformats.count("hCard", |
|
138 document.getElementById("contentbody"), |
|
139 {recurseExternalFrames: true}); |
|
140 is(count, 1, "One hCard"); |
|
141 } |
|
142 </script> |
|
143 |
|
144 <!-- Geo Fire the test from here so we know this is loaded at the outset --> |
|
145 <iframe src="geo.html" onload="test_MicroformatsAPI();"> |
|
146 </iframe> |
|
147 |
|
148 <!-- adr --> |
|
149 <div class="adr" id="01-extended-address"> |
|
150 <span class="extended-address">Park Bench</span> |
|
151 </div> |
|
152 |
|
153 </body> |
|
154 </html> |