Chromium Code Reviews| 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.WebEmbed; | 7 import org.chromium.distiller.webdocument.WebEmbed; |
| 8 import org.chromium.distiller.webdocument.WebImage; | |
| 8 import org.chromium.distiller.extractors.embeds.EmbedExtractor; | 9 import org.chromium.distiller.extractors.embeds.EmbedExtractor; |
| 9 import org.chromium.distiller.extractors.embeds.TwitterExtractor; | 10 import org.chromium.distiller.extractors.embeds.TwitterExtractor; |
| 10 import org.chromium.distiller.extractors.embeds.VimeoExtractor; | 11 import org.chromium.distiller.extractors.embeds.VimeoExtractor; |
| 11 import org.chromium.distiller.extractors.embeds.YouTubeExtractor; | 12 import org.chromium.distiller.extractors.embeds.YouTubeExtractor; |
| 13 import org.chromium.distiller.extractors.embeds.ImageExtractor; | |
| 12 | 14 |
| 13 import com.google.gwt.dom.client.Document; | 15 import com.google.gwt.dom.client.Document; |
| 14 import com.google.gwt.dom.client.Element; | 16 import com.google.gwt.dom.client.Element; |
| 15 import com.google.gwt.dom.client.IFrameElement; | 17 import com.google.gwt.dom.client.IFrameElement; |
| 18 import com.google.gwt.dom.client.ImageElement; | |
| 16 | 19 |
| 17 import java.util.List; | 20 import java.util.List; |
| 18 | 21 |
| 19 public class EmbedExtractorTest extends DomDistillerJsTestCase { | 22 public class EmbedExtractorTest extends DomDistillerJsTestCase { |
| 20 | 23 |
| 21 public void testYouTubeExtractor() { | 24 public void testYouTubeExtractor() { |
| 22 Element youtube = TestUtil.createIframe(); | 25 Element youtube = TestUtil.createIframe(); |
| 23 youtube.setAttribute("src", "http://www.youtube.com/embed/M7lc1UVf-VE?au toplay=1"); | 26 youtube.setAttribute("src", "http://www.youtube.com/embed/M7lc1UVf-VE?au toplay=1"); |
| 24 | 27 |
| 25 EmbedExtractor extractor = new YouTubeExtractor(); | 28 EmbedExtractor extractor = new YouTubeExtractor(); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 | 196 |
| 194 // Test no important twitter content. | 197 // Test no important twitter content. |
| 195 notTwitter = TestUtil.createIframe(); | 198 notTwitter = TestUtil.createIframe(); |
| 196 mBody.appendChild(notTwitter); | 199 mBody.appendChild(notTwitter); |
| 197 notTwitter.getContentDocument().getBody().setInnerHTML( | 200 notTwitter.getContentDocument().getBody().setInnerHTML( |
| 198 iframeStructure.replaceAll("data-tweet-id", "data-bad-id")); | 201 iframeStructure.replaceAll("data-tweet-id", "data-bad-id")); |
| 199 | 202 |
| 200 result = (WebEmbed) extractor.extract(notTwitter); | 203 result = (WebEmbed) extractor.extract(notTwitter); |
| 201 assertNull(result); | 204 assertNull(result); |
| 202 } | 205 } |
| 206 | |
| 207 public void testImageExtractorWithWidthHeightAttributes() { | |
| 208 ImageElement image = TestUtil.createImage(); | |
| 209 image.setSrc("http://www.test.com/image.jpg"); | |
| 210 image.setAttribute("width", "32"); | |
| 211 image.setAttribute("height", "32"); | |
| 212 | |
| 213 EmbedExtractor extractor = new ImageExtractor(); | |
| 214 WebImage result = (WebImage) extractor.extract(image); | |
| 215 | |
| 216 assertNotNull(result); | |
| 217 assertEquals("http://www.test.com/image.jpg", result.getSrc()); | |
| 218 assertEquals(32, result.getWidth()); | |
| 219 assertEquals(32, result.getHeight()); | |
| 220 } | |
| 221 | |
| 222 public void testImageExtractorWithOneAttribute() { | |
| 223 ImageElement image = TestUtil.createImage(); | |
| 224 image.setSrc("http://www.test.com/image.jpg"); | |
| 225 image.setAttribute("width", "32"); | |
| 226 | |
| 227 EmbedExtractor extractor = new ImageExtractor(); | |
| 228 WebImage result = (WebImage) extractor.extract(image); | |
| 229 assertNotNull(result); | |
| 230 assertEquals("http://www.test.com/image.jpg", result.getSrc()); | |
| 231 assertEquals(32, result.getWidth()); | |
| 232 assertEquals(0, result.getHeight()); | |
|
wychen
2016/03/11 08:25:35
We need to keep aspect ratio.
dalmirsilva
2016/03/14 18:28:06
Aspect ratio will be kept. However, we could not r
wychen
2016/03/14 19:55:14
If it is not possible to test here, we can add bro
| |
| 233 } | |
| 203 } | 234 } |
| OLD | NEW |