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.ImageElement; |
12 import com.google.gwt.dom.client.Node; | 13 import com.google.gwt.dom.client.Node; |
13 import com.google.gwt.dom.client.NodeList; | 14 import com.google.gwt.dom.client.NodeList; |
14 | 15 |
15 import java.util.Map; | 16 import java.util.Map; |
16 import java.util.List; | 17 import java.util.List; |
17 | 18 |
18 public class DomUtilTest extends DomDistillerJsTestCase { | 19 public class DomUtilTest extends DomDistillerJsTestCase { |
19 public void testGetAttributes() { | 20 public void testGetAttributes() { |
20 Element e = Document.get().createDivElement(); | 21 Element e = Document.get().createDivElement(); |
21 e.setInnerHTML("<div style=\"width:50px; height:100px\" id=\"f\" class=\
"sdf\"></div>"); | 22 e.setInnerHTML("<div style=\"width:50px; height:100px\" id=\"f\" class=\
"sdf\"></div>"); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 mHead.setInnerHTML("<base href=\"http://example.com/\">"); | 267 mHead.setInnerHTML("<base href=\"http://example.com/\">"); |
267 mBody.setInnerHTML(html); | 268 mBody.setInnerHTML(html); |
268 | 269 |
269 mBody.setInnerHTML(html); | 270 mBody.setInnerHTML(html); |
270 for (int i = 0; i < mBody.getChildCount(); i++) { | 271 for (int i = 0; i < mBody.getChildCount(); i++) { |
271 DomUtil.makeAllLinksAbsolute(mBody.getChild(i)); | 272 DomUtil.makeAllLinksAbsolute(mBody.getChild(i)); |
272 } | 273 } |
273 assertEquals(expected, mBody.getInnerHTML()); | 274 assertEquals(expected, mBody.getInnerHTML()); |
274 } | 275 } |
275 | 276 |
| 277 public void testGetSrcSetUrls() { |
| 278 String html = |
| 279 "<img src=\"http://example.com/image\" " + |
| 280 "srcset=\"http://example.com/image200 200w, http://example.com/ima
ge400 400w\">"; |
| 281 |
| 282 mBody.setInnerHTML(html); |
| 283 List<String> list = DomUtil.getSrcSetUrls((ImageElement) mBody.getChild(
0)); |
| 284 assertEquals(2, list.size()); |
| 285 assertEquals("http://example.com/image200", list.get(0)); |
| 286 assertEquals("http://example.com/image400", list.get(1)); |
| 287 } |
| 288 |
276 public void testStripTableBackgroundColorAttributes() { | 289 public void testStripTableBackgroundColorAttributes() { |
277 String tableWithBGColorHTML = | 290 String tableWithBGColorHTML = |
278 "<table bgcolor=\"red\">" + | 291 "<table bgcolor=\"red\">" + |
279 "<tbody>" + | 292 "<tbody>" + |
280 "<tr bgcolor=\"red\">" + | 293 "<tr bgcolor=\"red\">" + |
281 "<th bgcolor=\"red\">text</th>" + | 294 "<th bgcolor=\"red\">text</th>" + |
282 "<th bgcolor=\"red\">text</th>" + | 295 "<th bgcolor=\"red\">text</th>" + |
283 "</tr><tr bgcolor=\"red\">" + | 296 "</tr><tr bgcolor=\"red\">" + |
284 "<td bgcolor=\"red\">text</td>" + | 297 "<td bgcolor=\"red\">text</td>" + |
285 "<td bgcolor=\"red\">text</td>" + | 298 "<td bgcolor=\"red\">text</td>" + |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 element = element.getNextSiblingElement(); | 625 element = element.getNextSiblingElement(); |
613 assertEquals(300*200, DomUtil.getArea(element)); | 626 assertEquals(300*200, DomUtil.getArea(element)); |
614 | 627 |
615 element = element.getNextSiblingElement(); | 628 element = element.getNextSiblingElement(); |
616 assertEquals(400*100, DomUtil.getArea(element)); | 629 assertEquals(400*100, DomUtil.getArea(element)); |
617 | 630 |
618 element = element.getFirstChildElement(); | 631 element = element.getFirstChildElement(); |
619 assertEquals(400*100, DomUtil.getArea(element)); | 632 assertEquals(400*100, DomUtil.getArea(element)); |
620 } | 633 } |
621 } | 634 } |
OLD | NEW |