toolkit/components/microformats/tests/test_Microformats_geo.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:7c6dd07628df
1 <html>
2 <head>
3 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
4 <title>Testing Microformats.js (geo)</title>
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"></link>
8 </head>
9 <body>
10 <div id="content" style="display: none">
11
12 <span class="geo" id="01-geo-basic">
13 <span class="latitude">37.77</span>
14 <span class="longitude">-122.411</span>
15 </span>
16
17
18 <span class="geo" id="01-geo-abbr-latlong" >
19 <abbr class="latitude" title="37.77">Northern</abbr>
20 <abbr class="longitude" title="-122.41">California</abbr>
21 </span>
22
23 <abbr class="geo" id="01-geo-abbr" title="30.267991;-97.739568">Paradise</abbr>
24
25 <span class="vcard">
26 <span class="fn org">John Doe</span>
27 <abbr class="geo" id="02-geo-vcard-01" title="37.77;-122.41"></abbr>
28 </span>
29
30 <span class="vcard">
31 <span class="fn org">John Doe</span>
32 <abbr class="geo" id="02-geo-vcard-02" title="37.77;-122.41">Northern California</abbr>
33 </span>
34
35 <span class="vevent">
36 <span class="summary">SXSW Interactive (South by Southwest)</span>
37 <ABBR title="20080307" class="dtstart">Friday, March 7, 2008</ABBR>
38 -
39 <ABBR title="20080311" class="dtend">Tuesday, March 11, 2008</ABBR>
40 <abbr class="geo" id="02-geo-vevent-01" title="30.2622;-97.7399"></abbr>
41 </span>
42
43 <span class="vevent">
44 <span class="summary">SXSW Interactive (South by Southwest)</span>
45 <ABBR title="20080307" class="dtstart">Friday, March 7, 2008</ABBR>
46 -
47 <ABBR title="20080311" class="dtend">Tuesday, March 11, 2008</ABBR>
48 <abbr class="geo" id="02-geo-vevent-02" title="30.2622;-97.7399">Convention Center</abbr>
49 </span>
50
51 <h3>Legal geos</h3>
52 <ul>
53 <li><span class="geo" id="legal_geo1"><span class="latitude">0</span>,<span class="longitude">0</span></span></li>
54 <li><span class="geo" id="legal_geo2"><span class="latitude">0.0</span>,<span class="longitude">0.0</span></span></li>
55 <li><span class="geo" id="legal_geo3"><span class="latitude">0.</span>,<span class="longitude">0.</span></span></li>
56 </ul>
57 <h3>Illegal geos</h3>
58
59 <ul>
60 <li><span class="geo" id="ill_geo1"><span class="latitude">abc</span>,<span class="longitude">def</span></span></li>
61 <li><span class="geo" id="ill_geo2"><span class="latitude">12.s2</span>,<span class="longitude">1d.23</span></span></li>
62 <li><span class="geo" id="ill_geo3"><span class="latitude">999.99</span>,<span class="longitude">999</span></span></li>
63 <li><span class="geo" id="ill_geo4"><span class="latitude">-181</span>,<span class="longitude">-361</span></span></li>
64 <li><span class="geo" id="ill_geo5">abc;def</span></li>
65 <li><span class="geo" id="ill_geo6">12.s2;1d.23</span></li>
66 <li><span class="geo" id="ill_geo7">999.99;999</span></li>
67 <li><span class="geo" id="ill_geo8">-181;-361</span></li>
68 <li><span class="geo" id="ill_geo9">-18;;-31</span></li>
69 <li><ABBR title="+23.70000;+90.30000" class="extra_geo">Dhaka, Bangladesh</ABBR></li>
70 <li><span class="geo" id="zero_geo">0;0</span></li>
71 </ul>
72
73
74
75
76
77
78 </div>
79 <pre id="test">
80 <script class="testbody" type="text/javascript">
81
82 test_Microformats();
83 test_geo();
84
85 function test_Microformats() {
86 var Microformats = SpecialPowers.Cu.import("resource://gre/modules/Microformats.js").Microformats;
87
88 ok(Microformats, "Check global access to Microformats");
89 };
90
91 function test_geo() {
92 var geo = SpecialPowers.Cu.import("resource://gre/modules/Microformats.js").geo;
93
94 var Geo;
95
96 Geo = new geo(document.getElementById("01-geo-basic"));
97
98 is(Geo.latitude, "37.77", "01-geo-basic - latitude");
99 is(Geo.longitude, "-122.411", "01-geo-basic - longitude");
100
101 Geo = new geo(document.getElementById("01-geo-abbr-latlong"));
102
103 is(Geo.latitude, "37.77", "02-geo-abbr-latlong - latitude");
104 is(Geo.longitude, "-122.41", "02-geo-abbr-latlong - longitude");
105
106 Geo = new geo(document.getElementById("01-geo-abbr"));
107
108 is(Geo.latitude, "30.267991", "01-geo-abbr - latitude");
109 is(Geo.longitude, "-97.739568", "01-geo-abbr - longitude");
110
111 Geo = new geo(document.getElementById("02-geo-vcard-01"));
112
113 is(Geo.toString(), "John Doe", "02-geo-vcard-01");
114
115 Geo = new geo(document.getElementById("02-geo-vcard-02"));
116
117 is(Geo.toString(), "Northern California", "02-geo-vcard-02");
118
119 Geo = new geo(document.getElementById("02-geo-vevent-01"));
120
121 is(Geo.toString(), "SXSW Interactive (South by Southwest)", "02-geo-vevent-01");
122
123 Geo = new geo(document.getElementById("02-geo-vevent-02"));
124
125 is(Geo.toString(), "Convention Center", "02-geo-vevent-02");
126
127 Geo = new geo(document.getElementById("legal_geo1"));
128
129 is(Geo.latitude, 0, "legal_geo1 - lat");
130 is(Geo.longitude, 0, "legal_geo1 - long");
131
132 Geo = new geo(document.getElementById("legal_geo2"));
133
134 is(Geo.latitude, 0, "legal_geo2 - lat");
135 is(Geo.longitude, 0, "legal_geo2 - long");
136
137 Geo = new geo(document.getElementById("legal_geo3"));
138
139 is(Geo.latitude, 0, "legal_geo3 - lat");
140 is(Geo.longitude, 0, "legal_geo3 - long");
141
142
143
144
145 try {
146 Geo = new geo(document.getElementById("ill_geo1"), true);
147 ok(0, "ill_geo1 - should have been caught as invalid geo");
148 } catch (ex) {
149 ok(1, "ill_geo1 - caught invalid geo");
150 }
151 try {
152 Geo = new geo(document.getElementById("ill_geo2"), true);
153 ok(0, "ill_geo2 - should have been caught as invalid geo");
154 } catch (ex) {
155 ok(1, "ill_geo2 - caught invalid geo");
156 }
157 try {
158 Geo = new geo(document.getElementById("ill_geo3"), true);
159 ok(0, "ill_geo3 - should have been caught as invalid geo");
160 } catch (ex) {
161 ok(1, "ill_geo3 - caught invalid geo");
162 }
163 try {
164 Geo = new geo(document.getElementById("ill_geo4"), true);
165 ok(0, "ill_geo4 - should have been caught as invalid geo");
166 } catch (ex) {
167 ok(1, "ill_geo4 - caught invalid geo");
168 }
169 try {
170 Geo = new geo(document.getElementById("ill_geo5"), true);
171 ok(0, "ill_geo5 - should have been caught as invalid geo");
172 } catch (ex) {
173 ok(1, "ill_geo5 - caught invalid geo");
174 }
175 try {
176 Geo = new geo(document.getElementById("ill_geo6"), true);
177 ok(0, "ill_geo6 - should have been caught as invalid geo");
178 } catch (ex) {
179 ok(1, "ill_geo6 - caught invalid geo");
180 }
181 try {
182 Geo = new geo(document.getElementById("ill_geo7"), true);
183 ok(0, "ill_geo7 - should have been caught as invalid geo");
184 } catch (ex) {
185 ok(1, "ill_geo7 - caught invalid geo");
186 }
187 try {
188 Geo = new geo(document.getElementById("ill_geo8"), true);
189 ok(0, "ill_geo8 - should have been caught as invalid geo");
190 } catch (ex) {
191 ok(1, "ill_geo8 - caught invalid geo");
192 }
193 try {
194 Geo = new geo(document.getElementById("ill_geo9"), true);
195 ok(0, "ill_geo9 - should have been caught as invalid geo");
196 } catch (ex) {
197 ok(1, "ill_geo9 - caught invalid geo");
198 }
199 try {
200 Geo = new geo(document.getElementById("zero_geo"), true);
201 ok(1, "zero_geo - creation succeeded");
202 } catch (ex) {
203 ok(0, "zero_geo - creation failed");
204 }
205 try {
206 Geo = new geo(document.getElementById("extra_geo"), true);
207 ok(1, "extra_geo - creation succeeded");
208 } catch (ex) {
209 ok(0, "extra_geo - creation failed");
210 }
211 }
212
213
214
215 </script>
216 </pre>
217 </body>
218 </html>

mercurial