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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 196 |
197 mHead.setInnerHTML("<base href=\"http://example.com/\">"); | 197 mHead.setInnerHTML("<base href=\"http://example.com/\">"); |
198 mBody.setInnerHTML(html); | 198 mBody.setInnerHTML(html); |
199 | 199 |
200 ContentExtractor extractor = new ContentExtractor(mRoot); | 200 ContentExtractor extractor = new ContentExtractor(mRoot); |
201 String extractedContent = extractor.extractContent(); | 201 String extractedContent = extractor.extractContent(); |
202 assertEquals(expected, | 202 assertEquals(expected, |
203 TestUtil.removeAllDirAttributes(extractedContent)); | 203 TestUtil.removeAllDirAttributes(extractedContent)); |
204 } | 204 } |
205 | 205 |
| 206 public void testKeepingWidthAndHeightAttributes() { |
| 207 String html = |
| 208 "<h1>" + |
| 209 CONTENT_TEXT + |
| 210 "</h1>" + |
| 211 "<p>" + |
| 212 CONTENT_TEXT + |
| 213 "</p>" + |
| 214 "<img style=\"align: left\" src=\"/test.png\" " + |
| 215 "width=\"200\" height=\"300\">" + |
| 216 "<img style=\"align: left\" src=\"/test.png\" " + |
| 217 "width=\"200\">" + |
| 218 "<img style=\"align: left\" src=\"/test.png\">"; |
| 219 |
| 220 final String expected = |
| 221 "<h1>" + |
| 222 CONTENT_TEXT + |
| 223 "</h1>" + |
| 224 "<p>" + |
| 225 CONTENT_TEXT + |
| 226 "</p>" + |
| 227 "<img src=\"http://example.com/test.png\" " + |
| 228 "width=\"200\" height=\"300\">" + |
| 229 "<img src=\"http://example.com/test.png\" " + |
| 230 "width=\"200\">" + |
| 231 "<img src=\"http://example.com/test.png\">"; |
| 232 |
| 233 mHead.setInnerHTML("<base href=\"http://example.com/\">"); |
| 234 mBody.setInnerHTML(html); |
| 235 |
| 236 ContentExtractor extractor = new ContentExtractor(mRoot); |
| 237 String extractedContent = extractor.extractContent(); |
| 238 assertEquals(expected, |
| 239 TestUtil.removeAllDirAttributes(extractedContent)); |
| 240 } |
| 241 |
206 public void testPreserveOrderedList() { | 242 public void testPreserveOrderedList() { |
207 Element outerListTag = Document.get().createElement("OL"); | 243 Element outerListTag = Document.get().createElement("OL"); |
208 mBody.appendChild(outerListTag); | 244 mBody.appendChild(outerListTag); |
209 | 245 |
210 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); | 246 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
211 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); | 247 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
212 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); | 248 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
213 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); | 249 outerListTag.appendChild(TestUtil.createListItem(CONTENT_TEXT)); |
214 | 250 |
215 ContentExtractor extractor = new ContentExtractor(mRoot); | 251 ContentExtractor extractor = new ContentExtractor(mRoot); |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 634 |
599 final String htmlArticle = | 635 final String htmlArticle = |
600 "<h1>" + CONTENT_TEXT + "</h1>" + | 636 "<h1>" + CONTENT_TEXT + "</h1>" + |
601 "<div itemscope itemtype=\"http://schema.org/Movie\">" + article + "
</div>"; | 637 "<div itemscope itemtype=\"http://schema.org/Movie\">" + article + "
</div>"; |
602 final String expected = "<h1>" + CONTENT_TEXT + "</h1>" + article; | 638 final String expected = "<h1>" + CONTENT_TEXT + "</h1>" + article; |
603 | 639 |
604 // Non-article schema.org types should not use the fast path. | 640 // Non-article schema.org types should not use the fast path. |
605 assertExtractor(expected, htmlArticle); | 641 assertExtractor(expected, htmlArticle); |
606 } | 642 } |
607 } | 643 } |
OLD | NEW |