toolkit/components/microformats/tests/test_Microformats_count.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial