| 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 com.dom_distiller.client; | 5 package com.dom_distiller.client; |
| 6 | 6 |
| 7 import com.google.gwt.dom.client.Document; | 7 import com.google.gwt.dom.client.Document; |
| 8 import com.google.gwt.dom.client.Element; | 8 import com.google.gwt.dom.client.Element; |
| 9 | 9 |
| 10 public class ContentExtractorTest extends DomDistillerTestCase { | 10 public class ContentExtractorTest extends DomDistillerTestCase { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 contentDiv = TestUtil.createDiv(3); | 28 contentDiv = TestUtil.createDiv(3); |
| 29 contentDiv.appendChild(TestUtil.createText(CONTENT_TEXT)); | 29 contentDiv.appendChild(TestUtil.createText(CONTENT_TEXT)); |
| 30 | 30 |
| 31 mBody.appendChild(contentDiv); | 31 mBody.appendChild(contentDiv); |
| 32 | 32 |
| 33 // Title hasn't been set yet, everything should be content. | 33 // Title hasn't been set yet, everything should be content. |
| 34 ContentExtractor extractor = new ContentExtractor(mRoot); | 34 ContentExtractor extractor = new ContentExtractor(mRoot); |
| 35 String extractedContent = extractor.extractContent(); | 35 String extractedContent = extractor.extractContent(); |
| 36 assertTrue(extractedContent + " must contain 'content':" + CONTENT_TEXT, | 36 assertTrue(extractedContent + " must contain 'content':" + CONTENT_TEXT, |
| 37 extractedContent.contains(contentDiv.getInnerText())); | 37 extractedContent.contains(DomUtil.getInnerText(contentDiv))); |
| 38 assertTrue( | 38 assertTrue( |
| 39 extractedContent + " must contain 'title':" + TITLE_TEXT, | 39 extractedContent + " must contain 'title':" + TITLE_TEXT, |
| 40 extractedContent.contains(titleDiv.getInnerText())); | 40 extractedContent.contains(DomUtil.getInnerText(titleDiv))); |
| 41 | 41 |
| 42 // Now set the title and it should excluded from the content. | 42 // Now set the title and it should excluded from the content. |
| 43 mHead.appendChild(TestUtil.createTitle(TITLE_TEXT)); | 43 mHead.appendChild(TestUtil.createTitle(TITLE_TEXT)); |
| 44 extractor = new ContentExtractor(mRoot); | 44 extractor = new ContentExtractor(mRoot); |
| 45 extractedContent = extractor.extractContent(); | 45 extractedContent = extractor.extractContent(); |
| 46 assertTrue(extractedContent + " must contain 'content':" + CONTENT_TEXT, | 46 assertTrue(extractedContent + " must contain 'content':" + CONTENT_TEXT, |
| 47 extractedContent.contains(contentDiv.getInnerText())); | 47 extractedContent.contains(DomUtil.getInnerText(contentDiv))); |
| 48 assertFalse( | 48 assertFalse( |
| 49 extractedContent + " must not contain 'title':" +TITLE_TEXT, | 49 extractedContent + " must not contain 'title':" + TITLE_TEXT, |
| 50 extractedContent.contains(titleDiv.getInnerText())); | 50 extractedContent.contains(DomUtil.getInnerText(titleDiv))); |
| 51 } | 51 } |
| 52 | 52 |
| 53 public void testExtractsEssentialWhitespace() { | 53 public void testExtractsEssentialWhitespace() { |
| 54 Element div = TestUtil.createDiv(0); | 54 Element div = TestUtil.createDiv(0); |
| 55 mBody.appendChild(div); | 55 mBody.appendChild(div); |
| 56 | 56 |
| 57 div.appendChild(TestUtil.createSpan(CONTENT_TEXT)); | 57 div.appendChild(TestUtil.createSpan(CONTENT_TEXT)); |
| 58 div.appendChild(TestUtil.createText(" ")); | 58 div.appendChild(TestUtil.createText(" ")); |
| 59 div.appendChild(TestUtil.createSpan(CONTENT_TEXT)); | 59 div.appendChild(TestUtil.createSpan(CONTENT_TEXT)); |
| 60 div.appendChild(TestUtil.createText("\n")); | 60 div.appendChild(TestUtil.createText("\n")); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 85 | 85 |
| 86 ContentExtractor extractor = new ContentExtractor(mRoot); | 86 ContentExtractor extractor = new ContentExtractor(mRoot); |
| 87 assertEquals("OpenGraph title should be picked over document.title", | 87 assertEquals("OpenGraph title should be picked over document.title", |
| 88 MARKUP_PARSER_TITLE, extractor.extractTitle()); | 88 MARKUP_PARSER_TITLE, extractor.extractTitle()); |
| 89 } | 89 } |
| 90 | 90 |
| 91 private void createMeta(String property, String content) { | 91 private void createMeta(String property, String content) { |
| 92 mHead.appendChild(TestUtil.createMetaProperty(property, content)); | 92 mHead.appendChild(TestUtil.createMetaProperty(property, content)); |
| 93 } | 93 } |
| 94 } | 94 } |
| OLD | NEW |