diff options
author | Artur Signell <artur@vaadin.com> | 2015-01-28 22:22:46 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2015-01-28 22:22:46 +0200 |
commit | 6aea785642f66dbde578765dcaa429415c8ac75c (patch) | |
tree | 2329b3b6f8a33a445cf97d7f63ba2172fa268392 /uitest | |
parent | e6ff02e314c8739537b688d2908571baa16764e8 (diff) | |
parent | 4ad7cefcc06e372df8b67a2456616d7410c768d8 (diff) | |
download | vaadin-framework-6aea785642f66dbde578765dcaa429415c8ac75c.tar.gz vaadin-framework-6aea785642f66dbde578765dcaa429415c8ac75c.zip |
Merge remote-tracking branch 'origin/master' into grid
Conflicts:
client/src/com/vaadin/client/ui/VWindow.java
Change-Id: I1a35db88a2b11acf76b58c417575451edfdb275d
Diffstat (limited to 'uitest')
7 files changed, 558 insertions, 9 deletions
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(); + } } |