1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/microformats/tests/test_Microformats_count.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,154 @@ 1.4 +<html> 1.5 +<head> 1.6 + <title>Testing Mixed Up Microformat APIs</title> 1.7 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.9 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"></link> 1.10 +</head> 1.11 +<body id="contentbody"> 1.12 + <!-- hCard --> 1.13 + <p class="vcard" id="23-abbr-title-everything"> 1.14 +<!-- perhaps the most annoying test ever --> 1.15 + <abbr class="fn" title="John Doe">foo</abbr> 1.16 + <span class="n"> 1.17 + <abbr class="honorific-prefix" title="Mister">Mr.</abbr> 1.18 + <abbr class="given-name" title="Jonathan">John</abbr> 1.19 + <abbr class="additional-name" title="John">J</abbr> 1.20 + <abbr class="family-name" title="Doe-Smith">Doe</abbr> 1.21 + <abbr class="honorific-suffix" title="Medical Doctor">M.D</abbr> 1.22 + </span> 1.23 + <abbr class="nickname" title="JJ">jj</abbr> 1.24 + <abbr class="bday" title="2006-04-04">April 4, 2006</abbr> 1.25 + <span class="adr"> 1.26 + <abbr class="post-office-box" title="Box 1234">B. 1234</abbr> 1.27 + <abbr class="extended-address" title="Suite 100">Ste. 100</abbr> 1.28 + <abbr class="street-address" title="123 Fake Street">123 Fake St.</abbr> 1.29 + <abbr class="locality" title="San Francisco">San Fran</abbr> 1.30 + <abbr class="region" title="California">CA</abbr> 1.31 + <abbr class="postal-code" title="12345-6789">12345</abbr> 1.32 + <abbr class="country-name" title="United States of America">USA</abbr> 1.33 + <abbr class="type" title="work">workplace</abbr> 1.34 + </span> 1.35 + <abbr class="tel" title="415.555.1234">1234</abbr> 1.36 + <abbr class="tel-type-value" title="work">workplace</abbr> 1.37 +<!-- mailer --> 1.38 + <abbr class="tz" title="-0700">Pacific Time</abbr> 1.39 + <span class="geo"> 1.40 + <abbr class="latitude" title="37.77">Northern</abbr> 1.41 + <abbr class="longitude" title="-122.41">California</abbr> 1.42 + </span> 1.43 + <abbr class="title" title="President">pres.</abbr> and 1.44 + <abbr class="role" title="Chief">cat wrangler</abbr> 1.45 +<!-- <span class="agent"></span> --> 1.46 + <span class="org"> 1.47 + <abbr class="organization-name" title="Intellicorp">foo</abbr> 1.48 + <abbr class="organization-unit" title="Intelligence">bar</abbr> 1.49 + </span> 1.50 +<!-- <abbr class="category" title=""></abbr> --> 1.51 + <abbr class="note" title="this is a note">this is not a note</abbr> 1.52 +<!-- <abbr class="rev" title=""></abbr> (revision datetime) --> 1.53 +<!-- <abbr class="sort-string" title=""></abbr> --> 1.54 + <abbr class="uid" title="abcdefghijklmnopqrstuvwxyz">alpha</abbr> 1.55 + <abbr class="class" title="public">pub</abbr> 1.56 +<!-- <abbr class="key" title=""></abbr> --> 1.57 + </p> 1.58 + 1.59 + <!-- hCalendar --> 1.60 + <frameset> 1.61 + <frame id="frame1"> 1.62 + <div> 1.63 + <span class="notAMicroformat" id="notme"> 1.64 + <abbr> class="foo">I am not a microformat</abbr> 1.65 + <abbr> class="title">Foolish title, not a format</abbr> 1.66 + </span> 1.67 + </div> 1.68 + </frame> 1.69 + <frame id="frame3"> 1.70 + <span class="geo" id="02-geo-abbr-latlong" > 1.71 + <abbr class="latitude" title="75.77">Far Northern</abbr> 1.72 + <abbr class="longitude" title="-122.41">Canada</abbr> 1.73 + </span> 1.74 + <frame id="frame2"> 1.75 + <div class="vcalendar"> 1.76 + <span class="vevent" id="15-calendar-xml-lang"> 1.77 + <a class="url" href="http://www.web2con.com/"> 1.78 + <span class="summary">Web 2.0 Conference</span>: 1.79 + <abbr class="dtstart" title="2005-10-05">October 5</abbr>- 1.80 + <abbr class="dtend" title="2005-10-08">7</abbr>, 1.81 + at the <span class="location">Argent Hotel, San Francisco, CA</span> 1.82 + </a> 1.83 + </span> 1.84 + </div> 1.85 + </frame> 1.86 + </frameset> 1.87 + 1.88 + <!-- Put the test code before the iframe just to be 1.89 + extra-sure it's been evaluated before the iframe onload fires --> 1.90 + <script class="testbody" type="text/javascript"> 1.91 + // Called from the onload of the iframe 1.92 + function test_MicroformatsAPI() { 1.93 + // I'm going to try to do this without getting XPConnect priv's, make sure 1.94 + // we throw 1.95 + try { 1.96 + Components.utils.import("resource://gre/modules/Microformats.js"); 1.97 + ok(false, "Should not execute this code"); 1.98 + } catch(ex) { 1.99 + ok(true, "Expected exception"); 1.100 + } 1.101 + 1.102 + // Gonna do things the right way 1.103 + var Microformats = SpecialPowers.Cu.import("resource://gre/modules/Microformats.js").Microformats; 1.104 + 1.105 + // Test Microformat frame recursion - start with counting 1.106 + var count = Microformats.count("adr", 1.107 + document.getElementById("contentbody"), 1.108 + {recurseExternalFrames: false}, // do not recurse frames 1.109 + 0); // current count 1.110 + is(count, 2, "No frame recursion, finds 2 adr's (none in frames)"); 1.111 + 1.112 + // Try it with frame recursion 1.113 + count = Microformats.count("adr", 1.114 + document.getElementById("contentbody"), 1.115 + {recurseExternalFrames: true}, 1.116 + count); 1.117 + // Should still find 2 1.118 + is(count, 2, "Only 2 adr nodes, even when recursing frames"); 1.119 + 1.120 + // Since "recurseExternalFrames" only affects the external frames, the microformat 1.121 + // in the <frameset> will always be counted. 1.122 + count = Microformats.count("geo", 1.123 + document.getElementById("contentbody"), 1.124 + {recurseExternalFrames: false}, 1.125 + 0); 1.126 + is(count, 2, "Should find two geo if we don't recurse external frames"); 1.127 + 1.128 + count = Microformats.count("geo", 1.129 + document.getElementById("contentbody"), 1.130 + {recurseExternalFrames: true}, 1.131 + 0); 1.132 + is(count, 3, "Three geos,one outside, one in a frameset, and one in iframe"); 1.133 + 1.134 + count = Microformats.count("hCalendar", 1.135 + document.getElementById("contentbody"), 1.136 + {recurseExternalFrames: true}, 1.137 + 0); 1.138 + is(count, 1, "One hCalendar"); 1.139 + 1.140 + count = Microformats.count("hCard", 1.141 + document.getElementById("contentbody"), 1.142 + {recurseExternalFrames: true}); 1.143 + is(count, 1, "One hCard"); 1.144 + } 1.145 + </script> 1.146 + 1.147 + <!-- Geo Fire the test from here so we know this is loaded at the outset --> 1.148 + <iframe src="geo.html" onload="test_MicroformatsAPI();"> 1.149 + </iframe> 1.150 + 1.151 + <!-- adr --> 1.152 + <div class="adr" id="01-extended-address"> 1.153 + <span class="extended-address">Park Bench</span> 1.154 + </div> 1.155 + 1.156 +</body> 1.157 +</html>