]> source.dussan.org Git - vaadin-framework.git/commitdiff
Tests for new componets split from Embedded (#9087)
authorJohannes Dahlström <johannesd@vaadin.com>
Thu, 23 Aug 2012 16:00:33 +0000 (19:00 +0300)
committerJohannes Dahlström <johannesd@vaadin.com>
Fri, 24 Aug 2012 13:09:47 +0000 (16:09 +0300)
tests/testbench/com/vaadin/tests/components/embeddedbrowser/EmbeddedBrowserIsVisible.html [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/embeddedbrowser/EmbeddedBrowserIsVisible.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/flash/FlashIsVisible.html [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/flash/FlashIsVisible.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/flash/FlashPresentation.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/image/ImageAltText.html [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/image/ImageAltText.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/image/ImageClicks.html [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/image/ImageClicks.java [new file with mode: 0644]

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 (file)
index 0000000..2d76cd4
--- /dev/null
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>EmbeddedBrowserIsVisible</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">EmbeddedBrowserIsVisible</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.embeddedbrowser.EmbeddedBrowserIsVisible?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>show_initial</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsembeddedbrowserEmbeddedBrowserIsVisible::/VVerticalLayout[0]/VVerticalLayout[0]/VHorizontalLayout[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>show_hello</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsembeddedbrowserEmbeddedBrowserIsVisible::/VVerticalLayout[0]/VVerticalLayout[0]/VHorizontalLayout[0]/VButton[1]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>show_lorem</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsembeddedbrowserEmbeddedBrowserIsVisible::/VVerticalLayout[0]/VVerticalLayout[0]/VHorizontalLayout[0]/VButton[2]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>show_alternative_text</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsembeddedbrowserEmbeddedBrowserIsVisible::/VVerticalLayout[0]/VVerticalLayout[0]/VHorizontalLayout[0]/VButton[1]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>show_lorem2</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
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 (file)
index 0000000..fdf9405
--- /dev/null
@@ -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 (file)
index 0000000..82834cf
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.flash.FlashIsVisible</td>
+       <td></td>
+</tr>
+<!--Allow the flash plugin to load before taking the screenshot-->
+<tr>
+       <td>pause</td>
+       <td>5000</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td></td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
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 (file)
index 0000000..66cb881
--- /dev/null
@@ -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 (file)
index 0000000..843e61a
--- /dev/null
@@ -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 (file)
index 0000000..743aa5c
--- /dev/null
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>ImageAltText</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">ImageAltText</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.image.ImageAltText?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertAttribute</td>
+       <td>vaadin=runcomvaadintestscomponentsimageImageAltText::/VVerticalLayout[0]/VVerticalLayout[0]/VImage[0]@alt</td>
+       <td>Original alt text</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsimageImageAltText::/VVerticalLayout[0]/VVerticalLayout[0]/VButton[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertAttribute</td>
+       <td>vaadin=runcomvaadintestscomponentsimageImageAltText::/VVerticalLayout[0]/VVerticalLayout[0]/VImage[0]@alt</td>
+       <td>New alt text!</td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>image_alt_text</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
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 (file)
index 0000000..1f787fd
--- /dev/null
@@ -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 (file)
index 0000000..14afaab
--- /dev/null
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>ImageClicks</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">ImageClicks</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.image.ImageClicks?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>0_clicks</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsimageImageClicks::/VVerticalLayout[0]/VVerticalLayout[0]/VImage[0]</td>
+       <td>129,107</td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>1_click</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsimageImageClicks::/VVerticalLayout[0]/VVerticalLayout[0]/VImage[0]</td>
+       <td>129,107</td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>2_clicks</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsimageImageClicks::/VVerticalLayout[0]/VVerticalLayout[0]/VImage[0]</td>
+       <td>273,273</td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>3_clicks</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
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 (file)
index 0000000..394e38a
--- /dev/null
@@ -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;
+            }
+        }
+
+    }
+}