From d379f5cb09a8530b9f6f24c600c5cc5acc7f36ea Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Thu, 23 Aug 2012 19:00:33 +0300 Subject: Tests for new componets split from Embedded (#9087) --- .../embeddedbrowser/EmbeddedBrowserIsVisible.html | 67 +++++++++++ .../embeddedbrowser/EmbeddedBrowserIsVisible.java | 112 +++++++++++++++++ .../tests/components/flash/FlashIsVisible.html | 33 +++++ .../tests/components/flash/FlashIsVisible.java | 31 +++++ .../tests/components/flash/FlashPresentation.java | 33 +++++ .../tests/components/image/ImageAltText.html | 42 +++++++ .../tests/components/image/ImageAltText.java | 38 ++++++ .../vaadin/tests/components/image/ImageClicks.html | 57 +++++++++ .../vaadin/tests/components/image/ImageClicks.java | 133 +++++++++++++++++++++ 9 files changed, 546 insertions(+) create mode 100644 tests/testbench/com/vaadin/tests/components/embeddedbrowser/EmbeddedBrowserIsVisible.html create mode 100644 tests/testbench/com/vaadin/tests/components/embeddedbrowser/EmbeddedBrowserIsVisible.java create mode 100644 tests/testbench/com/vaadin/tests/components/flash/FlashIsVisible.html create mode 100644 tests/testbench/com/vaadin/tests/components/flash/FlashIsVisible.java create mode 100644 tests/testbench/com/vaadin/tests/components/flash/FlashPresentation.java create mode 100644 tests/testbench/com/vaadin/tests/components/image/ImageAltText.html create mode 100644 tests/testbench/com/vaadin/tests/components/image/ImageAltText.java create mode 100644 tests/testbench/com/vaadin/tests/components/image/ImageClicks.html create mode 100644 tests/testbench/com/vaadin/tests/components/image/ImageClicks.java diff --git a/tests/testbench/com/vaadin/tests/components/embeddedbrowser/EmbeddedBrowserIsVisible.html b/tests/testbench/com/vaadin/tests/components/embeddedbrowser/EmbeddedBrowserIsVisible.html new file mode 100644 index 0000000000..2d76cd48b2 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/embeddedbrowser/EmbeddedBrowserIsVisible.html @@ -0,0 +1,67 @@ + + + + + + +EmbeddedBrowserIsVisible + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EmbeddedBrowserIsVisible
open/run/com.vaadin.tests.components.embeddedbrowser.EmbeddedBrowserIsVisible?restartApplication
screenCaptureshow_initial
clickvaadin=runcomvaadintestscomponentsembeddedbrowserEmbeddedBrowserIsVisible::/VVerticalLayout[0]/VVerticalLayout[0]/VHorizontalLayout[0]/VButton[0]/domChild[0]/domChild[0]
screenCaptureshow_hello
clickvaadin=runcomvaadintestscomponentsembeddedbrowserEmbeddedBrowserIsVisible::/VVerticalLayout[0]/VVerticalLayout[0]/VHorizontalLayout[0]/VButton[1]/domChild[0]/domChild[0]
screenCaptureshow_lorem
clickvaadin=runcomvaadintestscomponentsembeddedbrowserEmbeddedBrowserIsVisible::/VVerticalLayout[0]/VVerticalLayout[0]/VHorizontalLayout[0]/VButton[2]/domChild[0]/domChild[0]
screenCaptureshow_alternative_text
clickvaadin=runcomvaadintestscomponentsembeddedbrowserEmbeddedBrowserIsVisible::/VVerticalLayout[0]/VVerticalLayout[0]/VHorizontalLayout[0]/VButton[1]/domChild[0]/domChild[0]
screenCaptureshow_lorem2
+ + diff --git a/tests/testbench/com/vaadin/tests/components/embeddedbrowser/EmbeddedBrowserIsVisible.java b/tests/testbench/com/vaadin/tests/components/embeddedbrowser/EmbeddedBrowserIsVisible.java new file mode 100644 index 0000000000..fdf9405855 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/embeddedbrowser/EmbeddedBrowserIsVisible.java @@ -0,0 +1,112 @@ +package com.vaadin.tests.components.embeddedbrowser; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; + +import com.vaadin.terminal.StreamResource; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.EmbeddedBrowser; +import com.vaadin.ui.HorizontalLayout; + +public class EmbeddedBrowserIsVisible extends TestBase { + + @Override + protected void setup() { + + HorizontalLayout buttonLayout = new HorizontalLayout(); + addComponent(buttonLayout); + + Button page1 = new Button("Hello World"); + buttonLayout.addComponent(page1); + + Button page2 = new Button("Lorem ipsum"); + buttonLayout.addComponent(page2); + + Button page3 = new Button("null"); + buttonLayout.addComponent(page3); + + final EmbeddedBrowser browser = new EmbeddedBrowser(); + browser.setDebugId("browser"); + browser.setWidth("600px"); + browser.setHeight("300px"); + browser.setAlternateText("Browser alternative text"); + final TextSource textSource = new TextSource("initial"); + final StreamResource textResource = new StreamResource(textSource, + "initial.txt", this); + textResource.setMIMEType("text/plain"); + browser.setSource(textResource); + addComponent(browser); + + page1.addListener(new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + TextSource helloSource = new TextSource("Hello World"); + StreamResource helloResource = new StreamResource(helloSource, + "helloworld.txt", EmbeddedBrowserIsVisible.this); + helloResource.setMIMEType("text/plain"); + browser.setSource(helloResource); + } + }); + + page2.addListener(new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + TextSource helloSource = new TextSource("Lorem Ipsum"); + StreamResource helloResource = new StreamResource(helloSource, + "loremipsum.txt", EmbeddedBrowserIsVisible.this); + helloResource.setMIMEType("text/plain"); + browser.setSource(helloResource); + } + }); + + page3.addListener(new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + browser.setSource(null); + } + }); + } + + @Override + protected String getDescription() { + return "Embedded browser should be visible for all browsers"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + + public class TextSource implements StreamResource.StreamSource { + private String text; + + public TextSource(String text) { + this.text = text; + } + + public InputStream getStream() { + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 200; ++i) { + sb.append(text); + sb.append("\n"); + } + + ByteArrayInputStream istream; + try { + istream = new ByteArrayInputStream(sb.toString().getBytes( + "UTF-8")); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } + return istream; // new DownloadStream (istream,null,null); + + } + } + +} diff --git a/tests/testbench/com/vaadin/tests/components/flash/FlashIsVisible.html b/tests/testbench/com/vaadin/tests/components/flash/FlashIsVisible.html new file mode 100644 index 0000000000..82834cf405 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/flash/FlashIsVisible.html @@ -0,0 +1,33 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.flash.FlashIsVisible
pause5000
screenCapture
+ + diff --git a/tests/testbench/com/vaadin/tests/components/flash/FlashIsVisible.java b/tests/testbench/com/vaadin/tests/components/flash/FlashIsVisible.java new file mode 100644 index 0000000000..66cb8819d4 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/flash/FlashIsVisible.java @@ -0,0 +1,31 @@ +package com.vaadin.tests.components.flash; + +import com.vaadin.terminal.ExternalResource; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Flash; + +public class FlashIsVisible extends TestBase { + + @Override + protected void setup() { + Flash player = new Flash(); + player.setWidth("400px"); + player.setHeight("300px"); + String url = "http://www.youtube.com/v/qQ9N742QB4g&autoplay=0"; + player.setSource(new ExternalResource(url)); + addComponent(player); + } + + @Override + protected String getDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/tests/testbench/com/vaadin/tests/components/flash/FlashPresentation.java b/tests/testbench/com/vaadin/tests/components/flash/FlashPresentation.java new file mode 100644 index 0000000000..843e61ace1 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/flash/FlashPresentation.java @@ -0,0 +1,33 @@ +package com.vaadin.tests.components.flash; + +import com.vaadin.terminal.ExternalResource; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Flash; + +public class FlashPresentation extends TestBase { + + @Override + protected String getDescription() { + return "The embedded flash should have the movie parameter set to \"someRandomValue\" and an allowFullScreen parameter set to \"true\"."; + } + + @Override + protected Integer getTicketNumber() { + return 3367; + } + + @Override + public void setup() { + Flash player = new Flash(); + player.setWidth("400px"); + player.setHeight("300px"); + String url = "http://www.youtube.com/v/qQ9N742QB4g&autoplay=1"; + player.setSource(new ExternalResource(url)); + player.setParameter("movie", "someRandomValue"); + player.setParameter("allowFullScreen", "true"); + player.setAlternateText("Flash alternative text"); + + addComponent(player); + } + +} diff --git a/tests/testbench/com/vaadin/tests/components/image/ImageAltText.html b/tests/testbench/com/vaadin/tests/components/image/ImageAltText.html new file mode 100644 index 0000000000..743aa5caaf --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/image/ImageAltText.html @@ -0,0 +1,42 @@ + + + + + + +ImageAltText + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ImageAltText
open/run/com.vaadin.tests.components.image.ImageAltText?restartApplication
assertAttributevaadin=runcomvaadintestscomponentsimageImageAltText::/VVerticalLayout[0]/VVerticalLayout[0]/VImage[0]@altOriginal alt text
clickvaadin=runcomvaadintestscomponentsimageImageAltText::/VVerticalLayout[0]/VVerticalLayout[0]/VButton[0]/domChild[0]
assertAttributevaadin=runcomvaadintestscomponentsimageImageAltText::/VVerticalLayout[0]/VVerticalLayout[0]/VImage[0]@altNew alt text!
screenCaptureimage_alt_text
+ + diff --git a/tests/testbench/com/vaadin/tests/components/image/ImageAltText.java b/tests/testbench/com/vaadin/tests/components/image/ImageAltText.java new file mode 100644 index 0000000000..1f787fd64f --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/image/ImageAltText.java @@ -0,0 +1,38 @@ +package com.vaadin.tests.components.image; + +import com.vaadin.terminal.ThemeResource; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Image; + +public class ImageAltText extends TestBase { + + @Override + protected void setup() { + final Image image = new Image("Caption", new ThemeResource( + "../runo/icons/64/ok.png")); + image.setDebugId("image"); + image.setAlternateText("Original alt text"); + addComponent(image); + + Button changeAltTexts = new Button("Change alt text", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + image.setAlternateText("New alt text!"); + } + }); + addComponent(changeAltTexts); + } + + @Override + protected String getDescription() { + return "Test alternative text of image"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + +} diff --git a/tests/testbench/com/vaadin/tests/components/image/ImageClicks.html b/tests/testbench/com/vaadin/tests/components/image/ImageClicks.html new file mode 100644 index 0000000000..14afaab98d --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/image/ImageClicks.html @@ -0,0 +1,57 @@ + + + + + + +ImageClicks + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ImageClicks
open/run/com.vaadin.tests.components.image.ImageClicks?restartApplication
screenCapture0_clicks
mouseClickvaadin=runcomvaadintestscomponentsimageImageClicks::/VVerticalLayout[0]/VVerticalLayout[0]/VImage[0]129,107
screenCapture1_click
mouseClickvaadin=runcomvaadintestscomponentsimageImageClicks::/VVerticalLayout[0]/VVerticalLayout[0]/VImage[0]129,107
screenCapture2_clicks
mouseClickvaadin=runcomvaadintestscomponentsimageImageClicks::/VVerticalLayout[0]/VVerticalLayout[0]/VImage[0]273,273
screenCapture3_clicks
+ + diff --git a/tests/testbench/com/vaadin/tests/components/image/ImageClicks.java b/tests/testbench/com/vaadin/tests/components/image/ImageClicks.java new file mode 100644 index 0000000000..394e38a106 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/image/ImageClicks.java @@ -0,0 +1,133 @@ +package com.vaadin.tests.components.image; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import javax.imageio.ImageIO; + +import com.vaadin.event.MouseEvents.ClickEvent; +import com.vaadin.event.MouseEvents.ClickListener; +import com.vaadin.terminal.StreamResource; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Image; +import com.vaadin.ui.Label; + +public class ImageClicks extends TestBase { + + private int clickCounter = 0; + + @Override + protected void setup() { + + final Label label = new Label(labelText()); + addComponent(label); + + Image image = new Image(); + final MyImageSource imageSource = new MyImageSource(); + final StreamResource imageResource = new StreamResource(imageSource, + "testimage.png", this); + image.setSource(imageResource); + image.addListener(new ClickListener() { + + public void click(ClickEvent event) { + ++clickCounter; + label.setValue(labelText()); + } + + }); + addComponent(image); + + } + + private String labelText() { + StringBuilder sb = new StringBuilder(); + sb.append("Image clicked "); + sb.append(clickCounter); + sb.append(" times."); + return sb.toString(); + } + + @Override + protected String getDescription() { + return "Test click event handling of images"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + + public class MyImageSource implements StreamResource.StreamSource { + public MyImageSource() { + } + + int intervalPos(int pos, int resolution, int cells) { + return (int) Math.round(pos * resolution / (cells * 1.0)); + } + + public InputStream getStream() { + // Create an image and draw some background on it. + BufferedImage image = new BufferedImage(300, 300, + BufferedImage.TYPE_INT_RGB); + Graphics drawable = image.getGraphics(); + + // Background + drawable.setColor(Color.white); + drawable.fillRect(0, 0, 300, 300); + + final int rows = 4; + final int cols = 4; + + // Grid + for (int row = 0; row < rows; row++) { + int gridy = intervalPos(row, 300, rows); + int gridynext = intervalPos(row + 1, 300, rows); + + // Horizontal grid line + if (row > 0) { + drawable.setColor(Color.lightGray); + drawable.drawLine(0, gridy, 300 - 1, gridy); + } + + for (int col = 0; col < cols; col++) { + int gridx = intervalPos(col, 300, cols); + int gridxnext = intervalPos(col + 1, 300, cols); + + // Vertical grid line + if (row == 0 && col > 0) { + drawable.setColor(Color.lightGray); + drawable.drawLine(gridx, 0, gridx, 300 - 1); + } + + // Cell + if (Math.random() < 0.5f) { + drawable.setColor(Color.white); + } else { + drawable.setColor(Color.black); + } + drawable.fillRect(gridx + 1, gridy + 1, gridxnext - gridx + - 1, gridynext - gridy - 1); + } + } + + try { + // Write the image to a buffer. + ByteArrayOutputStream imagebuffer = new ByteArrayOutputStream(); + ImageIO.write(image, "png", imagebuffer); + + // Return a stream from the buffer. + ByteArrayInputStream istream = new ByteArrayInputStream( + imagebuffer.toByteArray()); + return istream; // new DownloadStream (istream,null,null); + } catch (IOException e) { + return null; + } + } + + } +} -- cgit v1.2.3