| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 | 8 |
| 9 import java.util.List; | 9 import java.util.List; |
| 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.ImageElement; | 13 import com.google.gwt.dom.client.ImageElement; |
| 14 import org.chromium.distiller.DomUtil; |
| 13 | 15 |
| 14 public class WebImageTest extends DomDistillerJsTestCase { | 16 public class WebImageTest extends DomDistillerJsTestCase { |
| 15 public void testGetSrcList() { | 17 public void testGetSrcList() { |
| 18 mHead.setInnerHTML("<base href=\"http://example.com/\">"); |
| 19 |
| 16 ImageElement img = Document.get().createImageElement(); | 20 ImageElement img = Document.get().createImageElement(); |
| 17 img.setSrc("http://example.com/image"); | 21 img.setSrc("image"); |
| 18 img.setAttribute("srcset", | 22 img.setAttribute("srcset", |
| 19 "http://example.com/image200 200w, http://example.com/image400 4
00w"); | 23 "image200 200w, image400 400w"); |
| 20 WebImage wi = new WebImage(img, 1, 1, img.getSrc()); | 24 WebImage wi = new WebImage(img, 1, 1, img.getSrc()); |
| 21 List<String> urls = wi.getUrlList(); | 25 List<String> urls = wi.getUrlList(); |
| 22 assertEquals(3, urls.size()); | 26 assertEquals(3, urls.size()); |
| 23 assertEquals("http://example.com/image", urls.get(0)); | 27 assertEquals("http://example.com/image", urls.get(0)); |
| 24 assertEquals("http://example.com/image200", urls.get(1)); | 28 assertEquals("http://example.com/image200", urls.get(1)); |
| 25 assertEquals("http://example.com/image400", urls.get(2)); | 29 assertEquals("http://example.com/image400", urls.get(2)); |
| 26 } | 30 } |
| 31 |
| 32 public void testGetSrcListInPicture() { |
| 33 mHead.setInnerHTML("<base href=\"http://example.com/\">"); |
| 34 |
| 35 String html = |
| 36 "<picture>" + |
| 37 "<source data-srcset=\"image200 200w, //example.org/image400 400w\
">" + |
| 38 "<source srcset=\"image100 100w, //example.org/image300 300w\">" + |
| 39 "<img>" + |
| 40 "</picture>"; |
| 41 Element container = Document.get().createDivElement(); |
| 42 container.setInnerHTML(html); |
| 43 WebImage wi = new WebImage(container.getFirstChildElement(), 1, 1, ""); |
| 44 List<String> urls = wi.getUrlList(); |
| 45 assertEquals(4, urls.size()); |
| 46 assertEquals("http://example.com/image200", urls.get(0)); |
| 47 assertEquals("http://example.org/image400", urls.get(1)); |
| 48 assertEquals("http://example.com/image100", urls.get(2)); |
| 49 assertEquals("http://example.org/image300", urls.get(3)); |
| 50 } |
| 51 |
| 52 public void testGenerateOutput() { |
| 53 mHead.setInnerHTML("<base href=\"http://example.com/\">"); |
| 54 |
| 55 String html = |
| 56 "<picture>" + |
| 57 "<source srcset=\"image\">" + |
| 58 "<img dirty-attributes>" + |
| 59 "</picture>"; |
| 60 Element container = Document.get().createDivElement(); |
| 61 container.setInnerHTML(html); |
| 62 WebImage wi = new WebImage(container.getFirstChildElement(), 0, 0, ""); |
| 63 assertEquals("<picture><source srcset=\"http://example.com/image\"><img>
</picture>", |
| 64 wi.generateOutput(false)); |
| 65 } |
| 27 } | 66 } |
| OLD | NEW |