diff options
author | Artur Signell <artur@vaadin.com> | 2015-01-27 13:51:22 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-01-27 15:30:20 +0000 |
commit | 2af61caa596eb39b211bb6c71809e6ecca63bae8 (patch) | |
tree | e192c92e7747153fc9dc0181ea06560ac8899f77 | |
parent | b8d69b6b397ba2d669aa16e297d900e5e079d1e9 (diff) | |
download | vaadin-framework-2af61caa596eb39b211bb6c71809e6ecca63bae8.tar.gz vaadin-framework-2af61caa596eb39b211bb6c71809e6ecca63bae8.zip |
Render Window caption as text when requested (#16273)
Change-Id: I15813f5fc305776282bdc9cb3d5dffd4f09ebf55
5 files changed, 201 insertions, 14 deletions
diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java index 615841ccb6..786ecf1267 100644 --- a/client/src/com/vaadin/client/ui/VWindow.java +++ b/client/src/com/vaadin/client/ui/VWindow.java @@ -880,11 +880,12 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, } public void setCaption(String c, String iconURL, boolean asHtml) { - String html = c; - if (!asHtml) { - c = Util.escapeHTML(c); + String html; + if (asHtml) { + html = c == null ? "" : c; + } else { + html = Util.escapeHTML(c); } - // Provide information to assistive device users that a sub window was // opened String prefix = "<span class='" diff --git a/client/src/com/vaadin/client/ui/window/WindowConnector.java b/client/src/com/vaadin/client/ui/window/WindowConnector.java index 703bcbbb5e..33cabd563a 100644 --- a/client/src/com/vaadin/client/ui/window/WindowConnector.java +++ b/client/src/com/vaadin/client/ui/window/WindowConnector.java @@ -378,7 +378,7 @@ public class WindowConnector extends AbstractSingleComponentContainerConnector window.setAssistivePrefix(state.assistivePrefix); window.setAssistivePostfix(state.assistivePostfix); - window.setCaption(state.caption, iconURL); + window.setCaption(state.caption, iconURL, getState().captionAsHtml); window.setWaiAriaRole(getState().role); window.setAssistiveDescription(state.contentDescription); diff --git a/uitest/src/com/vaadin/tests/components/window/WindowCaption.java b/uitest/src/com/vaadin/tests/components/window/WindowCaption.java new file mode 100644 index 0000000000..fcb915f363 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/WindowCaption.java @@ -0,0 +1,82 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.window; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Label; +import com.vaadin.ui.Window; + +public class WindowCaption extends AbstractTestUI { + + private Window htmlWindow; + private Window textWindow; + + @Override + protected void setup(VaadinRequest request) { + htmlWindow = new Window("", new Label("HTML caption")); + htmlWindow.setId("htmlWindow"); + htmlWindow.setCaptionAsHtml(true); + htmlWindow.setPositionX(300); + htmlWindow.setPositionY(200); + + textWindow = new Window("", new Label("Text caption")); + textWindow.setId("textWindow"); + textWindow.setCaptionAsHtml(false); + textWindow.setPositionX(300); + textWindow.setPositionY(400); + + addWindow(htmlWindow); + addWindow(textWindow); + + Button red = new Button("Red", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + setWindowCaption("<font style='color: red;'>This may or may not be red</font>"); + } + }); + Button plainText = new Button("Plain text", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + setWindowCaption("This is just text"); + } + }); + Button nullCaption = new Button("Null", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + setWindowCaption(null); + } + }); + Button empty = new Button("Empty", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + setWindowCaption(""); + } + }); + + addComponents(red, plainText, nullCaption, empty); + red.click(); + } + + private void setWindowCaption(String string) { + htmlWindow.setCaption(string); + textWindow.setCaption(string); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/window/WindowCaptionTest.java b/uitest/src/com/vaadin/tests/components/window/WindowCaptionTest.java new file mode 100644 index 0000000000..f580d7c501 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/WindowCaptionTest.java @@ -0,0 +1,92 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.window; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.tests.tb3.newelements.WindowElement; + +public class WindowCaptionTest extends SingleBrowserTest { + + private WindowElement htmlWindow; + private WindowElement textWindow; + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + waitForElementPresent(By.className("v-window")); + htmlWindow = $(WindowElement.class).id("htmlWindow"); + textWindow = $(WindowElement.class).id("textWindow"); + } + + @Test + public void htmlCaption() { + Assert.assertEquals("HtmlWindow's caption didn't match,", + "This may or may not be red", htmlWindow.getCaption()); + Assert.assertEquals("TextWindow's caption didn't match,", + "<font style='color: red;'>This may or may not be red</font>", + textWindow.getCaption()); + } + + @Test + public void textCaption() { + clickButton("Plain text"); + ensureCaptionsEqual("This is just text"); + } + + @Test + public void nullCaption() { + clickButton("Null"); + ensureCaptionsEqual(""); + } + + @Test + public void emptyCaption() { + clickButton("Empty"); + ensureCaptionsEqual(""); + } + + private void clickButton(String caption) { + $(ButtonElement.class).caption(caption).first().click(); + } + + private void ensureCaptionsEqual(final String expectedCaption) { + waitUntil(new ExpectedCondition<Boolean>() { + @Override + public Boolean apply(WebDriver input) { + return expectedCaption.equals(htmlWindow.getCaption()); + } + + @Override + public String toString() { + // Timed out after 10 seconds waiting for ... + return "htmlWindow's caption to be '" + expectedCaption + + "' (was: '" + htmlWindow.getCaption() + "')"; + } + + }); + + Assert.assertEquals("TextWindow's caption didn't match,", + expectedCaption, textWindow.getCaption()); + } +} diff --git a/uitest/src/com/vaadin/tests/tb3/newelements/WindowElement.java b/uitest/src/com/vaadin/tests/tb3/newelements/WindowElement.java index dd7cb55d01..9e3433f1af 100644 --- a/uitest/src/com/vaadin/tests/tb3/newelements/WindowElement.java +++ b/uitest/src/com/vaadin/tests/tb3/newelements/WindowElement.java @@ -1,10 +1,11 @@ package com.vaadin.tests.tb3.newelements; -import com.vaadin.testbench.By; -import com.vaadin.testbench.elements.ServerClass; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ServerClass; + /* Suggestions for new elemental api for Window */ @@ -15,10 +16,11 @@ public class WindowElement extends com.vaadin.testbench.elements.WindowElement { private final String maximizeBoxClass = "v-window-maximizebox"; public void restore() { - if(isMaximized()) { + if (isMaximized()) { getRestoreButton().click(); } else { - throw new AssertionError("Window is not maximized, cannot be restored."); + throw new AssertionError( + "Window is not maximized, cannot be restored."); } } @@ -27,27 +29,37 @@ public class WindowElement extends com.vaadin.testbench.elements.WindowElement { } private WebElement getRestoreButton() { - return this.findElement(By.className("v-window-restorebox")); + return findElement(By.className("v-window-restorebox")); } public void maximize() { - if(!isMaximized()) { + if (!isMaximized()) { getMaximizeButton().click(); } else { - throw new AssertionError("Window is already maximized, cannot maximize."); + throw new AssertionError( + "Window is already maximized, cannot maximize."); } } private WebElement getMaximizeButton() { - return this.findElement(By.className(maximizeBoxClass)); + return findElement(By.className(maximizeBoxClass)); } public void move(int xOffset, int yOffset) { Actions action = new Actions(getDriver()); - action.moveToElement(this.findElement(org.openqa.selenium.By.className("v-window-wrap")), 5, 5); + action.moveToElement( + findElement(org.openqa.selenium.By.className("v-window-wrap")), + 5, 5); action.clickAndHold(); action.moveByOffset(xOffset, yOffset); action.release(); action.build().perform(); } + + /** + * @return the caption of the window + */ + public String getCaption() { + return findElement(By.className("v-window-header")).getText(); + } } |