Chromium Code Reviews| 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 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("", wi.generateOutput(false)); | |
|
mdjones
2017/01/17 17:41:47
Remove commented line.
wychen
2017/01/18 17:29:54
Done.
| |
| 46 assertEquals(4, urls.size()); | |
| 47 assertEquals("http://example.com/image200", urls.get(0)); | |
| 48 assertEquals("http://example.org/image400", urls.get(1)); | |
| 49 assertEquals("http://example.com/image100", urls.get(2)); | |
| 50 assertEquals("http://example.org/image300", urls.get(3)); | |
| 51 } | |
| 27 } | 52 } |
| OLD | NEW |