From eceb044f0d9c60e2a37a7a778d20f68341c9dae8 Mon Sep 17 00:00:00 2001 From: Ilya Ermakov Date: Thu, 11 Dec 2014 16:29:39 +0300 Subject: Fix Table pageup/pagedown navigation (#15332) After this patch navigation with PageDown, PageUp, Home, End works properly. What was changed in this patch (new state): the first visible row number is updated before sending selected rows to the server while handling these keys. Change-Id: I3bdebc434f886ef55f90f3fed5fd607d5f65f87f --- .../components/table/TableNavigationPageDown.java | 56 ++++++ .../table/TableNavigationPageDownTest.java | 223 +++++++++++++++++++++ 2 files changed, 279 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/table/TableNavigationPageDown.java create mode 100644 uitest/src/com/vaadin/tests/components/table/TableNavigationPageDownTest.java (limited to 'uitest') 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() { + @Override + public Boolean apply(WebDriver input) { + List 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() { + @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 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 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 getBrowsersToTest() { + // Sending PageDown has no effect on PhantomJS. On IE focus + // in Table is often lost, so default scrolling happens on PageDown. + List browsers = new ArrayList( + getBrowsersExcludingIE()); + browsers.remove(Browser.PHANTOMJS.getDesiredCapabilities()); + return browsers; + } + +} -- cgit v1.2.3 From b8d69b6b397ba2d669aa16e297d900e5e079d1e9 Mon Sep 17 00:00:00 2001 From: Alexey Fansky Date: Mon, 22 Dec 2014 12:05:53 -0800 Subject: FileDownloader opens file in a new tab (iOS) (#15366) Opening files in a new tab because iframe with a file isn't opened in iOS. Change-Id: I7f8af4b9348ade0f845e3a656c7287490b9482cf --- .../client/extensions/FileDownloaderConnector.java | 36 ++++++++++------- .../tests/extensions/IframeIsOpenedInNonIOS.java | 45 ++++++++++++++++++++++ .../extensions/IframeIsOpenedInNonIOSTest.java | 39 +++++++++++++++++++ 3 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/extensions/IframeIsOpenedInNonIOS.java create mode 100644 uitest/src/com/vaadin/tests/extensions/IframeIsOpenedInNonIOSTest.java (limited to 'uitest') 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/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 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 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(); + } +} -- cgit v1.2.3 From 2af61caa596eb39b211bb6c71809e6ecca63bae8 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 27 Jan 2015 13:51:22 +0200 Subject: Render Window caption as text when requested (#16273) Change-Id: I15813f5fc305776282bdc9cb3d5dffd4f09ebf55 --- client/src/com/vaadin/client/ui/VWindow.java | 9 ++- .../vaadin/client/ui/window/WindowConnector.java | 2 +- .../tests/components/window/WindowCaption.java | 82 +++++++++++++++++++ .../tests/components/window/WindowCaptionTest.java | 92 ++++++++++++++++++++++ .../tests/tb3/newelements/WindowElement.java | 30 ++++--- 5 files changed, 201 insertions(+), 14 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/window/WindowCaption.java create mode 100644 uitest/src/com/vaadin/tests/components/window/WindowCaptionTest.java (limited to 'uitest') 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 = "This may or may not be red"); + } + }); + 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,", + "This may or may not be red", + 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() { + @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(); + } } -- cgit v1.2.3