summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components
diff options
context:
space:
mode:
authorJonatan Kronqvist <jonatan@vaadin.com>2014-02-07 15:46:30 +0200
committerJonatan Kronqvist <jonatan@vaadin.com>2014-02-07 15:46:30 +0200
commit0e8500a5af0c4924d4a164bbd548128cf474b203 (patch)
tree8453e88b1c777d0a4ac28e6cad9a61de16aed785 /uitest/src/com/vaadin/tests/components
parent2659a54ebed8af66dce22b27d3ea285d1c8eb221 (diff)
parent407bdb39f7d87acaf15c399e46baf6d6a858fa6d (diff)
downloadvaadin-framework-0e8500a5af0c4924d4a164bbd548128cf474b203.tar.gz
vaadin-framework-0e8500a5af0c4924d4a164bbd548128cf474b203.zip
Merge changes from origin/7.1
8245079 Decrease the websocket buffer size due to a Jetty 9.1 issue (#13087) ea8f381 Show the widgetset name to more easily spot misconfigurations 797ebdf Allow user to override Atmosphere init params set by Vaadin (#13088) 65c2f2b Properly remove shadow event listeners to prevent IE8 memory leak (#13129) e9a547a Fixed spelling mistake in log message. 0b95f8d Moved selection of selected rows in TableConnector to occur after the new rows are created (#13008) 0579fba Upload control with empty selection (#9602) db4dba4 Ensure event listener is a widget before casting #13130 5e8e866 Changes padding for Textfields with Chameleon theme. (#12974) 171e68d Only use ClientRcp and ServerRpc types that are interfaces (#13056) e41a2ce Add helper for adding multiple components to AbstractTestUI 407bdb3 Ignores scroll events while update from server is in progress (#11454) Change-Id: I5d21b4071165b02da0f53bd055fb1c64e90cae5b
Diffstat (limited to 'uitest/src/com/vaadin/tests/components')
-rw-r--r--uitest/src/com/vaadin/tests/components/AbstractTestUI.java4
-rw-r--r--uitest/src/com/vaadin/tests/components/table/ExpandingContainer.java429
-rw-r--r--uitest/src/com/vaadin/tests/components/table/ExpandingContainerVisibleRowRaceCondition.java67
-rw-r--r--uitest/src/com/vaadin/tests/components/table/ExpandingContainerVisibleRowRaceConditionTest.java90
-rw-r--r--uitest/src/com/vaadin/tests/components/table/SelectAllRows.java83
-rw-r--r--uitest/src/com/vaadin/tests/components/table/SelectAllRowsTest.java105
-rw-r--r--uitest/src/com/vaadin/tests/components/upload/UploadNoSelection.java83
-rw-r--r--uitest/src/com/vaadin/tests/components/upload/UploadNoSelectionTest.java56
8 files changed, 917 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java
index cbca4bcf7f..5c7076c07e 100644
--- a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java
+++ b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java
@@ -148,6 +148,10 @@ public abstract class AbstractTestUI extends UI {
getLayout().addComponent(c);
}
+ public void addComponents(Component... c) {
+ getLayout().addComponents(c);
+ }
+
public void removeComponent(Component c) {
getLayout().removeComponent(c);
}
diff --git a/uitest/src/com/vaadin/tests/components/table/ExpandingContainer.java b/uitest/src/com/vaadin/tests/components/table/ExpandingContainer.java
new file mode 100644
index 0000000000..829c29b95b
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/ExpandingContainer.java
@@ -0,0 +1,429 @@
+package com.vaadin.tests.components.table;
+
+import java.util.AbstractList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.logging.Logger;
+
+import com.vaadin.data.Container;
+import com.vaadin.data.Item;
+import com.vaadin.data.Property;
+import com.vaadin.data.util.AbstractContainer;
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.server.VaadinSession;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Label;
+
+@SuppressWarnings("serial")
+public class ExpandingContainer extends AbstractContainer implements
+ Container.Ordered, Container.Indexed, Container.ItemSetChangeNotifier {
+
+ public static final List<String> PROPERTY_IDS = Arrays.asList("id",
+ "column1", "column2");
+
+ private final Label sizeLabel;
+ private final Logger log = Logger.getLogger(this.getClass().getName());
+
+ private int currentSize = 300;
+
+ private boolean loggingEnabled;
+
+ public ExpandingContainer(Label sizeLabel) {
+ this.sizeLabel = sizeLabel;
+ updateLabel();
+ }
+
+ private void log(String message) {
+ if (loggingEnabled) {
+ log.info(message);
+ }
+ }
+
+ // Expand container if we scroll past 85%
+ public int checkExpand(int index) {
+ log("checkExpand(" + index + ")");
+ if (index >= currentSize * 0.85) {
+ final int oldsize = currentSize;
+ currentSize = (int) (oldsize * 1.3333);
+ log("*** getSizeWithHint(" + index + "): went past 85% of size="
+ + oldsize + ", new size=" + currentSize);
+ updateLabel();
+ }
+ return currentSize;
+ };
+
+ @Override
+ public void fireItemSetChange() {
+ super.fireItemSetChange();
+ }
+
+ private void updateLabel() {
+ sizeLabel.setValue("Container size: " + currentSize);
+ }
+
+ public void triggerItemSetChange() {
+ log("*** triggerItemSetChange(): scheduling item set change event");
+ final VaadinSession session = VaadinSession.getCurrent();
+ new Thread() {
+ @Override
+ public void run() {
+ ExpandingContainer.this.invoke(session, new Runnable() {
+ @Override
+ public void run() {
+ log("*** Firing item set change event");
+ ExpandingContainer.this.fireItemSetChange();
+ }
+ });
+ }
+ }.start();
+ }
+
+ private void invoke(VaadinSession session, Runnable action) {
+ session.lock();
+ VaadinSession previousSession = VaadinSession.getCurrent();
+ VaadinSession.setCurrent(session);
+ try {
+ action.run();
+ } finally {
+ session.unlock();
+ VaadinSession.setCurrent(previousSession);
+ }
+ }
+
+ // Container
+
+ @Override
+ public BeanItem<MyBean> getItem(Object itemId) {
+ if (!(itemId instanceof Integer)) {
+ return null;
+ }
+ final int index = ((Integer) itemId).intValue();
+ return new BeanItem<MyBean>(new MyBean(index));
+ }
+
+ @Override
+ public Collection<Integer> getItemIds() {
+ return new IntList(size());
+ }
+
+ @Override
+ public List<String> getContainerPropertyIds() {
+ return PROPERTY_IDS;
+ }
+
+ @Override
+ @SuppressWarnings("rawtypes")
+ public Property/* <?> */getContainerProperty(Object itemId,
+ Object propertyId) {
+ BeanItem<MyBean> item = getItem(itemId);
+ return item != null ? item.getItemProperty(propertyId) : null;
+ }
+
+ @Override
+ public Class<?> getType(Object propertyId) {
+ return Component.class;
+ }
+
+ @Override
+ public int size() {
+ return currentSize;
+ }
+
+ @Override
+ public boolean containsId(Object itemId) {
+ if (!(itemId instanceof Integer)) {
+ return false;
+ }
+ int index = ((Integer) itemId).intValue();
+ checkExpand(index);
+ return index >= 0 && index < currentSize;
+ }
+
+ /**
+ * @throws UnsupportedOperationException
+ * always
+ */
+ @Override
+ public Item addItem(Object itemId) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @throws UnsupportedOperationException
+ * always
+ */
+ @Override
+ public Item addItem() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @throws UnsupportedOperationException
+ * always
+ */
+ @Override
+ public boolean removeItem(Object itemId) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @throws UnsupportedOperationException
+ * always
+ */
+ @Override
+ public boolean addContainerProperty(Object propertyId, Class<?> type,
+ Object defaultValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @throws UnsupportedOperationException
+ * always
+ */
+ @Override
+ public boolean removeContainerProperty(Object propertyId) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @throws UnsupportedOperationException
+ * always
+ */
+ @Override
+ public boolean removeAllItems() {
+ throw new UnsupportedOperationException();
+ }
+
+ // Container.Indexed
+
+ /**
+ * @throws UnsupportedOperationException
+ * always
+ */
+ @Override
+ public Object addItemAt(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @throws UnsupportedOperationException
+ * always
+ */
+ @Override
+ public Item addItemAt(int index, Object newItemId) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Integer getIdByIndex(int index) {
+ if (index < 0) {
+ throw new IndexOutOfBoundsException("index < " + index);
+ }
+ final int size = currentSize;
+ if (index >= size) {
+ throw new IndexOutOfBoundsException("index=" + index + " but size="
+ + size);
+ }
+ checkExpand(index);
+ return index;
+ }
+
+ @Override
+ public List<Integer> getItemIds(int startIndex, int numberOfItems) {
+ if (numberOfItems < 0) {
+ throw new IllegalArgumentException("numberOfItems < 0");
+ }
+ final int size = currentSize;
+ checkExpand(startIndex);
+ if (startIndex < 0 || startIndex > size) {
+ throw new IndexOutOfBoundsException("startIndex=" + startIndex
+ + " but size=" + size);
+ }
+ if (startIndex + numberOfItems > size) {
+ numberOfItems = size - startIndex;
+ }
+ return new IntList(startIndex, numberOfItems);
+ }
+
+ @Override
+ public int indexOfId(Object itemId) {
+ if (!(itemId instanceof Integer)) {
+ return -1;
+ }
+ final int index = ((Integer) itemId).intValue();
+ checkExpand(index);
+ if (index < 0 || index >= currentSize) {
+ return -1;
+ }
+ return index;
+ }
+
+ // Container.Ordered
+
+ @Override
+ public Integer nextItemId(Object itemId) {
+ if (!(itemId instanceof Integer)) {
+ return null;
+ }
+ int index = ((Integer) itemId).intValue();
+ checkExpand(index);
+ if (index < 0 || index + 1 >= currentSize) {
+ return null;
+ }
+ return index + 1;
+ }
+
+ @Override
+ public Integer prevItemId(Object itemId) {
+ if (!(itemId instanceof Integer)) {
+ return null;
+ }
+ int index = ((Integer) itemId).intValue();
+ checkExpand(index);
+ if (index - 1 < 0 || index >= currentSize) {
+ return null;
+ }
+ return index - 1;
+ }
+
+ @Override
+ public Integer firstItemId() {
+ return currentSize == 0 ? null : 0;
+ }
+
+ @Override
+ public Integer lastItemId() {
+ final int size = currentSize;
+ return size == 0 ? null : size - 1;
+ }
+
+ @Override
+ public boolean isFirstId(Object itemId) {
+ if (!(itemId instanceof Integer)) {
+ return false;
+ }
+ final int index = ((Integer) itemId).intValue();
+ checkExpand(index);
+ final int size = currentSize;
+ return size > 0 && index == 0;
+ }
+
+ @Override
+ public boolean isLastId(Object itemId) {
+ if (!(itemId instanceof Integer)) {
+ return false;
+ }
+ int index = ((Integer) itemId).intValue();
+ checkExpand(index);
+ int size = currentSize;
+ return size > 0 && index == size - 1;
+ }
+
+ /**
+ * @throws UnsupportedOperationException
+ * always
+ */
+ @Override
+ public Item addItemAfter(Object previousItemId) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @throws UnsupportedOperationException
+ * always
+ */
+ @Override
+ public Item addItemAfter(Object previousItemId, Object newItemId) {
+ throw new UnsupportedOperationException();
+ }
+
+ // Container.ItemSetChangeNotifier
+
+ @Override
+ @SuppressWarnings("deprecation")
+ public void addListener(Container.ItemSetChangeListener listener) {
+ super.addListener(listener);
+ }
+
+ @Override
+ public void addItemSetChangeListener(
+ Container.ItemSetChangeListener listener) {
+ super.addItemSetChangeListener(listener);
+ }
+
+ @Override
+ @SuppressWarnings("deprecation")
+ public void removeListener(Container.ItemSetChangeListener listener) {
+ super.removeListener(listener);
+ }
+
+ @Override
+ public void removeItemSetChangeListener(
+ Container.ItemSetChangeListener listener) {
+ super.removeItemSetChangeListener(listener);
+ }
+
+ // IntList
+
+ private static class IntList extends AbstractList<Integer> {
+
+ private final int min;
+ private final int size;
+
+ public IntList(int size) {
+ this(0, size);
+ }
+
+ public IntList(int min, int size) {
+ if (size < 0) {
+ throw new IllegalArgumentException("size < 0");
+ }
+ this.min = min;
+ this.size = size;
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public Integer get(int index) {
+ if (index < 0 || index >= size) {
+ throw new IndexOutOfBoundsException();
+ }
+ return min + index;
+ }
+ }
+
+ // MyBean
+ public class MyBean {
+
+ private final int index;
+
+ public MyBean(int index) {
+ this.index = index;
+ }
+
+ public String getId() {
+ return "ROW #" + index;
+ }
+
+ public String getColumn1() {
+ return genText();
+ }
+
+ public String getColumn2() {
+ return genText();
+ }
+
+ private String genText() {
+ return "this is a line of text in row #" + index;
+ }
+ }
+
+ public void logDetails(boolean enabled) {
+ loggingEnabled = enabled;
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/table/ExpandingContainerVisibleRowRaceCondition.java b/uitest/src/com/vaadin/tests/components/table/ExpandingContainerVisibleRowRaceCondition.java
new file mode 100644
index 0000000000..8ad2d7f9c7
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/ExpandingContainerVisibleRowRaceCondition.java
@@ -0,0 +1,67 @@
+package com.vaadin.tests.components.table;
+
+import java.util.Map;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+
+@SuppressWarnings("serial")
+public class ExpandingContainerVisibleRowRaceCondition extends UI {
+
+ static final String TABLE = "table";
+
+ @Override
+ public void init(VaadinRequest request) {
+ final VerticalLayout rootLayout = new VerticalLayout();
+
+ rootLayout.setSpacing(true);
+ rootLayout.setSizeFull();
+ rootLayout.setMargin(true);
+
+ final Label sizeLabel = new Label();
+ final ExpandingContainer container = new ExpandingContainer(sizeLabel);
+ container.logDetails(false);
+
+ Table table = new Table(null, container) {
+ @Override
+ public void changeVariables(Object source,
+ Map<String, Object> variables) {
+ if (variables.containsKey("firstvisible")) {
+ int index = (Integer) variables.get("firstvisible");
+ container.checkExpand(index);
+ }
+ if (variables.containsKey("reqfirstrow")
+ || variables.containsKey("reqrows")) {
+ try {
+ int index = ((Integer) variables
+ .get("lastToBeRendered")).intValue();
+ container.checkExpand(index);
+ } catch (Exception e) {
+ // do nothing
+ }
+ }
+ super.changeVariables(source, variables);
+ }
+ };
+ table.setId(TABLE);
+ table.setCacheRate(0);
+ table.setSizeFull();
+ table.setVisibleColumns(ExpandingContainer.PROPERTY_IDS
+ .toArray(new String[ExpandingContainer.PROPERTY_IDS.size()]));
+
+ table.setCurrentPageFirstItemIndex(120);
+
+ rootLayout.addComponent(table);
+ rootLayout.setExpandRatio(table, 1);
+
+ rootLayout.addComponent(sizeLabel);
+
+ setContent(rootLayout);
+
+ container.checkExpand(300);
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/table/ExpandingContainerVisibleRowRaceConditionTest.java b/uitest/src/com/vaadin/tests/components/table/ExpandingContainerVisibleRowRaceConditionTest.java
new file mode 100644
index 0000000000..73dd7b1f81
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/ExpandingContainerVisibleRowRaceConditionTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2000-2013 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 com.vaadin.tests.components.table.ExpandingContainerVisibleRowRaceCondition.TABLE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class ExpandingContainerVisibleRowRaceConditionTest extends
+ MultiBrowserTest {
+
+ private static final int ROW_HEIGHT = 20;
+
+ @Test
+ public void testScrollingWorksWithoutJumpingWhenItemSetChangeOccurs() {
+ openTestURL();
+ sleep(1000);
+
+ WebElement table = vaadinElementById(TABLE);
+ assertFirstRowIdIs("ROW #120");
+
+ testBenchElement(table.findElement(By.className("v-scrollable")))
+ .scroll(320 * ROW_HEIGHT);
+ sleep(1000);
+
+ assertRowIdIsInThePage("ROW #330");
+ assertScrollPositionIsNotVisible();
+ }
+
+ @Override
+ protected void sleep(int milliseconds) {
+ try {
+ super.sleep(milliseconds);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void assertFirstRowIdIs(String expected) {
+ List<WebElement> cellsOfFirstColumn = getCellsOfFirstColumn();
+ WebElement first = cellsOfFirstColumn.get(0);
+ assertEquals(expected, first.getText());
+ }
+
+ private void assertRowIdIsInThePage(String expected) {
+ List<WebElement> cellsOfFirstColumn = getCellsOfFirstColumn();
+ for (WebElement rowId : cellsOfFirstColumn) {
+ if (expected.equals(rowId.getText())) {
+ return;
+ }
+ }
+ fail("Expected row was not found");
+ }
+
+ private void assertScrollPositionIsNotVisible() {
+ WebElement table = vaadinElementById(TABLE);
+ WebElement scrollPosition = table.findElement(By
+ .className("v-table-scrollposition"));
+ assertFalse(scrollPosition.isDisplayed());
+ }
+
+ private List<WebElement> getCellsOfFirstColumn() {
+ WebElement table = vaadinElementById(TABLE);
+ List<WebElement> firstCellOfRows = table.findElements(By
+ .cssSelector(".v-table-table tr > td"));
+ return firstCellOfRows;
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/table/SelectAllRows.java b/uitest/src/com/vaadin/tests/components/table/SelectAllRows.java
new file mode 100644
index 0000000000..6007ea2984
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/SelectAllRows.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2000-2013 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 java.util.Set;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.VerticalLayout;
+
+public class SelectAllRows extends AbstractTestUI {
+
+ static final String TABLE = "table";
+ static final String COUNT_SELECTED_BUTTON = "button";
+ static final int TOTAL_NUMBER_OF_ROWS = 300;
+ static final String COUNT_OF_SELECTED_ROWS_LABEL = "label";
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ VerticalLayout layout = new VerticalLayout();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+ setContent(layout);
+
+ final Table table = new Table();
+ table.setId(TABLE);
+ table.setImmediate(true);
+ table.setMultiSelect(true);
+ table.setSelectable(true);
+ table.addContainerProperty("row", String.class, null);
+ layout.addComponent(table);
+
+ Button button = new Button("Count");
+ button.setId(COUNT_SELECTED_BUTTON);
+ layout.addComponent(button);
+
+ final Label label = new Label();
+ label.setId(COUNT_OF_SELECTED_ROWS_LABEL);
+ label.setCaption("Selected count:");
+ layout.addComponent(label);
+
+ button.addClickListener(new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(Button.ClickEvent event) {
+ Set selected = (Set) table.getValue();
+ label.setValue(String.valueOf(selected.size()));
+ }
+ });
+
+ for (int i = 0; i < TOTAL_NUMBER_OF_ROWS; i++) {
+ Object itemId = table.addItem();
+ table.getContainerProperty(itemId, "row").setValue("row " + i);
+ }
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Selecting all rows does not work by selecting first row, press shift then select last row";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 13008;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/table/SelectAllRowsTest.java b/uitest/src/com/vaadin/tests/components/table/SelectAllRowsTest.java
new file mode 100644
index 0000000000..664b36fa75
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/SelectAllRowsTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2000-2013 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 com.vaadin.tests.components.table.SelectAllRows.COUNT_OF_SELECTED_ROWS_LABEL;
+import static com.vaadin.tests.components.table.SelectAllRows.COUNT_SELECTED_BUTTON;
+import static com.vaadin.tests.components.table.SelectAllRows.TABLE;
+import static com.vaadin.tests.components.table.SelectAllRows.TOTAL_NUMBER_OF_ROWS;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class SelectAllRowsTest extends MultiBrowserTest {
+
+ private final static String TABLE_ROW = "v-table-row";
+
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ // Pressing Shift modifier key does not work with TestBench and IE
+ // (#8621)
+ return Arrays.asList(Browser.FIREFOX.getDesiredCapabilities(),
+ Browser.CHROME.getDesiredCapabilities());
+ }
+
+ @Test
+ public void testAllRowsAreSelected() {
+ openTestURL();
+
+ selectAllRowsInTable();
+ int selectedRows = countSelectedItems();
+
+ assertEquals(TOTAL_NUMBER_OF_ROWS, selectedRows);
+ }
+
+ private int countSelectedItems() {
+ WebElement countButton = vaadinElementById(COUNT_SELECTED_BUTTON);
+ countButton.click();
+ WebElement countOfSelectedRows = vaadinElementById(COUNT_OF_SELECTED_ROWS_LABEL);
+ String count = countOfSelectedRows.getText();
+ return Integer.parseInt(count);
+ }
+
+ private void selectAllRowsInTable() {
+ clickFirstRow();
+ scrollTableToBottom();
+ new Actions(getDriver()).keyDown(Keys.SHIFT).perform();
+ clickLastRow();
+ new Actions(getDriver()).keyUp(Keys.SHIFT).perform();
+ }
+
+ private void clickLastRow() {
+ List<WebElement> rows = allVisibleTableRows();
+ WebElement lastRow = rows.get(rows.size() - 1);
+ lastRow.click();
+ }
+
+ private void clickFirstRow() {
+ WebElement firstRow = allVisibleTableRows().get(0);
+ firstRow.click();
+ }
+
+ private void scrollTableToBottom() {
+ WebElement table = vaadinElementById(TABLE);
+ testBenchElement(table.findElement(By.className("v-scrollable")))
+ .scroll(TOTAL_NUMBER_OF_ROWS * 30);
+
+ // Wait for scrolling to complete. Otherwise, clicking last row will
+ // fail with Chrome
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private List<WebElement> allVisibleTableRows() {
+ WebElement table = vaadinElementById(TABLE);
+ List<WebElement> rows = table.findElements(By
+ .cssSelector(".v-table-table tr"));
+ return rows;
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/upload/UploadNoSelection.java b/uitest/src/com/vaadin/tests/components/upload/UploadNoSelection.java
new file mode 100644
index 0000000000..c304293170
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/upload/UploadNoSelection.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2000-2013 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.upload;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Upload;
+import com.vaadin.ui.Upload.FailedEvent;
+import com.vaadin.ui.Upload.FinishedEvent;
+import com.vaadin.ui.Upload.Receiver;
+
+public class UploadNoSelection extends AbstractTestUIWithLog implements
+ Receiver {
+
+ static final String LOG_ID_PREFIX = "Log_row_";
+ static final String UPLOAD_ID = "u";
+
+ static final String UPLOAD_FINISHED = "Upload Finished";
+ static final String RECEIVING_UPLOAD = "Receiving upload";
+
+ static final String FILE_LENGTH_PREFIX = "File length:";
+ static final String FILE_NAME_PREFIX = "File name:";
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 9602;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Uploading an empty selection (no file) will trigger FinishedEvent with 0-length file size and empty filename.";
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Upload u = new Upload("Upload", this);
+ u.setId(UPLOAD_ID);
+ u.setSizeUndefined();
+
+ addComponent(u);
+
+ u.addFinishedListener(new Upload.FinishedListener() {
+ @Override
+ public void uploadFinished(FinishedEvent event) {
+ log(UPLOAD_FINISHED);
+ log(FILE_LENGTH_PREFIX + " " + event.getLength());
+ log(FILE_NAME_PREFIX + " " + event.getFilename());
+ }
+ });
+ u.addFailedListener(new Upload.FailedListener() {
+
+ @Override
+ public void uploadFailed(FailedEvent event) {
+ log("Upload Failed");
+ log(FILE_LENGTH_PREFIX + " " + event.getLength());
+ log(FILE_NAME_PREFIX + " " + event.getFilename());
+ }
+ });
+ }
+
+ @Override
+ public OutputStream receiveUpload(String filename, String MIMEType) {
+ log(RECEIVING_UPLOAD);
+ return new ByteArrayOutputStream();
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/upload/UploadNoSelectionTest.java b/uitest/src/com/vaadin/tests/components/upload/UploadNoSelectionTest.java
new file mode 100644
index 0000000000..1b30c4080a
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/upload/UploadNoSelectionTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2000-2013 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.upload;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class UploadNoSelectionTest extends MultiBrowserTest {
+
+ @Test
+ public void testUploadNoSelection() throws Exception {
+ openTestURL();
+
+ // empty content is populated by com.vaadin.tests.util.Log
+ Assert.assertEquals(" ", getLogRow(0));
+
+ getSubmitButton().click();
+
+ // expecting empty file name
+ assertLogRow(0, 4, UploadNoSelection.FILE_NAME_PREFIX);
+ // expecting 0-length file
+ assertLogRow(1, 3, UploadNoSelection.FILE_LENGTH_PREFIX + " " + 0);
+ assertLogRow(2, 2, UploadNoSelection.UPLOAD_FINISHED);
+ assertLogRow(3, 1, UploadNoSelection.RECEIVING_UPLOAD);
+ }
+
+ private WebElement getSubmitButton() {
+ WebElement element = getDriver().findElement(
+ By.id(UploadNoSelection.UPLOAD_ID));
+ WebElement submitButton = element.findElement(By.className("v-button"));
+ return submitButton;
+ }
+
+ private void assertLogRow(int index, int expentedRowNo,
+ String expectedValueWithoutRowNo) {
+ Assert.assertEquals(expentedRowNo + ". " + expectedValueWithoutRowNo,
+ getLogRow(index));
+ }
+}