toolkit/components/microformats/tests/test_Microformats_geo.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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">
    12     <span class="geo" id="01-geo-basic">
    13       <span class="latitude">37.77</span>
    14       <span class="longitude">-122.411</span>
    15     </span>
    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>
    23     <abbr class="geo" id="01-geo-abbr" title="30.267991;-97.739568">Paradise</abbr>
    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>
    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>
    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>
    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>
    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>
    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>
    78 </div>
    79 <pre id="test">
    80 <script class="testbody" type="text/javascript">
    82 test_Microformats();
    83 test_geo();
    85 function test_Microformats() {
    86   var Microformats = SpecialPowers.Cu.import("resource://gre/modules/Microformats.js").Microformats;
    88   ok(Microformats, "Check global access to Microformats");
    89 };
    91 function test_geo() {
    92   var geo = SpecialPowers.Cu.import("resource://gre/modules/Microformats.js").geo;
    94   var Geo;
    96   Geo = new geo(document.getElementById("01-geo-basic"));
    98   is(Geo.latitude, "37.77", "01-geo-basic - latitude");
    99   is(Geo.longitude, "-122.411", "01-geo-basic - longitude");
   101   Geo = new geo(document.getElementById("01-geo-abbr-latlong"));
   103   is(Geo.latitude, "37.77", "02-geo-abbr-latlong - latitude");
   104   is(Geo.longitude, "-122.41", "02-geo-abbr-latlong - longitude");
   106   Geo = new geo(document.getElementById("01-geo-abbr"));
   108   is(Geo.latitude, "30.267991", "01-geo-abbr - latitude");
   109   is(Geo.longitude, "-97.739568", "01-geo-abbr - longitude");
   111   Geo = new geo(document.getElementById("02-geo-vcard-01"));
   113   is(Geo.toString(), "John Doe", "02-geo-vcard-01");
   115   Geo = new geo(document.getElementById("02-geo-vcard-02"));
   117   is(Geo.toString(), "Northern California", "02-geo-vcard-02");
   119   Geo = new geo(document.getElementById("02-geo-vevent-01"));
   121   is(Geo.toString(), "SXSW Interactive (South by Southwest)", "02-geo-vevent-01");
   123   Geo = new geo(document.getElementById("02-geo-vevent-02"));
   125   is(Geo.toString(), "Convention Center", "02-geo-vevent-02");
   127   Geo = new geo(document.getElementById("legal_geo1"));
   129   is(Geo.latitude, 0, "legal_geo1 - lat");
   130   is(Geo.longitude, 0, "legal_geo1 - long");
   132   Geo = new geo(document.getElementById("legal_geo2"));
   134   is(Geo.latitude, 0, "legal_geo2 - lat");
   135   is(Geo.longitude, 0, "legal_geo2 - long");
   137   Geo = new geo(document.getElementById("legal_geo3"));
   139   is(Geo.latitude, 0, "legal_geo3 - lat");
   140   is(Geo.longitude, 0, "legal_geo3 - long");
   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 }
   215 </script>
   216 </pre>
   217 </body>
   218 </html>

mercurial