| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.distiller; | 5 package org.chromium.distiller; |
| 6 | 6 |
| 7 import com.google.gwt.dom.client.AnchorElement; | 7 import com.google.gwt.dom.client.AnchorElement; |
| 8 import com.google.gwt.dom.client.Element; | 8 import com.google.gwt.dom.client.Element; |
| 9 | 9 |
| 10 public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase { | 10 public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase { |
| 11 | 11 |
| 12 private static final String ITEM_TYPE = "itemscope itemtype=\"" + |
| 13 "http://schema.org/"; |
| 14 private static final String ITEM_TYPE_ARTICLE = ITEM_TYPE + |
| 15 "Article\""; |
| 16 private static final String ITEM_TYPE_PERSON = ITEM_TYPE + |
| 17 "Person\""; |
| 18 private static final String ITEM_TYPE_RECIPE = ITEM_TYPE + |
| 19 "Recipe\""; |
| 20 private static final String ITEM_TYPE_MOVIE = ITEM_TYPE + |
| 21 "Movie\""; |
| 22 private static final String ITEM_TYPE_IMAGE_OBJECT = ITEM_TYPE + |
| 23 "ImageObject\""; |
| 24 private static final String ITEM_TYPE_ORGANIZATION = ITEM_TYPE + |
| 25 "Organization\""; |
| 26 private static final String ITEM_TYPE_AGGREGATE_RATING = |
| 27 ITEM_TYPE + "AggregateRating\""; |
| 28 private static final String RECIPE_DESCRIPTION = |
| 29 "Testing RECIPE with required recipe schema.org attributes"; |
| 30 private static final String RECIPE_URL = |
| 31 "http://dummy/test_article_with_embedded_items.html"; |
| 32 private static final String RECIPE_IMAGE_URL = |
| 33 "http://dummy/test_article_with_embedded_items.jpeg"; |
| 34 |
| 12 public void testImageWithEmbeddedPublisher() { | 35 public void testImageWithEmbeddedPublisher() { |
| 13 String expectedUrl = "http://dummy/test_image_with_embedded_item.html"; | 36 String expectedUrl = "http://dummy/test_image_with_embedded_item.html"; |
| 14 String expectedFormat = "jpeg"; | 37 String expectedFormat = "jpeg"; |
| 15 String expectedCaption = "A test for IMAGE with embedded publisher"; | 38 String expectedCaption = "A test for IMAGE with embedded publisher"; |
| 16 String htmlStr = | 39 String htmlStr = |
| 17 "<div id=\"1\" itemscope itemtype=\"http://schema.org/ImageObject\">
" + | 40 "<div id=\"1\" " + ITEM_TYPE_IMAGE_OBJECT + ">" + |
| 18 "<h1 itemprop=\"headline\">Testcase for IMAGE" + | 41 "<h1 itemprop=\"headline\">Testcase for IMAGE" + |
| 19 "</h1>" + | 42 "</h1>" + |
| 20 "<h2 itemprop=\"description\">Testing IMAGE with embedded publis
her" + | 43 "<h2 itemprop=\"description\">Testing IMAGE with embedded publis
her" + |
| 21 "</h2>" + | 44 "</h2>" + |
| 22 "<a itemprop=\"contentUrl\" href=\"" + expectedUrl + "\">test re
sults" + | 45 "<a itemprop=\"contentUrl\" href=\"" + expectedUrl + "\">test re
sults" + |
| 23 "</a>" + | 46 "</a>" + |
| 24 "<div id=\"2\" itemscope itemtype=\"http://schema.org/Organizati
on\"" + | 47 "<div id=\"2\"" + ITEM_TYPE_ORGANIZATION + "" + |
| 25 " itemprop=\"publisher\">Publisher: " + | 48 " itemprop=\"publisher\">Publisher: " + |
| 26 "<span itemprop=\"name\">Whatever Image Incorporated" + | 49 "<span itemprop=\"name\">Whatever Image Incorporated" + |
| 27 "</span>" + | 50 "</span>" + |
| 28 "</div>" + | 51 "</div>" + |
| 29 "<div id=\"3\">" + | 52 "<div id=\"3\">" + |
| 30 "<span itemprop=\"copyrightYear\">1999-2022" + | 53 "<span itemprop=\"copyrightYear\">1999-2022" + |
| 31 "</span>" + | 54 "</span>" + |
| 32 "<span itemprop=\"copyrightHolder\">Whoever Image Copyrighte
d" + | 55 "<span itemprop=\"copyrightHolder\">Whoever Image Copyrighte
d" + |
| 33 "</span>" + | 56 "</span>" + |
| 34 "</div>" + | 57 "</div>" + |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 90 |
| 68 public void test2Images() { | 91 public void test2Images() { |
| 69 String expectedUrl1 = "http://dummy/test_1st image.html"; | 92 String expectedUrl1 = "http://dummy/test_1st image.html"; |
| 70 String expectedPublisher1 = "Whatever 1st Image Incorporated"; | 93 String expectedPublisher1 = "Whatever 1st Image Incorporated"; |
| 71 String expectedFormat1 = "jpeg"; | 94 String expectedFormat1 = "jpeg"; |
| 72 String expectedCaption1 = "A test for 1st IMAGE"; | 95 String expectedCaption1 = "A test for 1st IMAGE"; |
| 73 String expectedUrl2 = "http://dummy/test_2nd image.html"; | 96 String expectedUrl2 = "http://dummy/test_2nd image.html"; |
| 74 String expectedFormat2 = "gif"; | 97 String expectedFormat2 = "gif"; |
| 75 String expectedCaption2 = "A test for 2nd IMAGE"; | 98 String expectedCaption2 = "A test for 2nd IMAGE"; |
| 76 String htmlStr = | 99 String htmlStr = |
| 77 "<div id=\"1\" itemscope itemtype=\"http://schema.org/ImageObject\">
" + | 100 "<div id=\"1\" " + ITEM_TYPE_IMAGE_OBJECT + ">" + |
| 78 "<h1 itemprop=\"headline\">Testcase for 1st IMAGE" + | 101 "<h1 itemprop=\"headline\">Testcase for 1st IMAGE" + |
| 79 "</h1>" + | 102 "</h1>" + |
| 80 "<h2 itemprop=\"description\">Testing 1st IMAGE" + | 103 "<h2 itemprop=\"description\">Testing 1st IMAGE" + |
| 81 "</h2>" + | 104 "</h2>" + |
| 82 "<a itemprop=\"contentUrl\" href=\"" + expectedUrl1 + "\">1st te
st results" + | 105 "<a itemprop=\"contentUrl\" href=\"" + expectedUrl1 + "\">1st te
st results" + |
| 83 "</a>" + | 106 "</a>" + |
| 84 "<div id=\"2\" itemprop=\"publisher\">" + expectedPublisher1 + | 107 "<div id=\"2\" itemprop=\"publisher\">" + expectedPublisher1 + |
| 85 "</div>" + | 108 "</div>" + |
| 86 "<div id=\"3\">" + | 109 "<div id=\"3\">" + |
| 87 "<span itemprop=\"copyrightYear\">1000-1999" + | 110 "<span itemprop=\"copyrightYear\">1000-1999" + |
| 88 "</span>" + | 111 "</span>" + |
| 89 "<span itemprop=\"copyrightHolder\">Whoever 1st Image Copyri
ghted" + | 112 "<span itemprop=\"copyrightHolder\">Whoever 1st Image Copyri
ghted" + |
| 90 "</span>" + | 113 "</span>" + |
| 91 "</div>" + | 114 "</div>" + |
| 92 "<span itemprop=\"encodingFormat\">" + expectedFormat1 + | 115 "<span itemprop=\"encodingFormat\">" + expectedFormat1 + |
| 93 "</span>" + | 116 "</span>" + |
| 94 "<span itemprop=\"caption\">" + expectedCaption1 + | 117 "<span itemprop=\"caption\">" + expectedCaption1 + |
| 95 "</span>" + | 118 "</span>" + |
| 96 "<meta itemprop=\"representativeOfPage\" content=\"false\">" + | 119 "<meta itemprop=\"representativeOfPage\" content=\"false\">" + |
| 97 "<meta itemprop=\"width\" content=\"400\">" + | 120 "<meta itemprop=\"width\" content=\"400\">" + |
| 98 "<meta itemprop=\"height\" content=\"300\">" + | 121 "<meta itemprop=\"height\" content=\"300\">" + |
| 99 "</div>" + | 122 "</div>" + |
| 100 "<div id=\"4\" itemscope itemtype=\"http://schema.org/ImageObject\">
" + | 123 "<div id=\"4\" " + ITEM_TYPE_IMAGE_OBJECT + ">" + |
| 101 "<h3 itemprop=\"headline\">Testcase for 2nd IMAGE" + | 124 "<h3 itemprop=\"headline\">Testcase for 2nd IMAGE" + |
| 102 "</h3>" + | 125 "</h3>" + |
| 103 "<h4 itemprop=\"description\">Testing 2nd IMAGE" + | 126 "<h4 itemprop=\"description\">Testing 2nd IMAGE" + |
| 104 "</h4>" + | 127 "</h4>" + |
| 105 "<a itemprop=\"contentUrl\" href=\"" + expectedUrl2 + "\">2nd te
st results" + | 128 "<a itemprop=\"contentUrl\" href=\"" + expectedUrl2 + "\">2nd te
st results" + |
| 106 "</a>" + | 129 "</a>" + |
| 107 "<div id=\"5\" itemprop=\"publisher\">Whatever 2nd Image Incorpo
rated" + | 130 "<div id=\"5\" itemprop=\"publisher\">Whatever 2nd Image Incorpo
rated" + |
| 108 "</div>" + | 131 "</div>" + |
| 109 "<div id=\"6\">" + | 132 "<div id=\"6\">" + |
| 110 "<span itemprop=\"copyrightYear\">2000-2999" + | 133 "<span itemprop=\"copyrightYear\">2000-2999" + |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 assertEquals("", image.secureUrl); | 176 assertEquals("", image.secureUrl); |
| 154 assertEquals(expectedFormat1, image.type); | 177 assertEquals(expectedFormat1, image.type); |
| 155 assertEquals(expectedCaption1, image.caption); | 178 assertEquals(expectedCaption1, image.caption); |
| 156 assertEquals(400, image.width); | 179 assertEquals(400, image.width); |
| 157 assertEquals(300, image.height); | 180 assertEquals(300, image.height); |
| 158 } | 181 } |
| 159 | 182 |
| 160 public void testArticleWithEmbeddedAuthorAndPublisher() { | 183 public void testArticleWithEmbeddedAuthorAndPublisher() { |
| 161 String expectedTitle = "Testcase for ARTICLE"; | 184 String expectedTitle = "Testcase for ARTICLE"; |
| 162 String expectedDescription = "Testing ARTICLE with embedded author and p
ublisher"; | 185 String expectedDescription = "Testing ARTICLE with embedded author and p
ublisher"; |
| 163 String expectedUrl = "http://dummy/test_article_with_embedded_items.html
"; | |
| 164 String expectedImage = "http://dummy/test_article_with_embedded_items.jp
eg"; | |
| 165 String expectedAuthor = "Whoever authored"; | 186 String expectedAuthor = "Whoever authored"; |
| 166 String expectedPublisher = "Whatever Article Incorporated"; | 187 String expectedPublisher = "Whatever Article Incorporated"; |
| 167 String expectedDatePublished = "April 15, 2014"; | 188 String expectedDatePublished = "April 15, 2014"; |
| 168 String expectedTimeModified = "2014-04-16T23:59"; | 189 String expectedTimeModified = "2014-04-16T23:59"; |
| 169 String expectedCopyrightYear = "2000-2014"; | 190 String expectedCopyrightYear = "2000-2014"; |
| 170 String expectedCopyrightHolder = "Whoever Article Copyrighted"; | 191 String expectedCopyrightHolder = "Whoever Article Copyrighted"; |
| 171 String expectedSection = "Romance thriller"; | 192 String expectedSection = "Romance thriller"; |
| 172 String htmlStr = | 193 String htmlStr = |
| 173 "<div id=\"1\" itemscope itemtype=\"http://schema.org/Article\">" + | 194 "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" + |
| 174 "<h1 itemprop=\"headline\">" + expectedTitle + | 195 "<h1 itemprop=\"headline\">" + expectedTitle + |
| 175 "</h1>" + | 196 "</h1>" + |
| 176 "<h2 itemprop=\"description\">" + expectedDescription + | 197 "<h2 itemprop=\"description\">" + expectedDescription + |
| 177 "</h2>" + | 198 "</h2>" + |
| 178 "<a itemprop=\"url\" href=\"" + expectedUrl + "\">test results"
+ | 199 "<a itemprop=\"url\" href=\"" + RECIPE_URL + "\">test results" + |
| 179 "</a>" + | 200 "</a>" + |
| 180 "<img itemprop=\"image\" src=\"" + expectedImage + "\">" + | 201 "<img itemprop=\"image\" src=\"" + RECIPE_IMAGE_URL + "\">" + |
| 181 "<div id=\"2\" itemscope itemtype=\"http://schema.org/Person\""
+ | 202 "<div id=\"2\" " + ITEM_TYPE_PERSON + |
| 182 " itemprop=\"author\">Author: " + | 203 " itemprop=\"author\">Author: " + |
| 183 "<span itemprop=\"name\">" + expectedAuthor + | 204 "<span itemprop=\"name\">" + expectedAuthor + |
| 184 "</span>" + | 205 "</span>" + |
| 185 "</div>" + | 206 "</div>" + |
| 186 "<div id=\"3\" itemscope itemtype=\"http://schema.org/Organizati
on\"" + | 207 "<div id=\"3\"" + ITEM_TYPE_ORGANIZATION + "" + |
| 187 " itemprop=\"publisher\">Publisher: " + | 208 " itemprop=\"publisher\">Publisher: " + |
| 188 "<span itemprop=\"name\">" + expectedPublisher + | 209 "<span itemprop=\"name\">" + expectedPublisher + |
| 189 "</span>" + | 210 "</span>" + |
| 190 "</div>" + | 211 "</div>" + |
| 191 "<span itemprop=\"datePublished\">" + expectedDatePublished + | 212 "<span itemprop=\"datePublished\">" + expectedDatePublished + |
| 192 "</span>" + | 213 "</span>" + |
| 193 "<time itemprop=\"dateModified\" datetime=\"" + expectedTimeModi
fied + | 214 "<time itemprop=\"dateModified\" datetime=\"" + expectedTimeModi
fied + |
| 194 "\">April 16, 2014 11:59pm" + | 215 "\">April 16, 2014 11:59pm" + |
| 195 "</time>" + | 216 "</time>" + |
| 196 "<span itemprop=\"copyrightYear\">" + expectedCopyrightYear + | 217 "<span itemprop=\"copyrightYear\">" + expectedCopyrightYear + |
| 197 "</span>" + | 218 "</span>" + |
| 198 "<span itemprop=\"copyrightHolder\">" + expectedCopyrightHolder
+ | 219 "<span itemprop=\"copyrightHolder\">" + expectedCopyrightHolder
+ |
| 199 "</span>" + | 220 "</span>" + |
| 200 "<span itemprop=\"articleSection\">" + expectedSection + | 221 "<span itemprop=\"articleSection\">" + expectedSection + |
| 201 "</span>" + | 222 "</span>" + |
| 202 "</div>"; | 223 "</div>"; |
| 203 | 224 |
| 204 Element rootDiv = TestUtil.createDiv(0); | 225 Element rootDiv = TestUtil.createDiv(0); |
| 205 rootDiv.setInnerHTML(htmlStr); | 226 rootDiv.setInnerHTML(htmlStr); |
| 206 mBody.appendChild(rootDiv); | 227 mBody.appendChild(rootDiv); |
| 207 | 228 |
| 208 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); | 229 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); |
| 209 assertEquals("Article", parser.getType()); | 230 assertEquals("Article", parser.getType()); |
| 210 assertEquals(expectedTitle, parser.getTitle()); | 231 assertEquals(expectedTitle, parser.getTitle()); |
| 211 assertEquals(expectedDescription, parser.getDescription()); | 232 assertEquals(expectedDescription, parser.getDescription()); |
| 212 assertEquals(expectedUrl, parser.getUrl()); | 233 assertEquals(RECIPE_URL, parser.getUrl()); |
| 213 assertEquals(expectedAuthor, parser.getAuthor()); | 234 assertEquals(expectedAuthor, parser.getAuthor()); |
| 214 assertEquals(expectedPublisher, parser.getPublisher()); | 235 assertEquals(expectedPublisher, parser.getPublisher()); |
| 215 assertEquals( "Copyright " + expectedCopyrightYear + " " + expectedCopyr
ightHolder, | 236 assertEquals( "Copyright " + expectedCopyrightYear + " " + expectedCopyr
ightHolder, |
| 216 parser.getCopyright()); | 237 parser.getCopyright()); |
| 217 MarkupParser.Image[] images = parser.getImages(); | 238 MarkupParser.Image[] images = parser.getImages(); |
| 218 assertEquals(1, images.length); | 239 assertEquals(1, images.length); |
| 219 assertEquals(expectedImage, images[0].url); | 240 assertEquals(RECIPE_IMAGE_URL, images[0].url); |
| 220 MarkupParser.Article article = parser.getArticle(); | 241 MarkupParser.Article article = parser.getArticle(); |
| 221 assertEquals(expectedDatePublished, article.publishedTime); | 242 assertEquals(expectedDatePublished, article.publishedTime); |
| 222 assertEquals(expectedTimeModified, article.modifiedTime); | 243 assertEquals(expectedTimeModified, article.modifiedTime); |
| 223 assertEquals("", article.expirationTime); | 244 assertEquals("", article.expirationTime); |
| 224 assertEquals(expectedSection, article.section); | 245 assertEquals(expectedSection, article.section); |
| 225 assertEquals(1, article.authors.length); | 246 assertEquals(1, article.authors.length); |
| 226 assertEquals(expectedAuthor, article.authors[0]); | 247 assertEquals(expectedAuthor, article.authors[0]); |
| 227 } | 248 } |
| 228 | 249 |
| 229 public void testArticleWithEmbeddedAndTopLevelImages() { | 250 public void testArticleWithEmbeddedAndTopLevelImages() { |
| 230 String expectedTitle = "Testcase for ARTICLE with Embedded and Top-Level
IMAGEs"; | 251 String expectedTitle = "Testcase for ARTICLE with Embedded and Top-Level
IMAGEs"; |
| 231 String expectedDescription = "Testing ARTICLE with embedded and top-leve
l images"; | 252 String expectedDescription = "Testing ARTICLE with embedded and top-leve
l images"; |
| 232 String expectedUrl = "http://dummy/test_article_with_embedded_and_toplev
el_images.html"; | 253 String expectedUrl = "http://dummy/test_article_with_embedded_and_toplev
el_images.html"; |
| 233 String expectedImage1 = "http://dummy/test_toplevel image.html"; | 254 String expectedImage1 = "http://dummy/test_toplevel image.html"; |
| 234 String expectedFormat1 = "gif"; | 255 String expectedFormat1 = "gif"; |
| 235 String expectedCaption1 = "A test for top-level IMAGE"; | 256 String expectedCaption1 = "A test for top-level IMAGE"; |
| 236 String expectedImage2 = "http://dummy/test_article_with_embedded_and_top
level_images.html"; | 257 String expectedImage2 = "http://dummy/test_article_with_embedded_and_top
level_images.html"; |
| 237 String expectedFormat2 = "jpeg"; | 258 String expectedFormat2 = "jpeg"; |
| 238 String expectedCaption2 = "A test for emedded IMAGE in ARTICLE"; | 259 String expectedCaption2 = "A test for emedded IMAGE in ARTICLE"; |
| 239 String htmlStr = | 260 String htmlStr = |
| 240 "<div id=\"1\" itemscope itemtype=\"http://schema.org/ImageObject\">
" + | 261 "<div id=\"1\" " + ITEM_TYPE_IMAGE_OBJECT + ">" + |
| 241 "<span itemprop=\"headline\">Title should be ignored" + | 262 "<span itemprop=\"headline\">Title should be ignored" + |
| 242 "</span>" + | 263 "</span>" + |
| 243 "<span itemprop=\"description\">Testing top-level IMAGE" + | 264 "<span itemprop=\"description\">Testing top-level IMAGE" + |
| 244 "</span>" + | 265 "</span>" + |
| 245 "<a itemprop=\"url\" href=\"http://dummy/to_be_ignored_url.html\
">test results" + | 266 "<a itemprop=\"url\" href=\"http://dummy/to_be_ignored_url.html\
">test results" + |
| 246 "</a>" + | 267 "</a>" + |
| 247 "<a itemprop=\"contentUrl\" href=\"" + expectedImage1 + "\">top-
level image" + | 268 "<a itemprop=\"contentUrl\" href=\"" + expectedImage1 + "\">top-
level image" + |
| 248 "</a>" + | 269 "</a>" + |
| 249 "<span itemprop=\"encodingFormat\">" + expectedFormat1 + | 270 "<span itemprop=\"encodingFormat\">" + expectedFormat1 + |
| 250 "</span>" + | 271 "</span>" + |
| 251 "<span itemprop=\"caption\">" + expectedCaption1 + | 272 "<span itemprop=\"caption\">" + expectedCaption1 + |
| 252 "</span>" + | 273 "</span>" + |
| 253 "<meta itemprop=\"representativeOfPage\" content=\"true\">" + | 274 "<meta itemprop=\"representativeOfPage\" content=\"true\">" + |
| 254 "<meta itemprop=\"width\" content=\"1000\">" + | 275 "<meta itemprop=\"width\" content=\"1000\">" + |
| 255 "<meta itemprop=\"height\" content=\"600\">" + | 276 "<meta itemprop=\"height\" content=\"600\">" + |
| 256 "</div>" + | 277 "</div>" + |
| 257 "<div id=\"2\" itemscope itemtype=\"http://schema.org/Article\">" + | 278 "<div id=\"2\" " + ITEM_TYPE_ARTICLE + ">" + |
| 258 "<span itemprop=\"headline\">" + expectedTitle + | 279 "<span itemprop=\"headline\">" + expectedTitle + |
| 259 "</span>" + | 280 "</span>" + |
| 260 "<span itemprop=\"description\">" + expectedDescription + | 281 "<span itemprop=\"description\">" + expectedDescription + |
| 261 "</span>" + | 282 "</span>" + |
| 262 "<a itemprop=\"url\" href=\"" + expectedUrl + "\">test results"
+ | 283 "<a itemprop=\"url\" href=\"" + expectedUrl + "\">test results"
+ |
| 263 "</a>" + | 284 "</a>" + |
| 264 "<img itemprop=\"image\" src=\"http://dummy/should_be_ignored_im
age.jpeg\">" + | 285 "<img itemprop=\"image\" src=\"http://dummy/should_be_ignored_im
age.jpeg\">" + |
| 265 "<div id=\"3\" itemscope itemtype=\"http://schema.org/ImageObjec
t\"" + | 286 "<div id=\"3\" " + ITEM_TYPE_IMAGE_OBJECT + "" + |
| 266 " itemprop=\"associatedMedia\">" + | 287 " itemprop=\"associatedMedia\">" + |
| 267 "<a itemprop=\"url\" href=\"" + expectedImage2 + "\">associa
ted image" + | 288 "<a itemprop=\"url\" href=\"" + expectedImage2 + "\">associa
ted image" + |
| 268 "</a>" + | 289 "</a>" + |
| 269 "<span itemprop=\"encodingFormat\">" + expectedFormat2 + | 290 "<span itemprop=\"encodingFormat\">" + expectedFormat2 + |
| 270 "</span>" + | 291 "</span>" + |
| 271 "<span itemprop=\"caption\">" + expectedCaption2 + | 292 "<span itemprop=\"caption\">" + expectedCaption2 + |
| 272 "</span>" + | 293 "</span>" + |
| 273 "<meta itemprop=\"representativeOfPage\" content=\"false\">"
+ | 294 "<meta itemprop=\"representativeOfPage\" content=\"false\">"
+ |
| 274 "<meta itemprop=\"width\" content=\"600\">" + | 295 "<meta itemprop=\"width\" content=\"600\">" + |
| 275 "<meta itemprop=\"height\" content=\"400\">" + | 296 "<meta itemprop=\"height\" content=\"400\">" + |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 // Remove "itemscope" and "itemtype" attributes in <html> tag, so that | 340 // Remove "itemscope" and "itemtype" attributes in <html> tag, so that |
| 320 // other testcases won't be affected. | 341 // other testcases won't be affected. |
| 321 mRoot.removeAttribute("ITEMSCOPE"); | 342 mRoot.removeAttribute("ITEMSCOPE"); |
| 322 mRoot.removeAttribute("ITEMTYPE"); | 343 mRoot.removeAttribute("ITEMTYPE"); |
| 323 } | 344 } |
| 324 | 345 |
| 325 public void testSupportedWithUnsupportedItemprop() { | 346 public void testSupportedWithUnsupportedItemprop() { |
| 326 String expectedTitle = "Testcase for Supported With Unsupported Itemprop
"; | 347 String expectedTitle = "Testcase for Supported With Unsupported Itemprop
"; |
| 327 String expectedSection = "Testing"; | 348 String expectedSection = "Testing"; |
| 328 String htmlStr = | 349 String htmlStr = |
| 329 "<div id=\"1\" itemscope itemtype=\"http://schema.org/Article\">" + | 350 "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" + |
| 330 "<span itemprop=\"headline\">" + expectedTitle + | 351 "<span itemprop=\"headline\">" + expectedTitle + |
| 331 "</span>" + | 352 "</span>" + |
| 332 "<span itemprop=\"articleSection\">" + expectedSection + | 353 "<span itemprop=\"articleSection\">" + expectedSection + |
| 333 "</span>" + | 354 "</span>" + |
| 334 // Add unsupported AggregateRating to supported Article as itemp
rop. | 355 // Add unsupported AggregateRating to supported Article as itemp
rop. |
| 335 "<div id=\"2\" itemscope itemtype=\"http://schema.org/AggregateR
ating\"" + | 356 "<div id=\"2\" " + ITEM_TYPE_AGGREGATE_RATING + "" + |
| 336 " itemprop=\"aggregateRating\">Ratings: " + | 357 " itemprop=\"aggregateRating\">Ratings: " + |
| 337 "<span itemprop=\"ratingValue\">9.9" + | 358 "<span itemprop=\"ratingValue\">9.9" + |
| 338 "</span>" + | 359 "</span>" + |
| 339 // Add supported Person to unsupported AggregateRating as it
emprop. | 360 // Add supported Person to unsupported AggregateRating as it
emprop. |
| 340 "<div id=\"3\" itemscope itemtype=\"http://schema.org/Person
\"" + | 361 "<div id=\"3\" " + ITEM_TYPE_PERSON + |
| 341 " itemprop=\"author\">Author: " + | 362 " itemprop=\"author\">Author: " + |
| 342 "<span itemprop=\"name\">Whoever authored" + | 363 "<span itemprop=\"name\">Whoever authored" + |
| 343 "</span>" + | 364 "</span>" + |
| 344 "</div>" + | 365 "</div>" + |
| 345 "</div>" + | 366 "</div>" + |
| 346 "</div>"; | 367 "</div>"; |
| 347 | 368 |
| 348 Element rootDiv = TestUtil.createDiv(0); | 369 Element rootDiv = TestUtil.createDiv(0); |
| 349 rootDiv.setInnerHTML(htmlStr); | 370 rootDiv.setInnerHTML(htmlStr); |
| 350 mBody.appendChild(rootDiv); | 371 mBody.appendChild(rootDiv); |
| 351 | 372 |
| 352 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); | 373 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); |
| 353 assertEquals("Article", parser.getType()); | 374 assertEquals("Article", parser.getType()); |
| 354 assertEquals(expectedTitle, parser.getTitle()); | 375 assertEquals(expectedTitle, parser.getTitle()); |
| 355 assertEquals("", parser.getDescription()); | 376 assertEquals("", parser.getDescription()); |
| 356 assertEquals("", parser.getUrl()); | 377 assertEquals("", parser.getUrl()); |
| 357 assertEquals("", parser.getAuthor()); | 378 assertEquals("", parser.getAuthor()); |
| 358 assertEquals("", parser.getPublisher()); | 379 assertEquals("", parser.getPublisher()); |
| 359 assertEquals("", parser.getCopyright()); | 380 assertEquals("", parser.getCopyright()); |
| 360 MarkupParser.Article article = parser.getArticle(); | 381 MarkupParser.Article article = parser.getArticle(); |
| 361 assertEquals("", article.publishedTime); | 382 assertEquals("", article.publishedTime); |
| 362 assertEquals("", article.modifiedTime); | 383 assertEquals("", article.modifiedTime); |
| 363 assertEquals("", article.expirationTime); | 384 assertEquals("", article.expirationTime); |
| 364 assertEquals(expectedSection, article.section); | 385 assertEquals(expectedSection, article.section); |
| 365 assertEquals(0, article.authors.length); | 386 assertEquals(0, article.authors.length); |
| 366 } | 387 } |
| 367 | 388 |
| 368 public void testUnsupportedWithSupportedItemprop() { | 389 public void testUnsupportedWithSupportedItemprop() { |
| 369 String htmlStr = | 390 String htmlStr = |
| 370 "<div id=\"1\" itemscope itemtype=\"http://schema.org/Movie\">" + | 391 "<div id=\"1\" " + ITEM_TYPE_MOVIE + ">" + |
| 371 "<span itemprop=\"headline\">Testcase for Unsupported With Suppo
rted Itemprop" + | 392 "<span itemprop=\"headline\">Testcase for Unsupported With Suppo
rted Itemprop" + |
| 372 "</span>" + | 393 "</span>" + |
| 373 // Add supported Person to unsupported Movie as itemprop. | 394 // Add supported Person to unsupported Movie as itemprop. |
| 374 "<div id=\"3\" itemscope itemtype=\"http://schema.org/Person\""
+ | 395 "<div id=\"3\" " + ITEM_TYPE_PERSON + |
| 375 " itemprop=\"publisher\">Publisher: " + | 396 " itemprop=\"publisher\">Publisher: " + |
| 376 "<span itemprop=\"name\">Whoever published" + | 397 "<span itemprop=\"name\">Whoever published" + |
| 377 "</span>" + | 398 "</span>" + |
| 378 "</div>" + | 399 "</div>" + |
| 379 "</div>"; | 400 "</div>"; |
| 380 Element rootDiv = TestUtil.createDiv(0); | 401 Element rootDiv = TestUtil.createDiv(0); |
| 381 rootDiv.setInnerHTML(htmlStr); | 402 rootDiv.setInnerHTML(htmlStr); |
| 382 mBody.appendChild(rootDiv); | 403 mBody.appendChild(rootDiv); |
| 383 | 404 |
| 384 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); | 405 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); |
| 385 assertEquals("", parser.getType()); | 406 assertEquals("", parser.getType()); |
| 386 assertEquals("", parser.getTitle()); | 407 assertEquals("", parser.getTitle()); |
| 387 assertEquals("", parser.getDescription()); | 408 assertEquals("", parser.getDescription()); |
| 388 assertEquals("", parser.getUrl()); | 409 assertEquals("", parser.getUrl()); |
| 389 assertEquals("", parser.getAuthor()); | 410 assertEquals("", parser.getAuthor()); |
| 390 assertEquals("", parser.getPublisher()); | 411 assertEquals("", parser.getPublisher()); |
| 391 assertEquals("", parser.getCopyright()); | 412 assertEquals("", parser.getCopyright()); |
| 392 assertEquals(null, parser.getArticle()); | 413 assertEquals(null, parser.getArticle()); |
| 393 assertEquals(0, parser.getImages().length); | 414 assertEquals(0, parser.getImages().length); |
| 394 } | 415 } |
| 395 | 416 |
| 396 public void testUnsupportedWithNestedSupported() { | 417 public void testUnsupportedWithNestedSupported() { |
| 397 String expectedTitle = "Testcase for ARTICLE nested in Unsupported Type"
; | 418 String expectedTitle = "Testcase for ARTICLE nested in Unsupported Type"
; |
| 398 String expectedDescription = "Testing ARTICLE that is nested within unsu
pported type"; | 419 String expectedDescription = "Testing ARTICLE that is nested within unsu
pported type"; |
| 399 String expectedUrl = "http://dummy/test_article_with_embedded_items.html
"; | |
| 400 String expectedImage = "http://dummy/test_article_with_embedded_items.jp
eg"; | |
| 401 String expectedAuthor = "Whoever authored"; | 420 String expectedAuthor = "Whoever authored"; |
| 402 String expectedPublisher = "Whatever Article Incorporated"; | 421 String expectedPublisher = "Whatever Article Incorporated"; |
| 403 String expectedDatePublished = "April 15, 2014"; | 422 String expectedDatePublished = "April 15, 2014"; |
| 404 String htmlStr = | 423 String htmlStr = |
| 405 "<div id=\"1\" itemscope itemtype=\"http://schema.org/Movie\">" + | 424 "<div id=\"1\" " + ITEM_TYPE_MOVIE + ">" + |
| 406 "<span itemprop=\"headline\">Testcase for Unsupported With Suppo
rted Itemprop" + | 425 "<span itemprop=\"headline\">Testcase for Unsupported With Suppo
rted Itemprop" + |
| 407 "</span>" + | 426 "</span>" + |
| 408 // Add supported Article to unsupported Movie as a non-itemprop. | 427 // Add supported Article to unsupported Movie as a non-itemprop. |
| 409 "<div id=\"2\" itemscope itemtype=\"http://schema.org/Article\">
" + | 428 "<div id=\"2\" " + ITEM_TYPE_ARTICLE + ">" + |
| 410 "<span itemprop=\"headline\">" + expectedTitle + | 429 "<span itemprop=\"headline\">" + expectedTitle + |
| 411 "</span>" + | 430 "</span>" + |
| 412 "<span itemprop=\"description\">" + expectedDescription + | 431 "<span itemprop=\"description\">" + expectedDescription + |
| 413 "</span>" + | 432 "</span>" + |
| 414 "<a itemprop=\"url\" href=\"" + expectedUrl + "\">test resul
ts" + | 433 "<a itemprop=\"url\" href=\"" + RECIPE_URL + "\">test result
s" + |
| 415 "</a>" + | 434 "</a>" + |
| 416 "<img itemprop=\"image\" src=\"" + expectedImage + "\">" + | 435 "<img itemprop=\"image\" src=\"" + RECIPE_IMAGE_URL + "\">"
+ |
| 417 "<div id=\"3\" itemscope itemtype=\"http://schema.org/Person
\"" + | 436 "<div id=\"3\" " + ITEM_TYPE_PERSON + |
| 418 " itemprop=\"author\">Author: " + | 437 " itemprop=\"author\">Author: " + |
| 419 "<span itemprop=\"name\">" + expectedAuthor + | 438 "<span itemprop=\"name\">" + expectedAuthor + |
| 420 "</span>" + | 439 "</span>" + |
| 421 "</div>" + | 440 "</div>" + |
| 422 "<div id=\"4\" itemscope itemtype=\"http://schema.org/Organi
zation\"" + | 441 "<div id=\"4\"" + ITEM_TYPE_ORGANIZATION + "" + |
| 423 " itemprop=\"publisher\">Publisher: " + | 442 " itemprop=\"publisher\">Publisher: " + |
| 424 "<span itemprop=\"name\">" + expectedPublisher + | 443 "<span itemprop=\"name\">" + expectedPublisher + |
| 425 "</span>" + | 444 "</span>" + |
| 426 "</div>" + | 445 "</div>" + |
| 427 "<span itemprop=\"datePublished\">" + expectedDatePublished
+ | 446 "<span itemprop=\"datePublished\">" + expectedDatePublished
+ |
| 428 "</span>" + | 447 "</span>" + |
| 429 "</div>" + | 448 "</div>" + |
| 430 "</div>"; | 449 "</div>"; |
| 431 Element rootDiv = TestUtil.createDiv(0); | 450 Element rootDiv = TestUtil.createDiv(0); |
| 432 rootDiv.setInnerHTML(htmlStr); | 451 rootDiv.setInnerHTML(htmlStr); |
| 433 mBody.appendChild(rootDiv); | 452 mBody.appendChild(rootDiv); |
| 434 | 453 |
| 435 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); | 454 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); |
| 436 assertEquals("Article", parser.getType()); | 455 assertEquals("Article", parser.getType()); |
| 437 assertEquals(expectedTitle, parser.getTitle()); | 456 assertEquals(expectedTitle, parser.getTitle()); |
| 438 assertEquals(expectedDescription, parser.getDescription()); | 457 assertEquals(expectedDescription, parser.getDescription()); |
| 439 assertEquals(expectedUrl, parser.getUrl()); | 458 assertEquals(RECIPE_URL, parser.getUrl()); |
| 440 assertEquals(expectedAuthor, parser.getAuthor()); | 459 assertEquals(expectedAuthor, parser.getAuthor()); |
| 441 assertEquals(expectedPublisher, parser.getPublisher()); | 460 assertEquals(expectedPublisher, parser.getPublisher()); |
| 442 assertEquals("", parser.getCopyright()); | 461 assertEquals("", parser.getCopyright()); |
| 443 MarkupParser.Image[] images = parser.getImages(); | 462 MarkupParser.Image[] images = parser.getImages(); |
| 444 assertEquals(1, images.length); | 463 assertEquals(1, images.length); |
| 445 assertEquals(expectedImage, images[0].url); | 464 assertEquals(RECIPE_IMAGE_URL, images[0].url); |
| 446 MarkupParser.Article article = parser.getArticle(); | 465 MarkupParser.Article article = parser.getArticle(); |
| 447 assertEquals(expectedDatePublished, article.publishedTime); | 466 assertEquals(expectedDatePublished, article.publishedTime); |
| 448 assertEquals("", article.expirationTime); | 467 assertEquals("", article.expirationTime); |
| 449 assertEquals(1, article.authors.length); | 468 assertEquals(1, article.authors.length); |
| 450 assertEquals(expectedAuthor, article.authors[0]); | 469 assertEquals(expectedAuthor, article.authors[0]); |
| 451 } | 470 } |
| 452 | 471 |
| 453 public void testSameItempropDifferentValues() { | 472 public void testSameItempropDifferentValues() { |
| 454 String expectedAuthor = "Author 1"; | 473 String expectedAuthor = "Author 1, Author 2"; |
| 455 String htmlStr = | 474 String htmlStr = |
| 456 "<div id=\"1\" itemscope itemtype=\"http://schema.org/Article\">" + | 475 "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" + |
| 457 "<div id=\"2\" itemscope itemtype=\"http://schema.org/Person\""
+ | 476 "<div id=\"2\" " + ITEM_TYPE_PERSON + |
| 458 " itemprop=\"author\">Authors: " + | 477 " itemprop=\"author\">Authors: " + |
| 459 "<span itemprop=\"name\">" + expectedAuthor + | 478 "<span itemprop=\"name\">Author 1" + |
| 460 "</span>" + | 479 "</span>" + |
| 461 "<span itemprop=\"name\">Author 2" + | 480 "<span itemprop=\"name\">Author 2" + |
| 462 "</span>" + | 481 "</span>" + |
| 463 "</div>" + | 482 "</div>" + |
| 464 "</div>"; | 483 "</div>"; |
| 465 | 484 |
| 466 Element rootDiv = TestUtil.createDiv(0); | 485 Element rootDiv = TestUtil.createDiv(0); |
| 467 rootDiv.setInnerHTML(htmlStr); | 486 rootDiv.setInnerHTML(htmlStr); |
| 468 mBody.appendChild(rootDiv); | 487 mBody.appendChild(rootDiv); |
| 469 | 488 |
| 470 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); | 489 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); |
| 471 assertEquals("Article", parser.getType()); | 490 assertEquals("Article", parser.getType()); |
| 472 assertEquals(expectedAuthor, parser.getAuthor()); | 491 assertEquals(expectedAuthor, parser.getAuthor()); |
| 473 MarkupParser.Article article = parser.getArticle(); | 492 MarkupParser.Article article = parser.getArticle(); |
| 474 assertEquals(1, article.authors.length); | 493 assertEquals(1, article.authors.length); |
| 475 assertEquals(expectedAuthor, article.authors[0]); | 494 assertEquals(expectedAuthor, article.authors[0]); |
| 476 } | 495 } |
| 477 | 496 |
| 478 public void testItempropWithMultiProperties() { | 497 public void testItempropWithMultiProperties() { |
| 479 String expectedPerson = "Person foo"; | 498 String expectedPerson = "Person foo"; |
| 480 String htmlStr = | 499 String htmlStr = |
| 481 "<div id=\"1\" itemscope itemtype=\"http://schema.org/Article\">" + | 500 "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" + |
| 482 "<div id=\"2\" itemscope itemtype=\"http://schema.org/Person\""
+ | 501 "<div id=\"2\" " + ITEM_TYPE_PERSON + |
| 483 " itemprop=\"author publisher\">" + | 502 " itemprop=\"author publisher\">" + |
| 484 "<span itemprop=\"name\">" + expectedPerson + | 503 "<span itemprop=\"name\">" + expectedPerson + |
| 485 "</span>" + | 504 "</span>" + |
| 486 "</div>" + | 505 "</div>" + |
| 487 "</div>"; | 506 "</div>"; |
| 488 | 507 |
| 489 Element rootDiv = TestUtil.createDiv(0); | 508 Element rootDiv = TestUtil.createDiv(0); |
| 490 rootDiv.setInnerHTML(htmlStr); | 509 rootDiv.setInnerHTML(htmlStr); |
| 491 mBody.appendChild(rootDiv); | 510 mBody.appendChild(rootDiv); |
| 492 | 511 |
| 493 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); | 512 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); |
| 494 assertEquals("Article", parser.getType()); | 513 assertEquals("Article", parser.getType()); |
| 495 assertEquals(expectedPerson, parser.getAuthor()); | 514 assertEquals(expectedPerson, parser.getAuthor()); |
| 496 assertEquals(expectedPerson, parser.getPublisher()); | 515 assertEquals(expectedPerson, parser.getPublisher()); |
| 497 MarkupParser.Article article = parser.getArticle(); | 516 MarkupParser.Article article = parser.getArticle(); |
| 498 assertEquals(1, article.authors.length); | 517 assertEquals(1, article.authors.length); |
| 499 assertEquals(expectedPerson, article.authors[0]); | 518 assertEquals(expectedPerson, article.authors[0]); |
| 500 } | 519 } |
| 501 | 520 |
| 502 public void testAuthorPropertyFromDifferentSources() { | 521 public void testAuthorPropertyFromDifferentSources() { |
| 503 // Test that "creator" property is used when "author" property doens't e
xist. | 522 // Test that "creator" property is used when "author" property doens't e
xist. |
| 504 String expectedCreator = "Whoever created"; | 523 String expectedCreator = "Whoever created"; |
| 505 String htmlStr = | 524 String htmlStr = |
| 506 "<div id=\"1\" itemscope itemtype=\"http://schema.org/Article\">" + | 525 "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" + |
| 507 "<div id=\"2\" itemscope itemtype=\"http://schema.org/Person\""
+ | 526 "<div id=\"2\" " + ITEM_TYPE_PERSON + |
| 508 " itemprop=\"author\">Creator: " + | 527 " itemprop=\"author\">Creator: " + |
| 509 "<span itemprop=\"name\">" + expectedCreator + | 528 "<span itemprop=\"name\">" + expectedCreator + |
| 510 "</span>" + | 529 "</span>" + |
| 511 "</div>" + | 530 "</div>" + |
| 512 "</div>"; | 531 "</div>"; |
| 513 | 532 |
| 514 Element rootDiv = TestUtil.createDiv(0); | 533 Element rootDiv = TestUtil.createDiv(0); |
| 515 rootDiv.setInnerHTML(htmlStr); | 534 rootDiv.setInnerHTML(htmlStr); |
| 516 mBody.appendChild(rootDiv); | 535 mBody.appendChild(rootDiv); |
| 517 | 536 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 534 | 553 |
| 535 parser = new SchemaOrgParserAccessor(mRoot); | 554 parser = new SchemaOrgParserAccessor(mRoot); |
| 536 assertEquals("", parser.getType()); | 555 assertEquals("", parser.getType()); |
| 537 assertEquals(expectedAuthor, parser.getAuthor()); | 556 assertEquals(expectedAuthor, parser.getAuthor()); |
| 538 assertEquals(null, parser.getArticle()); | 557 assertEquals(null, parser.getArticle()); |
| 539 | 558 |
| 540 // Remove anchor from parent, so that other testcases won't be affected. | 559 // Remove anchor from parent, so that other testcases won't be affected. |
| 541 link.removeFromParent(); | 560 link.removeFromParent(); |
| 542 } | 561 } |
| 543 | 562 |
| 563 public void testSingleRecipe() { |
| 564 String htmlStr = |
| 565 "<div id=\"1\" " + ITEM_TYPE_RECIPE + ">" + |
| 566 "<meta http-equiv=\"Content-Language\" " + |
| 567 "content=\"en_US\">" + |
| 568 "<h1 itemprop=\"name\">Bat Rice Recipe</h1>" + |
| 569 "<h2 itemprop=\"description\">" + |
| 570 RECIPE_DESCRIPTION + "</h2>" + |
| 571 "<a itemprop=\"url\" " + |
| 572 "href=\"" + RECIPE_URL + "\">" + |
| 573 "test results" + "</a>" + |
| 574 "<img itemprop=\"image\" " + |
| 575 "src=\"" + RECIPE_IMAGE_URL + "\" />" + |
| 576 "<div itemprop=\"author\">Whoever authored</div>" + |
| 577 "<div itemprop=\"recipeYield\" content=\"4\">" + |
| 578 "4 servings</div>" + |
| 579 "<time itemprop=\"prepTime\" datetime=\"PT15M\">" + |
| 580 "15 Minutes" + "</time>" + |
| 581 "<time itemprop=\"cookTime\" datetime=\"PT45M\">" + |
| 582 "45 Minutes" + "</time>" + |
| 583 "<time itemprop=\"totalTime\" datetime=\"PT9H\">" + |
| 584 "9 Hours</time>" + |
| 585 "<span itemprop=\"ingredients\">4 bats</span>" + |
| 586 "<span itemprop=\"ingredients\">1/4 milk</span>" + |
| 587 "<span itemprop=\"recipeInstructions\">" + |
| 588 "Mix everything and wait for cook</span>" + |
| 589 "</div>"; |
| 590 |
| 591 Element rootDiv = TestUtil.createDiv(0); |
| 592 rootDiv.setInnerHTML(htmlStr); |
| 593 mBody.appendChild(rootDiv); |
| 594 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); |
| 595 String result = parser.getStructuredData(); |
| 596 |
| 597 String expected = |
| 598 "<img src='" + RECIPE_IMAGE_URL + "' />" + |
| 599 "<p>Author: Whoever authored</p><p>Description: " + |
| 600 RECIPE_DESCRIPTION + "</p>" + |
| 601 "<p>Serves: 4 servings</p>" + |
| 602 "<p>Prep time: 15 minute(s)</p>" + |
| 603 "<p>Cook time: 45 minute(s)</p>" + |
| 604 "<p>Total time: 9 hour(s)</p>" + |
| 605 "Ingredients: <ul><li>4 bats</li>" + |
| 606 "<li>1/4 milk</li>" + |
| 607 "</ul><p>Instructions: <br />" + |
| 608 "Mix everything and wait for cook</p>"; |
| 609 assertEquals(expected, result); |
| 610 } |
| 611 |
| 612 public void testSingleRecipeWithEmbeddedPerson() { |
| 613 String htmlStr = |
| 614 "<div id=\"1\" " + ITEM_TYPE_RECIPE + ">" + |
| 615 "<h1 itemprop=\"name\">Bat Rice Recipe</h1>" + |
| 616 "<h2 itemprop=\"description\">" + |
| 617 RECIPE_DESCRIPTION + "</h2>" + |
| 618 "<a itemprop=\"url\" href=\"" + RECIPE_URL + "\">" + |
| 619 "test results" + "</a>" + |
| 620 "<img itemprop=\"image\" " + |
| 621 "src=\"" + RECIPE_IMAGE_URL + "\" />" + |
| 622 "<span itemprop=\"author\" " + ITEM_TYPE_PERSON + ">" + |
| 623 "<span itemprop=\"givenName\">Guest</span>" + |
| 624 "<span itemprop=\"familyName\">Smith</span>" + |
| 625 "</span>" + |
| 626 "<div itemprop=\"recipeYield\" content=\"4\">" + |
| 627 "4 servings</div>" + |
| 628 "<time itemprop=\"prepTime\" datetime=\"PT15M\">1" + |
| 629 "5 Minutes" + "</time>" + |
| 630 "<time itemprop=\"cookTime\" datetime=\"PT45M\">" + |
| 631 "45 Minutes" + "</time>" + |
| 632 "<time itemprop=\"totalTime\" datetime=\"PT9H\">" + |
| 633 "9 Hours</time>" + |
| 634 "<span itemprop=\"ingredients\">4 bats</span>" + |
| 635 "<span itemprop=\"ingredients\">1/4 milk</span>" + |
| 636 "<span itemprop=\"recipeInstructions\">" + |
| 637 "Mix everything and wait for cook</span>" + |
| 638 "</div>"; |
| 639 |
| 640 Element rootDiv = TestUtil.createDiv(0); |
| 641 rootDiv.setInnerHTML(htmlStr); |
| 642 mRoot.setAttribute("lang", "en"); |
| 643 mBody.appendChild(rootDiv); |
| 644 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); |
| 645 String result = parser.getStructuredData(); |
| 646 |
| 647 String expected = |
| 648 "<img src='" + RECIPE_IMAGE_URL + "' />" + |
| 649 "<p>Author: <span>Guest Smith</span></p>" + |
| 650 "<p>Description: " + |
| 651 RECIPE_DESCRIPTION + "</p>" + |
| 652 "<p>Serves: 4 servings</p>" + |
| 653 "<p>Prep time: 15 minute(s)</p>" + |
| 654 "<p>Cook time: 45 minute(s)</p>" + |
| 655 "<p>Total time: 9 hour(s)</p>" + |
| 656 "Ingredients: <ul><li>4 bats</li>" + |
| 657 "<li>1/4 milk</li>" + |
| 658 "</ul><p>Instructions: <br />" + |
| 659 "Mix everything and wait for cook</p>"; |
| 660 assertEquals(expected, result); |
| 661 } |
| 662 |
| 663 public void testMoreThanOneSchemaOrg() { |
| 664 String htmlStr = |
| 665 "<div id=\"1\" " + ITEM_TYPE_RECIPE + ">" + |
| 666 "<h1 itemprop=\"name\">Bat Rice Recipe</h1>" + |
| 667 "<meta name=\"Language\" " + |
| 668 "content=\"en_US\">" + |
| 669 "<h2 itemprop=\"description\">" + |
| 670 RECIPE_DESCRIPTION + "</h2>" + |
| 671 "<a itemprop=\"url\" href=\"" + RECIPE_URL + "\">" + |
| 672 "test results" + "</a>" + |
| 673 "<img itemprop=\"image\" src=\"" + |
| 674 RECIPE_IMAGE_URL + "\" />" + |
| 675 "<div itemprop=\"author\">Whoever authored</div>" + |
| 676 "<div itemprop=\"recipeYield\" content=\"4\">" + |
| 677 "4 servings</div>" + |
| 678 "<time itemprop=\"prepTime\" datetime=\"PT15M\">" + |
| 679 "15 Minutes" + "</time>" + |
| 680 "<time itemprop=\"cookTime\" datetime=\"PT45M\">" + |
| 681 "45 Minutes" + "</time>" + |
| 682 "<time itemprop=\"totalTime\" datetime=\"PT9H\">" + |
| 683 "9 Hours</time>" + |
| 684 "<span itemprop=\"ingredients\">4 bats</span>" + |
| 685 "<span itemprop=\"ingredients\">1/4 milk</span>" + |
| 686 "<span itemprop=\"recipeInstructions\">" + |
| 687 "Mix everything and wait for cook</span>" + |
| 688 "</div>" + |
| 689 "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" + |
| 690 "<div id=\"2\" " + ITEM_TYPE_PERSON + |
| 691 "itemprop=\"author\">Creator: " + |
| 692 "<span itemprop=\"name\"> User </span>" + |
| 693 "</div>" + |
| 694 "</div>"; |
| 695 |
| 696 Element rootDiv = TestUtil.createDiv(0); |
| 697 rootDiv.setInnerHTML(htmlStr); |
| 698 mBody.appendChild(rootDiv); |
| 699 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); |
| 700 String result = parser.getStructuredData(); |
| 701 |
| 702 assertEquals("", result); |
| 703 } |
| 704 |
| 705 public void testNonEnglishPageSchemaOrgSupport() { |
| 706 String htmlStr = |
| 707 "<div id=\"1\" " + ITEM_TYPE_RECIPE + ">" + |
| 708 "<meta itemprop=\"mainEntityOfPage\" " + |
| 709 "content=\"true\">" + |
| 710 "<h1 itemprop=\"name\">Bat Rice Recipe</h1>" + |
| 711 "<h2 itemprop=\"description\">" + |
| 712 RECIPE_DESCRIPTION + "</h2>" + |
| 713 "<a itemprop=\"url\" href=\"" + RECIPE_URL + "\">" + |
| 714 "test results" + "</a>" + |
| 715 "<img itemprop=\"image\" src=\"" + |
| 716 RECIPE_IMAGE_URL + "\" />" + |
| 717 "<span itemprop=\"recipeInstructions\">" + |
| 718 "Mix everything and wait for cook</span>" + |
| 719 "</div>" + |
| 720 "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" + |
| 721 "<div id=\"2\" " + ITEM_TYPE_PERSON + |
| 722 "itemprop=\"author\">Creator: " + |
| 723 "<span itemprop=\"name\"> User </span>" + |
| 724 "</div>" + |
| 725 "</div>"; |
| 726 |
| 727 Element rootDiv = TestUtil.createDiv(0); |
| 728 rootDiv.setInnerHTML(htmlStr); |
| 729 mBody.appendChild(rootDiv); |
| 730 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); |
| 731 String result = parser.getStructuredData(); |
| 732 assertEquals("", result); |
| 733 } |
| 734 |
| 735 public void testMultipleSchemaOrgWithMainEntity() { |
| 736 String htmlStr = |
| 737 "<div id=\"1\" " + ITEM_TYPE_RECIPE + ">" + |
| 738 "<meta http-equiv=\"Content-Language\" " + |
| 739 "content=\"en_US\">" + |
| 740 "<meta itemprop=\"mainEntityOfPage\" " + |
| 741 "content=\"true\">" + |
| 742 "<h1 itemprop=\"name\">Bat Rice Recipe</h1>" + |
| 743 "<h2 itemprop=\"description\">" + |
| 744 RECIPE_DESCRIPTION + "</h2>" + |
| 745 "<a itemprop=\"url\" href=\"" + RECIPE_URL + "\">" + |
| 746 "test results" + "</a>" + |
| 747 "<img itemprop=\"image\" src=\"" + |
| 748 RECIPE_IMAGE_URL + "\" />" + |
| 749 "<div itemprop=\"author\">Whoever authored</div>" + |
| 750 "<div itemprop=\"recipeYield\" content=\"4\">" + |
| 751 "4 servings</div>" + |
| 752 "<time itemprop=\"prepTime\" datetime=\"PT15M\">" + |
| 753 "15 Minutes" + "</time>" + |
| 754 "<time itemprop=\"cookTime\" datetime=\"PT45M\">" + |
| 755 "45 Minutes" + "</time>" + |
| 756 "<time itemprop=\"totalTime\" datetime=\"PT9H\">" + |
| 757 "9 Hours</time>" + |
| 758 "<span itemprop=\"ingredients\">4 bats</span>" + |
| 759 "<span itemprop=\"ingredients\">1/4 milk</span>" + |
| 760 "<span itemprop=\"recipeInstructions\">" + |
| 761 "Mix everything and wait for cook</span>" + |
| 762 "</div>" + |
| 763 "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" + |
| 764 "<div id=\"2\" " + ITEM_TYPE_PERSON + |
| 765 "itemprop=\"author\">Creator: " + |
| 766 "<span itemprop=\"name\"> User </span>" + |
| 767 "</div>" + |
| 768 "</div>"; |
| 769 |
| 770 Element rootDiv = TestUtil.createDiv(0); |
| 771 rootDiv.setInnerHTML(htmlStr); |
| 772 mBody.appendChild(rootDiv); |
| 773 SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot); |
| 774 String result = parser.getStructuredData(); |
| 775 |
| 776 String expected = |
| 777 "<img src='" + RECIPE_IMAGE_URL + "' />" + |
| 778 "<p>Author: Whoever authored</p><p>Description: " + |
| 779 RECIPE_DESCRIPTION + "</p>" + |
| 780 "<p>Serves: 4 servings</p>" + |
| 781 "<p>Prep time: 15 minute(s)</p>" + |
| 782 "<p>Cook time: 45 minute(s)</p>" + |
| 783 "<p>Total time: 9 hour(s)</p>" + |
| 784 "Ingredients: <ul><li>4 bats</li>" + |
| 785 "<li>1/4 milk</li>" + |
| 786 "</ul><p>Instructions: <br />" + |
| 787 "Mix everything and wait for cook</p>"; |
| 788 assertEquals(expected, result); |
| 789 } |
| 790 |
| 544 public void testGetTitleWhenTheMainArticleDoesntHaveHeadline() { | 791 public void testGetTitleWhenTheMainArticleDoesntHaveHeadline() { |
| 545 String expectedTitle = "This is a headline"; | 792 String expectedTitle = "This is a headline"; |
| 546 String elements = | 793 String elements = |
| 547 "<div itemscope itemtype=\"http://schema.org/Article\" " + | 794 "<div itemscope itemtype=\"http://schema.org/Article\" " + |
| 548 "style=\"width: 200; height: 300\">" + | 795 "style=\"width: 200; height: 300\">" + |
| 549 "<span itemprop=\"name\">A headline</span>" + | 796 "<span itemprop=\"name\">A headline</span>" + |
| 550 "</div>" + | 797 "</div>" + |
| 551 "<div itemscope itemtype=\"http://schema.org/Article\" " + | 798 "<div itemscope itemtype=\"http://schema.org/Article\" " + |
| 552 "style=\"width: 200; height: 400\">" + | 799 "style=\"width: 200; height: 400\">" + |
| 553 "<span itemprop=\"name\">" + expectedTitle + "</span>" + | 800 "<span itemprop=\"name\">" + expectedTitle + "</span>" + |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 } | 849 } |
| 603 | 850 |
| 604 private void setItemScopeAndType(Element e, String type) { | 851 private void setItemScopeAndType(Element e, String type) { |
| 605 e.setAttribute("ITEMSCOPE", ""); | 852 e.setAttribute("ITEMSCOPE", ""); |
| 606 e.setAttribute("ITEMTYPE", "http://schema.org/" + type); | 853 e.setAttribute("ITEMTYPE", "http://schema.org/" + type); |
| 607 } | 854 } |
| 608 | 855 |
| 609 private void setItemProp(Element e, String name) { | 856 private void setItemProp(Element e, String name) { |
| 610 e.setAttribute("itemprop", name); | 857 e.setAttribute("itemprop", name); |
| 611 } | 858 } |
| 612 } | 859 } |
| OLD | NEW |