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 org.chromium.distiller.webdocument; | 5 package org.chromium.distiller.webdocument; |
6 | 6 |
7 import org.chromium.distiller.DomDistillerJsTestCase; | 7 import org.chromium.distiller.DomDistillerJsTestCase; |
8 import org.chromium.distiller.DomWalker; | 8 import org.chromium.distiller.DomWalker; |
9 | 9 |
10 import com.google.gwt.dom.client.Document; | 10 import com.google.gwt.dom.client.Document; |
11 import com.google.gwt.dom.client.Element; | 11 import com.google.gwt.dom.client.Element; |
12 | 12 |
13 import java.util.List; | 13 import java.util.List; |
14 | 14 |
15 public class DomConverterTest extends DomDistillerJsTestCase { | 15 public class DomConverterTest extends DomDistillerJsTestCase { |
16 private void runTest(String innerHtml, String expectedHtml) throws Throwable
{ | 16 private void runTest(String innerHtml, String expectedHtml) throws Throwable
{ |
| 17 runTest(innerHtml, expectedHtml, false); |
| 18 } |
| 19 |
| 20 private void runTest(String innerHtml, String expectedHtml, boolean mobileAr
ticle) |
| 21 throws Throwable { |
17 Element container = Document.get().createDivElement(); | 22 Element container = Document.get().createDivElement(); |
18 mBody.appendChild(container); | 23 mBody.appendChild(container); |
19 container.setInnerHTML(innerHtml); | 24 container.setInnerHTML(innerHtml); |
20 FakeWebDocumentBuilder builder = new FakeWebDocumentBuilder(); | 25 FakeWebDocumentBuilder builder = new FakeWebDocumentBuilder(); |
21 DomConverter filteringDomVisitor = new DomConverter(builder); | 26 DomConverter filteringDomVisitor = new DomConverter(builder); |
| 27 filteringDomVisitor.setHasArticleElement(mobileArticle); |
| 28 filteringDomVisitor.setIsMobileFriendly(mobileArticle); |
22 new DomWalker(filteringDomVisitor).walk(container); | 29 new DomWalker(filteringDomVisitor).walk(container); |
23 String expectedDocument = "<div>" + expectedHtml + "</div>"; | 30 String expectedDocument = "<div>" + expectedHtml + "</div>"; |
24 assertEquals(expectedDocument, builder.getDocumentString().toLowerCase()
); | 31 assertEquals(expectedDocument, builder.getDocumentString().toLowerCase()
); |
25 } | 32 } |
26 | 33 |
27 public void testVisibleText() throws Throwable { | 34 public void testVisibleText() throws Throwable { |
28 String html = "visible text"; | 35 String html = "visible text"; |
29 runTest(html, html); | 36 runTest(html, html); |
30 } | 37 } |
31 | 38 |
(...skipping 12 matching lines...) Expand all Loading... |
44 | 51 |
45 public void testInvisibleInVisible() throws Throwable { | 52 public void testInvisibleInVisible() throws Throwable { |
46 String html = "<div>visible parent" + | 53 String html = "<div>visible parent" + |
47 "<div style=\"display:none\">invisible child</div>" + | 54 "<div style=\"display:none\">invisible child</div>" + |
48 "</div>"; | 55 "</div>"; |
49 runTest(html, "<div>visible parent</div>"); | 56 runTest(html, "<div>visible parent</div>"); |
50 } | 57 } |
51 | 58 |
52 public void testVisibleInInvisible() throws Throwable { | 59 public void testVisibleInInvisible() throws Throwable { |
53 String html = "<div style=\"visibility:hidden\">invisible parent" + | 60 String html = "<div style=\"visibility:hidden\">invisible parent" + |
54 "<div>visible child</div>" + | 61 "<div>visible child</div>" + |
55 "</div>"; | 62 "</div>"; |
56 runTest(html, ""); | 63 runTest(html, ""); |
57 } | 64 } |
58 | 65 |
| 66 public void testVisibleInInvisible2() throws Throwable { |
| 67 String html = "<div style=\"display:none\">invisible parent" + |
| 68 "<div>visible child</div>" + |
| 69 "</div>"; |
| 70 runTest(html, ""); |
| 71 } |
| 72 |
59 public void testVisibleInVisible() throws Throwable { | 73 public void testVisibleInVisible() throws Throwable { |
60 String html = "<div>visible parent" + | 74 String html = "<div>visible parent" + |
61 "<div>visible child</div>" + | 75 "<div>visible child</div>" + |
62 "</div>"; | 76 "</div>"; |
63 runTest(html, html); | 77 runTest(html, html); |
64 } | 78 } |
65 | 79 |
66 public void testInvisibleInInvisible() throws Throwable { | 80 public void testInvisibleInInvisible() throws Throwable { |
67 String html = "<div style=\"visibility:hidden\">invisible parent" + | 81 String html = "<div style=\"visibility:hidden\">invisible parent" + |
68 "<div style=\"display:none\">invisible child</div>" + | 82 "<div style=\"display:none\">invisible child</div>" + |
(...skipping 16 matching lines...) Expand all Loading... |
85 String html = "<div style=\"visibility:hidden\">invisible parent" + | 99 String html = "<div style=\"visibility:hidden\">invisible parent" + |
86 "<div style=\"display:none\">invisible child0</div>" + | 100 "<div style=\"display:none\">invisible child0</div>" + |
87 "<div>visible child1" + | 101 "<div>visible child1" + |
88 "<div style=\"display:none\">invisible grandchild<
/div>" + | 102 "<div style=\"display:none\">invisible grandchild<
/div>" + |
89 "</div>" + | 103 "</div>" + |
90 "<div style=\"visibility:hidden\">invisible child2</di
v>" + | 104 "<div style=\"visibility:hidden\">invisible child2</di
v>" + |
91 "</div>"; | 105 "</div>"; |
92 runTest(html, ""); | 106 runTest(html, ""); |
93 } | 107 } |
94 | 108 |
| 109 public void testKeepHidden() throws Throwable { |
| 110 String html = "<div class=\"hidden\" style=\"display: none\">visible ele
ment</div>"; |
| 111 runTest(html, html, true); |
| 112 } |
| 113 |
| 114 public void testKeepHiddenNested() throws Throwable { |
| 115 // "visibility: hidden" is used. See crbug.com/599121 |
| 116 String html = "<div class=\"hidden\" style=\"visibility: hidden\">" + |
| 117 "<div>visible element</div></div>"; |
| 118 runTest(html, html, true); |
| 119 } |
| 120 |
| 121 public void testKeepContinue() throws Throwable { |
| 122 String html = "<div class=\"continue\" style=\"display: none\">visible e
lement</div>"; |
| 123 runTest(html, html, true); |
| 124 } |
| 125 |
| 126 public void testKeepContinueNested() throws Throwable { |
| 127 // "display: none" is used. See crbug.com/687071 |
| 128 String html = "<div class=\"continue\" style=\"display: none\">" + |
| 129 "<div>visible element</div></div>"; |
| 130 runTest(html, html, true); |
| 131 } |
| 132 |
95 public void testDataTable() throws Throwable { | 133 public void testDataTable() throws Throwable { |
96 String html = "<table align=\"left\" role=\"grid\">" + // role=grid make
this a data table. | 134 String html = "<table align=\"left\" role=\"grid\">" + // role=grid make
this a data table. |
97 "<tbody align=\"left\">" + | 135 "<tbody align=\"left\">" + |
98 "<tr>" + | 136 "<tr>" + |
99 "<td>row1col1</td>" + | 137 "<td>row1col1</td>" + |
100 "<td>row1col2</td>" + | 138 "<td>row1col2</td>" + |
101 "</tr>" + | 139 "</tr>" + |
102 "</tbody>" + | 140 "</tbody>" + |
103 "</table>"; | 141 "</table>"; |
104 runTest(html, "<datatable/>"); | 142 runTest(html, "<datatable/>"); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 225 |
188 assertTrue(elements.get(5) instanceof WebText); | 226 assertTrue(elements.get(5) instanceof WebText); |
189 | 227 |
190 assertTrue(elements.get(6) instanceof WebTag); | 228 assertTrue(elements.get(6) instanceof WebTag); |
191 assertFalse(((WebTag) elements.get(6)).isStartTag()); | 229 assertFalse(((WebTag) elements.get(6)).isStartTag()); |
192 | 230 |
193 assertTrue(elements.get(7) instanceof WebTag); | 231 assertTrue(elements.get(7) instanceof WebTag); |
194 assertFalse(((WebTag) elements.get(7)).isStartTag()); | 232 assertFalse(((WebTag) elements.get(7)).isStartTag()); |
195 } | 233 } |
196 } | 234 } |
OLD | NEW |