diff options
author | John Ahlroos <john@vaadin.com> | 2013-03-06 11:23:48 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-03-13 08:05:24 +0000 |
commit | 41798f820c60c43c89d8fb480821d8bda4c42bfb (patch) | |
tree | c31d1e1da2b39ff215c185ce2064611d4a62549f /uitest/src/com/vaadin | |
parent | 28aa793d8ede78aef0b458d6362b1475288d6495 (diff) | |
download | vaadin-framework-41798f820c60c43c89d8fb480821d8bda4c42bfb.tar.gz vaadin-framework-41798f820c60c43c89d8fb480821d8bda4c42bfb.zip |
Implemented injection of css styles #5500
Change-Id: Iaccffb4a3e137968d5f51672cdd56f803a9e9d2e
Diffstat (limited to 'uitest/src/com/vaadin')
-rw-r--r-- | uitest/src/com/vaadin/tests/themes/CSSInjectTest.html | 57 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/themes/CSSInjectTest.java | 87 |
2 files changed, 144 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/themes/CSSInjectTest.html b/uitest/src/com/vaadin/tests/themes/CSSInjectTest.html new file mode 100644 index 0000000000..05a0f256c2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/themes/CSSInjectTest.html @@ -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="http://localhost:8888/" /> +<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.themes.CSSInjectTest?restartApplication</td> + <td></td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>hello-world-gray</td> +</tr> +<tr> + <td>type</td> + <td>vaadin=runcomvaadinteststhemesCSSInjectTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VTextArea[0]</td> + <td>.hello{color:blue;}</td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadinteststhemesCSSInjectTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>hello-blue</td> +</tr> +<tr> + <td>type</td> + <td>vaadin=runcomvaadinteststhemesCSSInjectTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VTextArea[0]</td> + <td>.world{color:red;}</td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadinteststhemesCSSInjectTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>world-red</td> +</tr> + +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/themes/CSSInjectTest.java b/uitest/src/com/vaadin/tests/themes/CSSInjectTest.java new file mode 100644 index 0000000000..bedbf47fe2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/themes/CSSInjectTest.java @@ -0,0 +1,87 @@ +package com.vaadin.tests.themes; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.UUID; + +import com.vaadin.server.Page; +import com.vaadin.server.Page.StyleSheet; +import com.vaadin.server.StreamResource; +import com.vaadin.shared.ui.label.ContentMode; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Label; +import com.vaadin.ui.TextArea; + +public class CSSInjectTest extends TestBase { + + @Override + protected void setup() { + + final StyleSheet stylesheet = Page.getCurrent().getStyleSheet(); + + // Inject some resources initially + stylesheet.inject(new StreamResource(new StreamResource.StreamSource() { + + @Override + public InputStream getStream() { + return new ByteArrayInputStream( + ".hello, .world { color:silver; }".getBytes()); + } + }, "mystyles-" + System.currentTimeMillis() + ".css")); + + Label hello = new Label( + "<span class='hello'>Hello</span> <span class='world'>world</span>", + ContentMode.HTML); + addComponent(hello); + + final TextArea cssToInject = new TextArea(); + cssToInject.setImmediate(true); + addComponent(cssToInject); + + Button inject = new Button("Inject!", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + stylesheet.inject(cssToInject.getValue()); + cssToInject.setValue(""); + } + }); + addComponent(inject); + + Button injectRandom = new Button("Inject as resource!", + new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + + final String css = cssToInject.getValue(); + + stylesheet.inject(new StreamResource( + new StreamResource.StreamSource() { + + @Override + public InputStream getStream() { + return new ByteArrayInputStream(css + .getBytes()); + } + }, UUID.randomUUID().toString() + ".css")); + + cssToInject.setValue(""); + } + }); + addComponent(injectRandom); + } + + @Override + protected String getDescription() { + return "Demonstrates how CSS injections can be used to theme the \"Hello world\" label below"; + } + + @Override + protected Integer getTicketNumber() { + return 5500; + } + +} |