| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 import org.chromium.distiller.TestUtil; | 8 import org.chromium.distiller.TestUtil; |
| 9 | 9 |
| 10 import java.util.List; | 10 import java.util.List; |
| 11 | 11 |
| 12 import com.google.gwt.dom.client.Document; | 12 import com.google.gwt.dom.client.Document; |
| 13 import com.google.gwt.dom.client.Element; | 13 import com.google.gwt.dom.client.Element; |
| 14 | 14 |
| 15 public class WebTableTest extends DomDistillerJsTestCase { | 15 public class WebTableTest extends DomDistillerJsTestCase { |
| 16 public void testGetImageUrlList() { |
| 17 mHead.setInnerHTML("<base href=\"http://example.com/\">"); |
| 18 Element table = Document.get().createTableElement(); |
| 19 |
| 20 String html = |
| 21 "<tbody>" + |
| 22 "<tr>" + |
| 23 "<td><img src=\"http://example.com/table.png\" " + |
| 24 "srcset=\"image100 100w, //example.org/image300 300
w\"></td>" + |
| 25 "<td>" + |
| 26 "<picture>" + |
| 27 "<source srcset=\"image200 200w, //example.org/image400
400w\">" + |
| 28 "<img>" + |
| 29 "</picture>" + |
| 30 "</td>" + |
| 31 "</tr>" + |
| 32 "</tbody>"; |
| 33 |
| 34 table.setInnerHTML(html); |
| 35 mBody.appendChild(table); |
| 36 |
| 37 WebTable webTable = new WebTable(table); |
| 38 List<String> urls = webTable.getImageUrlList(); |
| 39 assertEquals(5, urls.size()); |
| 40 assertEquals("http://example.com/table.png", urls.get(0)); |
| 41 assertEquals("http://example.com/image100", urls.get(1)); |
| 42 assertEquals("http://example.org/image300", urls.get(2)); |
| 43 assertEquals("http://example.com/image200", urls.get(3)); |
| 44 assertEquals("http://example.org/image400", urls.get(4)); |
| 45 } |
| 46 |
| 16 public void testGenerateOutput() { | 47 public void testGenerateOutput() { |
| 17 Element table = Document.get().createTableElement(); | 48 Element table = Document.get().createTableElement(); |
| 18 String html = "<tbody>" + | 49 String html = "<tbody>" + |
| 19 "<tr>" + | 50 "<tr>" + |
| 20 "<td>row1col1</td>" + | 51 "<td>row1col1</td>" + |
| 21 "<td><img src=\"http://example.com/table.png\"></t
d>" + | 52 "<td><img src=\"http://example.com/table.png\"></t
d>" + |
| 53 "<td><picture><img></picture></td>" + |
| 22 "</tr>" + | 54 "</tr>" + |
| 23 "</tbody>"; | 55 "</tbody>"; |
| 24 table.setInnerHTML(html); | 56 table.setInnerHTML(html); |
| 25 mBody.appendChild(table); | 57 mBody.appendChild(table); |
| 26 | 58 |
| 27 WebTable webTable = new WebTable(table); | 59 WebTable webTable = new WebTable(table); |
| 28 String got = webTable.generateOutput(false); | 60 String got = webTable.generateOutput(false); |
| 29 | 61 |
| 30 // Output should be the same as the input in this case. | 62 // Output should be the same as the input in this case. |
| 31 assertEquals("<table>" + html + "</table>", TestUtil.removeAllDirAttribu
tes(got)); | 63 assertEquals("<table>" + html + "</table>", TestUtil.removeAllDirAttribu
tes(got)); |
| 64 |
| 65 // Test getImageUrlList() as well. |
| 32 List<String> imgUrls = webTable.getImageUrlList(); | 66 List<String> imgUrls = webTable.getImageUrlList(); |
| 33 assertEquals(1, imgUrls.size()); | 67 assertEquals(1, imgUrls.size()); |
| 34 assertEquals("http://example.com/table.png", imgUrls.get(0)); | 68 assertEquals("http://example.com/table.png", imgUrls.get(0)); |
| 35 } | 69 } |
| 36 } | 70 } |
| OLD | NEW |