Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Unified Diff: javatests/org/chromium/distiller/SchemaOrgParserAccessorTest.java

Issue 1705123002: Add support for Schema.org/Recipe Base URL: https://github.com/chromium/dom-distiller.git@master
Patch Set: wychen's comments addressed Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: javatests/org/chromium/distiller/SchemaOrgParserAccessorTest.java
diff --git a/javatests/org/chromium/distiller/SchemaOrgParserAccessorTest.java b/javatests/org/chromium/distiller/SchemaOrgParserAccessorTest.java
index eca7267b06f30ec5483a2f76055f25ad11d46e5b..6d10fc9f0fe84a79d19335a1a605040455e279d7 100644
--- a/javatests/org/chromium/distiller/SchemaOrgParserAccessorTest.java
+++ b/javatests/org/chromium/distiller/SchemaOrgParserAccessorTest.java
@@ -9,19 +9,42 @@ import com.google.gwt.dom.client.Element;
public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
+ private static final String ITEM_TYPE = "itemscope itemtype=\"" +
+ "http://schema.org/";
+ private static final String ITEM_TYPE_ARTICLE = ITEM_TYPE +
+ "Article\"";
+ private static final String ITEM_TYPE_PERSON = ITEM_TYPE +
+ "Person\"";
+ private static final String ITEM_TYPE_RECIPE = ITEM_TYPE +
+ "Recipe\"";
+ private static final String ITEM_TYPE_MOVIE = ITEM_TYPE +
+ "Movie\"";
+ private static final String ITEM_TYPE_IMAGE_OBJECT = ITEM_TYPE +
+ "ImageObject\"";
+ private static final String ITEM_TYPE_ORGANIZATION = ITEM_TYPE +
+ "Organization\"";
+ private static final String ITEM_TYPE_AGGREGATE_RATING =
+ ITEM_TYPE + "AggregateRating\"";
+ private static final String RECIPE_DESCRIPTION =
+ "Testing RECIPE with required recipe schema.org attributes";
+ private static final String RECIPE_URL =
+ "http://dummy/test_article_with_embedded_items.html";
+ private static final String RECIPE_IMAGE_URL =
+ "http://dummy/test_article_with_embedded_items.jpeg";
+
public void testImageWithEmbeddedPublisher() {
String expectedUrl = "http://dummy/test_image_with_embedded_item.html";
String expectedFormat = "jpeg";
String expectedCaption = "A test for IMAGE with embedded publisher";
String htmlStr =
- "<div id=\"1\" itemscope itemtype=\"http://schema.org/ImageObject\">" +
+ "<div id=\"1\" " + ITEM_TYPE_IMAGE_OBJECT + ">" +
"<h1 itemprop=\"headline\">Testcase for IMAGE" +
"</h1>" +
"<h2 itemprop=\"description\">Testing IMAGE with embedded publisher" +
"</h2>" +
"<a itemprop=\"contentUrl\" href=\"" + expectedUrl + "\">test results" +
"</a>" +
- "<div id=\"2\" itemscope itemtype=\"http://schema.org/Organization\"" +
+ "<div id=\"2\"" + ITEM_TYPE_ORGANIZATION + "" +
" itemprop=\"publisher\">Publisher: " +
"<span itemprop=\"name\">Whatever Image Incorporated" +
"</span>" +
@@ -74,7 +97,7 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
String expectedFormat2 = "gif";
String expectedCaption2 = "A test for 2nd IMAGE";
String htmlStr =
- "<div id=\"1\" itemscope itemtype=\"http://schema.org/ImageObject\">" +
+ "<div id=\"1\" " + ITEM_TYPE_IMAGE_OBJECT + ">" +
"<h1 itemprop=\"headline\">Testcase for 1st IMAGE" +
"</h1>" +
"<h2 itemprop=\"description\">Testing 1st IMAGE" +
@@ -97,7 +120,7 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
"<meta itemprop=\"width\" content=\"400\">" +
"<meta itemprop=\"height\" content=\"300\">" +
"</div>" +
- "<div id=\"4\" itemscope itemtype=\"http://schema.org/ImageObject\">" +
+ "<div id=\"4\" " + ITEM_TYPE_IMAGE_OBJECT + ">" +
"<h3 itemprop=\"headline\">Testcase for 2nd IMAGE" +
"</h3>" +
"<h4 itemprop=\"description\">Testing 2nd IMAGE" +
@@ -160,8 +183,6 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
public void testArticleWithEmbeddedAuthorAndPublisher() {
String expectedTitle = "Testcase for ARTICLE";
String expectedDescription = "Testing ARTICLE with embedded author and publisher";
- String expectedUrl = "http://dummy/test_article_with_embedded_items.html";
- String expectedImage = "http://dummy/test_article_with_embedded_items.jpeg";
String expectedAuthor = "Whoever authored";
String expectedPublisher = "Whatever Article Incorporated";
String expectedDatePublished = "April 15, 2014";
@@ -170,20 +191,20 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
String expectedCopyrightHolder = "Whoever Article Copyrighted";
String expectedSection = "Romance thriller";
String htmlStr =
- "<div id=\"1\" itemscope itemtype=\"http://schema.org/Article\">" +
+ "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" +
"<h1 itemprop=\"headline\">" + expectedTitle +
"</h1>" +
"<h2 itemprop=\"description\">" + expectedDescription +
"</h2>" +
- "<a itemprop=\"url\" href=\"" + expectedUrl + "\">test results" +
+ "<a itemprop=\"url\" href=\"" + RECIPE_URL + "\">test results" +
"</a>" +
- "<img itemprop=\"image\" src=\"" + expectedImage + "\">" +
- "<div id=\"2\" itemscope itemtype=\"http://schema.org/Person\"" +
+ "<img itemprop=\"image\" src=\"" + RECIPE_IMAGE_URL + "\">" +
+ "<div id=\"2\" " + ITEM_TYPE_PERSON +
" itemprop=\"author\">Author: " +
"<span itemprop=\"name\">" + expectedAuthor +
"</span>" +
"</div>" +
- "<div id=\"3\" itemscope itemtype=\"http://schema.org/Organization\"" +
+ "<div id=\"3\"" + ITEM_TYPE_ORGANIZATION + "" +
" itemprop=\"publisher\">Publisher: " +
"<span itemprop=\"name\">" + expectedPublisher +
"</span>" +
@@ -209,14 +230,14 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
assertEquals("Article", parser.getType());
assertEquals(expectedTitle, parser.getTitle());
assertEquals(expectedDescription, parser.getDescription());
- assertEquals(expectedUrl, parser.getUrl());
+ assertEquals(RECIPE_URL, parser.getUrl());
assertEquals(expectedAuthor, parser.getAuthor());
assertEquals(expectedPublisher, parser.getPublisher());
assertEquals( "Copyright " + expectedCopyrightYear + " " + expectedCopyrightHolder,
parser.getCopyright());
MarkupParser.Image[] images = parser.getImages();
assertEquals(1, images.length);
- assertEquals(expectedImage, images[0].url);
+ assertEquals(RECIPE_IMAGE_URL, images[0].url);
MarkupParser.Article article = parser.getArticle();
assertEquals(expectedDatePublished, article.publishedTime);
assertEquals(expectedTimeModified, article.modifiedTime);
@@ -237,7 +258,7 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
String expectedFormat2 = "jpeg";
String expectedCaption2 = "A test for emedded IMAGE in ARTICLE";
String htmlStr =
- "<div id=\"1\" itemscope itemtype=\"http://schema.org/ImageObject\">" +
+ "<div id=\"1\" " + ITEM_TYPE_IMAGE_OBJECT + ">" +
"<span itemprop=\"headline\">Title should be ignored" +
"</span>" +
"<span itemprop=\"description\">Testing top-level IMAGE" +
@@ -254,7 +275,7 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
"<meta itemprop=\"width\" content=\"1000\">" +
"<meta itemprop=\"height\" content=\"600\">" +
"</div>" +
- "<div id=\"2\" itemscope itemtype=\"http://schema.org/Article\">" +
+ "<div id=\"2\" " + ITEM_TYPE_ARTICLE + ">" +
"<span itemprop=\"headline\">" + expectedTitle +
"</span>" +
"<span itemprop=\"description\">" + expectedDescription +
@@ -262,7 +283,7 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
"<a itemprop=\"url\" href=\"" + expectedUrl + "\">test results" +
"</a>" +
"<img itemprop=\"image\" src=\"http://dummy/should_be_ignored_image.jpeg\">" +
- "<div id=\"3\" itemscope itemtype=\"http://schema.org/ImageObject\"" +
+ "<div id=\"3\" " + ITEM_TYPE_IMAGE_OBJECT + "" +
" itemprop=\"associatedMedia\">" +
"<a itemprop=\"url\" href=\"" + expectedImage2 + "\">associated image" +
"</a>" +
@@ -326,18 +347,18 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
String expectedTitle = "Testcase for Supported With Unsupported Itemprop";
String expectedSection = "Testing";
String htmlStr =
- "<div id=\"1\" itemscope itemtype=\"http://schema.org/Article\">" +
+ "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" +
"<span itemprop=\"headline\">" + expectedTitle +
"</span>" +
"<span itemprop=\"articleSection\">" + expectedSection +
"</span>" +
// Add unsupported AggregateRating to supported Article as itemprop.
- "<div id=\"2\" itemscope itemtype=\"http://schema.org/AggregateRating\"" +
+ "<div id=\"2\" " + ITEM_TYPE_AGGREGATE_RATING + "" +
" itemprop=\"aggregateRating\">Ratings: " +
"<span itemprop=\"ratingValue\">9.9" +
"</span>" +
// Add supported Person to unsupported AggregateRating as itemprop.
- "<div id=\"3\" itemscope itemtype=\"http://schema.org/Person\"" +
+ "<div id=\"3\" " + ITEM_TYPE_PERSON +
" itemprop=\"author\">Author: " +
"<span itemprop=\"name\">Whoever authored" +
"</span>" +
@@ -367,11 +388,11 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
public void testUnsupportedWithSupportedItemprop() {
String htmlStr =
- "<div id=\"1\" itemscope itemtype=\"http://schema.org/Movie\">" +
+ "<div id=\"1\" " + ITEM_TYPE_MOVIE + ">" +
"<span itemprop=\"headline\">Testcase for Unsupported With Supported Itemprop" +
"</span>" +
// Add supported Person to unsupported Movie as itemprop.
- "<div id=\"3\" itemscope itemtype=\"http://schema.org/Person\"" +
+ "<div id=\"3\" " + ITEM_TYPE_PERSON +
" itemprop=\"publisher\">Publisher: " +
"<span itemprop=\"name\">Whoever published" +
"</span>" +
@@ -396,30 +417,28 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
public void testUnsupportedWithNestedSupported() {
String expectedTitle = "Testcase for ARTICLE nested in Unsupported Type";
String expectedDescription = "Testing ARTICLE that is nested within unsupported type";
- String expectedUrl = "http://dummy/test_article_with_embedded_items.html";
- String expectedImage = "http://dummy/test_article_with_embedded_items.jpeg";
String expectedAuthor = "Whoever authored";
String expectedPublisher = "Whatever Article Incorporated";
String expectedDatePublished = "April 15, 2014";
String htmlStr =
- "<div id=\"1\" itemscope itemtype=\"http://schema.org/Movie\">" +
+ "<div id=\"1\" " + ITEM_TYPE_MOVIE + ">" +
"<span itemprop=\"headline\">Testcase for Unsupported With Supported Itemprop" +
"</span>" +
// Add supported Article to unsupported Movie as a non-itemprop.
- "<div id=\"2\" itemscope itemtype=\"http://schema.org/Article\">" +
+ "<div id=\"2\" " + ITEM_TYPE_ARTICLE + ">" +
"<span itemprop=\"headline\">" + expectedTitle +
"</span>" +
"<span itemprop=\"description\">" + expectedDescription +
"</span>" +
- "<a itemprop=\"url\" href=\"" + expectedUrl + "\">test results" +
+ "<a itemprop=\"url\" href=\"" + RECIPE_URL + "\">test results" +
"</a>" +
- "<img itemprop=\"image\" src=\"" + expectedImage + "\">" +
- "<div id=\"3\" itemscope itemtype=\"http://schema.org/Person\"" +
+ "<img itemprop=\"image\" src=\"" + RECIPE_IMAGE_URL + "\">" +
+ "<div id=\"3\" " + ITEM_TYPE_PERSON +
" itemprop=\"author\">Author: " +
"<span itemprop=\"name\">" + expectedAuthor +
"</span>" +
"</div>" +
- "<div id=\"4\" itemscope itemtype=\"http://schema.org/Organization\"" +
+ "<div id=\"4\"" + ITEM_TYPE_ORGANIZATION + "" +
" itemprop=\"publisher\">Publisher: " +
"<span itemprop=\"name\">" + expectedPublisher +
"</span>" +
@@ -436,13 +455,13 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
assertEquals("Article", parser.getType());
assertEquals(expectedTitle, parser.getTitle());
assertEquals(expectedDescription, parser.getDescription());
- assertEquals(expectedUrl, parser.getUrl());
+ assertEquals(RECIPE_URL, parser.getUrl());
assertEquals(expectedAuthor, parser.getAuthor());
assertEquals(expectedPublisher, parser.getPublisher());
assertEquals("", parser.getCopyright());
MarkupParser.Image[] images = parser.getImages();
assertEquals(1, images.length);
- assertEquals(expectedImage, images[0].url);
+ assertEquals(RECIPE_IMAGE_URL, images[0].url);
MarkupParser.Article article = parser.getArticle();
assertEquals(expectedDatePublished, article.publishedTime);
assertEquals("", article.expirationTime);
@@ -451,12 +470,12 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
}
public void testSameItempropDifferentValues() {
- String expectedAuthor = "Author 1";
+ String expectedAuthor = "Author 1, Author 2";
String htmlStr =
- "<div id=\"1\" itemscope itemtype=\"http://schema.org/Article\">" +
- "<div id=\"2\" itemscope itemtype=\"http://schema.org/Person\"" +
+ "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" +
+ "<div id=\"2\" " + ITEM_TYPE_PERSON +
" itemprop=\"author\">Authors: " +
- "<span itemprop=\"name\">" + expectedAuthor +
+ "<span itemprop=\"name\">Author 1" +
"</span>" +
"<span itemprop=\"name\">Author 2" +
"</span>" +
@@ -478,8 +497,8 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
public void testItempropWithMultiProperties() {
String expectedPerson = "Person foo";
String htmlStr =
- "<div id=\"1\" itemscope itemtype=\"http://schema.org/Article\">" +
- "<div id=\"2\" itemscope itemtype=\"http://schema.org/Person\"" +
+ "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" +
+ "<div id=\"2\" " + ITEM_TYPE_PERSON +
" itemprop=\"author publisher\">" +
"<span itemprop=\"name\">" + expectedPerson +
"</span>" +
@@ -503,8 +522,8 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
// Test that "creator" property is used when "author" property doens't exist.
String expectedCreator = "Whoever created";
String htmlStr =
- "<div id=\"1\" itemscope itemtype=\"http://schema.org/Article\">" +
- "<div id=\"2\" itemscope itemtype=\"http://schema.org/Person\"" +
+ "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" +
+ "<div id=\"2\" " + ITEM_TYPE_PERSON +
" itemprop=\"author\">Creator: " +
"<span itemprop=\"name\">" + expectedCreator +
"</span>" +
@@ -541,6 +560,234 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
link.removeFromParent();
}
+ public void testSingleRecipe() {
+ String htmlStr =
+ "<div id=\"1\" " + ITEM_TYPE_RECIPE + ">" +
+ "<meta http-equiv=\"Content-Language\" " +
+ "content=\"en_US\">" +
+ "<h1 itemprop=\"name\">Bat Rice Recipe</h1>" +
+ "<h2 itemprop=\"description\">" +
+ RECIPE_DESCRIPTION + "</h2>" +
+ "<a itemprop=\"url\" " +
+ "href=\"" + RECIPE_URL + "\">" +
+ "test results" + "</a>" +
+ "<img itemprop=\"image\" " +
+ "src=\"" + RECIPE_IMAGE_URL + "\" />" +
+ "<div itemprop=\"author\">Whoever authored</div>" +
+ "<div itemprop=\"recipeYield\" content=\"4\">" +
+ "4 servings</div>" +
+ "<time itemprop=\"prepTime\" datetime=\"PT15M\">" +
+ "15 Minutes" + "</time>" +
+ "<time itemprop=\"cookTime\" datetime=\"PT45M\">" +
+ "45 Minutes" + "</time>" +
+ "<time itemprop=\"totalTime\" datetime=\"PT9H\">" +
+ "9 Hours</time>" +
+ "<span itemprop=\"ingredients\">4 bats</span>" +
+ "<span itemprop=\"ingredients\">1/4 milk</span>" +
+ "<span itemprop=\"recipeInstructions\">" +
+ "Mix everything and wait for cook</span>" +
+ "</div>";
+
+ Element rootDiv = TestUtil.createDiv(0);
+ rootDiv.setInnerHTML(htmlStr);
+ mBody.appendChild(rootDiv);
+ SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot);
+ String result = parser.getStructuredData();
+
+ String expected =
+ "<img src='" + RECIPE_IMAGE_URL + "' />" +
+ "<p>Author: Whoever authored</p><p>Description: " +
+ RECIPE_DESCRIPTION + "</p>" +
+ "<p>Serves: 4 servings</p>" +
+ "<p>Prep time: 15 minute(s)</p>" +
+ "<p>Cook time: 45 minute(s)</p>" +
+ "<p>Total time: 9 hour(s)</p>" +
+ "Ingredients: <ul><li>4 bats</li>" +
+ "<li>1/4 milk</li>" +
+ "</ul><p>Instructions: <br />" +
+ "Mix everything and wait for cook</p>";
+ assertEquals(expected, result);
+ }
+
+ public void testSingleRecipeWithEmbeddedPerson() {
+ String htmlStr =
+ "<div id=\"1\" " + ITEM_TYPE_RECIPE + ">" +
+ "<h1 itemprop=\"name\">Bat Rice Recipe</h1>" +
+ "<h2 itemprop=\"description\">" +
+ RECIPE_DESCRIPTION + "</h2>" +
+ "<a itemprop=\"url\" href=\"" + RECIPE_URL + "\">" +
+ "test results" + "</a>" +
+ "<img itemprop=\"image\" " +
+ "src=\"" + RECIPE_IMAGE_URL + "\" />" +
+ "<span itemprop=\"author\" " + ITEM_TYPE_PERSON + ">" +
+ "<span itemprop=\"givenName\">Guest</span>" +
+ "<span itemprop=\"familyName\">Smith</span>" +
+ "</span>" +
+ "<div itemprop=\"recipeYield\" content=\"4\">" +
+ "4 servings</div>" +
+ "<time itemprop=\"prepTime\" datetime=\"PT15M\">1" +
+ "5 Minutes" + "</time>" +
+ "<time itemprop=\"cookTime\" datetime=\"PT45M\">" +
+ "45 Minutes" + "</time>" +
+ "<time itemprop=\"totalTime\" datetime=\"PT9H\">" +
+ "9 Hours</time>" +
+ "<span itemprop=\"ingredients\">4 bats</span>" +
+ "<span itemprop=\"ingredients\">1/4 milk</span>" +
+ "<span itemprop=\"recipeInstructions\">" +
+ "Mix everything and wait for cook</span>" +
+ "</div>";
+
+ Element rootDiv = TestUtil.createDiv(0);
+ rootDiv.setInnerHTML(htmlStr);
+ mRoot.setAttribute("lang", "en");
+ mBody.appendChild(rootDiv);
+ SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot);
+ String result = parser.getStructuredData();
+
+ String expected =
+ "<img src='" + RECIPE_IMAGE_URL + "' />" +
+ "<p>Author: <span>Guest Smith</span></p>" +
+ "<p>Description: " +
+ RECIPE_DESCRIPTION + "</p>" +
+ "<p>Serves: 4 servings</p>" +
+ "<p>Prep time: 15 minute(s)</p>" +
+ "<p>Cook time: 45 minute(s)</p>" +
+ "<p>Total time: 9 hour(s)</p>" +
+ "Ingredients: <ul><li>4 bats</li>" +
+ "<li>1/4 milk</li>" +
+ "</ul><p>Instructions: <br />" +
+ "Mix everything and wait for cook</p>";
+ assertEquals(expected, result);
+ }
+
+ public void testMoreThanOneSchemaOrg() {
+ String htmlStr =
+ "<div id=\"1\" " + ITEM_TYPE_RECIPE + ">" +
+ "<h1 itemprop=\"name\">Bat Rice Recipe</h1>" +
+ "<meta name=\"Language\" " +
+ "content=\"en_US\">" +
+ "<h2 itemprop=\"description\">" +
+ RECIPE_DESCRIPTION + "</h2>" +
+ "<a itemprop=\"url\" href=\"" + RECIPE_URL + "\">" +
+ "test results" + "</a>" +
+ "<img itemprop=\"image\" src=\"" +
+ RECIPE_IMAGE_URL + "\" />" +
+ "<div itemprop=\"author\">Whoever authored</div>" +
+ "<div itemprop=\"recipeYield\" content=\"4\">" +
+ "4 servings</div>" +
+ "<time itemprop=\"prepTime\" datetime=\"PT15M\">" +
+ "15 Minutes" + "</time>" +
+ "<time itemprop=\"cookTime\" datetime=\"PT45M\">" +
+ "45 Minutes" + "</time>" +
+ "<time itemprop=\"totalTime\" datetime=\"PT9H\">" +
+ "9 Hours</time>" +
+ "<span itemprop=\"ingredients\">4 bats</span>" +
+ "<span itemprop=\"ingredients\">1/4 milk</span>" +
+ "<span itemprop=\"recipeInstructions\">" +
+ "Mix everything and wait for cook</span>" +
+ "</div>" +
+ "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" +
+ "<div id=\"2\" " + ITEM_TYPE_PERSON +
+ "itemprop=\"author\">Creator: " +
+ "<span itemprop=\"name\"> User </span>" +
+ "</div>" +
+ "</div>";
+
+ Element rootDiv = TestUtil.createDiv(0);
+ rootDiv.setInnerHTML(htmlStr);
+ mBody.appendChild(rootDiv);
+ SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot);
+ String result = parser.getStructuredData();
+
+ assertEquals("", result);
+ }
+
+ public void testNonEnglishPageSchemaOrgSupport() {
+ String htmlStr =
+ "<div id=\"1\" " + ITEM_TYPE_RECIPE + ">" +
+ "<meta itemprop=\"mainEntityOfPage\" " +
+ "content=\"true\">" +
+ "<h1 itemprop=\"name\">Bat Rice Recipe</h1>" +
+ "<h2 itemprop=\"description\">" +
+ RECIPE_DESCRIPTION + "</h2>" +
+ "<a itemprop=\"url\" href=\"" + RECIPE_URL + "\">" +
+ "test results" + "</a>" +
+ "<img itemprop=\"image\" src=\"" +
+ RECIPE_IMAGE_URL + "\" />" +
+ "<span itemprop=\"recipeInstructions\">" +
+ "Mix everything and wait for cook</span>" +
+ "</div>" +
+ "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" +
+ "<div id=\"2\" " + ITEM_TYPE_PERSON +
+ "itemprop=\"author\">Creator: " +
+ "<span itemprop=\"name\"> User </span>" +
+ "</div>" +
+ "</div>";
+
+ Element rootDiv = TestUtil.createDiv(0);
+ rootDiv.setInnerHTML(htmlStr);
+ mBody.appendChild(rootDiv);
+ SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot);
+ String result = parser.getStructuredData();
+ assertEquals("", result);
+ }
+
+ public void testMultipleSchemaOrgWithMainEntity() {
+ String htmlStr =
+ "<div id=\"1\" " + ITEM_TYPE_RECIPE + ">" +
+ "<meta http-equiv=\"Content-Language\" " +
+ "content=\"en_US\">" +
+ "<meta itemprop=\"mainEntityOfPage\" " +
+ "content=\"true\">" +
+ "<h1 itemprop=\"name\">Bat Rice Recipe</h1>" +
+ "<h2 itemprop=\"description\">" +
+ RECIPE_DESCRIPTION + "</h2>" +
+ "<a itemprop=\"url\" href=\"" + RECIPE_URL + "\">" +
+ "test results" + "</a>" +
+ "<img itemprop=\"image\" src=\"" +
+ RECIPE_IMAGE_URL + "\" />" +
+ "<div itemprop=\"author\">Whoever authored</div>" +
+ "<div itemprop=\"recipeYield\" content=\"4\">" +
+ "4 servings</div>" +
+ "<time itemprop=\"prepTime\" datetime=\"PT15M\">" +
+ "15 Minutes" + "</time>" +
+ "<time itemprop=\"cookTime\" datetime=\"PT45M\">" +
+ "45 Minutes" + "</time>" +
+ "<time itemprop=\"totalTime\" datetime=\"PT9H\">" +
+ "9 Hours</time>" +
+ "<span itemprop=\"ingredients\">4 bats</span>" +
+ "<span itemprop=\"ingredients\">1/4 milk</span>" +
+ "<span itemprop=\"recipeInstructions\">" +
+ "Mix everything and wait for cook</span>" +
+ "</div>" +
+ "<div id=\"1\" " + ITEM_TYPE_ARTICLE + ">" +
+ "<div id=\"2\" " + ITEM_TYPE_PERSON +
+ "itemprop=\"author\">Creator: " +
+ "<span itemprop=\"name\"> User </span>" +
+ "</div>" +
+ "</div>";
+
+ Element rootDiv = TestUtil.createDiv(0);
+ rootDiv.setInnerHTML(htmlStr);
+ mBody.appendChild(rootDiv);
+ SchemaOrgParserAccessor parser = new SchemaOrgParserAccessor(mRoot);
+ String result = parser.getStructuredData();
+
+ String expected =
+ "<img src='" + RECIPE_IMAGE_URL + "' />" +
+ "<p>Author: Whoever authored</p><p>Description: " +
+ RECIPE_DESCRIPTION + "</p>" +
+ "<p>Serves: 4 servings</p>" +
+ "<p>Prep time: 15 minute(s)</p>" +
+ "<p>Cook time: 45 minute(s)</p>" +
+ "<p>Total time: 9 hour(s)</p>" +
+ "Ingredients: <ul><li>4 bats</li>" +
+ "<li>1/4 milk</li>" +
+ "</ul><p>Instructions: <br />" +
+ "Mix everything and wait for cook</p>";
+ assertEquals(expected, result);
+ }
+
public void testGetTitleWhenTheMainArticleDoesntHaveHeadline() {
String expectedTitle = "This is a headline";
String elements =
@@ -609,4 +856,4 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase {
private void setItemProp(Element e, String name) {
e.setAttribute("itemprop", name);
}
-}
+}

Powered by Google App Engine
This is Rietveld 408576698