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; |
(...skipping 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 public void testVisibleElement() throws Throwable { | 32 public void testVisibleElement() throws Throwable { |
33 String html = "<div>visible element</div>"; | 33 String html = "<div>visible element</div>"; |
34 runTest(html, html); | 34 runTest(html, html); |
35 } | 35 } |
36 | 36 |
37 public void testDisplayNone() throws Throwable { | 37 public void testDisplayNone() throws Throwable { |
38 runTest("<div style=\"display:none\">diplay none</div>", ""); | 38 runTest("<div style=\"display:none\">diplay none</div>", ""); |
39 } | 39 } |
40 | 40 |
41 public void testVisibilityHidden() throws Throwable { | |
42 runTest("<div style=\"visibility:hidden\">visibility hidden</div>", ""); | |
43 } | |
44 | |
45 public void testInvisibleInVisible() throws Throwable { | 41 public void testInvisibleInVisible() throws Throwable { |
46 String html = "<div>visible parent" + | 42 String html = "<div>visible parent" + |
47 "<div style=\"display:none\">invisible child</div>" + | 43 "<div style=\"display:none\">invisible child</div>" + |
48 "</div>"; | 44 "</div>"; |
49 runTest(html, "<div>visible parent</div>"); | 45 runTest(html, "<div>visible parent</div>"); |
50 } | 46 } |
51 | 47 |
52 public void testVisibleInInvisible() throws Throwable { | 48 public void testVisibleInInvisible() throws Throwable { |
53 String html = "<div style=\"visibility:hidden\">invisible parent" + | 49 String html = "<div style=\"display:none\">invisible parent" + |
wychen
2016/06/06 18:11:22
Why changing this file? These are necessary for th
marcelorcorrea
2016/06/06 19:21:59
Done.
| |
54 "<div>visible child</div>" + | 50 "<div>visible child</div>" + |
55 "</div>"; | 51 "</div>"; |
56 runTest(html, ""); | 52 runTest(html, ""); |
57 } | 53 } |
58 | 54 |
59 public void testVisibleInVisible() throws Throwable { | 55 public void testVisibleInVisible() throws Throwable { |
60 String html = "<div>visible parent" + | 56 String html = "<div>visible parent" + |
61 "<div>visible child</div>" + | 57 "<div>visible child</div>" + |
62 "</div>"; | 58 "</div>"; |
63 runTest(html, html); | 59 runTest(html, html); |
64 } | 60 } |
65 | 61 |
66 public void testInvisibleInInvisible() throws Throwable { | 62 public void testInvisibleInInvisible() throws Throwable { |
67 String html = "<div style=\"visibility:hidden\">invisible parent" + | 63 String html = "<div style=\"display:none\">invisible parent" + |
68 "<div style=\"display:none\">invisible child</div>" + | 64 "<div style=\"display:none\">invisible child</div>" + |
69 "</div>"; | 65 "</div>"; |
70 runTest(html, ""); | 66 runTest(html, ""); |
71 } | 67 } |
72 | 68 |
73 public void testDifferentChildrenInVisible() throws Throwable { | 69 public void testDifferentChildrenInVisible() throws Throwable { |
74 String html = "<div>visible parent" + | 70 String html = "<div>visible parent" + |
75 "<div style=\"display:none\">invisible child0</div>" + | 71 "<div style=\"display:none\">invisible child0</div>" + |
76 "<div>visible child1" + | 72 "<div>visible child1" + |
77 "<div style=\"visibility:hidden\">invisible grandc hild</div>" + | 73 "<div style=\"display:none\">invisible grandchild< /div>" + |
78 "</div>" + | 74 "</div>" + |
79 "<div style=\"visibility:hidden\">invisible child2</di v>" + | 75 "<div style=\"display:none\">invisible child2</div>" + |
80 "</div>"; | 76 "</div>"; |
81 runTest(html, "<div>visible parent<div>visible child1</div></div>"); | 77 runTest(html, "<div>visible parent<div>visible child1</div></div>"); |
82 } | 78 } |
83 | 79 |
84 public void testDifferentChildrenInInvisible() throws Throwable { | 80 public void testDifferentChildrenInInvisible() throws Throwable { |
85 String html = "<div style=\"visibility:hidden\">invisible parent" + | 81 String html = "<div style=\"display:none\">invisible parent" + |
86 "<div style=\"display:none\">invisible child0</div>" + | 82 "<div style=\"display:none\">invisible child0</div>" + |
87 "<div>visible child1" + | 83 "<div>visible child1" + |
88 "<div style=\"display:none\">invisible grandchild< /div>" + | 84 "<div style=\"display:none\">invisible grandchild< /div>" + |
89 "</div>" + | 85 "</div>" + |
90 "<div style=\"visibility:hidden\">invisible child2</di v>" + | 86 "<div style=\"display:none\">invisible child2</div>" + |
91 "</div>"; | 87 "</div>"; |
92 runTest(html, ""); | 88 runTest(html, ""); |
93 } | 89 } |
94 | 90 |
95 // Note: getComputedStyle() doesn't work correctly when running ant test.dev or test.prod, | 91 // Note: getComputedStyle() doesn't work correctly when running ant test.dev or test.prod, |
96 // but it works in production mode in the browser, so the test is in chrome' s components/ | 92 // but it works in production mode in the browser, so the test is in chrome' s components/ |
97 // dom_distiller/content/distiller_page_web_contents_browsertest.cc::Visibil ityDetection(). | 93 // dom_distiller/content/distiller_page_web_contents_browsertest.cc::Visibil ityDetection(). |
98 | 94 |
99 public void testDataTable() throws Throwable { | 95 public void testDataTable() throws Throwable { |
100 String html = "<table align=\"left\" role=\"grid\">" + // role=grid make this a data table. | 96 String html = "<table align=\"left\" role=\"grid\">" + // role=grid make this a data table. |
(...skipping 26 matching lines...) Expand all Loading... | |
127 runTest("<noscript></noscript>", ""); | 123 runTest("<noscript></noscript>", ""); |
128 runTest("<applet></applet>", ""); | 124 runTest("<applet></applet>", ""); |
129 runTest("<object></object>", ""); | 125 runTest("<object></object>", ""); |
130 runTest("<option></option>", ""); | 126 runTest("<option></option>", ""); |
131 runTest("<embed></embed>", ""); | 127 runTest("<embed></embed>", ""); |
132 } | 128 } |
133 | 129 |
134 public void testElementOrder() { | 130 public void testElementOrder() { |
135 Element container = Document.get().createDivElement(); | 131 Element container = Document.get().createDivElement(); |
136 container.setInnerHTML("Text content <img src=\"http://example.com/1.jpg \"> more content"); | 132 container.setInnerHTML("Text content <img src=\"http://example.com/1.jpg \"> more content"); |
133 mBody.appendChild(container); | |
wychen
2016/06/06 18:11:23
Good catch! How did you find this?
marcelorcorrea
2016/06/06 19:21:59
Actually, I copied from your CL.
Sorry for changin
wychen
2016/06/06 21:11:27
lol. I totally forget this.
Well, since we don't h
| |
137 | 134 |
138 WebDocumentBuilder builder = new WebDocumentBuilder(); | 135 WebDocumentBuilder builder = new WebDocumentBuilder(); |
139 DomConverter converter = new DomConverter(builder); | 136 DomConverter converter = new DomConverter(builder); |
140 new DomWalker(converter).walk(container); | 137 new DomWalker(converter).walk(container); |
141 | 138 |
142 WebDocument doc = builder.toWebDocument(); | 139 WebDocument doc = builder.toWebDocument(); |
143 List<WebElement> elements = doc.getElements(); | 140 List<WebElement> elements = doc.getElements(); |
144 | 141 |
145 assertEquals(3, elements.size()); | 142 assertEquals(3, elements.size()); |
146 assertTrue(elements.get(0) instanceof WebText); | 143 assertTrue(elements.get(0) instanceof WebText); |
147 assertTrue(elements.get(1) instanceof WebImage); | 144 assertTrue(elements.get(1) instanceof WebImage); |
148 assertTrue(elements.get(2) instanceof WebText); | 145 assertTrue(elements.get(2) instanceof WebText); |
149 } | 146 } |
150 | 147 |
151 public void testLineBreak() throws Throwable { | 148 public void testLineBreak() throws Throwable { |
152 String html = "text<br>split<br/>with<br/>lines"; | 149 String html = "text<br>split<br/>with<br/>lines"; |
153 runTest(html, "text\nsplit\nwith\nlines"); | 150 runTest(html, "text\nsplit\nwith\nlines"); |
154 } | 151 } |
155 | 152 |
156 public void testList() throws Throwable { | 153 public void testList() throws Throwable { |
157 Element container = Document.get().createDivElement(); | 154 Element container = Document.get().createDivElement(); |
158 container.setInnerHTML("<ol><li>some text1</li><li>some text2</li></ol>" ); | 155 container.setInnerHTML("<ol><li>some text1</li><li>some text2</li></ol>" ); |
156 mBody.appendChild(container); | |
wychen
2016/06/06 21:11:27
ditto
| |
159 | 157 |
160 WebDocumentBuilder builder = new WebDocumentBuilder(); | 158 WebDocumentBuilder builder = new WebDocumentBuilder(); |
161 DomConverter converter = new DomConverter(builder); | 159 DomConverter converter = new DomConverter(builder); |
162 new DomWalker(converter).walk(container); | 160 new DomWalker(converter).walk(container); |
163 | 161 |
164 WebDocument doc = builder.toWebDocument(); | 162 WebDocument doc = builder.toWebDocument(); |
165 List<WebElement> elements = doc.getElements(); | 163 List<WebElement> elements = doc.getElements(); |
166 | 164 |
167 assertEquals(8, elements.size()); | 165 assertEquals(8, elements.size()); |
168 assertTrue(elements.get(0) instanceof WebTag); | 166 assertTrue(elements.get(0) instanceof WebTag); |
(...skipping 12 matching lines...) Expand all Loading... | |
181 | 179 |
182 assertTrue(elements.get(5) instanceof WebText); | 180 assertTrue(elements.get(5) instanceof WebText); |
183 | 181 |
184 assertTrue(elements.get(6) instanceof WebTag); | 182 assertTrue(elements.get(6) instanceof WebTag); |
185 assertFalse(((WebTag) elements.get(6)).isStartTag()); | 183 assertFalse(((WebTag) elements.get(6)).isStartTag()); |
186 | 184 |
187 assertTrue(elements.get(7) instanceof WebTag); | 185 assertTrue(elements.get(7) instanceof WebTag); |
188 assertFalse(((WebTag) elements.get(7)).isStartTag()); | 186 assertFalse(((WebTag) elements.get(7)).isStartTag()); |
189 } | 187 } |
190 } | 188 } |
OLD | NEW |