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

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

Issue 2020403002: Add support for figure element (Closed) Base URL: https://github.com/chromium/dom-distiller.git@master
Patch Set: merged from master Created 4 years, 6 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 com.google.gwt.dom.client.Style;
8 import org.chromium.distiller.webdocument.WebEmbed; 8 import org.chromium.distiller.webdocument.WebEmbed;
9 import org.chromium.distiller.webdocument.WebImage; 9 import org.chromium.distiller.webdocument.WebImage;
10 import org.chromium.distiller.extractors.embeds.EmbedExtractor; 10 import org.chromium.distiller.extractors.embeds.EmbedExtractor;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 result = (WebEmbed) extractor.extract(nontweet); 203 result = (WebEmbed) extractor.extract(nontweet);
204 assertNull(result); 204 assertNull(result);
205 } 205 }
206 206
207 public void testRenderedTwitterExtractor() { 207 public void testRenderedTwitterExtractor() {
208 IFrameElement twitter = TestUtil.createIframe(); 208 IFrameElement twitter = TestUtil.createIframe();
209 // Add iframe to body so its document is generated. 209 // Add iframe to body so its document is generated.
210 mBody.appendChild(twitter); 210 mBody.appendChild(twitter);
211 211
212 // This string represents a very simplified version of the twitter ifram e embed structure. 212 // This string represents a very simplified version of the twitter ifram e embed structure.
213 String iframeStructure = 213 String iframeStructure =
214 "<div class=\"media-forward root standalone-tweet ltr\"" + 214 "<div class=\"media-forward root standalone-tweet ltr\"" +
215 "data-iframe-title=\"Embedded Tweet\"" + 215 "data-iframe-title=\"Embedded Tweet\"" +
216 "data-scribe=\"page:tweet\">" + 216 "data-scribe=\"page:tweet\">" +
217 "<blockquote data-tweet-id=\"1234567890\"" + 217 "<blockquote data-tweet-id=\"1234567890\"" +
218 "data-scribe=\"section:subject\">" + 218 "data-scribe=\"section:subject\">" +
219 "<div class=\"cards-base cards-multimedia customisable-b order\"" + 219 "<div class=\"cards-base cards-multimedia customisable-b order\"" +
220 "data-scribe=\"component:card\"" + 220 "data-scribe=\"component:card\"" +
221 "data-video-content-id=\"0987654321\">" + 221 "data-video-content-id=\"0987654321\">" +
222 "</div>" + 222 "</div>" +
223 "<div class=\"header\">" + 223 "<div class=\"header\">" +
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 assertNotNull(result); 393 assertNotNull(result);
394 assertEquals("<img src=\"http://example.com/image.png\">", result.genera teOutput(false)); 394 assertEquals("<img src=\"http://example.com/image.png\">", result.genera teOutput(false));
395 } 395 }
396 396
397 public void testImageExtractorLazy() { 397 public void testImageExtractorLazy() {
398 extractLazilyLoadedImage("data-src"); 398 extractLazilyLoadedImage("data-src");
399 extractLazilyLoadedImage("datasrc"); 399 extractLazilyLoadedImage("datasrc");
400 extractLazilyLoadedImage("data-original"); 400 extractLazilyLoadedImage("data-original");
401 extractLazilyLoadedImage("data-url"); 401 extractLazilyLoadedImage("data-url");
402 } 402 }
403
404 public void testFigureWithoutCaption() {
405 ImageElement image = TestUtil.createImage();
406 image.setSrc("http://wwww.example.com/image.jpeg");
407 image.setAttribute("width", "100");
408 image.setAttribute("height", "100");
409 Element figure = Document.get().createElement("FIGURE");
410 figure.appendChild(image);
411 mBody.appendChild(figure);
412
413 EmbedExtractor extractor = new ImageExtractor();
414 WebImage result = (WebImage) extractor.extract(figure);
415 String got = result.generateOutput(false);
416 String expected =
417 "<figure>" +
418 "<img src=\"http://wwww.example.com/image.jpeg\"" +
419 " width=\"100\" height=\"100\">" +
420 "</figure>";
421 assertNotNull(result);
422 assertEquals(100, result.getHeight());
423 assertEquals(100, result.getWidth());
424 assertEquals(expected, got);
425 }
426
427 public void testFigureWithCaption() {
428 ImageElement image = TestUtil.createImage();
429 image.setSrc("http://wwww.example.com/image.jpeg");
430 image.setAttribute("width", "100");
431 image.setAttribute("height", "100");
432 Element figure = Document.get().createElement("FIGURE");
433 figure.appendChild(image);
434 Element figcaption = Document.get().createElement("FIGCAPTION");
435 figcaption.setInnerHTML("This is a caption");
436 figure.appendChild(figcaption);
437 mBody.appendChild(figure);
438
439 EmbedExtractor extractor = new ImageExtractor();
440 WebImage result = (WebImage) extractor.extract(figure);
441 String got = result.generateOutput(false);
442 String expected =
443 "<figure>" +
444 "<img src=\"http://wwww.example.com/image.jpeg\"" +
445 " width=\"100\" height=\"100\">" +
446 "<figcaption>This is a caption</figcaption>" +
447 "</figure>";
448 assertNotNull(result);
449 assertEquals(100, result.getHeight());
450 assertEquals(100, result.getWidth());
451 assertEquals(expected, got);
452 }
453
454 public void testFigureWithoutImageAndCaption() {
455 Element figure = Document.get().createElement("FIGURE");
456 mBody.appendChild(figure);
457
458 EmbedExtractor extractor = new ImageExtractor();
459 WebImage result = (WebImage) extractor.extract(figure);
460 assertNull(result);
461 }
403 } 462 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698