diff options
author | Pekka Hyvönen <pekka@vaadin.com> | 2015-04-17 09:42:07 +0300 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2015-04-17 09:42:52 +0300 |
commit | 33c61533ad8a3ed8a38ea606aa9e3d5f4da4dae8 (patch) | |
tree | 3d4edf6b9676e0967b7a08e11642c66cf1abfe0c /uitest/src/com | |
parent | 6ed28680346c648a6b4e974568a56f6d4d0e000b (diff) | |
parent | 0636e2d177a933dae13e50eb1b1f4609855f735e (diff) | |
download | vaadin-framework-33c61533ad8a3ed8a38ea606aa9e3d5f4da4dae8.tar.gz vaadin-framework-33c61533ad8a3ed8a38ea606aa9e3d5f4da4dae8.zip |
Merge branch 'master' into grid-7.5
Change-Id: I6175398df4c3a07656a2682843615a0d7bd32a45
Diffstat (limited to 'uitest/src/com')
53 files changed, 2784 insertions, 239 deletions
diff --git a/uitest/src/com/vaadin/tests/components/DeclarativeTestUI.java b/uitest/src/com/vaadin/tests/components/DeclarativeTestUI.java new file mode 100644 index 0000000000..568c484760 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/DeclarativeTestUI.java @@ -0,0 +1,175 @@ +/* + * 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; + +import java.io.File; +import java.io.FileInputStream; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Component; +import com.vaadin.ui.declarative.Design; + +/** + * Declarative test UI. Provides simple instantiation of HTML designs located + * under {@code uitest/src}. Also provides {@link OnLoad} annotation that lets + * you easily hook up methods to run after the UI has been created. Note: you + * <i>must</i> add the {@link DeclarativeUI} annotation to your subclass; not + * doing this will result in program failure. + */ +@SuppressWarnings("serial") +public class DeclarativeTestUI extends AbstractTestUI { + + private Logger logger; + private Component component; + + /** + * Class marker indicating the design .html file to load + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.TYPE) + public static @interface DeclarativeUI { + String value(); + + /** + * Set this property to true if you provide an absolute path to your + * design; otherwise, the DeclarativeTestUI logic will look for the HTML + * design file under {@code vaadin_project/uitest/src/<package path>/}. + */ + boolean absolutePath() default false; + } + + /** + * Method marker interface indicating that a method should be run after the + * declarative UI has been created + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public static @interface OnLoad { + + } + + /** + * Figure out the proper path for the HTML design file + */ + private String getDesignPath() { + Class<?> clazz = getClass(); + String designFilePath = null; + if (clazz.getAnnotation(DeclarativeUI.class).absolutePath()) { + designFilePath = ""; + } else { + // This is rather nasty.. but it works well enough for now. + String userDir = System.getProperty("user.dir"); + designFilePath = userDir + "/uitest/src/" + + clazz.getPackage().getName().replace('.', '/') + "/"; + } + + String designFileName = clazz.getAnnotation(DeclarativeUI.class) + .value(); + + return designFilePath + designFileName; + } + + private Component readDesign() throws Exception { + String path = getDesignPath(); + getLogger().log(Level.INFO, "Reading design from " + path); + + File file = new File(path); + return Design.read(new FileInputStream(file)); + } + + @Override + protected void setup(VaadinRequest request) { + Class<?> clazz = getClass(); + + if (clazz.isAnnotationPresent(DeclarativeUI.class)) { + + // Create component + try { + component = readDesign(); + } catch (Exception e1) { + getLogger().log(Level.SEVERE, "Error reading design", e1); + return; + } + + addComponent(component); + + // Call on-load methods (if applicable) + Method[] methods = clazz.getMethods(); + for (Method m : methods) { + if (m.isAnnotationPresent(OnLoad.class)) { + try { + m.invoke(this, (Object[]) null); + } catch (IllegalAccessException e) { + getLogger().log(Level.SEVERE, + "Error invoking @OnLoad method", e); + return; + } catch (IllegalArgumentException e) { + getLogger().log(Level.SEVERE, + "Error invoking @OnLoad method", e); + return; + } catch (InvocationTargetException e) { + getLogger().log(Level.SEVERE, + "Error invoking @OnLoad method", e); + return; + } + } + } + + } else { + throw new IllegalStateException( + "Cannot find declarative UI annotation"); + } + } + + /** + * Get access to the declaratively created component. This method typecasts + * the component to the receiving type; if there's a mismatch between what + * you expect and what's written in the design, this will fail with a + * ClassCastException. + * + * @return a Vaadin component + */ + @SuppressWarnings("unchecked") + public <T extends Component> T getComponent() { + try { + return (T) component; + } catch (ClassCastException ex) { + getLogger().log(Level.SEVERE, + "Component code/design type mismatch", ex); + } + return null; + } + + /** + * Get access to the logger of this class + * + * @return a Logger instance + */ + protected Logger getLogger() { + if (logger == null) { + logger = Logger.getLogger(getClass().getName()); + } + return logger; + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridEditingWithNoScrollBars.java b/uitest/src/com/vaadin/tests/components/grid/GridEditingWithNoScrollBars.java new file mode 100644 index 0000000000..d3e0a2a7c7 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridEditingWithNoScrollBars.java @@ -0,0 +1,53 @@ +/* + * 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.grid; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; +import com.vaadin.ui.Grid.SelectionMode; + +public class GridEditingWithNoScrollBars extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + grid.addColumn("foo", String.class); + grid.addColumn("bar", String.class); + for (int i = 0; i < 10; ++i) { + grid.addRow("foo", "" + (i % 3 + 1)); + } + + ComboBox stCombo = new ComboBox(); + stCombo.addItem("" + 1); + stCombo.addItem("" + 2); + stCombo.addItem("" + 3); + stCombo.setNullSelectionAllowed(false); + stCombo.setSizeFull(); + + Column stCol = grid.getColumn("bar"); + stCol.setEditorField(stCombo); + + grid.setSelectionMode(SelectionMode.SINGLE); + grid.setEditorEnabled(true); + grid.setSizeFull(); + + addComponent(grid); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridEditingWithNoScrollBarsTest.java b/uitest/src/com/vaadin/tests/components/grid/GridEditingWithNoScrollBarsTest.java new file mode 100644 index 0000000000..6400b17449 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridEditingWithNoScrollBarsTest.java @@ -0,0 +1,36 @@ +/* + * 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.grid; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridEditingWithNoScrollBarsTest extends MultiBrowserTest { + + @Test + public void testEditorWideEnough() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + grid.getCell(1, 1).doubleClick(); + assertEquals(grid.getEditor().getSize().width, grid.getTableWrapper() + .getSize().width); + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/declarative/GridBasicFeatures.html b/uitest/src/com/vaadin/tests/components/grid/declarative/GridBasicFeatures.html new file mode 100644 index 0000000000..c2de666641 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/declarative/GridBasicFeatures.html @@ -0,0 +1,499 @@ +<v-grid + editor-save-caption='Save' + editor-cancel-caption='Cancel' + frozen-columns=1 + style-name='grid-basics' + width='750px' height='100%'> +<table> + <colgroup> + <col min-width='150'/> + <col width='115'/> + <col width='115'/> + <col width='115'/> + <col width='115'/> + <col width='115'/> + <col width='115'/> + <col width='115'/> + <col width='115'/> + </colgroup> + <thead> + <tr> + <th /> + <th colspan=2><b>2012</b></th> + <th colspan=2><b>2013</b></th> + <th colspan=2><b>2014</b></th> + <th colspan=2><b>2015</b></th> + </tr> + <tr default=true> + <th>Company</th> + <th>H1</th> + <th>H2</th> + <th>H1</th> + <th>H2</th> + <th>H1</th> + <th>H2</th> + <th>H1</th> + <th>H2</th> + </tr> + <tr> + <th> + <v-text-field width='100%' input-prompt='Filter'></v-textfield> + <!-- + --> + </th> + <th /> + <th /> + <th /> + <th /> + <th /> + <th /> + <th /> + <th /> + </tr> + </thead> + <tbody> + <tr> + <td>Deomic</td> + <td>$6,063.67</td> + <td>$7,116.66</td> + <td>$5,879.24</td> + <td>$5,270.28</td> + <td>$393.65</td> + <td>$4,922.45</td> + <td>$5,443.97</td> + <td>$203.05</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$6,508.00</td> + <td>$8,904.53</td> + <td>$3,938.05</td> + <td>$2,283.44</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$4,543.26</td> + <td>$2,004.65</td> + <td>$5,961.86</td> + <td>$5,753.23</td> + </tr> + <tr> + <td>Deomic</td> + <td>$6,063.67</td> + <td>$7,116.66</td> + <td>$5,879.24</td> + <td>$5,270.28</td> + <td>$393.65</td> + <td>$4,922.45</td> + <td>$5,443.97</td> + <td>$203.05</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$6,508.00</td> + <td>$8,904.53</td> + <td>$3,938.05</td> + <td>$2,283.44</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$4,543.26</td> + <td>$2,004.65</td> + <td>$5,961.86</td> + <td>$5,753.23</td> + </tr> + <tr> + <td>Deomic</td> + <td>$6,063.67</td> + <td>$7,116.66</td> + <td>$5,879.24</td> + <td>$5,270.28</td> + <td>$393.65</td> + <td>$4,922.45</td> + <td>$5,443.97</td> + <td>$203.05</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$6,508.00</td> + <td>$8,904.53</td> + <td>$3,938.05</td> + <td>$2,283.44</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$4,543.26</td> + <td>$2,004.65</td> + <td>$5,961.86</td> + <td>$5,753.23</td> + </tr> + <tr> + <td>Deomic</td> + <td>$6,063.67</td> + <td>$7,116.66</td> + <td>$5,879.24</td> + <td>$5,270.28</td> + <td>$393.65</td> + <td>$4,922.45</td> + <td>$5,443.97</td> + <td>$203.05</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$6,508.00</td> + <td>$8,904.53</td> + <td>$3,938.05</td> + <td>$2,283.44</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$4,543.26</td> + <td>$2,004.65</td> + <td>$5,961.86</td> + <td>$5,753.23</td> + </tr> + <tr> + <td>Deomic</td> + <td>$6,063.67</td> + <td>$7,116.66</td> + <td>$5,879.24</td> + <td>$5,270.28</td> + <td>$393.65</td> + <td>$4,922.45</td> + <td>$5,443.97</td> + <td>$203.05</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$6,508.00</td> + <td>$8,904.53</td> + <td>$3,938.05</td> + <td>$2,283.44</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$4,543.26</td> + <td>$2,004.65</td> + <td>$5,961.86</td> + <td>$5,753.23</td> + </tr> + <tr> + <td>Deomic</td> + <td>$6,063.67</td> + <td>$7,116.66</td> + <td>$5,879.24</td> + <td>$5,270.28</td> + <td>$393.65</td> + <td>$4,922.45</td> + <td>$5,443.97</td> + <td>$203.05</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$6,508.00</td> + <td>$8,904.53</td> + <td>$3,938.05</td> + <td>$2,283.44</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$4,543.26</td> + <td>$2,004.65</td> + <td>$5,961.86</td> + <td>$5,753.23</td> + </tr> + <tr> + <td>Deomic</td> + <td>$6,063.67</td> + <td>$7,116.66</td> + <td>$5,879.24</td> + <td>$5,270.28</td> + <td>$393.65</td> + <td>$4,922.45</td> + <td>$5,443.97</td> + <td>$203.05</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$6,508.00</td> + <td>$8,904.53</td> + <td>$3,938.05</td> + <td>$2,283.44</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$4,543.26</td> + <td>$2,004.65</td> + <td>$5,961.86</td> + <td>$5,753.23</td> + </tr> + <tr> + <td>Deomic</td> + <td>$6,063.67</td> + <td>$7,116.66</td> + <td>$5,879.24</td> + <td>$5,270.28</td> + <td>$393.65</td> + <td>$4,922.45</td> + <td>$5,443.97</td> + <td>$203.05</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$6,508.00</td> + <td>$8,904.53</td> + <td>$3,938.05</td> + <td>$2,283.44</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$4,543.26</td> + <td>$2,004.65</td> + <td>$5,961.86</td> + <td>$5,753.23</td> + </tr> + <tr> + <td>Deomic</td> + <td>$6,063.67</td> + <td>$7,116.66</td> + <td>$5,879.24</td> + <td>$5,270.28</td> + <td>$393.65</td> + <td>$4,922.45</td> + <td>$5,443.97</td> + <td>$203.05</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$6,508.00</td> + <td>$8,904.53</td> + <td>$3,938.05</td> + <td>$2,283.44</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$4,543.26</td> + <td>$2,004.65</td> + <td>$5,961.86</td> + <td>$5,753.23</td> + </tr> + <tr> + <td>Deomic</td> + <td>$6,063.67</td> + <td>$7,116.66</td> + <td>$5,879.24</td> + <td>$5,270.28</td> + <td>$393.65</td> + <td>$4,922.45</td> + <td>$5,443.97</td> + <td>$203.05</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$6,508.00</td> + <td>$8,904.53</td> + <td>$3,938.05</td> + <td>$2,283.44</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$4,543.26</td> + <td>$2,004.65</td> + <td>$5,961.86</td> + <td>$5,753.23</td> + </tr> + <tr> + <td>Deomic</td> + <td>$6,063.67</td> + <td>$7,116.66</td> + <td>$5,879.24</td> + <td>$5,270.28</td> + <td>$393.65</td> + <td>$4,922.45</td> + <td>$5,443.97</td> + <td>$203.05</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$6,508.00</td> + <td>$8,904.53</td> + <td>$3,938.05</td> + <td>$2,283.44</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$4,543.26</td> + <td>$2,004.65</td> + <td>$5,961.86</td> + <td>$5,753.23</td> + </tr> + <tr> + <td>Deomic</td> + <td>$6,063.67</td> + <td>$7,116.66</td> + <td>$5,879.24</td> + <td>$5,270.28</td> + <td>$393.65</td> + <td>$4,922.45</td> + <td>$5,443.97</td> + <td>$203.05</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$6,508.00</td> + <td>$8,904.53</td> + <td>$3,938.05</td> + <td>$2,283.44</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$4,543.26</td> + <td>$2,004.65</td> + <td>$5,961.86</td> + <td>$5,753.23</td> + </tr> + <tr> + <td>Deomic</td> + <td>$6,063.67</td> + <td>$7,116.66</td> + <td>$5,879.24</td> + <td>$5,270.28</td> + <td>$393.65</td> + <td>$4,922.45</td> + <td>$5,443.97</td> + <td>$203.05</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$6,508.00</td> + <td>$8,904.53</td> + <td>$3,938.05</td> + <td>$2,283.44</td> + </tr> + <tr> + <td>Deomic</td> + <td>$4,802.82</td> + <td>$7,083.74</td> + <td>$6,418.09</td> + <td>$9,964.82</td> + <td>$4,543.26</td> + <td>$2,004.65</td> + <td>$5,961.86</td> + <td>$5,753.23</td> + </tr> + </tbody> + <tfoot> + <tr> + <td /> + <td>$$$</td> + <td>$$$</td> + <td>$$$</td> + <td>$$$</td> + <td>$$$</td> + <td>$$$</td> + <td>$$$</td> + <td>$$$</td> + </tr> + </tfoot> +</table> +</v-grid>
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/grid/declarative/GridDeclarativeBasicFeatures.java b/uitest/src/com/vaadin/tests/components/grid/declarative/GridDeclarativeBasicFeatures.java new file mode 100644 index 0000000000..cd4bf4e69b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/declarative/GridDeclarativeBasicFeatures.java @@ -0,0 +1,27 @@ +/* + * 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.grid.declarative; + +import com.vaadin.annotations.Theme; +import com.vaadin.tests.components.DeclarativeTestUI; +import com.vaadin.tests.components.DeclarativeTestUI.DeclarativeUI; + +@SuppressWarnings("serial") +@Theme("valo") +@DeclarativeUI("GridBasicFeatures.html") +public class GridDeclarativeBasicFeatures extends DeclarativeTestUI { + +} diff --git a/uitest/src/com/vaadin/tests/components/grid/declarative/GridItemEditor.html b/uitest/src/com/vaadin/tests/components/grid/declarative/GridItemEditor.html new file mode 100644 index 0000000000..b1532d282a --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/declarative/GridItemEditor.html @@ -0,0 +1,81 @@ +<v-grid caption="Double click to edit" width="100%" height="100%" + editable selection-mode="none"> +<table> + <colgroup> + <col property-id="index" editable=false width="50" expand=0> + <col property-id="name" expand=2> + <col property-id="progress" expand=2> + <col property-id="weight" editable=false expand=4> + </colgroup> + <thead> + <tr> + <th>## + <th>Name + <th>Progress + <th>Weight + </tr> + </thead> + <tbody> + <tr> + <td>00 + <td>Marc Addams + <td>0.42 + <td>[SparkLine] + </tr> + <tr> + <td>01 + <td>Kenny Black + <td>0.72 + <td>[SparkLine] + </tr> + <tr> + <td>02 + <td>Sarah McGoff + <td>0.12 + <td>[SparkLine] + </tr> + <tr> + <td>03 + <td>Jos Jones + <td>0.62 + <td>[SparkLine] + </tr> + <tr> + <td>04 + <td>Jane Fielding + <td>0.92 + <td>[SparkLine] + </tr> + <tr> + <td>05 + <td>Marc Einstein + <td>0.05 + <td>[SparkLine] + </tr> + <tr> + <td>06 + <td>Lenny McGoff + <td>0.40 + <td>[SparkLine] + </tr> + <tr> + <td>07 + <td>Peter Adams + <td>0.85 + <td>[SparkLine] + </tr> + <tr> + <td>08 + <td>Tony Stark + <td>0.22 + <td>[SparkLine] + </tr> + <tr> + <td>09 + <td>Nathan Fillion + <td>0.15 + <td>[SparkLine] + </tr> + </tbody> +</table> +</v-grid>
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/grid/declarative/GridItemEditor.java b/uitest/src/com/vaadin/tests/components/grid/declarative/GridItemEditor.java new file mode 100644 index 0000000000..9673626f45 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/declarative/GridItemEditor.java @@ -0,0 +1,23 @@ +/* + * 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.grid.declarative; + +import com.vaadin.tests.components.DeclarativeTestUI; +import com.vaadin.tests.components.DeclarativeTestUI.DeclarativeUI; + +@DeclarativeUI("GridItemEditor.html") +public class GridItemEditor extends DeclarativeTestUI { +} diff --git a/uitest/src/com/vaadin/tests/components/menubar/MenuItemStyleRemoved.java b/uitest/src/com/vaadin/tests/components/menubar/MenuItemStyleRemoved.java new file mode 100644 index 0000000000..ea8bf5aec7 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/menubar/MenuItemStyleRemoved.java @@ -0,0 +1,43 @@ +package com.vaadin.tests.components.menubar; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.JavaScript; +import com.vaadin.ui.MenuBar; + +public class MenuItemStyleRemoved extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + MenuBar menuBar = new MenuBar(); + + MenuBar.MenuItem first = menuBar.addItem("first", null, null); + first.addItem("first sub-item 1", null, null); + first.addItem("first sub-item 2", null, null); + MenuBar.MenuItem second = menuBar.addItem("second", null, null); + second.addItem("second sub-item 2", null, null); + second.addItem("second sub-item 2", null, null); + + addComponent(menuBar); + addButton("Add styles", new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent event) { + JavaScript.getCurrent().execute( + "var x=document.getElementsByClassName('v-menubar-menuitem');" + + " var i; for(i=0; i < x.length; i++)" + + " {x[i].className += ' custom-menu-item'};"); + } + }); + } + + @Override + protected Integer getTicketNumber() { + return 17242; + } + + @Override + public String getDescription() { + return "MenuItem's custom class names removed when hovering"; + } +} diff --git a/uitest/src/com/vaadin/tests/components/menubar/MenuItemStyleRemovedTest.java b/uitest/src/com/vaadin/tests/components/menubar/MenuItemStyleRemovedTest.java new file mode 100644 index 0000000000..2ba63587fe --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/menubar/MenuItemStyleRemovedTest.java @@ -0,0 +1,30 @@ +package com.vaadin.tests.components.menubar; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.MenuBarElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class MenuItemStyleRemovedTest extends MultiBrowserTest { + + @Test + public void testCustomStyleShouldStayAfterMenuSelect() { + openTestURL(); + + $(ButtonElement.class).caption("Add styles").first().click(); + + MenuBarElement menu = $(MenuBarElement.class).first(); + List<WebElement> elements = menu.findElements(By.className("custom-menu-item")); + Assert.assertEquals(2, elements.size()); + + menu.clickItem("first"); + menu.clickItem("second"); + elements = menu.findElements(By.className("custom-menu-item")); + Assert.assertEquals(2, elements.size()); + } +} diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/FirstTabNotVisibleWhenTabsheetNotClipped.java b/uitest/src/com/vaadin/tests/components/tabsheet/FirstTabNotVisibleWhenTabsheetNotClipped.java new file mode 100644 index 0000000000..6d66f1d295 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/FirstTabNotVisibleWhenTabsheetNotClipped.java @@ -0,0 +1,130 @@ +package com.vaadin.tests.components.tabsheet; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.*; + +import java.util.HashMap; +import java.util.Map; + +public class FirstTabNotVisibleWhenTabsheetNotClipped extends AbstractTestUI { + + private TabSheet.Tab firstNotClippedTab; + private TabSheet.Tab firstClippedTab; + + @Override + protected void setup(VaadinRequest request) { + addButton("Toggle first not clipped tab", new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent event) { + firstNotClippedTab.setVisible(!firstNotClippedTab.isVisible()); + } + }); + addComponent(createNotClippedTabSheet()); + + addButton("Toggle first clipped tab", new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent event) { + firstClippedTab.setVisible(!firstClippedTab.isVisible()); + } + }); + addComponent(createClippedTabSheet()); + + addComponent(new Label("VerticalLayout:")); + addBlock(new VerticalLayout()); + addComponent(new Label("HorizontalLayout:")); + addBlock(new HorizontalLayout()); + } + + private TabSheet createNotClippedTabSheet() { + TabSheet notClippedTabSheet = new TabSheet(); + for (int i = 0; i < 2; i++) { + notClippedTabSheet.addTab(createTabContent(i), "Tab " + i); + } + firstNotClippedTab = notClippedTabSheet.getTab(0); + return notClippedTabSheet; + } + + private TabSheet createClippedTabSheet() { + TabSheet clippedTabSheet = new TabSheet(); + for (int i = 0; i < 50; i++) { + clippedTabSheet.addTab(createTabContent(i), "Tab " + i); + } + firstClippedTab = clippedTabSheet.getTab(0); + return clippedTabSheet; + } + + private VerticalLayout createTabContent(int index) { + VerticalLayout layout = new VerticalLayout(); + layout.addComponent(new Label("Tab " + index + " Content")); + return layout; + } + + private void addBlock(Layout layout) { + layout.setWidth("300px"); + + TabSheet tabsheet = new TabSheet(); + String[] letters = { "A", "B", "C", "D" }; + HashMap<String, TabSheet.Tab> tabMap = new HashMap<String, TabSheet.Tab>(); + + for (String letter : letters) { + VerticalLayout vLayout = new VerticalLayout(); + vLayout.addComponent(new Label(letter + 1)); + vLayout.addComponent(new Label(letter + 2)); + vLayout.addComponent(new Label(letter + 3)); + + tabsheet.addTab(vLayout); + tabsheet.getTab(vLayout).setCaption("tab " + letter); + + tabMap.put("tab " + letter, tabsheet.getTab(vLayout)); + } + + VerticalLayout vtabLayout = new VerticalLayout(); + + for (String letter : letters) { + Button btntab = new Button("show tab " + letter); + btntab.setId("tab " + letter); + btntab.addClickListener(createTabListener(tabMap, tabsheet)); + vtabLayout.addComponent(btntab); + } + + layout.addComponent(vtabLayout); + layout.addComponent(tabsheet); + addComponent(layout); + } + + private Button.ClickListener createTabListener(final HashMap<String, TabSheet.Tab> map, + final TabSheet tabsheet) { + + Button.ClickListener clickListener = new Button.ClickListener() { + + @Override + public void buttonClick(Button.ClickEvent event) { + // id of the button is the same as the tab's caption + String tabName = event.getComponent().getId(); + + for (Map.Entry<String, TabSheet.Tab> entry : map.entrySet()) { + TabSheet.Tab tab = entry.getValue(); + + if (entry.getKey().equals(tabName)) { + tab.setVisible(true); + tabsheet.setSelectedTab(tab.getComponent()); + } else { + tab.setVisible(false); + } + } + } + }; + return clickListener; + } + + @Override + protected Integer getTicketNumber() { + return 17096; + } + + @Override + public String getDescription() { + return "TabSheet should display re-shown tab if there's room for it"; + } +} diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/FirstTabNotVisibleWhenTabsheetNotClippedTest.java b/uitest/src/com/vaadin/tests/components/tabsheet/FirstTabNotVisibleWhenTabsheetNotClippedTest.java new file mode 100644 index 0000000000..74a725f5ed --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/FirstTabNotVisibleWhenTabsheetNotClippedTest.java @@ -0,0 +1,56 @@ +package com.vaadin.tests.components.tabsheet; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.TabSheetElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +public class FirstTabNotVisibleWhenTabsheetNotClippedTest extends MultiBrowserTest { + @Test + public void testNotClippedTabIsVisible() throws InterruptedException { + openTestURL(); + + ButtonElement toggleNotClipped = $(ButtonElement.class) + .caption("Toggle first not clipped tab").first(); + + toggleNotClipped.click(); + TabSheetElement notClippedTabSheet = $(TabSheetElement.class).get(0); + WebElement firstTab = notClippedTabSheet.findElement( + By.className("v-tabsheet-tabitemcell-first")); + String caption = firstTab.findElement(By.className("v-captiontext")).getText(); + Assert.assertEquals("Tab with -first style should be Tab 1", "Tab 1", caption); + + toggleNotClipped.click(); + firstTab = notClippedTabSheet.findElement( + By.className("v-tabsheet-tabitemcell-first")); + caption = firstTab.findElement(By.className("v-captiontext")).getText(); + Assert.assertEquals("Tab with -first style should be Tab 0", "Tab 0", caption); + } + + + @Test + public void testShowPreviouslyHiddenTab() { + openTestURL(); + + $(ButtonElement.class).caption("show tab D").get(0).click(); + $(ButtonElement.class).caption("show tab C").get(0).click(); + + WebElement firstTab = $(TabSheetElement.class).get(2) + .findElement(By.className("v-tabsheet-tabitemcell-first")); + String firstCaption = firstTab.findElement(By.className("v-captiontext")).getText(); + + org.junit.Assert.assertEquals("tab C", firstCaption); + + $(ButtonElement.class).caption("show tab D").get(1).click(); + $(ButtonElement.class).caption("show tab C").get(1).click(); + + WebElement secondTab = $(TabSheetElement.class).get(3) + .findElement(By.className("v-tabsheet-tabitemcell-first")); + String secondCaption = secondTab.findElement(By.className("v-captiontext")).getText(); + + org.junit.Assert.assertEquals("tab C", secondCaption); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/CurrentUiRetainedTest.java b/uitest/src/com/vaadin/tests/components/ui/CurrentUiRetainedTest.java new file mode 100644 index 0000000000..d4e1ecb5ce --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/CurrentUiRetainedTest.java @@ -0,0 +1,24 @@ +package com.vaadin.tests.components.ui; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class CurrentUiRetainedTest extends MultiBrowserTest { + @Test + public void testCurrentUiRetained() throws Exception { + openTestURL(); + $(ButtonElement.class).first().click(); + assertLogText(3, "1. Correct UI.getCurrent before GC: true"); + assertLogText(2, "2. Correct UI.getCurrent after GC: true"); + assertLogText(1, "3. GC probe available before GC: true"); + assertLogText(0, "4. GC probe available after GC: false"); + } + + private void assertLogText(int index, String expected) { + Assert.assertEquals("Unexpected log contents,", expected, + getLogRow(index)); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/InitialFragmentEvent.java b/uitest/src/com/vaadin/tests/components/ui/InitialFragmentEvent.java index ce8ca8e083..d8d197c881 100644 --- a/uitest/src/com/vaadin/tests/components/ui/InitialFragmentEvent.java +++ b/uitest/src/com/vaadin/tests/components/ui/InitialFragmentEvent.java @@ -3,15 +3,13 @@ package com.vaadin.tests.components.ui; import com.vaadin.server.Page.UriFragmentChangedEvent; import com.vaadin.server.Page.UriFragmentChangedListener; import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.util.Log; +import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; -public class InitialFragmentEvent extends AbstractTestUI { +public class InitialFragmentEvent extends AbstractTestUIWithLog { private String lastKnownFragment = "\"no event received\""; - private Log log = new Log(5); @Override protected void setup(VaadinRequest request) { @@ -22,28 +20,25 @@ public class InitialFragmentEvent extends AbstractTestUI { public void uriFragmentChanged( UriFragmentChangedEvent source) { String newFragment = source.getUriFragment(); - log.log("Fragment changed from " + lastKnownFragment + log("Fragment changed from " + lastKnownFragment + " to " + newFragment); lastKnownFragment = newFragment; } }); - addComponent(log); - addComponent(new Button("Set fragment to 'foo'", - new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - setFragment("foo"); - } - })); - addComponent(new Button("Set fragment to 'bar'", - new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - setFragment("bar"); - } - })); + addButton("Set fragment to 'foo'", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + setFragment("foo"); + } + }); + addButton("Set fragment to 'bar'", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + setFragment("bar"); + } + }); } protected void setFragment(String fragment) { @@ -52,14 +47,12 @@ public class InitialFragmentEvent extends AbstractTestUI { @Override protected Integer getTicketNumber() { - // TODO Auto-generated method stub - return null; + return 9558; } @Override protected String getTestDescription() { - // TODO Auto-generated method stub - return null; + return "URI fragment handling should fire for initial fragment change"; } } diff --git a/uitest/src/com/vaadin/tests/components/ui/InitiallyEmptyFragmentTest.java b/uitest/src/com/vaadin/tests/components/ui/InitiallyEmptyFragmentTest.java new file mode 100644 index 0000000000..fc948ab3db --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/InitiallyEmptyFragmentTest.java @@ -0,0 +1,30 @@ +package com.vaadin.tests.components.ui; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class InitiallyEmptyFragmentTest extends MultiBrowserTest { + + @Override + protected Class<?> getUIClass() { + return InitialFragmentEvent.class; + } + + @Test + public void testNoFragmentChangeEventWhenInitiallyEmpty() throws Exception { + openTestURL(); + /* + * There is no fragment change event when the fragment is initially + * empty + */ + assertLogText(" "); + executeScript("window.location.hash='bar'"); + assertLogText("1. Fragment changed from \"no event received\" to bar"); + } + + private void assertLogText(String expected) { + Assert.assertEquals("Unexpected log contents,", expected, getLogRow(0)); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/PollListenerTest.java b/uitest/src/com/vaadin/tests/components/ui/PollListening.java index c5861147a5..1ec4f4d9f7 100644 --- a/uitest/src/com/vaadin/tests/components/ui/PollListenerTest.java +++ b/uitest/src/com/vaadin/tests/components/ui/PollListening.java @@ -22,7 +22,7 @@ import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.Label; -public class PollListenerTest extends AbstractTestUI { +public class PollListening extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { diff --git a/uitest/src/com/vaadin/tests/components/ui/PollListeningTest.java b/uitest/src/com/vaadin/tests/components/ui/PollListeningTest.java new file mode 100644 index 0000000000..5770570ed1 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/PollListeningTest.java @@ -0,0 +1,32 @@ +package com.vaadin.tests.components.ui; + +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class PollListeningTest extends MultiBrowserTest { + + @Test + public void testReceivePollEvent() { + openTestURL(); + waitUntilPollEventReceived(); + } + + private void waitUntilPollEventReceived() { + waitUntil(new ExpectedCondition<Boolean>() { + private String expected = "PollEvent received"; + + @Override + public Boolean apply(WebDriver arg0) { + return driver.getPageSource().contains(expected); + } + + @Override + public String toString() { + return String.format("page to contain text '%s'", expected); + } + }); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/RpcInvocationHandlerToString.java b/uitest/src/com/vaadin/tests/components/ui/RpcInvocationHandlerToString.java index 40ec51cf1f..1dbcc0ab2b 100644 --- a/uitest/src/com/vaadin/tests/components/ui/RpcInvocationHandlerToString.java +++ b/uitest/src/com/vaadin/tests/components/ui/RpcInvocationHandlerToString.java @@ -17,48 +17,42 @@ package com.vaadin.tests.components.ui; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.ui.PageClientRpc; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.util.Log; +import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; -public class RpcInvocationHandlerToString extends AbstractTestUI { +public class RpcInvocationHandlerToString extends AbstractTestUIWithLog { - private Log log = new Log(5); PageClientRpc dummyProxy = getRpcProxy(PageClientRpc.class); @Override protected void setup(VaadinRequest request) { - addComponent(log); - Button b = new Button("Exec toString() for an invocation proxy", + addButton("Exec toString() for an invocation proxy", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { - log.log("An invoation proxy: " + dummyProxy.toString()); + log("An invoation proxy: " + dummyProxy.toString()); } }); - addComponent(b); - b = new Button("Exec hashCode() for an invocation proxy", + addButton("Exec hashCode() for an invocation proxy", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { - log.log("Invocation proxy.hashCode(): " + log("Invocation proxy.hashCode(): " + dummyProxy.hashCode()); } }); - addComponent(b); - b = new Button("Exec equals(false) for an invocation proxy", + addButton("Exec equals(false) for an invocation proxy", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { - log.log("Invocation proxy.equals(false): " + log("Invocation proxy.equals(false): " + dummyProxy.equals(false)); } }); - addComponent(b); } @Override diff --git a/uitest/src/com/vaadin/tests/components/ui/RpcInvocationHandlerToStringTest.java b/uitest/src/com/vaadin/tests/components/ui/RpcInvocationHandlerToStringTest.java new file mode 100644 index 0000000000..10a297d47b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/RpcInvocationHandlerToStringTest.java @@ -0,0 +1,27 @@ +package com.vaadin.tests.components.ui; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class RpcInvocationHandlerToStringTest extends MultiBrowserTest { + @Test + public void testMethodsOnInvocationProxy() throws Exception { + openTestURL(); + execMethodForProxy("toString()"); + execMethodForProxy("hashCode()"); + execMethodForProxy("equals(false)"); + } + + private void execMethodForProxy(String method) { + $(ButtonElement.class) + .caption("Exec " + method + " for an invocation proxy").first() + .click(); + Assert.assertFalse(method + + " for invocation proxy caused a notification", + $(NotificationElement.class).exists()); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/UIAccessExceptionHandling.java b/uitest/src/com/vaadin/tests/components/ui/UIAccessExceptionHandling.java index 7fb5f9cd9d..bd18d93328 100644 --- a/uitest/src/com/vaadin/tests/components/ui/UIAccessExceptionHandling.java +++ b/uitest/src/com/vaadin/tests/components/ui/UIAccessExceptionHandling.java @@ -128,7 +128,7 @@ public class UIAccessExceptionHandling extends AbstractTestUIWithLog implements } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { - log("Exception catched on get: " + e.getClass().getName()); + log("Exception caught on get: " + e.getClass().getName()); } finally { future = null; } @@ -136,6 +136,15 @@ public class UIAccessExceptionHandling extends AbstractTestUIWithLog implements } @Override + public void error(com.vaadin.server.ErrorEvent event) { + log("Exception caught on execution with " + + event.getClass().getSimpleName() + " : " + + event.getThrowable().getClass().getName()); + + DefaultErrorHandler.doDefault(event); + } + + @Override protected String getTestDescription() { return "Test for handling exceptions in UI.access and Session.access"; } @@ -145,13 +154,4 @@ public class UIAccessExceptionHandling extends AbstractTestUIWithLog implements return Integer.valueOf(12703); } - @Override - public void error(com.vaadin.server.ErrorEvent event) { - log("Exception catched on execution with " - + event.getClass().getSimpleName() + " : " - + event.getThrowable().getClass().getName()); - - DefaultErrorHandler.doDefault(event); - } - } diff --git a/uitest/src/com/vaadin/tests/components/ui/UIAccessExceptionHandlingTest.java b/uitest/src/com/vaadin/tests/components/ui/UIAccessExceptionHandlingTest.java new file mode 100644 index 0000000000..b49de55a56 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UIAccessExceptionHandlingTest.java @@ -0,0 +1,39 @@ +package com.vaadin.tests.components.ui; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class UIAccessExceptionHandlingTest extends MultiBrowserTest { + + @Test + public void testExceptionHandlingOnUIAccess() throws Exception { + openTestURL(); + $(ButtonElement.class).first().click(); + assertLogTexts( + "1. Exception caught on get: java.util.concurrent.ExecutionException", + "0. Exception caught on execution with ConnectorErrorEvent : java.util.concurrent.ExecutionException"); + + $(ButtonElement.class).get(1).click(); + assertLogTexts( + "1. Exception caught on get: java.util.concurrent.ExecutionException", + "0. Exception caught on execution with ErrorEvent : java.util.concurrent.ExecutionException"); + + $(ButtonElement.class).get(2).click(); + assertLogTexts( + "1. Exception caught on get: java.util.concurrent.ExecutionException", + "0. Exception caught on execution with ConnectorErrorEvent : java.util.concurrent.ExecutionException"); + } + + private void assertLogTexts(String first, String second) { + assertLogText(0, first); + assertLogText(1, second); + } + + private void assertLogText(int index, String expected) { + Assert.assertEquals("Unexpected log contents,", expected, + getLogRow(index)); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.java b/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.java index df537145cf..130d432940 100644 --- a/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.java +++ b/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.java @@ -39,6 +39,14 @@ public class UIInitBrowserDetails extends AbstractTestUI { addDetail("current date", "v-curdate", wb.getCurrentDate()); } + private void addDetail(String name, String param, Object value) { + Label requestLabel = new Label(r.getParameter(param)); + requestLabel.setId(param); + Label browserLabel = new Label("" + value); + browserLabel.setId(name); + l.addComponents(new Label(name), requestLabel, browserLabel); + } + @Override public String getTestDescription() { return "Browser details should be available in UI init"; @@ -48,9 +56,4 @@ public class UIInitBrowserDetails extends AbstractTestUI { protected Integer getTicketNumber() { return Integer.valueOf(9037); } - - private void addDetail(String name, String param, Object value) { - l.addComponents(new Label(name), new Label(r.getParameter(param)), - new Label("" + value)); - } } diff --git a/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetailsTest.java b/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetailsTest.java new file mode 100644 index 0000000000..1e69662935 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetailsTest.java @@ -0,0 +1,58 @@ +package com.vaadin.tests.components.ui; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class UIInitBrowserDetailsTest extends MultiBrowserTest { + + @Test + public void testBrowserDetails() throws Exception { + openTestURL(); + /* location */ + compareRequestAndBrowserValue("v-loc", "location", "null"); + /* browser window width */ + compareRequestAndBrowserValue("v-cw", "browser window width", "-1"); + /* browser window height */ + compareRequestAndBrowserValue("v-ch", "browser window height", "-1"); + /* screen width */ + compareRequestAndBrowserValue("v-sw", "screen width", "-1"); + /* screen height */ + compareRequestAndBrowserValue("v-sh", "screen height", "-1"); + /* timezone offset */ + assertTextNotNull("timezone offset"); + /* raw timezone offset */ + assertTextNotNull("raw timezone offset"); + /* dst saving */ + assertTextNotNull("dst saving"); + /* dst in effect */ + assertTextNotNull("dst in effect"); + /* current date */ + assertTextNotNull("v-curdate"); + assertTextNotNull("current date"); + } + + private void compareRequestAndBrowserValue(String paramName, + String browserName, String errorValue) { + assertTextNotEquals(browserName, errorValue); + Assert.assertEquals(String.format( + "Browser and request values differ in '%s',", browserName), + getLabelText(paramName), getLabelText(browserName)); + } + + private String getLabelText(String id) { + return $(LabelElement.class).id(id).getText(); + } + + private void assertTextNotNull(String id) { + assertTextNotEquals(id, "null"); + } + + private void assertTextNotEquals(String id, String notExpected) { + String actual = getLabelText(id); + Assert.assertNotEquals(String.format("Unexpected value for '%s'", id), + notExpected, actual); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/UIInitExceptionTest.java b/uitest/src/com/vaadin/tests/components/ui/UIInitExceptionTest.java new file mode 100644 index 0000000000..d002642a74 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UIInitExceptionTest.java @@ -0,0 +1,15 @@ +package com.vaadin.tests.components.ui; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class UIInitExceptionTest extends MultiBrowserTest { + @Test + public void testExceptionOnUIInit() throws Exception { + openTestURL(); + Assert.assertTrue("Page does not contain the given text", driver + .getPageSource().contains("Catch me if you can")); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/UIPollingTest.java b/uitest/src/com/vaadin/tests/components/ui/UIPollingTest.java new file mode 100644 index 0000000000..c4a41d135a --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UIPollingTest.java @@ -0,0 +1,39 @@ +package com.vaadin.tests.components.ui; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class UIPollingTest extends MultiBrowserTest { + + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + // Manually testing IE8 stops polling with -1, but with automated test + // it seems to be highly unpredictable. + return super.getBrowsersExcludingIE8(); + } + + @Test + public void testPolling() throws Exception { + openTestURL(); + getTextField().setValue("500"); + sleep(2000); + /* Ensure polling has taken place */ + Assert.assertTrue("Page does not contain the given text", driver + .getPageSource().contains("2. 1000ms has passed")); + getTextField().setValue("-1"); + sleep(2000); + /* Ensure polling has stopped */ + Assert.assertFalse("Page contains the given text", driver + .getPageSource().contains("20. 10000ms has passed")); + } + + public TextFieldElement getTextField() { + return $(TextFieldElement.class).first(); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/UITabIndex.java b/uitest/src/com/vaadin/tests/components/ui/UITabIndex.java index 083eaf3f7d..c3bb036966 100644 --- a/uitest/src/com/vaadin/tests/components/ui/UITabIndex.java +++ b/uitest/src/com/vaadin/tests/components/ui/UITabIndex.java @@ -2,7 +2,6 @@ package com.vaadin.tests.components.ui; 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; @@ -10,32 +9,24 @@ public class UITabIndex extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { - Button b; - - b = new Button("Set tabIndex to -1"); - b.addClickListener(new ClickListener() { + addButton("Set tabIndex to -1", new ClickListener() { @Override public void buttonClick(ClickEvent event) { setTabIndex(-1); } }); - addComponent(b); - b = new Button("Set tabIndex to 0"); - b.addClickListener(new ClickListener() { + addButton("Set tabIndex to 0", new ClickListener() { @Override public void buttonClick(ClickEvent event) { setTabIndex(0); } }); - addComponent(b); - b = new Button("Set tabIndex to 1"); - b.addClickListener(new ClickListener() { + addButton("Set tabIndex to 1", new ClickListener() { @Override public void buttonClick(ClickEvent event) { setTabIndex(1); } }); - addComponent(b); } @Override diff --git a/uitest/src/com/vaadin/tests/components/ui/UITabIndexTest.java b/uitest/src/com/vaadin/tests/components/ui/UITabIndexTest.java new file mode 100644 index 0000000000..390907ee8a --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UITabIndexTest.java @@ -0,0 +1,28 @@ +package com.vaadin.tests.components.ui; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.UIElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class UITabIndexTest extends MultiBrowserTest { + + @Test + public void testTabIndexOnUIRoot() throws Exception { + openTestURL(); + assertTabIndex("1"); + $(ButtonElement.class).first().click(); + assertTabIndex("-1"); + $(ButtonElement.class).get(1).click(); + assertTabIndex("0"); + $(ButtonElement.class).get(2).click(); + assertTabIndex("1"); + } + + private void assertTabIndex(String expected) { + Assert.assertEquals("Unexpected tab index,", expected, + $(UIElement.class).first().getAttribute("tabIndex")); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabsTest.java b/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabsTest.java new file mode 100644 index 0000000000..e703deb634 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabsTest.java @@ -0,0 +1,25 @@ +package com.vaadin.tests.components.ui; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class UIsInMultipleTabsTest extends MultiBrowserTest { + + @Test + public void testPageReloadChangesUI() throws Exception { + openTestURL(); + assertUI(1); + openTestURL(); + assertUI(2); + openTestURL("restartApplication"); + assertUI(1); + } + + private void assertUI(int i) { + Assert.assertEquals("Unexpected UI found,", "This is UI number " + i, + $(LabelElement.class).first().getText()); + } +} diff --git a/uitest/src/com/vaadin/tests/components/window/CloseSubWindow.java b/uitest/src/com/vaadin/tests/components/window/CloseSubWindow.java index 6aad3e9170..83eebc4531 100644 --- a/uitest/src/com/vaadin/tests/components/window/CloseSubWindow.java +++ b/uitest/src/com/vaadin/tests/components/window/CloseSubWindow.java @@ -1,7 +1,7 @@ package com.vaadin.tests.components.window; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.util.Log; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; @@ -10,23 +10,20 @@ import com.vaadin.ui.Window; import com.vaadin.ui.Window.CloseEvent; import com.vaadin.ui.Window.CloseListener; -public class CloseSubWindow extends TestBase { - - private Log log = new Log(5); +public class CloseSubWindow extends AbstractTestUIWithLog { @Override - protected void setup() { + protected void setup(VaadinRequest request) { Button openWindowButton = new Button("Open sub-window"); openWindowButton.setId("opensub"); - openWindowButton.addListener(new ClickListener() { + openWindowButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { Window sub = createClosableSubWindow("Sub-window"); - getMainWindow().addWindow(sub); + getUI().addWindow(sub); } }); - addComponent(log); addComponent(openWindowButton); } @@ -39,7 +36,7 @@ public class CloseSubWindow extends TestBase { window.setClosable(true); Button closeButton = new Button("Close"); - closeButton.addListener(new ClickListener() { + closeButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { event.getButton().findAncestor(Window.class).close(); @@ -47,19 +44,19 @@ public class CloseSubWindow extends TestBase { }); layout.addComponent(closeButton); - Button removeButton = new Button("Remove from parent"); - removeButton.addListener(new ClickListener() { + Button removeButton = new Button("Remove from UI"); + removeButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { - window.close(); + getUI().removeWindow(window); } }); - layout.addComponent(closeButton); + layout.addComponent(removeButton); - window.addListener(new CloseListener() { + window.addCloseListener(new CloseListener() { @Override public void windowClose(CloseEvent e) { - log.log("Window '" + title + "' closed"); + log("Window '" + title + "' closed"); } }); @@ -67,7 +64,7 @@ public class CloseSubWindow extends TestBase { } @Override - protected String getDescription() { + protected String getTestDescription() { return "Close sub-windows both from code and with the close button in the window title bar, and check for close events. Contains an ugly workaround for the Opera bug (Opera does not send close events)"; } diff --git a/uitest/src/com/vaadin/tests/components/window/CloseSubWindowTest.java b/uitest/src/com/vaadin/tests/components/window/CloseSubWindowTest.java new file mode 100644 index 0000000000..48ac923082 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/CloseSubWindowTest.java @@ -0,0 +1,47 @@ +package com.vaadin.tests.components.window; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.WindowElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class CloseSubWindowTest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + openSubWindow(); + } + + @Test + public void testClosingFromClickHandler() throws Exception { + $(WindowElement.class).$(ButtonElement.class).first().click(); + assertLogText(); + } + + @Test + public void testClosingFromTitleBar() throws Exception { + $(WindowElement.class).first() + .findElement(By.className("v-window-closebox")).click(); + assertLogText(); + } + + @Test + public void testClosingByRemovingFromUI() throws Exception { + $(WindowElement.class).$(ButtonElement.class).get(1).click(); + assertLogText(); + } + + private void openSubWindow() { + $(ButtonElement.class).id("opensub").click(); + } + + private void assertLogText() { + Assert.assertEquals("Unexpected log contents,", + "1. Window 'Sub-window' closed", getLogRow(0)); + } +} diff --git a/uitest/src/com/vaadin/tests/components/window/ExtraWindowShown.java b/uitest/src/com/vaadin/tests/components/window/ExtraWindowShown.java index 35a4b8c761..92fbcffd01 100644 --- a/uitest/src/com/vaadin/tests/components/window/ExtraWindowShown.java +++ b/uitest/src/com/vaadin/tests/components/window/ExtraWindowShown.java @@ -1,17 +1,18 @@ package com.vaadin.tests.components.window; import com.vaadin.server.ThemeResource; -import com.vaadin.tests.components.TestBase; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; -public class ExtraWindowShown extends TestBase { +public class ExtraWindowShown extends AbstractTestUI { @Override - protected void setup() { + protected void setup(VaadinRequest request) { Button b = new Button("Open window", new Button.ClickListener() { @Override @@ -37,21 +38,20 @@ public class ExtraWindowShown extends TestBase { } }); - getLayout().setHeight("100%"); + getLayout().getParent().setSizeFull(); + getLayout().setSizeFull(); getLayout().addComponent(b); getLayout().setComponentAlignment(b, Alignment.MIDDLE_CENTER); } @Override - protected String getDescription() { - // TODO Auto-generated method stub - return null; + protected String getTestDescription() { + return "Sub window shouldn't reappear after closing."; } @Override protected Integer getTicketNumber() { - // TODO Auto-generated method stub - return null; + return 5987; } } diff --git a/uitest/src/com/vaadin/tests/components/window/ExtraWindowShownTest.java b/uitest/src/com/vaadin/tests/components/window/ExtraWindowShownTest.java new file mode 100644 index 0000000000..abbc7ddac0 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/ExtraWindowShownTest.java @@ -0,0 +1,37 @@ +package com.vaadin.tests.components.window; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.WindowElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class ExtraWindowShownTest extends MultiBrowserTest { + + @Test + public void testNoExtraWindowAfterClosing() throws Exception { + openTestURL(); + + openWindow(); + closeWindow(); + assertNoWindow(); + + openWindow(); + closeWindow(); + assertNoWindow(); + } + + private void openWindow() { + $(ButtonElement.class).first().click(); + } + + private void closeWindow() { + $(WindowElement.class).$(ButtonElement.class).first().click(); + } + + private void assertNoWindow() { + Assert.assertFalse("Window found when there should be none.", + $(WindowElement.class).exists()); + } +} diff --git a/uitest/src/com/vaadin/tests/components/window/RepaintWindowContents.java b/uitest/src/com/vaadin/tests/components/window/RepaintWindowContents.java index 99aa15b47d..18fe8f2fac 100644 --- a/uitest/src/com/vaadin/tests/components/window/RepaintWindowContents.java +++ b/uitest/src/com/vaadin/tests/components/window/RepaintWindowContents.java @@ -28,7 +28,7 @@ public class RepaintWindowContents extends AbstractTestUI { window.setContent(layout1); - button1.addListener(new ClickListener() { + button1.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { @@ -36,7 +36,7 @@ public class RepaintWindowContents extends AbstractTestUI { } }); - button2.addListener(new ClickListener() { + button2.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { diff --git a/uitest/src/com/vaadin/tests/components/window/RepaintWindowContentsTest.java b/uitest/src/com/vaadin/tests/components/window/RepaintWindowContentsTest.java new file mode 100644 index 0000000000..d097aa183c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/RepaintWindowContentsTest.java @@ -0,0 +1,36 @@ +package com.vaadin.tests.components.window; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.WindowElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class RepaintWindowContentsTest extends MultiBrowserTest { + + @Test + public void testRepaintWindowContents() throws Exception { + openTestURL(); + assertWindowContents("Button 1"); + toggleWindowContents(); + assertWindowContents("Button 2"); + toggleWindowContents(); + assertWindowContents("Button 1"); + toggleWindowContents(); + assertWindowContents("Button 2"); + } + + private void toggleWindowContents() { + getWindowButton().click(); + } + + private void assertWindowContents(String expected) { + Assert.assertEquals("Unexpected window contents,", expected, + getWindowButton().getText()); + } + + private ButtonElement getWindowButton() { + return $(WindowElement.class).$(ButtonElement.class).first(); + } +} diff --git a/uitest/src/com/vaadin/tests/components/window/WindowShouldRemoveActionHandler.java b/uitest/src/com/vaadin/tests/components/window/WindowShouldRemoveActionHandler.java index fa01706c56..ba991eebec 100644 --- a/uitest/src/com/vaadin/tests/components/window/WindowShouldRemoveActionHandler.java +++ b/uitest/src/com/vaadin/tests/components/window/WindowShouldRemoveActionHandler.java @@ -7,15 +7,19 @@ import com.vaadin.event.Action; import com.vaadin.event.Action.Handler; import com.vaadin.event.ShortcutAction; import com.vaadin.event.ShortcutAction.ModifierKey; -import com.vaadin.tests.components.TestBase; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.MarginInfo; +import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Label; +import com.vaadin.ui.Notification; import com.vaadin.ui.TextField; -public class WindowShouldRemoveActionHandler extends TestBase { +public class WindowShouldRemoveActionHandler extends AbstractTestUI { @Override - protected String getDescription() { + protected String getTestDescription() { return "Adding action handlers to the window should make them appear on the client side. Removing the action handlers should remove them also from the client side, also if all action handlers are removed."; } @@ -24,54 +28,49 @@ public class WindowShouldRemoveActionHandler extends TestBase { return 2941; } + private Label state; + @Override - protected void setup() { - addComponent(new TextField()); - Button add = new Button("Add an action handler", - new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - add(); - } - - }); - Button addAnother = new Button("Add another action handler", - new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - addAnother(); - } - - }); - Button remove = new Button("Remove an action handler", - new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - remove(); - } - - }); - - addComponent(add); - addComponent(addAnother); - addComponent(remove); + protected void setup(VaadinRequest request) { + getLayout().setMargin(new MarginInfo(true, false, false, false)); + state = new Label("An UI with no action handlers."); + state.setId("state"); + addComponents(state, new TextField()); + + addButton("Add an action handler", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + add(); + } + + }); + addButton("Add another action handler", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + addAnother(); + } + + }); + addButton("Remove an action handler", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + remove(); + } + + }); } public void remove() { - getMainWindow().setCaption( - getMainWindow().getCaption() + " - Removed handler"); - getMainWindow().removeActionHandler( - actionHandlers.remove(actionHandlers.size() - 1)); + state.setValue(state.getValue() + " - Removed handler"); + removeActionHandler(actionHandlers.remove(actionHandlers.size() - 1)); } private List<Handler> actionHandlers = new ArrayList<Handler>(); public void add() { - getMainWindow().setCaption( - getMainWindow().getCaption() + " - Added handler"); Handler actionHandler = new Handler() { @Override @@ -83,8 +82,7 @@ public class WindowShouldRemoveActionHandler extends TestBase { @Override public void handleAction(Action action, Object sender, Object target) { - getMainWindow().showNotification( - "Handling action " + action.getCaption()); + Notification.show("Handling action " + action.getCaption()); } }; @@ -104,8 +102,7 @@ public class WindowShouldRemoveActionHandler extends TestBase { @Override public void handleAction(Action action, Object sender, Object target) { - getMainWindow().showNotification( - "Handling action " + action.getCaption()); + Notification.show("Handling action " + action.getCaption()); } }; @@ -115,9 +112,9 @@ public class WindowShouldRemoveActionHandler extends TestBase { private void addHandler(Handler actionHandler) { actionHandlers.add(actionHandler); - getMainWindow().addActionHandler(actionHandler); - getMainWindow().setCaption( - "A panel with " + actionHandlers.size() + " action handlers"); + addActionHandler(actionHandler); + state.setValue("An UI with " + actionHandlers.size() + + " action handlers"); } } diff --git a/uitest/src/com/vaadin/tests/components/window/WindowShouldRemoveActionHandlerTest.java b/uitest/src/com/vaadin/tests/components/window/WindowShouldRemoveActionHandlerTest.java new file mode 100644 index 0000000000..755a4242ed --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/WindowShouldRemoveActionHandlerTest.java @@ -0,0 +1,50 @@ +package com.vaadin.tests.components.window; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class WindowShouldRemoveActionHandlerTest extends MultiBrowserTest { + + @Test + public void testRemovingActionHandlers() { + openTestURL(); + + addActionHandler(); + addAnotherActionHandler(); + + assertState("An UI with 2 action handlers"); + addActionHandler(); + + assertState("An UI with 3 action handlers"); + removeActionHandler(); + removeActionHandler(); + + assertState("An UI with 3 action handlers - Removed handler - Removed handler"); + addActionHandler(); + + assertState("An UI with 2 action handlers"); + } + + private void removeActionHandler() { + $(ButtonElement.class).caption("Remove an action handler").first() + .click(); + } + + private void addAnotherActionHandler() { + $(ButtonElement.class).caption("Add another action handler").first() + .click(); + } + + private void addActionHandler() { + $(ButtonElement.class).caption("Add an action handler").first().click(); + } + + private void assertState(String expected) { + Assert.assertEquals("Unexpected state,", expected, + $(LabelElement.class).id("state").getText()); + } +} diff --git a/uitest/src/com/vaadin/tests/components/window/WindowWithInvalidCloseListenerTest.java b/uitest/src/com/vaadin/tests/components/window/WindowWithInvalidCloseListenerTest.java new file mode 100644 index 0000000000..b77eced9cc --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/WindowWithInvalidCloseListenerTest.java @@ -0,0 +1,19 @@ +package com.vaadin.tests.components.window; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.WindowElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class WindowWithInvalidCloseListenerTest extends MultiBrowserTest { + @Test + public void testWindowClosesCorrectly() throws Exception { + openTestURL(); + $(WindowElement.class).first() + .findElement(By.className("v-window-closebox")).click(); + Assert.assertFalse("Window found when there should be none.", + $(WindowElement.class).exists()); + } +} diff --git a/uitest/src/com/vaadin/tests/containers/sqlcontainer/TableQueryWithNonUniqueFirstPrimaryKey.java b/uitest/src/com/vaadin/tests/containers/sqlcontainer/TableQueryWithNonUniqueFirstPrimaryKey.java index da3476610b..2ff74a76ef 100644 --- a/uitest/src/com/vaadin/tests/containers/sqlcontainer/TableQueryWithNonUniqueFirstPrimaryKey.java +++ b/uitest/src/com/vaadin/tests/containers/sqlcontainer/TableQueryWithNonUniqueFirstPrimaryKey.java @@ -12,17 +12,15 @@ import com.vaadin.data.util.sqlcontainer.SQLContainer; import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool; import com.vaadin.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool; import com.vaadin.data.util.sqlcontainer.query.TableQuery; -import com.vaadin.server.LegacyApplication; +import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.combobox.FilteringMode; +import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.ComboBox; -import com.vaadin.ui.LegacyWindow; -import com.vaadin.ui.VerticalLayout; -public class TableQueryWithNonUniqueFirstPrimaryKey extends LegacyApplication { +public class TableQueryWithNonUniqueFirstPrimaryKey extends AbstractTestUI { + @Override - public void init() { - LegacyWindow mainWindow = new LegacyWindow("Test Application"); - setMainWindow(mainWindow); + public void setup(VaadinRequest request) { try { JDBCConnectionPool connectionPool = new SimpleJDBCConnectionPool( @@ -41,9 +39,6 @@ public class TableQueryWithNonUniqueFirstPrimaryKey extends LegacyApplication { myContainer.removeAllContainerFilters(); myContainer.addContainerFilter(new Equal("PFX", "C")); - VerticalLayout layout = new VerticalLayout(); - mainWindow.setContent(layout); - final ComboBox myCombo = new ComboBox("MyCaption"); myCombo.setDescription("Description"); myCombo.setContainerDataSource(myContainer); @@ -64,7 +59,7 @@ public class TableQueryWithNonUniqueFirstPrimaryKey extends LegacyApplication { } } }); - layout.addComponent(myCombo); + addComponent(myCombo); } catch (Exception ex) { ex.printStackTrace(); } @@ -122,4 +117,14 @@ public class TableQueryWithNonUniqueFirstPrimaryKey extends LegacyApplication { connectionPool.releaseConnection(conn); } } + + @Override + protected String getTestDescription() { + return "Ensure unique ordering when using TableQuery with multiple primary key columns."; + } + + @Override + protected Integer getTicketNumber() { + return 10878; + } } diff --git a/uitest/src/com/vaadin/tests/containers/sqlcontainer/TableQueryWithNonUniqueFirstPrimaryKeyTest.java b/uitest/src/com/vaadin/tests/containers/sqlcontainer/TableQueryWithNonUniqueFirstPrimaryKeyTest.java new file mode 100644 index 0000000000..172d83e645 --- /dev/null +++ b/uitest/src/com/vaadin/tests/containers/sqlcontainer/TableQueryWithNonUniqueFirstPrimaryKeyTest.java @@ -0,0 +1,45 @@ +package com.vaadin.tests.containers.sqlcontainer; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TableQueryWithNonUniqueFirstPrimaryKeyTest extends + MultiBrowserTest { + + private static final String[] DATA = { "TARUSCIO GIOVANNI", + "RUSSO GAETANO AUTORICAMBI", "AMORUSO LUIGI SRL", "CARUSO ROCCO", + "F.LLI RUSSO DI GAETANO RUSSO & C", "RUSSO GIUSEPPE", + "TRUSCELLI ANTONIO", "CARUSO CALOGERO" }; + + @Test + public void testComboBoxSuggestionsListedCorrectly() throws Exception { + openTestURL(); + $(ComboBoxElement.class).first().findElement(By.vaadin("#textbox")) + .sendKeys("rus", Keys.ENTER); + + List<String> result = new ArrayList<String>(); + + // pick list items that are shown in suggestion popup + List<WebElement> elems = findElements(By + .cssSelector("td[role=\"listitem\"]")); + Assert.assertEquals("not enough suggestions shown", DATA.length, + elems.size()); + + for (WebElement elem : elems) { + result.add(elem.getText()); + } + + Assert.assertArrayEquals("popup items not what they should be", DATA, + result.toArray()); + + } +} diff --git a/uitest/src/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java b/uitest/src/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java index a37aa521ba..9d0c835c68 100644 --- a/uitest/src/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java +++ b/uitest/src/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java @@ -4,24 +4,24 @@ import java.util.Locale; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.data.Property.ValueChangeListener; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.util.Log; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.ui.TextField; -public class ConverterThatEnforcesAFormat extends TestBase { - - private Log log = new Log(5); +public class ConverterThatEnforcesAFormat extends AbstractTestUIWithLog { @Override - protected void setup() { + protected void setup(VaadinRequest request) { final TextField tf = new TextField( "This field should always be formatted with 3 digits"); tf.setLocale(Locale.ENGLISH); + // this is needed so that IE tests pass + tf.setNullRepresentation(""); tf.setConverter(new StringToDoubleConverterWithThreeFractionDigits()); tf.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { - log.log("Value changed to " + log("Value changed to " + event.getProperty().getValue() + "(converted value is " + tf.getConvertedValue() @@ -33,13 +33,12 @@ public class ConverterThatEnforcesAFormat extends TestBase { } }); tf.setImmediate(true); - addComponent(log); addComponent(tf); tf.setConvertedValue(50.0); } @Override - protected String getDescription() { + protected String getTestDescription() { return "Entering a valid double in the field should always cause the field contents to be formatted to contain 3 digits after the decimal point"; } diff --git a/uitest/src/com/vaadin/tests/converter/ConverterThatEnforcesAFormatTest.java b/uitest/src/com/vaadin/tests/converter/ConverterThatEnforcesAFormatTest.java new file mode 100644 index 0000000000..886e96700a --- /dev/null +++ b/uitest/src/com/vaadin/tests/converter/ConverterThatEnforcesAFormatTest.java @@ -0,0 +1,90 @@ +package com.vaadin.tests.converter; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class ConverterThatEnforcesAFormatTest extends MultiBrowserTest { + + private TextFieldElement field; + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + field = $(TextFieldElement.class).first(); + } + + @Test + public void checkDefault() { + waitUntilValueIs("50.000"); + } + + @Test + public void checkRounding() { + setValue("50.0202", Keys.ENTER); + waitUntilValueIs("50.020"); + } + + @Test + public void checkElaborating() { + setValue("12"); + waitUntilValueIs("12.000"); + } + + @Test + public void checkText() { + setValue("abc", Keys.ENTER); + waitUntilValueIs("abc"); + waitUntilHasCssClass("v-textfield-error"); + } + + private void setValue(String value, CharSequence... keysToSend) { + field.setValue(value); + if (keysToSend.length > 0) { + field.sendKeys(keysToSend); + } else { + field.submit(); + } + } + + private void waitUntilValueIs(final String expected) { + waitUntil(new ExpectedCondition<Boolean>() { + private String actual; + + @Override + public Boolean apply(WebDriver arg0) { + actual = field.getValue(); + return expected.equals(actual); + } + + @Override + public String toString() { + return String.format( + "the field to have value '%s' (was: '%s')", expected, + actual); + } + }); + } + + private void waitUntilHasCssClass(final String className) { + waitUntil(new ExpectedCondition<Boolean>() { + + @Override + public Boolean apply(WebDriver arg0) { + return hasCssClass(field, className); + } + + @Override + public String toString() { + return String.format("the field to have css class '%s'", + className); + } + }); + } + +} diff --git a/uitest/src/com/vaadin/tests/dd/DDTest8.java b/uitest/src/com/vaadin/tests/dd/DDTest8.java index ee7d8d9dc5..beaae4175e 100644 --- a/uitest/src/com/vaadin/tests/dd/DDTest8.java +++ b/uitest/src/com/vaadin/tests/dd/DDTest8.java @@ -10,8 +10,9 @@ import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.event.dd.DropHandler; import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; import com.vaadin.event.dd.acceptcriteria.Or; +import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.dd.VerticalDropLocation; -import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.AbstractSelect; import com.vaadin.ui.Tree; import com.vaadin.ui.Tree.TreeDragMode; @@ -20,36 +21,48 @@ import com.vaadin.ui.Tree.TreeTargetDetails; /** * DD playground. Better quality example/prototype codes in {@link DDTest2}. */ -public class DDTest8 extends TestBase { +public class DDTest8 extends AbstractTestUI { @Override - protected void setup() { - final Tree t = new Tree( + protected void setup(VaadinRequest request) { + final Tree tree = new Tree( "Tree with criteria from AbstractSelect (OverItem, ContainsItem). Foo can be dragged anywhere, anything can be dropped on Foo or Bar. Bar5 subtree is also valid drop target."); - final HierarchicalContainer idx = new HierarchicalContainer(); - t.setContainerDataSource(idx); - t.addItem("Foo"); - t.addItem("Bar"); - t.addItem("Bar1"); - t.addItem("Bar2"); - t.addItem("Bar3"); - t.addItem("Bar4"); - t.addItem("Bar5"); - t.addItem("Child"); - t.setParent("Child", "Foo"); - t.setSizeFull(); - t.setDragMode(TreeDragMode.NODE); - - /* - * Moves items in tree (and could work in Table too). Also supports - * "building" tree. - * - * TODO fix algorithm, broken in some cases. - */ - DropHandler itemSorter = new DropHandler() { + final HierarchicalContainer container = new HierarchicalContainer(); + tree.setContainerDataSource(container); + tree.addItem("Foo"); + tree.addItem("Bar"); + tree.addItem("Bar1"); + tree.addItem("Bar2"); + tree.addItem("Bar3"); + tree.addItem("Bar4"); + tree.addItem("Bar5"); + tree.addItem("Child"); + tree.setParent("Child", "Foo"); + tree.setSizeFull(); + tree.setDragMode(TreeDragMode.NODE); + tree.setDropHandler(getDropHandler(tree, container)); - @SuppressWarnings("unused") + getLayout().setSizeFull(); + getLayout().getParent().setSizeFull(); + addComponent(tree); + } + + /** + * Moves items in tree (and could work in Table too). Also supports + * "building" tree. + * + * TODO fix algorithm, broken in some cases. + * + * @param tree + * @param container + * @return drop handler + */ + private DropHandler getDropHandler(final Tree tree, + final HierarchicalContainer container) { + return new DropHandler() { + + @SuppressWarnings({ "unused", "unchecked" }) private void populateSubTree(HierarchicalContainer idx, HierarchicalContainer subtree, Object itemId) { Collection<?> children = subtree.getChildren(itemId); @@ -91,6 +104,7 @@ public class DDTest8 extends TestBase { return hierarchicalContainer; } + @SuppressWarnings("unchecked") private void copyChildren(HierarchicalContainer source, HierarchicalContainer target, Object itemId) { Collection<?> children = source.getChildren(itemId); @@ -135,16 +149,16 @@ public class DDTest8 extends TestBase { Object itemIdAfter = details.getItemIdAfter(); if (itemIdOver.equals(itemIdInto)) { // directly on a node - t.setParent(itemId, itemIdOver); + container.setParent(itemId, itemIdOver); return; } - idx.setParent(itemId, itemIdInto); + container.setParent(itemId, itemIdInto); if (dropLocation == null) { System.err.println("No detail of drop place available"); } - idx.moveAfterSibling(itemId, itemIdAfter); + container.moveAfterSibling(itemId, itemIdAfter); } return; @@ -152,23 +166,17 @@ public class DDTest8 extends TestBase { @Override public AcceptCriterion getAcceptCriterion() { - return new Or(new AbstractSelect.TargetItemIs(t, "Foo", "Bar"), - new AbstractSelect.AcceptItem(t, "Foo"), - t.new TargetInSubtree("Bar5") // + return new Or(new AbstractSelect.TargetItemIs(tree, "Foo", + "Bar"), new AbstractSelect.AcceptItem(tree, "Foo"), + tree.new TargetInSubtree("Bar5") // ); } }; - - t.setDropHandler(itemSorter); - - getLayout().setSizeFull(); - addComponent(t); - } @Override - protected String getDescription() { + protected String getTestDescription() { return "Random DD tests"; } diff --git a/uitest/src/com/vaadin/tests/dd/DnDOnSubtreeTest.java b/uitest/src/com/vaadin/tests/dd/DnDOnSubtreeTest.java new file mode 100644 index 0000000000..2bceb905c4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/dd/DnDOnSubtreeTest.java @@ -0,0 +1,52 @@ +package com.vaadin.tests.dd; + +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.TreeElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class DnDOnSubtreeTest extends MultiBrowserTest { + + @Override + protected Class<?> getUIClass() { + return DDTest8.class; + } + + @Test + public void testDragAndDropOnSubTrees() throws Exception { + openTestURL(); + TreeElement tree = $(TreeElement.class).first(); + WebElement bar2 = tree.findElement(By.vaadin("#n[3]")); + WebElement bar5 = tree.findElement(By.vaadin("#n[6]")); + new Actions(driver).moveToElement(bar2, 11, 8).clickAndHold() + .moveByOffset(10, 10).perform(); + /* Drop on Bar5, which is a subtree target */ + new Actions(driver).moveToElement(bar5, 34, 9).release().perform(); + testBenchElement(tree.findElement(By.vaadin("#n[5]/expand"))).click(5, + 5); + /* Assert that the dragged & dropped node is now a child of Bar5 */ + waitUntilElementPresent(tree, "#n[5]/n[0]"); + } + + private void waitUntilElementPresent(final TestBenchElement parent, + final String vaadinSelector) { + waitUntil(new ExpectedCondition<Boolean>() { + + @Override + public Boolean apply(WebDriver arg0) { + return parent.isElementPresent(By.vaadin(vaadinSelector)); + } + + @Override + public String toString() { + return String.format("element to contain '%s'", vaadinSelector); + } + }); + } +} diff --git a/uitest/src/com/vaadin/tests/fieldgroup/BasicPersonForm.java b/uitest/src/com/vaadin/tests/fieldgroup/BasicPersonForm.java index e418116cd5..a223cea6a0 100644 --- a/uitest/src/com/vaadin/tests/fieldgroup/BasicPersonForm.java +++ b/uitest/src/com/vaadin/tests/fieldgroup/BasicPersonForm.java @@ -10,12 +10,12 @@ import com.vaadin.data.util.converter.StringToBooleanConverter; import com.vaadin.data.validator.EmailValidator; import com.vaadin.data.validator.IntegerRangeValidator; import com.vaadin.data.validator.StringLengthValidator; -import com.vaadin.tests.components.TestBase; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.tests.data.bean.Address; import com.vaadin.tests.data.bean.Country; import com.vaadin.tests.data.bean.Person; import com.vaadin.tests.data.bean.Sex; -import com.vaadin.tests.util.Log; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.ComponentContainer; @@ -26,9 +26,8 @@ import com.vaadin.ui.TextArea; import com.vaadin.ui.TextField; import com.vaadin.ui.VerticalLayout; -public class BasicPersonForm extends TestBase { +public class BasicPersonForm extends AbstractTestUIWithLog { - private Log log = new Log(5); private TextField firstName; private TextArea lastName; private TextField email; @@ -80,7 +79,7 @@ public class BasicPersonForm extends TestBase { } @Override - protected void setup() { + protected void setup(VaadinRequest request) { addComponent(log); Panel confPanel = new ConfigurationPanel(); addComponent(confPanel); @@ -133,7 +132,7 @@ public class BasicPersonForm extends TestBase { msg = "Commit failed: " + e.getMessage(); } Notification.show(msg); - log.log(msg); + log(msg); } }); @@ -143,7 +142,7 @@ public class BasicPersonForm extends TestBase { @Override public void buttonClick(ClickEvent event) { fieldGroup.discard(); - log.log("Discarded changes"); + log("Discarded changes"); } }); @@ -152,7 +151,7 @@ public class BasicPersonForm extends TestBase { @Override public void buttonClick(ClickEvent event) { - log.log(getPerson(fieldGroup).toString()); + log(getPerson(fieldGroup).toString()); } }); @@ -182,20 +181,19 @@ public class BasicPersonForm extends TestBase { fieldGroup.setItemDataSource(new BeanItem<Person>(p)); } + @SuppressWarnings("unchecked") public static Person getPerson(FieldGroup binder) { return ((BeanItem<Person>) binder.getItemDataSource()).getBean(); } @Override - protected String getDescription() { - // TODO Auto-generated method stub - return null; + public String getDescription() { + return "Basic Person Form"; } @Override protected Integer getTicketNumber() { - // TODO Auto-generated method stub - return null; + return 8094; } } diff --git a/uitest/src/com/vaadin/tests/fieldgroup/BasicPersonFormTest.java b/uitest/src/com/vaadin/tests/fieldgroup/BasicPersonFormTest.java new file mode 100644 index 0000000000..f611325719 --- /dev/null +++ b/uitest/src/com/vaadin/tests/fieldgroup/BasicPersonFormTest.java @@ -0,0 +1,173 @@ +/* + * 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.fieldgroup; + +import org.junit.Assert; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.elements.TableElement; +import com.vaadin.testbench.elements.TableRowElement; +import com.vaadin.testbench.elements.TextAreaElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.data.bean.Sex; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public abstract class BasicPersonFormTest extends MultiBrowserTest { + + private static final String BEAN_VALUES = "Person [firstName=John, lastName=Doe, email=john@doe.com, age=64, sex=Male, address=Address [streetAddress=John street, postalCode=11223, city=John's town, country=USA], deceased=false, salary=null, salaryDouble=null, rent=null]"; + private int logCounter = 0; + + @Override + protected Class<?> getUIClass() { + return BasicPersonForm.class; + } + + protected TextFieldElement getFirstNameField() { + return $(TextFieldElement.class).caption("First Name").first(); + } + + protected TextAreaElement getLastNameArea() { + return $(TextAreaElement.class).caption("Last Name").first(); + } + + protected TextFieldElement getEmailField() { + return $(TextFieldElement.class).caption("Email").first(); + } + + protected TextFieldElement getAgeField() { + return $(TextFieldElement.class).caption("Age").first(); + } + + protected TableElement getGenderTable() { + return $(TableElement.class).caption("Sex").first(); + } + + protected TextFieldElement getDeceasedField() { + return $(TextFieldElement.class).caption("Deceased").first(); + } + + protected void showBeanValues() { + $(ButtonElement.class).caption("Show bean values").first().click(); + } + + protected CheckBoxElement getPreCommitFailsCheckBox() { + return $(CheckBoxElement.class).get(1); + } + + protected void commitChanges() { + $(ButtonElement.class).caption("Commit").first().click(); + } + + protected void closeNotification() { + $(NotificationElement.class).first().close(); + } + + protected CheckBoxElement getPostCommitFailsCheckBox() { + return $(CheckBoxElement.class).get(0); + } + + protected void discardChanges() { + $(ButtonElement.class).caption("Discard").first().click(); + } + + protected void assertFirstNameValue(String expected) { + assertFieldValue("First Name", expected, getFirstNameField()); + } + + protected void assertLastNameValue(String expected) { + assertFieldValue("Last Name", expected, getLastNameArea()); + } + + protected void assertEmailValue(String expected) { + assertFieldValue("Email", expected, getEmailField()); + } + + protected void assertAgeValue(String expected) { + assertFieldValue("Age", expected, getAgeField()); + } + + protected void assertDeceasedValue(String expected) { + assertFieldValue("Deceased", expected, getDeceasedField()); + } + + private void assertFieldValue(String caption, String expected, + TestBenchElement field) { + Assert.assertEquals( + String.format("Unexpected value for field '%s',", caption), + expected, field.getAttribute("value")); + } + + protected void assertSelectedSex(Sex sex) { + TableRowElement row = getGenderTable().getRow(getIndex(sex)); + Assert.assertTrue( + String.format("Given sex (%s) isn't selected.", + sex.getStringRepresentation()), + hasCssClass(row, "v-selected")); + } + + private int getIndex(Sex sex) { + switch (sex) { + case MALE: + return 0; + case FEMALE: + return 1; + default: + return 2; + } + } + + protected void assertBeanValuesUnchanged() { + showBeanValues(); + assertLogText(BEAN_VALUES); + } + + protected void assertCommitFails() { + commitChanges(); + closeNotification(); + assertLogText("Commit failed: Commit failed"); + } + + protected void assertCommitSuccessful() { + commitChanges(); + closeNotification(); + assertLogText("Commit succesful"); + } + + protected void assertDiscardResetsFields() { + discardChanges(); + assertLogText("Discarded changes"); + assertDefaults(); + } + + protected void assertLogText(String expected) { + ++logCounter; + Assert.assertEquals("Unexpected log contents,", logCounter + ". " + + expected, getLogRow(0)); + } + + protected void assertDefaults() { + assertFirstNameValue("John"); + assertLastNameValue("Doe"); + assertEmailValue("john@doe.com"); + assertAgeValue("64"); + assertSelectedSex(Sex.MALE); + assertDeceasedValue("NAAAAAH"); + } + +} diff --git a/uitest/src/com/vaadin/tests/fieldgroup/CommitHandlerFailuresTest.java b/uitest/src/com/vaadin/tests/fieldgroup/CommitHandlerFailuresTest.java new file mode 100644 index 0000000000..545c9c2e71 --- /dev/null +++ b/uitest/src/com/vaadin/tests/fieldgroup/CommitHandlerFailuresTest.java @@ -0,0 +1,60 @@ +package com.vaadin.tests.fieldgroup; + +import org.junit.Test; +import org.openqa.selenium.Keys; + +public class CommitHandlerFailuresTest extends BasicPersonFormTest { + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + } + + @Test + public void testDefaults() { + assertDefaults(); + assertBeanValuesUnchanged(); + } + + @Test + public void testUpdatingWithoutCommit() { + updateFields(); + assertBeanValuesUnchanged(); + } + + @Test + public void testPreCommitFails() { + updateFields(); + + getPreCommitFailsCheckBox().click(); + assertCommitFails(); + + assertBeanValuesUnchanged(); + } + + @Test + public void testPostCommitFails() { + updateFields(); + + getPostCommitFailsCheckBox().click(); + assertCommitFails(); + + assertBeanValuesUnchanged(); + } + + @Test + public void testDiscard() { + updateFields(); + assertDiscardResetsFields(); + assertBeanValuesUnchanged(); + } + + private void updateFields() { + getLastNameArea().sendKeys("Doeve", Keys.ENTER); + getFirstNameField().sendKeys("Mike", Keys.ENTER); + getEmailField().sendKeys("me@me.com", Keys.ENTER); + getAgeField().sendKeys("12", Keys.ENTER); + getGenderTable().getCell(2, 0).click(); + } +} diff --git a/uitest/src/com/vaadin/tests/fieldgroup/CommitWithValidationOrConversionErrorTest.java b/uitest/src/com/vaadin/tests/fieldgroup/CommitWithValidationOrConversionErrorTest.java new file mode 100644 index 0000000000..f5c751cd49 --- /dev/null +++ b/uitest/src/com/vaadin/tests/fieldgroup/CommitWithValidationOrConversionErrorTest.java @@ -0,0 +1,74 @@ +package com.vaadin.tests.fieldgroup; + +import org.junit.Test; + +public class CommitWithValidationOrConversionErrorTest extends + BasicPersonFormTest { + + private static final String UPDATED_BEAN_VALUES = "Person [firstName=John, lastName=Doever, email=john@doe.com, age=123, sex=Male, address=Address [streetAddress=John street, postalCode=11223, city=John's town, country=USA], deceased=false, salary=null, salaryDouble=null, rent=null]"; + private static final String UPDATED_NAME_BEAN_VALUES = "Person [firstName=John, lastName=Doever, email=john@doe.com, age=64, sex=Male, address=Address [streetAddress=John street, postalCode=11223, city=John's town, country=USA], deceased=false, salary=null, salaryDouble=null, rent=null]"; + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + } + + @Test + public void testCommitInvalidName() { + getLastNameArea().setValue("Doev"); + assertCommitFails(); + assertBeanValuesUnchanged(); + } + + @Test + public void testCommitInvalidAge() { + // default name invalid, must be fixed or doesn't test the correct error + getLastNameArea().setValue("Doever"); + + getAgeField().setValue("64,2"); + assertCommitFails(); + assertBeanValuesUnchanged(); + } + + @Test + public void testFixValidationError() { + getLastNameArea().setValue("Doev"); + assertCommitFails(); + assertBeanValuesUnchanged(); + + getLastNameArea().setValue("Doever"); + assertCommitSuccessful(); + showBeanValues(); + assertLogText(UPDATED_NAME_BEAN_VALUES); + } + + @Test + public void testFixConversionError() { + // default name invalid, must be fixed as well + getLastNameArea().setValue("Doever"); + + getAgeField().setValue("64,2"); + + assertCommitFails(); + assertBeanValuesUnchanged(); + + getAgeField().setValue("123"); + assertCommitSuccessful(); + + showBeanValues(); + assertLogText(UPDATED_BEAN_VALUES); + } + + @Test + public void testDiscardAfterSuccessfulCommit() { + getLastNameArea().setValue("Doever"); + getAgeField().setValue("123"); + assertCommitSuccessful(); + + discardChanges(); + assertLogText("Discarded changes"); + showBeanValues(); + assertLogText(UPDATED_BEAN_VALUES); + } +} diff --git a/uitest/src/com/vaadin/tests/fieldgroup/DateForm.java b/uitest/src/com/vaadin/tests/fieldgroup/DateForm.java index 3064856db9..6080f18391 100644 --- a/uitest/src/com/vaadin/tests/fieldgroup/DateForm.java +++ b/uitest/src/com/vaadin/tests/fieldgroup/DateForm.java @@ -8,9 +8,9 @@ import com.vaadin.data.fieldgroup.FieldGroup; import com.vaadin.data.fieldgroup.FieldGroup.CommitException; import com.vaadin.data.fieldgroup.PropertyId; import com.vaadin.data.util.BeanItem; -import com.vaadin.tests.components.TestBase; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.tests.data.bean.Person; -import com.vaadin.tests.util.Log; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.DateField; @@ -19,9 +19,8 @@ import com.vaadin.ui.Notification; import com.vaadin.ui.PopupDateField; import com.vaadin.ui.TextField; -public class DateForm extends TestBase { +public class DateForm extends AbstractTestUIWithLog { - private Log log = new Log(5); @PropertyId("date1") private DateField dateField; @PropertyId("date2") @@ -77,8 +76,8 @@ public class DateForm extends TestBase { } @Override - protected void setup() { - getMainWindow().setLocale(Locale.US); + protected void setup(VaadinRequest request) { + setLocale(Locale.US); addComponent(log); final FieldGroup fieldGroup = new BeanFieldGroup<DateObject>( DateObject.class); @@ -102,7 +101,7 @@ public class DateForm extends TestBase { msg = "Commit failed: " + e.getMessage(); } Notification.show(msg); - log.log(msg); + log(msg); } }); @@ -112,8 +111,7 @@ public class DateForm extends TestBase { @Override public void buttonClick(ClickEvent event) { fieldGroup.discard(); - log.log("Discarded changes"); - + log("Discarded changes"); } }); Button showBean = new Button("Show bean values", @@ -121,7 +119,7 @@ public class DateForm extends TestBase { @Override public void buttonClick(ClickEvent event) { - log.log(getPerson(fieldGroup).toString()); + log(getPerson(fieldGroup).toString()); } }); @@ -135,12 +133,13 @@ public class DateForm extends TestBase { fieldGroup.setItemDataSource(new BeanItem<DateObject>(d)); } + @SuppressWarnings("unchecked") public static Person getPerson(FieldGroup binder) { return ((BeanItem<Person>) binder.getItemDataSource()).getBean(); } @Override - protected String getDescription() { + public String getDescription() { return "Ensure FieldGroupFieldFactory supports Dates"; } diff --git a/uitest/src/com/vaadin/tests/fieldgroup/DateFormTest.java b/uitest/src/com/vaadin/tests/fieldgroup/DateFormTest.java new file mode 100644 index 0000000000..32d8bcb603 --- /dev/null +++ b/uitest/src/com/vaadin/tests/fieldgroup/DateFormTest.java @@ -0,0 +1,47 @@ +package com.vaadin.tests.fieldgroup; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.InlineDateFieldElement; +import com.vaadin.testbench.elements.PopupDateFieldElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class DateFormTest extends MultiBrowserTest { + + @Test + public void testCorrectDateFormat() throws Exception { + openTestURL(); + Assert.assertEquals("Unexpected DateField value,", "1/20/84", + getDateFieldValue()); + Assert.assertEquals("Unexpected PopupDateField value,", "1/20/84", + getPopupDateFieldValue()); + WebElement day20 = getInlineDateFieldCalendarPanel().findElement( + By.vaadin("#day20")); + Assert.assertTrue( + "Unexpected InlineDateField state, 20th not selected.", + hasCssClass(day20, + "v-inline-datefield-calendarpanel-day-selected")); + Assert.assertEquals("Unexpected TextField contents,", + "Jan 20, 1984 4:34:49 PM", $(TextFieldElement.class).first() + .getValue()); + } + + protected String getDateFieldValue() { + return $(DateFieldElement.class).first().getValue(); + } + + protected String getPopupDateFieldValue() { + return $(PopupDateFieldElement.class).first().getValue(); + } + + protected WebElement getInlineDateFieldCalendarPanel() { + return $(InlineDateFieldElement.class).first().findElement( + By.className("v-inline-datefield-calendarpanel")); + } + +} diff --git a/uitest/src/com/vaadin/tests/fieldgroup/FieldGroupDiscardTest.java b/uitest/src/com/vaadin/tests/fieldgroup/FieldGroupDiscardTest.java new file mode 100644 index 0000000000..7d8beb2106 --- /dev/null +++ b/uitest/src/com/vaadin/tests/fieldgroup/FieldGroupDiscardTest.java @@ -0,0 +1,32 @@ +package com.vaadin.tests.fieldgroup; + +import org.junit.Test; +import org.openqa.selenium.Keys; + +public class FieldGroupDiscardTest extends BasicPersonFormTest { + + @Test + public void testFieldGroupDiscard() throws Exception { + openTestURL(); + assertDefaults(); + + /* make some changes */ + getFirstNameField().sendKeys("John123", Keys.ENTER); + getLastNameArea().sendKeys("Doe123", Keys.ENTER); + getEmailField().sendKeys("john@doe.com123", Keys.ENTER); + getAgeField().sendKeys("64123", Keys.ENTER); + getGenderTable().getCell(2, 0); + getDeceasedField().click(); + getDeceasedField().click(); + getDeceasedField().sendKeys("YAY!", Keys.ENTER); + + assertBeanValuesUnchanged(); + + assertDiscardResetsFields(); + + assertBeanValuesUnchanged(); + + /* we should still be at the state we started from */ + assertDefaults(); + } +} diff --git a/uitest/src/com/vaadin/tests/fields/TabIndexes.java b/uitest/src/com/vaadin/tests/fields/TabIndexes.java index cf2e253d08..32fb36815b 100644 --- a/uitest/src/com/vaadin/tests/fields/TabIndexes.java +++ b/uitest/src/com/vaadin/tests/fields/TabIndexes.java @@ -4,8 +4,7 @@ import java.util.ArrayList; import java.util.List; import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.util.Log; +import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.ui.AbstractField; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; @@ -30,14 +29,13 @@ import com.vaadin.ui.Tree; import com.vaadin.ui.TreeTable; import com.vaadin.ui.TwinColSelect; -public class TabIndexes extends AbstractTestUI { +@SuppressWarnings("rawtypes") +public class TabIndexes extends AbstractTestUIWithLog { private List<AbstractField> fields; - private Log log = new Log(5); @Override protected void setup(VaadinRequest request) { - addComponent(log); HorizontalLayout buttonLayout = new HorizontalLayout(); addComponent(buttonLayout); Button clearTabIndexes = new Button("Set all tab indexes to 0"); @@ -45,7 +43,7 @@ public class TabIndexes extends AbstractTestUI { @Override public void buttonClick(ClickEvent event) { - log.log("Setting tab indexes to 0"); + log("Setting tab indexes to 0"); for (AbstractField f : fields) { f.setTabIndex(0); } @@ -57,7 +55,7 @@ public class TabIndexes extends AbstractTestUI { @Override public void buttonClick(ClickEvent event) { - log.log("Setting tab indexes to 1"); + log("Setting tab indexes to 1"); for (AbstractField f : fields) { f.setTabIndex(1); } @@ -70,7 +68,7 @@ public class TabIndexes extends AbstractTestUI { @Override public void buttonClick(ClickEvent event) { int tabIndex = 1; - log.log("Setting tab indexes to 1..N"); + log("Setting tab indexes to 1..N"); for (AbstractField f : fields) { f.setTabIndex(tabIndex++); } @@ -84,7 +82,7 @@ public class TabIndexes extends AbstractTestUI { @Override public void buttonClick(ClickEvent event) { int tabIndex = fields.size(); - log.log("Setting tab indexes to N..1"); + log("Setting tab indexes to N..1"); for (AbstractField f : fields) { f.setTabIndex(tabIndex--); } @@ -153,8 +151,7 @@ public class TabIndexes extends AbstractTestUI { @Override protected String getTestDescription() { - // TODO Auto-generated method stub - return null; + return "Tab index should be propagated into html"; } } diff --git a/uitest/src/com/vaadin/tests/fields/TabIndexesTest.java b/uitest/src/com/vaadin/tests/fields/TabIndexesTest.java new file mode 100644 index 0000000000..6bd456c7e2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/fields/TabIndexesTest.java @@ -0,0 +1,164 @@ +package com.vaadin.tests.fields; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TabIndexesTest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + } + + @Test + public void testTabIndexesSetToZero() { + // clicked by default + assertLogText("1. Setting tab indexes to 0"); + for (WebElement element : getFieldElements()) { + assertTabIndex("0", element); + } + } + + @Test + public void testTabIndexesSetToOne() { + setTabIndexesTo("1"); + for (WebElement element : getFieldElements()) { + assertTabIndex("1", element); + } + } + + @Test + public void testTabIndexesSetToOneThroughN() { + setTabIndexesTo("1..N"); + int counter = 0; + for (WebElement element : getFieldElements()) { + ++counter; + assertTabIndex(String.valueOf(counter), element); + } + } + + @Test + public void testTabIndexesSetToNThroughOne() { + setTabIndexesTo("N..1"); + List<WebElement> fieldElements = getFieldElements(); + int counter = fieldElements.size(); + for (WebElement element : fieldElements) { + assertTabIndex(String.valueOf(counter), element); + --counter; + } + } + + private void setTabIndexesTo(String expected) { + String caption = String.format("Set %stab indexes to %s", + (expected.contains("N") ? "" : "all "), expected); + $(ButtonElement.class).caption(caption).first().click(); + assertLogText("2. Setting tab indexes to " + expected); + } + + private void assertLogText(String expected) { + Assert.assertEquals("Unexpected log contents,", expected, getLogRow(0)); + } + + private void assertTabIndex(String expected, WebElement element) { + Assert.assertEquals("Unexpected tab index,", expected, + element.getAttribute("tabIndex")); + } + + private List<WebElement> getFieldElements() { + List<WebElement> fieldElements = new ArrayList<WebElement>(); + fieldElements.add(getElement1()); + fieldElements.add(getElement2()); + fieldElements.add(getElement3()); + fieldElements.add(getElement4()); + fieldElements.add(getElement5()); + fieldElements.add(getElement6()); + fieldElements.add(getElement7()); + fieldElements.add(getElement8()); + fieldElements.add(getElement9()); + fieldElements.add(getElement10()); + fieldElements.add(getElement11()); + fieldElements.add(getElement12()); + fieldElements.add(getElement13()); + fieldElements.add(getElement14()); + fieldElements.add(getElement15()); + fieldElements.add(getElement16()); + fieldElements.add(getElement17()); + return fieldElements; + } + + private WebElement getElement1() { + return vaadinElement("PID_Sfield-1/domChild[1]/domChild[1]"); + } + + private WebElement getElement2() { + return vaadinElement("PID_Sfield-2/domChild[0]"); + } + + private WebElement getElement3() { + return vaadinElement("PID_Sfield-3/domChild[0]"); + } + + private WebElement getElement4() { + return vaadinElement("PID_Sfield-4/domChild[0]"); + } + + private WebElement getElement5() { + return vaadinElement("PID_Sfield-5"); + } + + private WebElement getElement6() { + return vaadinElement("PID_Sfield-6/domChild[0]"); + } + + private WebElement getElement7() { + return vaadinElement("PID_Sfield-7/domChild[0]"); + } + + private WebElement getElement8() { + return vaadinElement("PID_Sfield-8/domChild[0]/domChild[0]"); + } + + private WebElement getElement9() { + return vaadinElement("PID_Sfield-9/domChild[1]/domChild[1]"); + } + + private WebElement getElement10() { + return vaadinElement("PID_Sfield-10/domChild[1]"); + } + + private WebElement getElement11() { + return vaadinElement("PID_Sfield-11/domChild[1]"); + } + + private WebElement getElement12() { + return vaadinElement("PID_Sfield-12"); + } + + private WebElement getElement13() { + return vaadinElement("PID_Sfield-13"); + } + + private WebElement getElement14() { + return vaadinElement("PID_Sfield-14"); + } + + private WebElement getElement15() { + return vaadinElement("PID_Sfield-15/domChild[1]"); + } + + private WebElement getElement16() { + return vaadinElement("PID_Sfield-16/domChild[0]"); + } + + private WebElement getElement17() { + return vaadinElement("PID_Sfield-17"); + } +} diff --git a/uitest/src/com/vaadin/tests/navigator/NavigatorListenerModifiesListeners.java b/uitest/src/com/vaadin/tests/navigator/NavigatorListenerModifiesListeners.java new file mode 100644 index 0000000000..139dbaefb6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/navigator/NavigatorListenerModifiesListeners.java @@ -0,0 +1,100 @@ +package com.vaadin.tests.navigator; + +import com.vaadin.navigator.Navigator; +import com.vaadin.navigator.View; +import com.vaadin.navigator.ViewChangeListener; +import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; +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.VerticalLayout; + +public class NavigatorListenerModifiesListeners extends AbstractTestUI { + + private Navigator navigator; + + protected static final String LABEL_MAINVIEW_ID = "LABEL_MAINVIEW_ID"; + protected static final String LABEL_ANOTHERVIEW_ID = "LABEL_ANOTHERVIEW_ID"; + + // NOP view change listener + private class MyViewChangeListener implements ViewChangeListener { + @Override + public boolean beforeViewChange(ViewChangeEvent event) { + navigator.removeViewChangeListener(listener1); + navigator.addViewChangeListener(listener2); + return true; + } + + @Override + public void afterViewChange(ViewChangeEvent event) { + navigator.removeViewChangeListener(listener2); + navigator.addViewChangeListener(listener1); + } + } + + private MyViewChangeListener listener1 = new MyViewChangeListener(); + private MyViewChangeListener listener2 = new MyViewChangeListener(); + + @Override + protected void setup(VaadinRequest request) { + navigator = new Navigator(this, this); + navigator.addView(MainView.NAME, new MainView()); + navigator.addView(AnotherView.NAME, new AnotherView()); + navigator.addViewChangeListener(listener1); + navigator.navigateTo(MainView.NAME); + } + + class MainView extends VerticalLayout implements View { + + public static final String NAME = "mainview"; + + public MainView() { + Label label = new Label("MainView content"); + label.setId(LABEL_MAINVIEW_ID); + addComponent(label); + + Button buttonNavToAnotherView = new Button( + "Navigate to another view", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + navigator.navigateTo(AnotherView.NAME); + } + }); + addComponent(buttonNavToAnotherView); + } + + @Override + public void enter(ViewChangeEvent event) { + } + + } + + class AnotherView extends VerticalLayout implements View { + + public static final String NAME = "another"; + + public AnotherView() { + Label label = new Label("AnotherView content"); + label.setId(LABEL_ANOTHERVIEW_ID); + addComponent(label); + } + + @Override + public void enter(ViewChangeEvent event) { + } + } + + @Override + protected String getTestDescription() { + return "Adding and removing view change listeners from view change listeners should not cause a ConcurrentModificationException"; + } + + @Override + protected Integer getTicketNumber() { + return 17477; + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/navigator/NavigatorListenerModifiesListenersTest.java b/uitest/src/com/vaadin/tests/navigator/NavigatorListenerModifiesListenersTest.java new file mode 100644 index 0000000000..d11ab790a8 --- /dev/null +++ b/uitest/src/com/vaadin/tests/navigator/NavigatorListenerModifiesListenersTest.java @@ -0,0 +1,68 @@ +/* + * 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.navigator; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class NavigatorListenerModifiesListenersTest extends SingleBrowserTest { + + @Test + public void testIfConfirmBack() { + openTestURL(); + + // keep URL of main view + final String initialUrl = driver.getCurrentUrl(); + + // do it 2 times to verify that this is not broken after first time + for (int i = 0; i < 2; i++) { + // go to prompted view + WebElement button = $(ButtonElement.class).first(); + button.click(); + + // verify we are in another view and url is correct + waitForElementPresent(By + .id(NavigatorListenerModifiesListeners.LABEL_ANOTHERVIEW_ID)); + String currentUrl = driver.getCurrentUrl(); + assertEquals( + "Current URL should be equal to another view URL", + initialUrl + .replace( + NavigatorListenerModifiesListeners.MainView.NAME, + NavigatorListenerModifiesListeners.AnotherView.NAME), + currentUrl); + + // click back button + driver.navigate().back(); + + // verify we are in main view and url is correct + // without the fix for #17477, we get + // ConcurrentModificationException + waitForElementPresent(By + .id(NavigatorListenerModifiesListeners.LABEL_MAINVIEW_ID)); + currentUrl = driver.getCurrentUrl(); + assertEquals("Current URL should be equal to the initial view URL", + initialUrl, currentUrl); + } + } + +} |