| Index: test/com/dom_distiller/client/ContentExtractorTest.java
|
| diff --git a/test/com/dom_distiller/client/ContentExtractorTest.java b/test/com/dom_distiller/client/ContentExtractorTest.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8f504a091e224bcf62cad5652609f83da4d88ab7
|
| --- /dev/null
|
| +++ b/test/com/dom_distiller/client/ContentExtractorTest.java
|
| @@ -0,0 +1,60 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package com.dom_distiller.client;
|
| +
|
| +import com.google.gwt.dom.client.Document;
|
| +import com.google.gwt.dom.client.Element;
|
| +import com.google.gwt.junit.client.GWTTestCase;
|
| +
|
| +public class ContentExtractorTest extends GWTTestCase {
|
| + private static final String CONTENT_TEXT = "Lorem Ipsum Lorem Ipsum Lorem Ipsum.";
|
| + private static final String TITLE_TEXT = "I am the document title";
|
| +
|
| + @Override
|
| + public String getModuleName() {
|
| + return "com.dom_distiller.DomDistillerJUnit";
|
| + }
|
| +
|
| + public void testDoesNotExtractTitle() {
|
| + Element root = Document.get().getDocumentElement();
|
| + root.appendChild(TestUtil.createTitle(TITLE_TEXT));
|
| +
|
| + Element body = Document.get().createElement("body");
|
| + root.appendChild(body);
|
| +
|
| + Element titleDiv = TestUtil.createDiv(0);
|
| + titleDiv.appendChild(TestUtil.createText(TITLE_TEXT));
|
| + body.appendChild(titleDiv);
|
| + Element contentDiv = TestUtil.createDiv(1);
|
| + contentDiv.appendChild(TestUtil.createText(CONTENT_TEXT));
|
| + body.appendChild(contentDiv);
|
| +
|
| + contentDiv = TestUtil.createDiv(2);
|
| + contentDiv.appendChild(TestUtil.createText(CONTENT_TEXT));
|
| + body.appendChild(contentDiv);
|
| +
|
| + contentDiv = TestUtil.createDiv(3);
|
| + contentDiv.appendChild(TestUtil.createText(CONTENT_TEXT));
|
| +
|
| + body.appendChild(contentDiv);
|
| +
|
| + // Title hasn't been set yet, everything should be content.
|
| + String extractedContent = ContentExtractor.extractContent();
|
| + assertTrue(extractedContent + " must contain 'content':" + CONTENT_TEXT,
|
| + extractedContent.contains(contentDiv.getInnerText()));
|
| + assertTrue(
|
| + extractedContent + " must contain 'title':" +TITLE_TEXT,
|
| + extractedContent.contains(titleDiv.getInnerText()));
|
| +
|
| + // Now set the title and it should excluded from the content.
|
| + Document.get().setTitle(TITLE_TEXT);
|
| + extractedContent = ContentExtractor.extractContent();
|
| + assertTrue(extractedContent + " must contain 'content':" + CONTENT_TEXT,
|
| + extractedContent.contains(contentDiv.getInnerText()));
|
| + assertFalse(
|
| + extractedContent + " must not contain 'title':" +TITLE_TEXT,
|
| + extractedContent.contains(titleDiv.getInnerText()));
|
| + }
|
| +}
|
|
|