diff options
16 files changed, 754 insertions, 41 deletions
diff --git a/client/src/com/vaadin/client/extensions/FileDownloaderConnector.java b/client/src/com/vaadin/client/extensions/FileDownloaderConnector.java index 66fc30575b..bed6622a6c 100644 --- a/client/src/com/vaadin/client/extensions/FileDownloaderConnector.java +++ b/client/src/com/vaadin/client/extensions/FileDownloaderConnector.java @@ -23,11 +23,14 @@ import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.dom.client.Style.Visibility; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; +import com.vaadin.client.BrowserInfo; import com.vaadin.client.ComponentConnector; import com.vaadin.client.ServerConnector; import com.vaadin.server.FileDownloader; +import com.vaadin.shared.VBrowserDetails; import com.vaadin.shared.ui.Connect; @Connect(FileDownloader.class) @@ -47,22 +50,27 @@ public class FileDownloaderConnector extends AbstractExtensionConnector public void onClick(ClickEvent event) { final String url = getResourceUrl("dl"); if (url != null && !url.isEmpty()) { - if (iframe != null) { - // make sure it is not on dom tree already, might start - // multiple downloads at once - iframe.removeFromParent(); - } - iframe = Document.get().createIFrameElement(); + BrowserInfo browser = BrowserInfo.get(); + if (browser.isIOS()) { + Window.open(url, "_blank", ""); + } else { + if (iframe != null) { + // make sure it is not on dom tree already, might start + // multiple downloads at once + iframe.removeFromParent(); + } + iframe = Document.get().createIFrameElement(); - Style style = iframe.getStyle(); - style.setVisibility(Visibility.HIDDEN); - style.setHeight(0, Unit.PX); - style.setWidth(0, Unit.PX); + Style style = iframe.getStyle(); + style.setVisibility(Visibility.HIDDEN); + style.setHeight(0, Unit.PX); + style.setWidth(0, Unit.PX); - iframe.setFrameBorder(0); - iframe.setTabIndex(-1); - iframe.setSrc(url); - RootPanel.getBodyElement().appendChild(iframe); + iframe.setFrameBorder(0); + iframe.setTabIndex(-1); + iframe.setSrc(url); + RootPanel.getBodyElement().appendChild(iframe); + } } } diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 4c6fc8874c..927e2c31db 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -1056,6 +1056,11 @@ public class VScrollTable extends FlowPanel implements HasWidgets, sendSelectedRows(immediate); } + private void updateFirstVisibleAndSendSelectedRows() { + updateFirstVisibleRow(); + sendSelectedRows(immediate); + } + /** * Sends the selection to the server if it has been changed since the last * update/visit. @@ -7238,6 +7243,20 @@ public class VScrollTable extends FlowPanel implements HasWidgets, return s; } + // Updates first visible row for the case we cannot wait + // for onScroll + private void updateFirstVisibleRow() { + scrollTop = scrollBodyPanel.getScrollPosition(); + firstRowInViewPort = calcFirstRowInViewPort(); + int maxFirstRow = totalRows - pageLength; + if (firstRowInViewPort > maxFirstRow && maxFirstRow >= 0) { + firstRowInViewPort = maxFirstRow; + } + lastRequestedFirstvisible = firstRowInViewPort; + client.updateVariable(paintableId, "firstvisible", firstRowInViewPort, + false); + } + /** * This method has logic which rows needs to be requested from server when * user scrolls @@ -7706,7 +7725,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // focus and select the last visible row setRowFocus(lastVisibleRowInViewPort); selectFocusedRow(ctrl, shift); - sendSelectedRows(); + updateFirstVisibleAndSendSelectedRows(); } else { int indexOfToBeFocused = focusedRow.getIndex() + getFullyVisibleRowCount(); @@ -7723,7 +7742,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, setRowFocus(toBeFocusedRow); selectFocusedRow(ctrl, shift); // TODO needs scrollintoview ? - sendSelectedRows(); + updateFirstVisibleAndSendSelectedRows(); } else { // scroll down by pixels and return, to wait for // new rows, then select the last item in the @@ -7759,7 +7778,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // focus and select the first visible row setRowFocus(firstVisibleRowInViewPort); selectFocusedRow(ctrl, shift); - sendSelectedRows(); + updateFirstVisibleAndSendSelectedRows(); } else { int indexOfToBeFocused = focusedRow.getIndex() - getFullyVisibleRowCount(); @@ -7774,7 +7793,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, setRowFocus(toBeFocusedRow); selectFocusedRow(ctrl, shift); // TODO needs scrollintoview ? - sendSelectedRows(); + updateFirstVisibleAndSendSelectedRows(); } else { // unless waiting for the next rowset already // scroll down by pixels and return, to wait for @@ -7806,7 +7825,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, if (rowByRowIndex.getIndex() == 0) { setRowFocus(rowByRowIndex); selectFocusedRow(ctrl, shift); - sendSelectedRows(); + updateFirstVisibleAndSendSelectedRows(); } else { // first row of table will come in next row fetch if (ctrl) { @@ -7832,7 +7851,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, if (focusedRow != rowByRowIndex) { setRowFocus(rowByRowIndex); selectFocusedRow(ctrl, shift); - sendSelectedRows(); + updateFirstVisibleAndSendSelectedRows(); } } else { if (ctrl) { diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java index 82407c981d..6977cf9e7f 100644 --- a/client/src/com/vaadin/client/ui/VWindow.java +++ b/client/src/com/vaadin/client/ui/VWindow.java @@ -881,11 +881,12 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, } public void setCaption(String c, String iconURL, boolean asHtml) { - String html = c; - if (!asHtml) { - c = WidgetUtil.escapeHTML(c); + String html; + if (asHtml) { + html = c == null ? "" : c; + } else { + html = WidgetUtil.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 5580793506..5214c33eec 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/server/src/com/vaadin/ui/PushConfiguration.java b/server/src/com/vaadin/ui/PushConfiguration.java index 84f59d0313..90ad28542c 100644 --- a/server/src/com/vaadin/ui/PushConfiguration.java +++ b/server/src/com/vaadin/ui/PushConfiguration.java @@ -208,7 +208,7 @@ class PushConfigurationImpl implements PushConfiguration { public Transport getTransport() { try { return Transport - .valueOf(getParameter(PushConfigurationState.TRANSPORT_PARAM)); + .getByIdentifier(getParameter(PushConfigurationState.TRANSPORT_PARAM)); } catch (IllegalArgumentException e) { return null; } diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index ec345e3fc3..e202a4e925 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -62,6 +62,7 @@ import com.vaadin.server.Resource; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.MultiSelectMode; import com.vaadin.shared.ui.table.TableConstants; +import com.vaadin.shared.util.SharedUtil; /** * <p> @@ -442,7 +443,7 @@ public class Table extends AbstractSelect implements Action.Container, /** * Holds value of property selectable. */ - private boolean selectable = false; + private Boolean selectable; /** * Holds value of property columnHeaderMode. @@ -1601,15 +1602,19 @@ public class Table extends AbstractSelect implements Action.Container, } /** - * Getter for property selectable. + * Returns whether table is selectable. * * <p> - * The table is not selectable by default. + * The table is not selectable until it's explicitly set as selectable or at + * least one {@link ValueChangeListener} is added. * </p> * - * @return the Value of property selectable. + * @return whether table is selectable. */ public boolean isSelectable() { + if (selectable == null) { + return hasListeners(ValueChangeEvent.class); + } return selectable; } @@ -1617,14 +1622,16 @@ public class Table extends AbstractSelect implements Action.Container, * Setter for property selectable. * * <p> - * The table is not selectable by default. + * The table is not selectable until it's explicitly set as selectable via + * this method or alternatively at least one {@link ValueChangeListener} is + * added. * </p> * * @param selectable * the New value of property selectable. */ public void setSelectable(boolean selectable) { - if (this.selectable != selectable) { + if (!SharedUtil.equals(this.selectable, selectable)) { this.selectable = selectable; markAsDirty(); } diff --git a/server/tests/src/com/vaadin/tests/server/component/table/TableSelectable.java b/server/tests/src/com/vaadin/tests/server/component/table/TableSelectable.java new file mode 100644 index 0000000000..1af99a08eb --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/table/TableSelectable.java @@ -0,0 +1,75 @@ +/* + * 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.server.component.table; + +import org.easymock.EasyMock; +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.ui.Table; + +/** + * Tests for 'selectable' property of {@link Table} class. + * + * @author Vaadin Ltd + */ +public class TableSelectable { + + @Test + public void setSelectable_explicitSelectable_tableIsSelectable() { + Table table = new Table(); + table.setSelectable(true); + + Assert.assertTrue(table.isSelectable()); + } + + @Test + public void addValueChangeListener_explicitSelectable_tableIsSelectable() { + TestTable table = new TestTable(); + table.addValueChangeListener(EasyMock + .createMock(ValueChangeListener.class)); + + Assert.assertTrue(table.isSelectable()); + Assert.assertTrue(table.markAsDirtyCalled); + } + + @Test + public void tableIsNotSelectableByDefult() { + Table table = new Table(); + + Assert.assertFalse(table.isSelectable()); + } + + @Test + public void setSelectable_explicitNotSelectable_tableIsNotSelectable() { + Table table = new Table(); + table.setSelectable(false); + table.addValueChangeListener(EasyMock + .createMock(ValueChangeListener.class)); + + Assert.assertFalse(table.isSelectable()); + } + + private static final class TestTable extends Table { + @Override + public void markAsDirty() { + markAsDirtyCalled = true; + } + + private boolean markAsDirtyCalled; + } +} diff --git a/server/tests/src/com/vaadin/ui/PushConfigurationTransportTest.java b/server/tests/src/com/vaadin/ui/PushConfigurationTransportTest.java new file mode 100644 index 0000000000..305b2e06cd --- /dev/null +++ b/server/tests/src/com/vaadin/ui/PushConfigurationTransportTest.java @@ -0,0 +1,46 @@ +/* + * 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.ui; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.ui.Transport; + +/** + * @author Vaadin Ltd + */ +public class PushConfigurationTransportTest { + @Test + public void testTransportModes() throws Exception { + UI ui = new UI() { + + @Override + protected void init(VaadinRequest request) { + // TODO Auto-generated method stub + + } + + }; + for (Transport transport : Transport.values()) { + ui.getPushConfiguration().setTransport(transport); + Assert.assertEquals(ui.getPushConfiguration().getTransport(), + transport); + } + + } +} diff --git a/shared/src/com/vaadin/shared/ui/ui/Transport.java b/shared/src/com/vaadin/shared/ui/ui/Transport.java index 6eafba185e..39174caddf 100644 --- a/shared/src/com/vaadin/shared/ui/ui/Transport.java +++ b/shared/src/com/vaadin/shared/ui/ui/Transport.java @@ -46,4 +46,12 @@ public enum Transport { return identifier; } + public static Transport getByIdentifier(String identifier) { + for (Transport t : values()) { + if (t.getIdentifier().equals(identifier)) { + return t; + } + } + return null; + } } diff --git a/uitest/src/com/vaadin/tests/components/table/TableNavigationPageDown.java b/uitest/src/com/vaadin/tests/components/table/TableNavigationPageDown.java new file mode 100644 index 0000000000..b1281dcc7b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableNavigationPageDown.java @@ -0,0 +1,56 @@ +/* + * 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.table; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Table; + +public class TableNavigationPageDown extends AbstractTestUI { + + private final static int ROW_NUMBER = 50; + + @Override + protected void setup(VaadinRequest req) { + Table table = new Table(); + table.setSelectable(true); + table.setImmediate(true); + table.setHeight("150px"); + + table.addContainerProperty("num", Integer.class, "num"); + table.addContainerProperty("Foo", String.class, "Foov"); + table.addContainerProperty("Bar", String.class, "Barv"); + + for (int i = 0; i < ROW_NUMBER; i++) { + Object key = table.addItem(); + table.getItem(key).getItemProperty("num").setValue(i); + } + + addComponent(table); + + } + + @Override + protected String getTestDescription() { + return "Navigation in Table with PageDown/PageUp/Home/End keys should work"; + } + + @Override + protected Integer getTicketNumber() { + return 15332; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/table/TableNavigationPageDownTest.java b/uitest/src/com/vaadin/tests/components/table/TableNavigationPageDownTest.java new file mode 100644 index 0000000000..866c033692 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableNavigationPageDownTest.java @@ -0,0 +1,223 @@ +/* + * 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.table; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.elements.TableElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests that navigation with PageDown/PageUp/Home/End in Table works + * + * @author Vaadin Ltd + */ +public class TableNavigationPageDownTest extends MultiBrowserTest { + + private static final int ROW_NUMBER = 50; + private int lowerWrapperY = -1; + private int pageHeight = -1; + private int rowHeight = -1; + private int lastRowNumber = -1; + + private WebElement lastRow; + private WebElement wrapper; + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + + TableElement table = $(TableElement.class).first(); + rowHeight = table.getCell(1, 0).getLocation().getY() + - table.getCell(0, 0).getLocation().getY(); + + wrapper = findElement(By.className("v-table-body-wrapper")); + pageHeight = wrapper.getSize().getHeight(); + lowerWrapperY = wrapper.getLocation().getY() + pageHeight; + } + + @Test + public void navigatePageDown() { + // Scroll to a point where you can reach the bottom with 3 PageDowns. + // Can't use v-table-body height because lower rows haven't been + // fetched yet. + testBenchElement(wrapper).scroll( + ROW_NUMBER * rowHeight - (int) (2.8 * pageHeight)); + waitForScrollToFinish(); + + lastRow = getLastVisibleRow(); + lastRow.click(); + + // Press PageDown 3 times, we should reach the last row + for (int j = 0; j < 3; j++) { + lastRowNumber = getRowNumber(lastRow); + new Actions(driver).sendKeys(Keys.PAGE_DOWN).build().perform(); + waitForRowsToUpdate(); + } + assertEquals("Last table row should be visible", ROW_NUMBER - 1, + lastRowNumber); + } + + @Test + public void navigatePageUp() { + // Scroll to a point where you can reach the top with 3 PageUps. + testBenchElement(wrapper).scroll((int) (2.8 * pageHeight)); + waitForScrollToFinish(); + + lastRow = getLastVisibleRow(); + getFirstVisibleRow().click(); + + // Press PageUp 3 times, we should reach the first row + for (int j = 0; j < 3; j++) { + lastRowNumber = getRowNumber(lastRow); + new Actions(driver).sendKeys(Keys.PAGE_UP).build().perform(); + waitForRowsToUpdate(); + } + assertEquals("First table row should be visible", 0, + getRowNumber(getFirstVisibleRow())); + } + + @Test + public void navigateEndAndHome() { + lastRow = getLastVisibleRow(); + lastRow.click(); + + new Actions(driver).sendKeys(Keys.END).build().perform(); + waitForScrollToFinish(); + + assertEquals("Last table row should be visible", ROW_NUMBER - 1, + getRowNumber(getLastVisibleRow())); + + new Actions(driver).sendKeys(Keys.HOME).build().perform(); + waitForScrollToFinish(); + + assertEquals("First table row should be visible", 0, + getRowNumber(getFirstVisibleRow())); + } + + /** + * Waits until the scroll position indicator goes away, signifying that all + * the required rows have been fetched. + */ + private void waitForScrollToFinish() { + waitUntil(new ExpectedCondition<Boolean>() { + @Override + public Boolean apply(WebDriver input) { + List<WebElement> elements = findElements(By + .className("v-table-scrollposition")); + return elements.isEmpty() || !elements.get(0).isDisplayed(); + } + + @Override + public String toString() { + // Timed out after 10 seconds waiting for ... + return "scroll position indicator to vanish"; + } + }); + } + + /** + * Waits until the visible rows have been updated to some other set of rows. + * Fails if there is no change. + */ + private void waitForRowsToUpdate() { + waitUntil(new ExpectedCondition<Boolean>() { + @Override + public Boolean apply(WebDriver input) { + lastRow = getLastVisibleRow(); + int rowNumber = getRowNumber(lastRow); + if (lastRowNumber != rowNumber) { + lastRowNumber = rowNumber; + return true; + } + return false; + } + + @Override + public String toString() { + // Timed out after 10 seconds waiting for ... + return "visible rows to be updated"; + } + }); + } + + /** + * Returns row number from its first cell + */ + private int getRowNumber(WebElement row) { + return Integer.valueOf(row.findElement( + By.className("v-table-cell-wrapper")).getText()); + } + + /** + * Returns the first fully visible row + */ + private WebElement getFirstVisibleRow() { + List<WebElement> allFetchedRows = wrapper + .findElements(By.tagName("tr")); + int wrapperY = wrapper.getLocation().getY(); + for (WebElement row : allFetchedRows) { + int rowY = row.getLocation().getY(); + if ((rowY >= wrapperY) && (rowY - rowHeight <= wrapperY)) { + return row; + } + } + fail("Could not find first visible row"); + return null; + } + + /** + * Returns the last fully visible row + */ + private WebElement getLastVisibleRow() { + List<WebElement> allFetchedRows = wrapper + .findElements(By.tagName("tr")); + for (WebElement row : allFetchedRows) { + int lowerY = row.getLocation().getY() + rowHeight; + if ((lowerY <= lowerWrapperY) + && (lowerY + rowHeight >= lowerWrapperY)) { + return row; + } + } + fail("Could not find last visible row"); + return null; + } + + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + // Sending PageDown has no effect on PhantomJS. On IE focus + // in Table is often lost, so default scrolling happens on PageDown. + List<DesiredCapabilities> browsers = new ArrayList<DesiredCapabilities>( + getBrowsersExcludingIE()); + browsers.remove(Browser.PHANTOMJS.getDesiredCapabilities()); + return browsers; + } + +} 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/extensions/IframeIsOpenedInNonIOS.java b/uitest/src/com/vaadin/tests/extensions/IframeIsOpenedInNonIOS.java new file mode 100644 index 0000000000..a62b6bba88 --- /dev/null +++ b/uitest/src/com/vaadin/tests/extensions/IframeIsOpenedInNonIOS.java @@ -0,0 +1,45 @@ +package com.vaadin.tests.extensions; + +import com.vaadin.server.FileDownloader; +import com.vaadin.server.StreamResource; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Label; + +import java.io.*; + +public class IframeIsOpenedInNonIOS extends AbstractTestUI { + + public static final String FILE_CONTENT = "New text file"; + public static final String FILE_NAME = "textfile.txt"; + + @Override + protected void setup(VaadinRequest request) { + final Label errorLabel = new Label("No error"); + Button button = new Button("Download"); + FileDownloader downloader = new FileDownloader(new StreamResource(new StreamResource.StreamSource() { + @Override + public InputStream getStream () { + return createSomeFile(); + } + }, FILE_NAME)); + downloader.extend(button); + + addComponents(errorLabel, button); + } + + private InputStream createSomeFile() { + return new ByteArrayInputStream(FILE_CONTENT.getBytes()); + } + + @Override + protected Integer getTicketNumber() { + return 15366; + } + + @Override + public String getDescription() { + return "IFrame with a file is not shown in iOS"; + } +} diff --git a/uitest/src/com/vaadin/tests/extensions/IframeIsOpenedInNonIOSTest.java b/uitest/src/com/vaadin/tests/extensions/IframeIsOpenedInNonIOSTest.java new file mode 100644 index 0000000000..c544b495ab --- /dev/null +++ b/uitest/src/com/vaadin/tests/extensions/IframeIsOpenedInNonIOSTest.java @@ -0,0 +1,39 @@ +package com.vaadin.tests.extensions; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; + +import java.util.List; + +public class IframeIsOpenedInNonIOSTest extends MultiBrowserTest { + + @Test + public void fileOpenedInNewTab() { + openTestURL(); + + $(ButtonElement.class).caption("Download").first().click(); + + List<WebElement> iframes = driver.findElements(By.tagName("iframe")); + boolean containsFileIframe = false; + for (WebElement iframe : iframes) { + containsFileIframe = containsFileIframe | + iframe.getAttribute("src").contains(IframeIsOpenedInNonIOS.FILE_NAME); + } + + Assert.assertTrue("page doesn't contain iframe with the file", containsFileIframe); + } + + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + //once running ios is possible, this test should be fixed to exclude it from the browsers list + + //The test is failing in all IEs for some reason even though the iframe is in place. + //Probably related to some IE driver issue + return getBrowsersExcludingIE(); + } +} 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(); + } } |