Chromium Code Reviews| Index: javatests/org/chromium/distiller/ContentExtractorTest.java |
| diff --git a/javatests/org/chromium/distiller/ContentExtractorTest.java b/javatests/org/chromium/distiller/ContentExtractorTest.java |
| index 63d349c923a4c341670a5bd85a4632cab8903c8f..5b5154da9071ba818d2dd70e0526f0f0c53a0ed2 100644 |
| --- a/javatests/org/chromium/distiller/ContentExtractorTest.java |
| +++ b/javatests/org/chromium/distiller/ContentExtractorTest.java |
| @@ -143,6 +143,206 @@ public class ContentExtractorTest extends DomDistillerJsTestCase { |
| TestUtil.removeAllDirAttributes(extractedContent)); |
| } |
| + public void testPreserveOrderedList() { |
| + Element outerListTag = Document.get().createElement("OL"); |
| + mBody.appendChild(outerListTag); |
| + |
| + outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + |
| + ContentExtractor extractor = new ContentExtractor(mRoot); |
| + String extractedContent = extractor.extractContent(); |
| + assertEquals("<ol>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "</ol>", |
| + TestUtil.removeAllDirAttributes(extractedContent)); |
| + } |
| + |
| + public void testPreserveNestedOrderedList() { |
| + Element outerListTag = Document.get().createElement("OL"); |
| + Element outerListItem = Document.get().createElement("LI"); |
| + |
| + Element innerListTag = Document.get().createElement("OL"); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + |
| + outerListItem.appendChild(innerListTag); |
| + outerListTag.appendChild(outerListItem); |
| + outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + |
| + mBody.appendChild(outerListTag); |
| + ContentExtractor extractor = new ContentExtractor(mRoot); |
| + String extractedContent = extractor.extractContent(); |
| + assertEquals("<ol>" + |
| + "<li>" + |
| + "<ol>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
|
wychen
2015/08/01 01:00:20
nitpick: nested html would be more readable if ind
|
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "</ol>" + |
| + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "</ol>", |
| + TestUtil.removeAllDirAttributes(extractedContent)); |
| + } |
| + |
| + public void testPreserveNestedOrderedListWithOtherElementsInside() { |
| + Element outerListTag = Document.get().createElement("OL"); |
| + Element outerListItem = Document.get().createElement("LI"); |
| + outerListItem.appendChild(TestUtil.createText(CONTENT_TEXT)); |
| + outerListItem.appendChild(TestUtil.createParagraph(CONTENT_TEXT)); |
| + |
| + Element innerListTag = Document.get().createElement("OL"); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + innerListTag.appendChild(TestUtil.createParagraph("")); |
| + |
| + outerListItem.appendChild(innerListTag); |
| + outerListTag.appendChild(outerListItem); |
| + outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + outerListTag.appendChild(TestUtil.createParagraph(CONTENT_TEXT)); |
| + |
| + mBody.appendChild(outerListTag); |
| + ContentExtractor extractor = new ContentExtractor(mRoot); |
| + String extractedContent = extractor.extractContent(); |
| + assertEquals("<ol>" + |
| + "<li>" + CONTENT_TEXT + |
| + "<p>" + CONTENT_TEXT + "</p>" + |
| + "<ol>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "</ol>" + |
| + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<p>" + CONTENT_TEXT + "</p>" + |
| + "</ol>", |
| + TestUtil.removeAllDirAttributes(extractedContent)); |
| + } |
| + |
| + public void testPreserveUnorderedList() { |
| + Element outerListTag = Document.get().createElement("UL"); |
| + mBody.appendChild(outerListTag); |
| + |
| + outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + |
| + ContentExtractor extractor = new ContentExtractor(mRoot); |
| + String extractedContent = extractor.extractContent(); |
| + assertEquals("<ul>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "</ul>", |
| + TestUtil.removeAllDirAttributes(extractedContent)); |
| + } |
| + |
| + public void testPreserveNestedUnorderedList() { |
|
wychen
2015/08/01 01:00:20
We can also create a test with malformed html, by
|
| + Element outerListTag = Document.get().createElement("UL"); |
| + Element outerListItem = Document.get().createElement("LI"); |
| + |
| + Element innerListTag = Document.get().createElement("UL"); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + |
| + outerListItem.appendChild(innerListTag); |
| + outerListTag.appendChild(outerListItem); |
| + outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + |
| + mBody.appendChild(outerListTag); |
| + ContentExtractor extractor = new ContentExtractor(mRoot); |
| + String extractedContent = extractor.extractContent(); |
| + assertEquals("<ul>" + |
| + "<li>" + |
| + "<ul>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "</ul>" + |
| + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "</ul>", |
| + TestUtil.removeAllDirAttributes(extractedContent)); |
| + } |
| + |
| + public void testPreserveNestedUnorderedListWithOtherElementsInside() { |
| + Element outerListTag = Document.get().createElement("UL"); |
| + Element outerListItem = Document.get().createElement("LI"); |
| + outerListItem.appendChild(TestUtil.createText(CONTENT_TEXT)); |
| + outerListItem.appendChild(TestUtil.createParagraph(CONTENT_TEXT)); |
| + |
| + Element innerListTag = Document.get().createElement("UL"); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + innerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + innerListTag.appendChild(TestUtil.createParagraph("")); |
| + |
| + outerListItem.appendChild(innerListTag); |
| + outerListTag.appendChild(outerListItem); |
| + outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + outerListTag.appendChild(TestUtil.createParagraph(CONTENT_TEXT)); |
| + |
| + mBody.appendChild(outerListTag); |
| + ContentExtractor extractor = new ContentExtractor(mRoot); |
| + String extractedContent = extractor.extractContent(); |
| + assertEquals("<ul>" + |
| + "<li>" + CONTENT_TEXT + |
| + "<p>" + CONTENT_TEXT + "</p>" + |
| + "<ul>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "</ul>" + |
| + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<p>" + CONTENT_TEXT + "</p>" + |
| + "</ul>", |
| + TestUtil.removeAllDirAttributes(extractedContent)); |
| + } |
| + |
| + public void testPreserveUnorderedListWithNestedOrderedList() { |
| + Element unorderedListTag = Document.get().createElement("UL"); |
| + Element li = Document.get().createElement("LI"); |
| + Element orderedList = Document.get().createElement("OL"); |
| + orderedList.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + orderedList.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + li.appendChild(orderedList); |
| + unorderedListTag.appendChild(li); |
| + unorderedListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
| + mBody.appendChild(unorderedListTag); |
| + ContentExtractor extractor = new ContentExtractor(mRoot); |
| + String extractedContent = extractor.extractContent(); |
| + assertEquals("<ul>" + |
| + "<li>" + |
| + "<ol>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "</ol>" + |
| + "</li>" + |
| + "<li>" + CONTENT_TEXT + "</li>" + |
| + "</ul>", |
| + TestUtil.removeAllDirAttributes(extractedContent)); |
| + } |
| + |
| private void assertExtractor(String expected, String html) { |
| mBody.setInnerHTML(""); |
| Element div = TestUtil.createDiv(0); |