OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package com.dom_distiller.client; |
| 6 |
| 7 import com.google.gwt.dom.client.Document; |
| 8 import com.google.gwt.dom.client.Element; |
| 9 import com.google.gwt.junit.client.GWTTestCase; |
| 10 |
| 11 public class ContentExtractorTest extends GWTTestCase { |
| 12 private static final String CONTENT_TEXT = "Lorem Ipsum Lorem Ipsum Lorem Ip
sum."; |
| 13 private static final String TITLE_TEXT = "I am the document title"; |
| 14 |
| 15 @Override |
| 16 public String getModuleName() { |
| 17 return "com.dom_distiller.DomDistillerJUnit"; |
| 18 } |
| 19 |
| 20 public void testDoesNotExtractTitle() { |
| 21 Element root = Document.get().getDocumentElement(); |
| 22 root.appendChild(TestUtil.createTitle(TITLE_TEXT)); |
| 23 |
| 24 Element body = Document.get().createElement("body"); |
| 25 root.appendChild(body); |
| 26 |
| 27 Element titleDiv = TestUtil.createDiv(0); |
| 28 titleDiv.appendChild(TestUtil.createText(TITLE_TEXT)); |
| 29 body.appendChild(titleDiv); |
| 30 Element contentDiv = TestUtil.createDiv(1); |
| 31 contentDiv.appendChild(TestUtil.createText(CONTENT_TEXT)); |
| 32 body.appendChild(contentDiv); |
| 33 |
| 34 contentDiv = TestUtil.createDiv(2); |
| 35 contentDiv.appendChild(TestUtil.createText(CONTENT_TEXT)); |
| 36 body.appendChild(contentDiv); |
| 37 |
| 38 contentDiv = TestUtil.createDiv(3); |
| 39 contentDiv.appendChild(TestUtil.createText(CONTENT_TEXT)); |
| 40 |
| 41 body.appendChild(contentDiv); |
| 42 |
| 43 // Title hasn't been set yet, everything should be content. |
| 44 String extractedContent = ContentExtractor.extractContent(); |
| 45 assertTrue(extractedContent + " must contain 'content':" + CONTENT_TEXT, |
| 46 extractedContent.contains(contentDiv.getInnerText())); |
| 47 assertTrue( |
| 48 extractedContent + " must contain 'title':" +TITLE_TEXT, |
| 49 extractedContent.contains(titleDiv.getInnerText())); |
| 50 |
| 51 // Now set the title and it should excluded from the content. |
| 52 Document.get().setTitle(TITLE_TEXT); |
| 53 extractedContent = ContentExtractor.extractContent(); |
| 54 assertTrue(extractedContent + " must contain 'content':" + CONTENT_TEXT, |
| 55 extractedContent.contains(contentDiv.getInnerText())); |
| 56 assertFalse( |
| 57 extractedContent + " must not contain 'title':" +TITLE_TEXT, |
| 58 extractedContent.contains(titleDiv.getInnerText())); |
| 59 } |
| 60 } |
OLD | NEW |