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

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: comments 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
« no previous file with comments | « javatests/org/chromium/distiller/ContentExtractorTest.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /**
26 * 5x5 red dot image
27 */
28 final String IMAGE_BASE64 = "data:image/png;base64,iVBORw0KGgo" +
29 "AAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/" +
30 "w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
31
21 public void testYouTubeExtractor() { 32 public void testYouTubeExtractor() {
22 Element youtube = TestUtil.createIframe(); 33 Element youtube = TestUtil.createIframe();
23 youtube.setAttribute("src", "http://www.youtube.com/embed/M7lc1UVf-VE?au toplay=1"); 34 youtube.setAttribute("src", "http://www.youtube.com/embed/M7lc1UVf-VE?au toplay=1");
24 35
25 EmbedExtractor extractor = new YouTubeExtractor(); 36 EmbedExtractor extractor = new YouTubeExtractor();
26 WebEmbed result = (WebEmbed) extractor.extract(youtube); 37 WebEmbed result = (WebEmbed) extractor.extract(youtube);
27 38
28 // Check YouTube specific attributes 39 // Check YouTube specific attributes
29 assertNotNull(result); 40 assertNotNull(result);
30 assertEquals("youtube", result.getType()); 41 assertEquals("youtube", result.getType());
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 204
194 // Test no important twitter content. 205 // Test no important twitter content.
195 notTwitter = TestUtil.createIframe(); 206 notTwitter = TestUtil.createIframe();
196 mBody.appendChild(notTwitter); 207 mBody.appendChild(notTwitter);
197 notTwitter.getContentDocument().getBody().setInnerHTML( 208 notTwitter.getContentDocument().getBody().setInnerHTML(
198 iframeStructure.replaceAll("data-tweet-id", "data-bad-id")); 209 iframeStructure.replaceAll("data-tweet-id", "data-bad-id"));
199 210
200 result = (WebEmbed) extractor.extract(notTwitter); 211 result = (WebEmbed) extractor.extract(notTwitter);
201 assertNull(result); 212 assertNull(result);
202 } 213 }
214
215 public void testImageExtractorWithWidthHeightAttributes() {
216 ImageElement image = TestUtil.createImage();
217 image.setSrc(IMAGE_BASE64);
218 image.setAttribute("width", "32");
219 image.setAttribute("height", "32");
220 EmbedExtractor extractor = new ImageExtractor();
221 WebImage result = (WebImage) extractor.extract(image);
222 assertNotNull(result);
223 assertEquals(32, result.getWidth());
224 assertEquals(32, result.getHeight());
225 }
226
227 public void testImageExtractorWithNoAttributes() {
228 ImageElement image = TestUtil.createImage();
229 mBody.appendChild(image);
230 EmbedExtractor extractor = new ImageExtractor();
231 WebImage result = (WebImage) extractor.extract(image);
232 assertNotNull(result);
233 assertEquals(0, result.getWidth());
234 assertEquals(0, result.getHeight());
235 }
236
237 public void testImageExtractorWithSettingDimension() {
238 ImageElement image = TestUtil.createImage();
239 image.setSrc(IMAGE_BASE64);
240 mBody.appendChild(image);
241 EmbedExtractor extractor = new ImageExtractor();
242 WebImage result = (WebImage) extractor.extract(image);
243 assertNotNull(result);
244 assertEquals(5, result.getWidth());
245 assertEquals(5, result.getHeight());
246 }
247
248 public void testImageExtractorWithOneAttribute() {
249 ImageElement image = TestUtil.createImage();
250 image.setSrc(IMAGE_BASE64);
251 image.setWidth(32);
252 mBody.appendChild(image);
253 EmbedExtractor extractor = new ImageExtractor();
254 WebImage result = (WebImage) extractor.extract(image);
255 assertNotNull(result);
256 assertEquals(32, result.getWidth());
257 assertEquals(32, result.getHeight());
258 }
259
260 public void testImageExtractorWithHeightCSS() {
261 ImageElement image = TestUtil.createImage();
262 image.setSrc(IMAGE_BASE64);
263 image.getStyle().setHeight(100, Style.Unit.PX);
264 mBody.appendChild(image);
265 EmbedExtractor extractor = new ImageExtractor();
266 WebImage result = (WebImage) extractor.extract(image);
267 assertNotNull(result);
268 assertEquals(100, result.getWidth());
269 assertEquals(100, result.getHeight());
270 }
271
272 public void testImageExtractorWithWidthHeightCSSPX() {
273 ImageElement image = TestUtil.createImage();
274 image.setSrc(IMAGE_BASE64);
275 image.getStyle().setHeight(100, Style.Unit.PX);
276 image.getStyle().setWidth(48, Style.Unit.PX);
277 mBody.appendChild(image);
278 EmbedExtractor extractor = new ImageExtractor();
279 WebImage result = (WebImage) extractor.extract(image);
280 assertNotNull(result);
281 assertEquals(48, result.getWidth());
282 assertEquals(100, result.getHeight());
283 }
284
285 public void testImageExtractorWithWidthAttributeHeightCSS() {
286 ImageElement image = TestUtil.createImage();
287 image.setSrc(IMAGE_BASE64);
288 image.getStyle().setHeight(100, Style.Unit.PX);
289 image.setAttribute("width", "144");
290 mBody.appendChild(image);
291 EmbedExtractor extractor = new ImageExtractor();
292 WebImage result = (WebImage) extractor.extract(image);
293 assertNotNull(result);
294 assertEquals(144, result.getWidth());
295 assertEquals(100, result.getHeight());
296 }
297
298 public void testImageExtractorWithAttributesCSS() {
299 ImageElement image = TestUtil.createImage();
300 image.setSrc(IMAGE_BASE64);
301 image.setAttribute("width", "32");
302 image.setAttribute("height", "32");
303 image.getStyle().setHeight(48, Style.Unit.PX);
304 image.getStyle().setWidth(48, Style.Unit.PX);
305 mBody.appendChild(image);
306 EmbedExtractor extractor = new ImageExtractor();
307 WebImage result = (WebImage) extractor.extract(image);
308 assertNotNull(result);
309 assertEquals(48, result.getWidth());
310 assertEquals(48, result.getHeight());
311 }
312
313 public void testImageExtractorWithAttributesCSSHeightCMAndWidthAttrb() {
314 ImageElement image = TestUtil.createImage();
315 image.setSrc(IMAGE_BASE64);
316 image.getStyle().setHeight(1, Style.Unit.CM);
317 image.setWidth(50);
318 mBody.appendChild(image);
319 EmbedExtractor extractor = new ImageExtractor();
320 WebImage result = (WebImage) extractor.extract(image);
321 assertNotNull(result);
322 assertEquals(38, result.getHeight());
323 assertEquals(50, result.getWidth());
324 }
325
326 public void testImageExtractorWithAttributesCSSHeightCM() {
327 ImageElement image = TestUtil.createImage();
328 image.setSrc(IMAGE_BASE64);
329 image.getStyle().setHeight(1, Style.Unit.CM);
330 mBody.appendChild(image);
331 EmbedExtractor extractor = new ImageExtractor();
332 WebImage result = (WebImage) extractor.extract(image);
333 assertNotNull(result);
334 assertEquals(38, result.getHeight());
335 assertEquals(38, result.getWidth());
336 }
203 } 337 }
OLDNEW
« no previous file with comments | « javatests/org/chromium/distiller/ContentExtractorTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698