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.DomUtil; | 8 import org.chromium.distiller.DomUtil; |
9 import org.chromium.distiller.labels.DefaultLabels; | 9 import org.chromium.distiller.labels.DefaultLabels; |
10 | 10 |
11 import com.google.gwt.dom.client.Document; | 11 import com.google.gwt.dom.client.Document; |
12 import com.google.gwt.dom.client.Element; | 12 import com.google.gwt.dom.client.Element; |
13 | 13 |
14 public class ElementActionTest extends DomDistillerJsTestCase { | 14 public class ElementActionTest extends DomDistillerJsTestCase { |
15 private ElementAction getForHtml(String html) { | 15 private Element createElementWithInnerHtml(String html) { |
16 Element container = Document.get().createDivElement(); | 16 Element container = Document.get().createDivElement(); |
17 mBody.appendChild(container); | 17 mBody.appendChild(container); |
18 container.setInnerHTML(html); | 18 container.setInnerHTML(html); |
| 19 return container; |
| 20 } |
| 21 |
| 22 private ElementAction getForHtml(String html) { |
| 23 Element container = createElementWithInnerHtml(html); |
19 assertEquals(1, container.getChildCount()); | 24 assertEquals(1, container.getChildCount()); |
20 Element e = container.getFirstChildElement(); | 25 Element e = container.getFirstChildElement(); |
21 return ElementAction.getForElement(e); | 26 return ElementAction.getForElement(e); |
22 } | 27 } |
23 | 28 |
| 29 private ElementAction getForHtmlFirstChild(String html) { |
| 30 Element container = createElementWithInnerHtml(html); |
| 31 assertEquals(1, container.getChildCount()); |
| 32 Element e = container.getFirstChildElement(); |
| 33 |
| 34 assertEquals(1, e.getChildCount()); |
| 35 Element firstChild = e.getFirstChildElement(); |
| 36 |
| 37 return ElementAction.getForElement(firstChild); |
| 38 } |
| 39 |
24 public void testFlush() { | 40 public void testFlush() { |
25 assertFalse(getForHtml("<span></span>").flush); | 41 assertFalse(getForHtml("<span></span>").flush); |
26 assertTrue(getForHtml("<div></div>").flush); | 42 assertTrue(getForHtml("<div></div>").flush); |
27 | 43 |
28 assertTrue(getForHtml("<span style=\"display: block\"></span>").flush); | 44 assertTrue(getForHtml("<span style=\"display: block\"></span>").flush); |
29 assertTrue(getForHtml("<span style=\"display: flex\"></span>").flush); | 45 assertTrue(getForHtml("<span style=\"display: flex\"></span>").flush); |
30 | 46 |
31 assertFalse(getForHtml("<div style=\"display: inline\"></div>").flush); | 47 assertFalse(getForHtml("<div style=\"display: inline\"></div>").flush); |
| 48 |
| 49 assertTrue(getForHtml("<li></li>").flush); |
| 50 assertTrue(getForHtmlFirstChild("<ul><li></li></ul>").flush); |
| 51 assertFalse(getForHtmlFirstChild("<ol><li></li></ol>").flush); |
32 } | 52 } |
33 | 53 |
34 public void testIsAnchor() { | 54 public void testIsAnchor() { |
35 assertFalse(getForHtml("<span></span>").isAnchor); | 55 assertFalse(getForHtml("<span></span>").isAnchor); |
36 assertFalse(getForHtml("<div></div>").isAnchor); | 56 assertFalse(getForHtml("<div></div>").isAnchor); |
37 assertFalse(getForHtml("<a></a>").isAnchor); | 57 assertFalse(getForHtml("<a></a>").isAnchor); |
38 assertTrue(getForHtml("<a href=\"http://example.com\"></a>").isAnchor); | 58 assertTrue(getForHtml("<a href=\"http://example.com\"></a>").isAnchor); |
39 } | 59 } |
40 | 60 |
41 public void testChangesTagLevel() { | 61 public void testChangesTagLevel() { |
42 assertFalse(getForHtml("<span></span>").changesTagLevel); | 62 assertFalse(getForHtml("<span></span>").changesTagLevel); |
43 assertFalse(getForHtml("<font></font>").changesTagLevel); | 63 assertFalse(getForHtml("<font></font>").changesTagLevel); |
44 assertFalse(getForHtml("<div style=\"display: inline\"></div>").changesT
agLevel); | 64 assertFalse(getForHtml("<div style=\"display: inline\"></div>").changesT
agLevel); |
45 | 65 |
46 assertTrue(getForHtml("<a></a>").changesTagLevel); | 66 assertTrue(getForHtml("<a></a>").changesTagLevel); |
47 assertTrue(getForHtml("<div></div>").changesTagLevel); | 67 assertTrue(getForHtml("<div></div>").changesTagLevel); |
48 assertTrue(getForHtml("<span style=\"display: inline-block\"></span>").c
hangesTagLevel); | 68 assertTrue(getForHtml("<span style=\"display: inline-block\"></span>").c
hangesTagLevel); |
49 assertTrue(getForHtml("<span style=\"display: block\"></span>").changesT
agLevel); | 69 assertTrue(getForHtml("<span style=\"display: block\"></span>").changesT
agLevel); |
50 assertTrue(getForHtml("<div style=\"display: inline-block\"></div>").cha
ngesTagLevel); | 70 assertTrue(getForHtml("<div style=\"display: inline-block\"></div>").cha
ngesTagLevel); |
51 assertTrue(getForHtml("<table></table>").changesTagLevel); | 71 assertTrue(getForHtml("<table></table>").changesTagLevel); |
| 72 |
| 73 assertTrue(getForHtml("<li></li>").changesTagLevel); |
| 74 assertTrue(getForHtmlFirstChild("<ul><li></li></ul>").changesTagLevel); |
| 75 assertFalse(getForHtmlFirstChild("<ol><li></li></ol>").changesTagLevel); |
52 } | 76 } |
53 | 77 |
54 private boolean hasLabel(ElementAction a, String label) { | 78 private boolean hasLabel(ElementAction a, String label) { |
55 for (int i = 0; i < a.labels.length(); i++) { | 79 for (int i = 0; i < a.labels.length(); i++) { |
56 if (a.labels.get(i).equals(label)) { | 80 if (a.labels.get(i).equals(label)) { |
57 return true; | 81 return true; |
58 } | 82 } |
59 } | 83 } |
60 return false; | 84 return false; |
61 } | 85 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 140 |
117 assertFalse(hasLabel(getForHtml( | 141 assertFalse(hasLabel(getForHtml( |
118 "<div class=\"user-comments another-class lots-of-classes too-ma
ny-classes" + | 142 "<div class=\"user-comments another-class lots-of-classes too-ma
ny-classes" + |
119 "class1 class2 class3 class4 class5 class6 class7 c
lass8\"></div>"), | 143 "class1 class2 class3 class4 class5 class6 class7 c
lass8\"></div>"), |
120 DefaultLabels.STRICTLY_NOT_CONTENT)); | 144 DefaultLabels.STRICTLY_NOT_CONTENT)); |
121 assertTrue(hasLabel(getForHtml( | 145 assertTrue(hasLabel(getForHtml( |
122 "<div class=\" user-comments a
b \"></div>"), | 146 "<div class=\" user-comments a
b \"></div>"), |
123 DefaultLabels.STRICTLY_NOT_CONTENT)); | 147 DefaultLabels.STRICTLY_NOT_CONTENT)); |
124 } | 148 } |
125 } | 149 } |
OLD | NEW |