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; | 5 package org.chromium.distiller; |
6 | 6 |
7 import org.chromium.distiller.webdocument.WebTable; | 7 import org.chromium.distiller.webdocument.WebTable; |
8 | 8 |
9 import com.google.gwt.core.client.JsArray; | 9 import com.google.gwt.core.client.JsArray; |
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 import com.google.gwt.dom.client.Node; | 12 import com.google.gwt.dom.client.Node; |
| 13 import com.google.gwt.dom.client.NodeList; |
13 | 14 |
14 import java.util.Map; | 15 import java.util.Map; |
15 import java.util.List; | 16 import java.util.List; |
16 | 17 |
17 public class DomUtilTest extends DomDistillerJsTestCase { | 18 public class DomUtilTest extends DomDistillerJsTestCase { |
18 public void testGetAttributes() { | 19 public void testGetAttributes() { |
19 Element e = Document.get().createDivElement(); | 20 Element e = Document.get().createDivElement(); |
20 e.setInnerHTML("<div style=\"width:50px; height:100px\" id=\"f\" class=\
"sdf\"></div>"); | 21 e.setInnerHTML("<div style=\"width:50px; height:100px\" id=\"f\" class=\
"sdf\"></div>"); |
21 e = Element.as(e.getChildNodes().getItem(0)); | 22 e = Element.as(e.getChildNodes().getItem(0)); |
22 JsArray<Node> jsAttrs = DomUtil.getAttributes(e); | 23 JsArray<Node> jsAttrs = DomUtil.getAttributes(e); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 104 |
104 Element currDiv = TestUtil.createDiv(3); | 105 Element currDiv = TestUtil.createDiv(3); |
105 div2.appendChild(currDiv); | 106 div2.appendChild(currDiv); |
106 Element finalDiv1 = currDiv; | 107 Element finalDiv1 = currDiv; |
107 | 108 |
108 currDiv = TestUtil.createDiv(4); | 109 currDiv = TestUtil.createDiv(4); |
109 div2.appendChild(currDiv); | 110 div2.appendChild(currDiv); |
110 currDiv.appendChild(TestUtil.createDiv(5)); | 111 currDiv.appendChild(TestUtil.createDiv(5)); |
111 | 112 |
112 assertEquals(div2, DomUtil.getNearestCommonAncestor(finalDiv1, currDiv.g
etChild(0))); | 113 assertEquals(div2, DomUtil.getNearestCommonAncestor(finalDiv1, currDiv.g
etChild(0))); |
113 assertEquals(div2, DomUtil.getNearestCommonAncestor( | 114 NodeList<Element> nodeList = DomUtil.querySelectorAll(mRoot, "[id=\"3\"]
,[id=\"5\"]"); |
114 DomUtil.querySelectorAll(mRoot, "[id=\"3\"],[id=\"5\"]"))); | 115 assertEquals(div2, DomUtil.getNearestCommonAncestor(TestUtil.nodeListToL
ist(nodeList))); |
| 116 |
115 } | 117 } |
116 | 118 |
117 /** | 119 /** |
118 * The tree graph is: | 120 * The tree graph is: |
119 * 1 - 2 - 3 | 121 * 1 - 2 - 3 |
120 */ | 122 */ |
121 public void testNearestCommonAncestorIsRoot() { | 123 public void testNearestCommonAncestorIsRoot() { |
122 Element div = TestUtil.createDiv(1); | 124 Element div = TestUtil.createDiv(1); |
123 mBody.appendChild(div); | 125 mBody.appendChild(div); |
124 | 126 |
125 Element div2 = TestUtil.createDiv(2); | 127 Element div2 = TestUtil.createDiv(2); |
126 div.appendChild(div2); | 128 div.appendChild(div2); |
127 | 129 |
128 Element div3 = TestUtil.createDiv(3); | 130 Element div3 = TestUtil.createDiv(3); |
129 div2.appendChild(div3); | 131 div2.appendChild(div3); |
130 | 132 |
131 assertEquals(div, DomUtil.getNearestCommonAncestor(div, div3)); | 133 assertEquals(div, DomUtil.getNearestCommonAncestor(div, div3)); |
132 assertEquals(div, DomUtil.getNearestCommonAncestor( | 134 NodeList<Element> nodeList = DomUtil.querySelectorAll(mRoot, "[id=\"1\"]
,[id=\"3\"]"); |
133 DomUtil.querySelectorAll(mRoot, "[id=\"1\"],[id=\"3\"]"))); | 135 assertEquals(div, DomUtil.getNearestCommonAncestor(TestUtil.nodeListToLi
st(nodeList))); |
134 } | 136 } |
135 | 137 |
136 public void testNodeDepth() { | 138 public void testNodeDepth() { |
137 Element div = TestUtil.createDiv(1); | 139 Element div = TestUtil.createDiv(1); |
138 | 140 |
139 Element div2 = TestUtil.createDiv(2); | 141 Element div2 = TestUtil.createDiv(2); |
140 div.appendChild(div2); | 142 div.appendChild(div2); |
141 | 143 |
142 Element div3 = TestUtil.createDiv(3); | 144 Element div3 = TestUtil.createDiv(3); |
143 div2.appendChild(div3); | 145 div2.appendChild(div3); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 "<td>text</td>" + | 340 "<td>text</td>" + |
339 "<td>text</td>" + | 341 "<td>text</td>" + |
340 "</tr>" + | 342 "</tr>" + |
341 "</tbody>" + | 343 "</tbody>" + |
342 "</table>"; | 344 "</table>"; |
343 | 345 |
344 mBody.setInnerHTML(html); | 346 mBody.setInnerHTML(html); |
345 DomUtil.stripStyleAttributes(mBody); | 347 DomUtil.stripStyleAttributes(mBody); |
346 assertEquals(expected, mBody.getInnerHTML()); | 348 assertEquals(expected, mBody.getInnerHTML()); |
347 } | 349 } |
| 350 |
| 351 public void testIsVisibleByItsOffsetParentDisplayNone() { |
| 352 String html = |
| 353 "<div style=\"display: none;\">" + |
| 354 "<div>Some Text</div>" + |
| 355 "</div>"; |
| 356 mBody.setInnerHTML(html); |
| 357 Element child = mBody.getFirstChildElement().getFirstChildElement(); |
| 358 assertFalse(DomUtil.isVisibleByItsOffset(child)); |
| 359 } |
| 360 |
| 361 public void testIsVisibleByItsOffsetChildDisplayNone() { |
| 362 String html = |
| 363 "<div>" + |
| 364 "<div style=\"display: none;\">Some Text</div>" + |
| 365 "</div>"; |
| 366 mBody.setInnerHTML(html); |
| 367 Element child = mBody.getFirstChildElement().getFirstChildElement(); |
| 368 assertFalse(DomUtil.isVisibleByItsOffset(child)); |
| 369 } |
| 370 |
| 371 public void testIsVisibleByItsOffsetDisplayBlock() { |
| 372 String html = |
| 373 "<div>" + |
| 374 "<div>Some Text</div>" + |
| 375 "</div>"; |
| 376 mBody.setInnerHTML(html); |
| 377 Element child = mBody.getFirstChildElement().getFirstChildElement(); |
| 378 assertTrue(DomUtil.isVisibleByItsOffset(child)); |
| 379 } |
348 } | 380 } |
OLD | NEW |