Search in sources :

Example 1 with MockImage

use of com.github.bordertech.wcomponents.MockImage in project wcomponents by BorderTech.

the class WVideoRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    MockVideo mockVideo = new MockVideo();
    mockVideo.setMimeType("video/mpeg");
    mockVideo.setSize(new Dimension(111, 222));
    // Test with no video tracks - should not render
    WVideo video = new WVideo();
    assertSchemaMatch(video);
    assertXpathNotExists("//ui:video", video);
    // Test with minimal options
    video = new WVideo(mockVideo);
    // so that the URIs are consistent
    video.setCacheKey("x");
    setActiveContext(createUIContext());
    assertSchemaMatch(video);
    assertXpathExists("//ui:video", video);
    assertXpathEvaluatesTo(video.getId(), "//ui:video/@id", video);
    assertXpathEvaluatesTo("none", "//ui:video/@preload", video);
    assertXpathNotExists("//ui:video/@alt", video);
    assertXpathNotExists("//ui:video/@autoplay", video);
    assertXpathNotExists("//ui:video/@loop", video);
    assertXpathNotExists("//ui:video/@muted", video);
    assertXpathNotExists("//ui:video/@controls", video);
    assertXpathNotExists("//ui:video/@hidden", video);
    assertXpathNotExists("//ui:video/@disabled", video);
    assertXpathNotExists("//ui:video/@tooltip", video);
    assertXpathNotExists("//ui:video/@width", video);
    assertXpathNotExists("//ui:video/@height", video);
    assertXpathNotExists("//ui:video/@duration", video);
    assertXpathNotExists("//ui:video/@poster", video);
    assertXpathEvaluatesTo("0", "count(//ui:video/ui:track)", video);
    assertXpathEvaluatesTo("1", "count(//ui:video/ui:src)", video);
    assertXpathUrlEvaluatesTo(video.getVideoUrls()[0], "//ui:video/ui:src/@uri", video);
    assertXpathEvaluatesTo(video.getVideo()[0].getMimeType(), "//ui:video/ui:src/@type", video);
    assertXpathEvaluatesTo(String.valueOf(mockVideo.getSize().width), "//ui:video/ui:src/@width", video);
    assertXpathEvaluatesTo(String.valueOf(mockVideo.getSize().height), "//ui:video/ui:src/@height", video);
    // Test other options, resetting them after each test
    video.setAltText("altText");
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("altText", "//ui:video/@alt", video);
    video.reset();
    video.setPreload(WVideo.Preload.META_DATA);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("metadata", "//ui:video/@preload", video);
    video.reset();
    video.setAutoplay(true);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("true", "//ui:video/@autoplay", video);
    video.reset();
    video.setLoop(true);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("true", "//ui:video/@loop", video);
    video.reset();
    video.setMuted(true);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("true", "//ui:video/@muted", video);
    video.reset();
    video.setControls(WVideo.Controls.NONE);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("none", "//ui:video/@controls", video);
    video.reset();
    video.setControls(WVideo.Controls.ALL);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("all", "//ui:video/@controls", video);
    video.reset();
    video.setControls(WVideo.Controls.PLAY_PAUSE);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("play", "//ui:video/@controls", video);
    video.reset();
    video.setControls(WVideo.Controls.DEFAULT);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("default", "//ui:video/@controls", video);
    video.reset();
    setFlag(video, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("true", "//ui:video/@hidden", video);
    video.reset();
    video.setDisabled(true);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("true", "//ui:video/@disabled", video);
    video.reset();
    video.setToolTip("toolTip");
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("toolTip", "//ui:video/@toolTip", video);
    video.reset();
    video.setWidth(123);
    video.setHeight(456);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("123", "//ui:video/@width", video);
    assertXpathEvaluatesTo("456", "//ui:video/@height", video);
    video.reset();
    video.setPoster(new MockImage());
    assertXpathUrlEvaluatesTo(video.getPosterUrl(), "//ui:video/@poster", video);
    video.reset();
    MockTrack track = new MockTrack();
    track.setLanguage("en");
    track.setDescription("trackDesc");
    track.setKind(Track.Kind.SUBTITLES);
    video.setTracks(new Track[] { track });
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("1", "count(//ui:video/ui:track)", video);
    assertXpathEvaluatesTo("en", "//ui:video/ui:track/@lang", video);
    assertXpathEvaluatesTo("subtitles", "//ui:video/ui:track/@kind", video);
    assertXpathEvaluatesTo("trackDesc", "//ui:video/ui:track/@desc", video);
    assertXpathUrlEvaluatesTo(video.getTrackUrls()[0], "//ui:video/ui:track/@src", video);
    track.setKind(Track.Kind.CAPTIONS);
    assertXpathEvaluatesTo("captions", "//ui:video/ui:track/@kind", video);
    track.setKind(Track.Kind.DESCRIPTIONS);
    assertXpathEvaluatesTo("descriptions", "//ui:video/ui:track/@kind", video);
    track.setKind(Track.Kind.CHAPTERS);
    assertXpathEvaluatesTo("chapters", "//ui:video/ui:track/@kind", video);
    track.setKind(Track.Kind.METADATA);
    assertXpathEvaluatesTo("metadata", "//ui:video/ui:track/@kind", video);
    video.reset();
    mockVideo.setDuration(123);
    assertXpathEvaluatesTo("123", "//ui:video/@duration", video);
}
Also used : MockVideo(com.github.bordertech.wcomponents.MockVideo) WVideo(com.github.bordertech.wcomponents.WVideo) Dimension(java.awt.Dimension) MockTrack(com.github.bordertech.wcomponents.MockTrack) MockImage(com.github.bordertech.wcomponents.MockImage) Test(org.junit.Test)

Example 2 with MockImage

use of com.github.bordertech.wcomponents.MockImage in project wcomponents by BorderTech.

the class WImageRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    MockImage content = new MockImage();
    WImage image = new WImage();
    assertSchemaMatch(image);
    image = new WImage();
    setActiveContext(createUIContext());
    image.setImage(content);
    assertSchemaMatch(image);
    assertXpathEvaluatesTo(image.getId(), "//html:img/@id", image);
    assertSrcMatch(image);
    assertXpathEvaluatesTo("", "//html:img/@alt", image);
    assertXpathNotExists("//html:img/@hidden", image);
    assertXpathNotExists("//html:img/@width", image);
    assertXpathNotExists("//html:img/@height", image);
    content.setDescription("WImage_Test.testRenderedFormat.description");
    content.setSize(new Dimension(-123, -456));
    setFlag(image, ComponentModel.HIDE_FLAG, true);
    assertXpathEvaluatesTo(content.getDescription(), "//html:img/@alt", image);
    assertXpathEvaluatesTo("hidden", "//html:img/@hidden", image);
    assertXpathNotExists("//html:img/@width", image);
    assertXpathNotExists("//html:img/@height", image);
    assertSrcMatch(image);
    content.setSize(new Dimension(123, 456));
    assertSchemaMatch(image);
    assertXpathEvaluatesTo("123", "//html:img/@width", image);
    assertXpathEvaluatesTo("456", "//html:img/@height", image);
    content.setSize(new Dimension(0, 0));
    assertSchemaMatch(image);
    assertXpathEvaluatesTo("0", "//html:img/@width", image);
    assertXpathEvaluatesTo("0", "//html:img/@height", image);
}
Also used : WImage(com.github.bordertech.wcomponents.WImage) Dimension(java.awt.Dimension) MockImage(com.github.bordertech.wcomponents.MockImage) Test(org.junit.Test)

Example 3 with MockImage

use of com.github.bordertech.wcomponents.MockImage in project wcomponents by BorderTech.

the class WImageRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WImage image = new WImage();
    MockImage content = new MockImage();
    content.setDescription(getMaliciousAttribute("html:img"));
    setActiveContext(createUIContext());
    image.setImage(content);
    assertSafeContent(image);
    image.setImageUrl(getMaliciousAttribute());
    assertSafeContent(image);
}
Also used : WImage(com.github.bordertech.wcomponents.WImage) MockImage(com.github.bordertech.wcomponents.MockImage) Test(org.junit.Test)

Aggregations

MockImage (com.github.bordertech.wcomponents.MockImage)3 Test (org.junit.Test)3 WImage (com.github.bordertech.wcomponents.WImage)2 Dimension (java.awt.Dimension)2 MockTrack (com.github.bordertech.wcomponents.MockTrack)1 MockVideo (com.github.bordertech.wcomponents.MockVideo)1 WVideo (com.github.bordertech.wcomponents.WVideo)1