From f9796817e8557d716a31d9411919431cfbfa63e6 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Wed, 26 Mar 2014 10:39:46 +0200 Subject: Fix VScrollTable to clear reported ranges (#13353) Change-Id: Ieb0e2dce37ae1564151bf40d9d51cb013490b865 --- .../table/AddSelectionToRemovedRange.java | 93 ++++++++++++++++++++++ .../table/AddSelectionToRemovedRangeTest.java | 74 +++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/table/AddSelectionToRemovedRange.java create mode 100644 uitest/src/com/vaadin/tests/components/table/AddSelectionToRemovedRangeTest.java (limited to 'uitest') diff --git a/uitest/src/com/vaadin/tests/components/table/AddSelectionToRemovedRange.java b/uitest/src/com/vaadin/tests/components/table/AddSelectionToRemovedRange.java new file mode 100644 index 0000000000..d54a8b467a --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/AddSelectionToRemovedRange.java @@ -0,0 +1,93 @@ +/* + * 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.tests.tb3.AbstractTB3Test.RunLocally; +import com.vaadin.ui.Button; +import com.vaadin.ui.Notification; +import com.vaadin.ui.Notification.Type; +import com.vaadin.ui.Table; +import com.vaadin.ui.VerticalLayout; + +/** + * Test to see if selecting and deselecting a table row after select range has + * been removed. + * + * @since 7.1.13 + * @author Vaadin Ltd + */ +@SuppressWarnings("serial") +@RunLocally() +public class AddSelectionToRemovedRange extends AbstractTestUI { + + @Override + @SuppressWarnings("unchecked") + protected void setup(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + layout.setSpacing(true); + setContent(layout); + + final Table table = new Table(); + table.setMultiSelect(true); + table.setSelectable(true); + table.addContainerProperty("value", String.class, ""); + + for (int i = 0; i < 100; i++) { + table.addItem(i); + table.getContainerProperty(i, "value").setValue("value " + i); + } + + layout.addComponent(table); + + Button button = new Button("Remove"); + button.addClickListener(new Button.ClickListener() { + + @Override + public void buttonClick(Button.ClickEvent event) { + Set selected = (Set) table.getValue(); + + for (Integer item : selected) { + if (null == item) { + new Notification( + "ERROR", + "Table value has null in Set of selected items!", + Type.ERROR_MESSAGE).show(getPage()); + } + table.removeItem(item); + } + } + }); + + layout.addComponent(button); + + } + + @Override + protected String getTestDescription() { + return "Verify that VScrollTable does not return bad ranges when "; + } + + @Override + protected Integer getTicketNumber() { + return 13353; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/table/AddSelectionToRemovedRangeTest.java b/uitest/src/com/vaadin/tests/components/table/AddSelectionToRemovedRangeTest.java new file mode 100644 index 0000000000..f6a503db72 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/AddSelectionToRemovedRangeTest.java @@ -0,0 +1,74 @@ +/* + * 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.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class AddSelectionToRemovedRangeTest extends MultiBrowserTest { + + @Override + public List getBrowsersToTest() { + return Collections.unmodifiableList(Arrays.asList(Browser.CHROME + .getDesiredCapabilities())); + } + + @Override + protected DesiredCapabilities getDesiredCapabilities() { + DesiredCapabilities cap = new DesiredCapabilities( + super.getDesiredCapabilities()); + cap.setCapability("requireWindowFocus", true); + return cap; + } + + @Test + public void addAndRemoveItemToRemovedRange() throws IOException { + openTestURL(); + List rows = driver.findElements(By + .className("v-table-cell-wrapper")); + WebElement rangeStart = rows.get(0); + WebElement rangeEnd = rows.get(1); + rangeStart.click(); + new Actions(driver).keyDown(Keys.SHIFT).perform(); + rangeEnd.click(); + new Actions(driver).keyUp(Keys.SHIFT).perform(); + driver.findElement(By.className("v-button")).click(); + WebElement extraRow = driver.findElements( + By.className("v-table-cell-wrapper")).get(1); + new Actions(driver).keyDown(Keys.CONTROL).click(extraRow) + .click(extraRow).keyUp(Keys.CONTROL).perform(); + driver.findElement(By.className("v-button")).click(); + try { + driver.findElement(By.vaadin("Root/VNotification[0]")); + Assert.fail("Notification is shown"); + } catch (NoSuchElementException e) { + // All is well. + } + } +} -- cgit v1.2.3 From a4732225bb9336131a9bfb39782279e7ba7ed950 Mon Sep 17 00:00:00 2001 From: Sauli Tähkäpää Date: Wed, 26 Mar 2014 10:25:58 +0200 Subject: Added browser inclusion and exclusion for TB3Runner. Change-Id: Ib7ef84027eebc0d9512964361419763631b9b29f --- uitest/src/com/vaadin/tests/tb3/TB3Runner.java | 159 +++++++++++++++++++++---- uitest/tb3test.xml | 2 + 2 files changed, 137 insertions(+), 24 deletions(-) (limited to 'uitest') diff --git a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java index 54bb2d86a5..18a2b69025 100644 --- a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java +++ b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java @@ -1,12 +1,12 @@ /* * 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 @@ -17,6 +17,7 @@ package com.vaadin.tests.tb3; import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; @@ -25,6 +26,7 @@ import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import org.junit.Ignore; import org.junit.Test; import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.Parameterized; @@ -74,31 +76,30 @@ public class TB3Runner extends BlockJUnit4ClassRunner { } try { - AbstractTB3Test testClassInstance = (AbstractTB3Test) getTestClass() - .getOnlyConstructor().newInstance(); - Collection desiredCapabilites = testClassInstance - .getBrowsersToTest(); - if (testClassInstance.getClass().getAnnotation(RunLocally.class) != null) { - desiredCapabilites = new ArrayList(); - desiredCapabilites.add(testClassInstance.getClass() - .getAnnotation(RunLocally.class).value() - .getDesiredCapabilities()); - } + AbstractTB3Test testClassInstance = getTestClassInstance(); + Collection desiredCapabilites = getDesiredCapabilities(testClassInstance); TestNameSuffix testNameSuffixProperty = findAnnotation( testClassInstance.getClass(), TestNameSuffix.class); - for (DesiredCapabilities capabilities : desiredCapabilites) { - // Find any methods marked with @Test. - for (FrameworkMethod m : getTestClass().getAnnotatedMethods( - Test.class)) { - TB3Method method = new TB3Method(m.getMethod(), - capabilities); - if (testNameSuffixProperty != null) { - method.setTestNameSuffix("-" - + System.getProperty(testNameSuffixProperty - .property())); + + for (FrameworkMethod m : getTestMethods()) { + if (desiredCapabilites.size() > 0) { + for (DesiredCapabilities capabilities : desiredCapabilites) { + TB3Method method = new TB3Method(m.getMethod(), + capabilities); + if (testNameSuffixProperty != null) { + method.setTestNameSuffix("-" + + System.getProperty(testNameSuffixProperty + .property())); + } + tests.add(method); } - tests.add(method); + + } else { + // No browsers available for this test, so we need to + // wrap the test method inside IgnoredTestMethod. + // This will add @Ignore annotation to it. + tests.add(new IgnoredTestMethod(m.getMethod())); } } } catch (Exception e) { @@ -108,6 +109,116 @@ public class TB3Runner extends BlockJUnit4ClassRunner { return tests; } + private List getTestMethods() { + return getTestClass().getAnnotatedMethods(Test.class); + } + + /* + * Returns a list of desired browser capabilities according to browsers + * defined in the test class, filtered by possible filter parameters. Use + * {@code @RunLocally} annotation to override all capabilities. + */ + private Collection getDesiredCapabilities( + AbstractTB3Test testClassInstance) { + Collection desiredCapabilites = getFilteredCapabilities(testClassInstance); + + if (isRunLocally(testClassInstance)) { + desiredCapabilites = new ArrayList(); + desiredCapabilites.add(testClassInstance.getClass() + .getAnnotation(RunLocally.class).value() + .getDesiredCapabilities()); + } + + return desiredCapabilites; + } + + /* + * Takes the desired browser capabilities defined in the test class and + * returns a list of browser capabilities filtered browsers.include and + * browsers.exclude system properties. (if present) + */ + private Collection getFilteredCapabilities( + AbstractTB3Test testClassInstance) { + Collection desiredCapabilites = testClassInstance + .getBrowsersToTest(); + + ArrayList filteredCapabilities = new ArrayList(); + + String include = System.getProperty("browsers.include"); + String exclude = System.getProperty("browsers.exclude"); + + for (DesiredCapabilities d : desiredCapabilites) { + String browserName = (d.getBrowserName() + d.getVersion()) + .toLowerCase(); + if (include != null) { + if (include.toLowerCase().contains(browserName)) { + filteredCapabilities.add(d); + } + } else { + filteredCapabilities.add(d); + } + + if (exclude != null) { + if (exclude.toLowerCase().contains(browserName)) { + filteredCapabilities.remove(d); + } + } + + } + return filteredCapabilities; + } + + private boolean isRunLocally(AbstractTB3Test testClassInstance) { + return testClassInstance.getClass().getAnnotation(RunLocally.class) != null; + } + + private AbstractTB3Test getTestClassInstance() + throws InstantiationException, IllegalAccessException, + InvocationTargetException { + AbstractTB3Test testClassInstance = (AbstractTB3Test) getTestClass() + .getOnlyConstructor().newInstance(); + return testClassInstance; + } + + // This is a FrameworkMethod class that will always + // return @Ignore and @Test annotations for the wrapped method. + private class IgnoredTestMethod extends FrameworkMethod { + + private class IgnoreTestAnnotations { + + // We use this method to easily get our hands on + // the Annotation instances for @Ignore and @Test + @Ignore + @Test + public void ignoredTest() { + } + } + + public IgnoredTestMethod(Method method) { + super(method); + } + + @Override + public Annotation[] getAnnotations() { + return getIgnoredTestMethod().getAnnotations(); + } + + private Method getIgnoredTestMethod() { + try { + return IgnoreTestAnnotations.class.getMethod("ignoredTest", + null); + } catch (Exception e) { + return null; + } + + } + + @Override + public T getAnnotation(Class annotationType) { + return getIgnoredTestMethod().getAnnotation(annotationType); + } + } + /** * Finds the given annotation in the given class or one of its super * classes. Return the first found annotation diff --git a/uitest/tb3test.xml b/uitest/tb3test.xml index 41cce8f0f2..ec78b9c9d2 100644 --- a/uitest/tb3test.xml +++ b/uitest/tb3test.xml @@ -29,6 +29,8 @@ + + -- cgit v1.2.3