Chromium Code Reviews| Index: javatests/org/chromium/distiller/SchemaOrgParserAccessorTest.java |
| diff --git a/javatests/org/chromium/distiller/SchemaOrgParserAccessorTest.java b/javatests/org/chromium/distiller/SchemaOrgParserAccessorTest.java |
| index 9675b4928d476a8918401f743eef0de7cd3b07dc..bcf419bfa9fb9180dfe5a74ebf41fcc2301e2802 100644 |
| --- a/javatests/org/chromium/distiller/SchemaOrgParserAccessorTest.java |
| +++ b/javatests/org/chromium/distiller/SchemaOrgParserAccessorTest.java |
| @@ -451,12 +451,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\"" + |
| " itemprop=\"author\">Authors: " + |
| - "<span itemprop=\"name\">" + expectedAuthor + |
| + "<span itemprop=\"name\">Author 1" + |
| "</span>" + |
| "<span itemprop=\"name\">Author 2" + |
| "</span>" + |
| @@ -541,6 +541,217 @@ public class SchemaOrgParserAccessorTest extends DomDistillerJsTestCase { |
| link.removeFromParent(); |
| } |
| + public void testSingleRecipe() { |
| + String htmlStr = |
| + "<div id=\"1\" itemscope itemtype=\"http://schema.org/Recipe\">" + |
|
wychen
2016/03/14 22:58:42
Lots of duplicated text here. Maybe saving the com
|
| + "<h1 itemprop=\"name\">Bat Rice Recipe</h1>" + |
| + "<h2 itemprop=\"description\">" + |
| + "Testing RECIPE with required recipe schema.org attributes" + |
| + "</h2>" + |
| + "<a itemprop=\"url\" " + |
| + "href=\"http://dummy/test_article_with_embedded_items.html\">" + |
| + "test results" + "</a>" + |
| + "<img itemprop=\"image\" " + |
| + "src=\"http://dummy/test_article_with_embedded_items.jpeg\" />" + |
| + "<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=\"ingredients\">1 rice</span>" + |
| + "<span itemprop=\"ingredients\">1 salt</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='http://dummy/test_article_with_embedded_items.jpeg' />" + |
| + "<p>Author: Whoever authored</p><p>Description: " + |
| + "Testing RECIPE with required recipe schema.org attributes</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>" + |
| + "<li>1 rice</li>" + |
| + "<li>1 salt</li>" + |
| + "</ul><p>Instructions: <br />" + |
| + "Mix everything and wait for cook</p>"; |
| + assertEquals(expected, result); |
| + } |
| + |
| + public void testSingleRecipeWithEmbeddedPerson() { |
| + String htmlStr = |
| + "<div id=\"1\" itemscope itemtype=\"http://schema.org/Recipe\">" + |
| + "<h1 itemprop=\"name\">Bat Rice Recipe</h1>" + |
| + "<h2 itemprop=\"description\">" + |
| + "Testing RECIPE with required recipe schema.org attributes</h2>" + |
| + "<a itemprop=\"url\" href=\"" + |
| + "http://dummy/test_article_with_embedded_items.html\">" + |
| + "test results" + "</a>" + |
| + "<img itemprop=\"image\" " + |
| + "src=\"http://dummy/test_article_with_embedded_items.jpeg\" />" + |
| + "<span itemprop=\"author\" " + |
| + "itemscope itemtype=\"http://schema.org/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=\"ingredients\">1 rice</span>" + |
| + "<span itemprop=\"ingredients\">1 salt</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='http://dummy/test_article_with_embedded_items.jpeg' />" + |
| + "<p>Author: <span>Guest Smith</span></p>" + |
| + "<p>Description: " + |
| + "Testing RECIPE with required recipe schema.org attributes</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>" + |
| + "<li>1 rice</li>" + |
| + "<li>1 salt</li>" + |
| + "</ul><p>Instructions: <br />" + |
| + "Mix everything and wait for cook</p>"; |
| + assertEquals(expected, result); |
| + } |
| + |
| + public void testMoreThanOneSchemaOrg() { |
| + String htmlStr = |
| + "<div id=\"1\" itemscope itemtype=\"http://schema.org/Recipe\">" + |
| + "<h1 itemprop=\"name\">Bat Rice Recipe</h1>" + |
| + "<h2 itemprop=\"description\">" + |
| + "Testing RECIPE with required recipe schema.org attributes" + |
| + "</h2>" + |
| + "<a itemprop=\"url\" href=\"" + |
| + "http://dummy/test_article_with_embedded_items.html\">" + |
| + "test results" + "</a>" + |
| + "<img itemprop=\"image\" src=\"" + |
| + "http://dummy/test_article_with_embedded_items.jpeg\" />" + |
| + "<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=\"ingredients\">1 rice</span>" + |
| + "<span itemprop=\"ingredients\">1 salt</span>" + |
| + "<span itemprop=\"recipeInstructions\">" + |
| + "Mix everything and wait for cook</span>" + |
| + "</div>" + |
| + "<div id=\"1\" itemscope itemtype=\"http://schema.org/Article\">" + |
| + "<div id=\"2\" itemscope itemtype=\"http://schema.org/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\" itemscope itemtype=\"http://schema.org/Recipe\">" + |
| + "<meta itemprop=\"mainEntityOfPage\" content=\"true\">" + |
| + "<h1 itemprop=\"name\">Bat Rice Recipe</h1>" + |
| + "<h2 itemprop=\"description\">" + |
| + "Testing RECIPE with required recipe schema.org attributes" + |
| + "</h2>" + |
| + "<a itemprop=\"url\" href=\"" + |
| + "http://dummy/test_article_with_embedded_items.html\">" + |
| + "test results" + "</a>" + |
| + "<img itemprop=\"image\" src=\"" + |
| + "http://dummy/test_article_with_embedded_items.jpeg\" />" + |
| + "<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=\"ingredients\">1 rice</span>" + |
| + "<span itemprop=\"ingredients\">1 salt</span>" + |
| + "<span itemprop=\"recipeInstructions\">" + |
| + "Mix everything and wait for cook</span>" + |
| + "</div>" + |
| + "<div id=\"1\" itemscope itemtype=\"http://schema.org/Article\">" + |
| + "<div id=\"2\" itemscope itemtype=\"http://schema.org/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='http://dummy/test_article_with_embedded_items.jpeg' />" + |
| + "<p>Author: Whoever authored</p><p>Description: " + |
| + "Testing RECIPE with required recipe schema.org attributes" + |
| + "</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>" + |
| + "<li>1 rice</li>" + |
| + "<li>1 salt</li>" + |
| + "</ul><p>Instructions: <br />" + |
| + "Mix everything and wait for cook</p>"; |
| + assertEquals(expected, result); |
| + } |
| + |
| private void setItemScopeAndType(Element e, String type) { |
| e.setAttribute("ITEMSCOPE", ""); |
| e.setAttribute("ITEMTYPE", "http://schema.org/" + type); |