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

Side by Side Diff: javatests/org/chromium/distiller/DomUtilTest.java

Issue 1411603004: Discard hidden articles when using fast path (Closed) Base URL: https://github.com/chromium/dom-distiller.git@master
Patch Set: Comments addressed Created 5 years, 2 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
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
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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
348 } 350 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698