Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: test/com/dom_distiller/client/DomToSaxParserTest.java

Issue 275493007: filter out invisible elements (Closed) Base URL: https://code.google.com/p/dom-distiller/@master
Patch Set: addressed comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 java.util.regex.Pattern;
8 import java.util.regex.Matcher;
9
10 import com.google.gwt.junit.client.GWTTestCase;
11
12 import com.google.gwt.core.client.JsArray;
13 import com.google.gwt.dom.client.Document;
14 import com.google.gwt.dom.client.Element;
15 import com.google.gwt.dom.client.Node;
16 import com.google.gwt.dom.client.NodeList;
17 import com.google.gwt.dom.client.Text;
18 import com.google.gwt.user.client.DOM;
19
20 import org.xml.sax.Attributes;
21
22 public class DomToSaxParserTest extends GWTTestCase {
23 @Override
24 public String getModuleName() {
25 return "com.dom_distiller.DomDistillerJUnit";
26 }
27
28 public void testGetAttributes() {
29 Element e = Document.get().createDivElement();
30 e.setInnerHTML("<div style=\"width:50px; height:100px\" id=\"f\" class=\ "sdf\"></div>");
31 e = Element.as(e.getChildNodes().getItem(0));
32 JsArray<Node> jsAttrs = DomUtil.getAttributes(e);
33 assertEquals(3, jsAttrs.length());
34 }
35
36 public void testGetSaxAttributes() {
37 Element e = Document.get().createDivElement();
38 e.setInnerHTML("<div style=\"width:50px; height:100px\" id=\"f\" class=\ "sdf\"></div>");
39 e = Element.as(e.getChildNodes().getItem(0));
40 Attributes attrs = DomToSaxParser.getSaxAttributes(e);
41 assertEquals(3, attrs.getLength());
42 assertEquals("f", attrs.getValue("id"));
43 assertEquals("sdf", attrs.getValue("class"));
44 }
45
46 private void runDomParserTest(String innerHtml) throws Throwable {
47 Element container = Document.get().createDivElement();
48 container.setInnerHTML(innerHtml);
49 SimpleContentHandler contentHandler = new SimpleContentHandler();
50 DomToSaxParser.parse(container, contentHandler);
51 String expectedDocument = "<div>" + innerHtml + "</div>";
52 assertEquals(expectedDocument, contentHandler.getDocumentString().toLowe rCase());
53 }
54
55 public void testDomParserText() throws Throwable {
56 runDomParserTest("foo");
57 }
58
59 public void testDomParserElement() throws Throwable {
60 runDomParserTest("<div></div>");
61 }
62
63 public void testDomParserSiblings() throws Throwable {
64 runDomParserTest("<div></div><div></div>");
65 }
66
67 public void testDomParserAttribute() throws Throwable {
68 runDomParserTest("<div style=\"width:50px; height:100px\" id=\"f\" class =\"sdf\"></div>");
69 }
70
71 public void testDomParserSimplePage() throws Throwable {
72 String simpleHtml =
73 "<div id=\"a\" class=\"foo\">foo<a href=\"x.com/#1\">x.com</a>ba r</div>" +
74 "<div>baz</div>";
75 runDomParserTest(simpleHtml);
76 }
77 }
OLDNEW
« no previous file with comments | « src/com/dom_distiller/client/FilteringDomVisitor.java ('k') | test/com/dom_distiller/client/DomToSaxVisitorTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698