Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: javatests/org/chromium/distiller/EmbedExtractorTest.java

Issue 1754213004: Retain image sizes (Closed) Base URL: https://github.com/chromium/dom-distiller.git@master
Patch Set: wychen's comment addressed Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 com.google.gwt.dom.client.Style;
7 import org.chromium.distiller.webdocument.WebEmbed; 8 import org.chromium.distiller.webdocument.WebEmbed;
9 import org.chromium.distiller.webdocument.WebImage;
8 import org.chromium.distiller.extractors.embeds.EmbedExtractor; 10 import org.chromium.distiller.extractors.embeds.EmbedExtractor;
9 import org.chromium.distiller.extractors.embeds.TwitterExtractor; 11 import org.chromium.distiller.extractors.embeds.TwitterExtractor;
10 import org.chromium.distiller.extractors.embeds.VimeoExtractor; 12 import org.chromium.distiller.extractors.embeds.VimeoExtractor;
11 import org.chromium.distiller.extractors.embeds.YouTubeExtractor; 13 import org.chromium.distiller.extractors.embeds.YouTubeExtractor;
14 import org.chromium.distiller.extractors.embeds.ImageExtractor;
12 15
13 import com.google.gwt.dom.client.Document; 16 import com.google.gwt.dom.client.Document;
14 import com.google.gwt.dom.client.Element; 17 import com.google.gwt.dom.client.Element;
15 import com.google.gwt.dom.client.IFrameElement; 18 import com.google.gwt.dom.client.IFrameElement;
19 import com.google.gwt.dom.client.ImageElement;
16 20
17 import java.util.List; 21 import java.util.List;
18 22
19 public class EmbedExtractorTest extends DomDistillerJsTestCase { 23 public class EmbedExtractorTest extends DomDistillerJsTestCase {
20 24
25 final String IMAGE_BASE64 = "data:image/png;base64,iVBORw0KGgo" +
wychen 2016/03/18 08:20:25 Add a comment about what this looks like, especial
26 "AAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/" +
27 "w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
28
21 public void testYouTubeExtractor() { 29 public void testYouTubeExtractor() {
22 Element youtube = TestUtil.createIframe(); 30 Element youtube = TestUtil.createIframe();
23 youtube.setAttribute("src", "http://www.youtube.com/embed/M7lc1UVf-VE?au toplay=1"); 31 youtube.setAttribute("src", "http://www.youtube.com/embed/M7lc1UVf-VE?au toplay=1");
24 32
25 EmbedExtractor extractor = new YouTubeExtractor(); 33 EmbedExtractor extractor = new YouTubeExtractor();
26 WebEmbed result = (WebEmbed) extractor.extract(youtube); 34 WebEmbed result = (WebEmbed) extractor.extract(youtube);
27 35
28 // Check YouTube specific attributes 36 // Check YouTube specific attributes
29 assertNotNull(result); 37 assertNotNull(result);
30 assertEquals("youtube", result.getType()); 38 assertEquals("youtube", result.getType());
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 201
194 // Test no important twitter content. 202 // Test no important twitter content.
195 notTwitter = TestUtil.createIframe(); 203 notTwitter = TestUtil.createIframe();
196 mBody.appendChild(notTwitter); 204 mBody.appendChild(notTwitter);
197 notTwitter.getContentDocument().getBody().setInnerHTML( 205 notTwitter.getContentDocument().getBody().setInnerHTML(
198 iframeStructure.replaceAll("data-tweet-id", "data-bad-id")); 206 iframeStructure.replaceAll("data-tweet-id", "data-bad-id"));
199 207
200 result = (WebEmbed) extractor.extract(notTwitter); 208 result = (WebEmbed) extractor.extract(notTwitter);
201 assertNull(result); 209 assertNull(result);
202 } 210 }
211
212 public void testImageExtractorWithWidthHeightAttributes() {
wychen 2016/03/18 08:20:25 Add a few more tests to handle 0.
dalmirsilva 2016/03/18 17:20:38 Done.
213 ImageElement image = TestUtil.createImage();
214 image.setSrc(IMAGE_BASE64);
215 image.setAttribute("width", "32");
216 image.setAttribute("height", "32");
217
218 EmbedExtractor extractor = new ImageExtractor();
219 WebImage result = (WebImage) extractor.extract(image);
220
221 assertNotNull(result);
222 assertEquals(32, result.getWidth());
223 assertEquals(32, result.getHeight());
224 }
225
226 public void testImageExtractorWithOneAttribute() {
227 ImageElement image = TestUtil.createImage();
228 image.setSrc(IMAGE_BASE64);
229 image.setWidth(32);
230 mBody.appendChild(image);
231 EmbedExtractor extractor = new ImageExtractor();
232 WebImage result = (WebImage) extractor.extract(image);
233 assertNotNull(result);
234 assertEquals(32, result.getWidth());
235 assertEquals(32, result.getHeight());
236 }
237
238 public void testImageExtractorWithHeightCSS() {
239 ImageElement image = TestUtil.createImage();
240 image.setSrc(IMAGE_BASE64);
241 image.getStyle().setHeight(100, Style.Unit.PX);
242 mBody.appendChild(image);
243 EmbedExtractor extractor = new ImageExtractor();
244 WebImage result = (WebImage) extractor.extract(image);
245 assertNotNull(result);
246 assertEquals(100, result.getWidth());
247 assertEquals(100, result.getHeight());
248 }
249
250 public void testImageExtractorWithWidthHeightCSSPX() {
251 ImageElement image = TestUtil.createImage();
252 image.setSrc(IMAGE_BASE64);
253 image.getStyle().setHeight(100, Style.Unit.PX);
254 image.getStyle().setWidth(48, Style.Unit.PX);
255 mBody.appendChild(image);
256 EmbedExtractor extractor = new ImageExtractor();
257 WebImage result = (WebImage) extractor.extract(image);
258 assertNotNull(result);
259 assertEquals(48, result.getWidth());
260 assertEquals(100, result.getHeight());
261 }
262
263 public void testImageExtractorWithWidthAttributeHeightCSS() {
264 ImageElement image = TestUtil.createImage();
265 image.setSrc(IMAGE_BASE64);
266 image.getStyle().setHeight(100, Style.Unit.PX);
267 image.setAttribute("width", "144");
268 mBody.appendChild(image);
269 EmbedExtractor extractor = new ImageExtractor();
270 WebImage result = (WebImage) extractor.extract(image);
271 assertNotNull(result);
272 assertEquals(144, result.getWidth());
273 assertEquals(100, result.getHeight());
274 }
275
276 public void testImageExtractorWithAttributesCSS() {
277 ImageElement image = TestUtil.createImage();
278 image.setSrc(IMAGE_BASE64);
279 image.setAttribute("width", "32");
280 image.setAttribute("height", "32");
281 image.getStyle().setHeight(48, Style.Unit.PX);
282 image.getStyle().setWidth(48, Style.Unit.PX);
283 mBody.appendChild(image);
284 EmbedExtractor extractor = new ImageExtractor();
285 WebImage result = (WebImage) extractor.extract(image);
286 assertNotNull(result);
287 assertEquals(48, result.getWidth());
288 assertEquals(48, result.getHeight());
289 }
290
291 public void testImageExtractorWithAttributesCSSHeightCMAndWidthAttrb() {
292 ImageElement image = TestUtil.createImage();
293 image.setSrc(IMAGE_BASE64);
294 image.getStyle().setHeight(1, Style.Unit.CM);
295 image.setWidth(50);
296 mBody.appendChild(image);
297 EmbedExtractor extractor = new ImageExtractor();
298 WebImage result = (WebImage) extractor.extract(image);
299 assertNotNull(result);
300 assertEquals(38, result.getHeight());
301 assertEquals(50, result.getWidth());
302 }
303
304 public void testImageExtractorWithAttributesCSSHeightCM() {
305 ImageElement image = TestUtil.createImage();
306 image.setSrc(IMAGE_BASE64);
307 image.getStyle().setHeight(1, Style.Unit.CM);
308 mBody.appendChild(image);
309 EmbedExtractor extractor = new ImageExtractor();
310 WebImage result = (WebImage) extractor.extract(image);
311 assertNotNull(result);
312 assertEquals(38, result.getHeight());
313 assertEquals(38, result.getWidth());
314 }
203 } 315 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698