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 com.google.gwt.dom.client.Document; | 7 import com.google.gwt.dom.client.Document; |
8 import com.google.gwt.dom.client.Element; | 8 import com.google.gwt.dom.client.Element; |
9 | 9 |
10 public class ContentExtractorTest extends DomDistillerJsTestCase { | 10 public class ContentExtractorTest extends DomDistillerJsTestCase { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 outerFontTag.appendChild(TestUtil.createText(" ")); | 136 outerFontTag.appendChild(TestUtil.createText(" ")); |
137 | 137 |
138 ContentExtractor extractor = new ContentExtractor(mRoot); | 138 ContentExtractor extractor = new ContentExtractor(mRoot); |
139 String extractedContent = extractor.extractContent(); | 139 String extractedContent = extractor.extractContent(); |
140 assertEquals("<font><span><font>" + CONTENT_TEXT + "</font></span> " + | 140 assertEquals("<font><span><font>" + CONTENT_TEXT + "</font></span> " + |
141 "<span><font>" + CONTENT_TEXT + "</font></span>\n" + | 141 "<span><font>" + CONTENT_TEXT + "</font></span>\n" + |
142 "<span><font>" + CONTENT_TEXT + "</font></span> </font>", | 142 "<span><font>" + CONTENT_TEXT + "</font></span> </font>", |
143 TestUtil.removeAllDirAttributes(extractedContent)); | 143 TestUtil.removeAllDirAttributes(extractedContent)); |
144 } | 144 } |
145 | 145 |
| 146 public void testRemoveStyleAttributes() { |
| 147 String html = |
| 148 "<h1 style=\"font-weight: folder\">" + |
| 149 CONTENT_TEXT + |
| 150 "</h1>" + |
| 151 "<p style=\"\">" + |
| 152 CONTENT_TEXT + |
| 153 "</p>" + |
| 154 "<table style=\"position: absolute\">" + |
| 155 "<tbody style=\"font-size: 2\">" + |
| 156 "<tr style=\"z-index: 0\">" + |
| 157 "<th style=\"top: 0px\">" + CONTENT_TEXT + "</th>" + |
| 158 "<th style=\"width: 20px\">" + CONTENT_TEXT + "</th>" + |
| 159 "</tr><tr style=\"left: 0\">" + |
| 160 "<td style=\"display: block\">" + CONTENT_TEXT + "</td>"
+ |
| 161 "<td style=\"color: #123\">" + CONTENT_TEXT + "</td>" + |
| 162 "</tr>" + |
| 163 "</tbody>" + |
| 164 "</table>"; |
| 165 |
| 166 final String expected = |
| 167 "<h1>" + |
| 168 CONTENT_TEXT + |
| 169 "</h1>" + |
| 170 "<p>" + |
| 171 CONTENT_TEXT + |
| 172 "</p>" + |
| 173 "<table>" + |
| 174 "<tbody>" + |
| 175 "<tr>" + |
| 176 "<th>" + CONTENT_TEXT + "</th>" + |
| 177 "<th>" + CONTENT_TEXT + "</th>" + |
| 178 "</tr><tr>" + |
| 179 "<td>" + CONTENT_TEXT + "</td>" + |
| 180 "<td>" + CONTENT_TEXT + "</td>" + |
| 181 "</tr>" + |
| 182 "</tbody>" + |
| 183 "</table>"; |
| 184 |
| 185 mBody.setInnerHTML(html); |
| 186 |
| 187 ContentExtractor extractor = new ContentExtractor(mRoot); |
| 188 String extractedContent = extractor.extractContent(); |
| 189 assertEquals(expected, |
| 190 TestUtil.removeAllDirAttributes(extractedContent)); |
| 191 } |
| 192 |
146 public void testPreserveOrderedList() { | 193 public void testPreserveOrderedList() { |
147 Element outerListTag = Document.get().createElement("OL"); | 194 Element outerListTag = Document.get().createElement("OL"); |
148 mBody.appendChild(outerListTag); | 195 mBody.appendChild(outerListTag); |
149 | 196 |
150 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); | 197 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
151 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); | 198 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
152 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); | 199 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
153 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); | 200 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
154 | 201 |
155 ContentExtractor extractor = new ContentExtractor(mRoot); | 202 ContentExtractor extractor = new ContentExtractor(mRoot); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 | 574 |
528 final String htmlArticle = | 575 final String htmlArticle = |
529 "<h1>" + CONTENT_TEXT + "</h1>" + | 576 "<h1>" + CONTENT_TEXT + "</h1>" + |
530 "<div itemscope itemtype=\"http://schema.org/Movie\">" + article + "
</div>"; | 577 "<div itemscope itemtype=\"http://schema.org/Movie\">" + article + "
</div>"; |
531 final String expected = "<h1>" + CONTENT_TEXT + "</h1>" + article; | 578 final String expected = "<h1>" + CONTENT_TEXT + "</h1>" + article; |
532 | 579 |
533 // Non-article schema.org types should not use the fast path. | 580 // Non-article schema.org types should not use the fast path. |
534 assertExtractor(expected, htmlArticle); | 581 assertExtractor(expected, htmlArticle); |
535 } | 582 } |
536 } | 583 } |
OLD | NEW |