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 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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 ImageElement image = TestUtil.createImage(); | 373 ImageElement image = TestUtil.createImage(); |
374 image.setSrc(IMAGE_BASE64); | 374 image.setSrc(IMAGE_BASE64); |
375 image.getStyle().setHeight(1, Style.Unit.CM); | 375 image.getStyle().setHeight(1, Style.Unit.CM); |
376 mBody.appendChild(image); | 376 mBody.appendChild(image); |
377 EmbedExtractor extractor = new ImageExtractor(); | 377 EmbedExtractor extractor = new ImageExtractor(); |
378 WebImage result = (WebImage) extractor.extract(image); | 378 WebImage result = (WebImage) extractor.extract(image); |
379 assertNotNull(result); | 379 assertNotNull(result); |
380 assertEquals(38, result.getHeight()); | 380 assertEquals(38, result.getHeight()); |
381 assertEquals(38, result.getWidth()); | 381 assertEquals(38, result.getWidth()); |
382 } | 382 } |
| 383 |
| 384 public void testFigureWithoutCaption() { |
| 385 ImageElement image = TestUtil.createImage(); |
| 386 image.setSrc("http://wwww.example.com/image.jpeg"); |
| 387 image.setAttribute("width", "100"); |
| 388 image.setAttribute("height", "100"); |
| 389 Element figure = Document.get().createElement("FIGURE"); |
| 390 figure.appendChild(image); |
| 391 mBody.appendChild(figure); |
| 392 |
| 393 EmbedExtractor extractor = new ImageExtractor(); |
| 394 WebImage result = (WebImage) extractor.extract(figure); |
| 395 String got = result.generateOutput(false); |
| 396 String expected = |
| 397 "<figure>" + |
| 398 "<img src=\"http://wwww.example.com/image.jpeg\"" + |
| 399 " width=\"100\" height=\"100\">" + |
| 400 "</figure>"; |
| 401 assertNotNull(result); |
| 402 assertEquals(100, result.getHeight()); |
| 403 assertEquals(100, result.getWidth()); |
| 404 assertEquals(expected, got); |
| 405 } |
| 406 |
| 407 public void testFigureWithCaption() { |
| 408 ImageElement image = TestUtil.createImage(); |
| 409 image.setSrc("http://wwww.example.com/image.jpeg"); |
| 410 image.setAttribute("width", "100"); |
| 411 image.setAttribute("height", "100"); |
| 412 Element figure = Document.get().createElement("FIGURE"); |
| 413 figure.appendChild(image); |
| 414 Element figcaption = Document.get().createElement("FIGCAPTION"); |
| 415 figcaption.setInnerHTML("This is a caption"); |
| 416 figure.appendChild(figcaption); |
| 417 mBody.appendChild(figure); |
| 418 |
| 419 EmbedExtractor extractor = new ImageExtractor(); |
| 420 WebImage result = (WebImage) extractor.extract(figure); |
| 421 String got = result.generateOutput(false); |
| 422 String expected = |
| 423 "<figure>" + |
| 424 "<img src=\"http://wwww.example.com/image.jpeg\"" + |
| 425 " width=\"100\" height=\"100\">" + |
| 426 "<figcaption>This is a caption</figcaption>" + |
| 427 "</figure>"; |
| 428 assertNotNull(result); |
| 429 assertEquals(100, result.getHeight()); |
| 430 assertEquals(100, result.getWidth()); |
| 431 assertEquals(expected, got); |
| 432 } |
| 433 |
| 434 public void testFigureWithoutImageAndCaption() { |
| 435 Element figure = Document.get().createElement("FIGURE"); |
| 436 mBody.appendChild(figure); |
| 437 |
| 438 EmbedExtractor extractor = new ImageExtractor(); |
| 439 WebImage result = (WebImage) extractor.extract(figure); |
| 440 assertNull(result); |
| 441 } |
383 } | 442 } |
OLD | NEW |