summaryrefslogtreecommitdiffstats
path: root/tests/testbench/com/vaadin/tests/components/abstractfield
diff options
context:
space:
mode:
authorJonatan Kronqvist <jonatan.kronqvist@itmill.com>2011-09-29 12:44:21 +0000
committerJonatan Kronqvist <jonatan.kronqvist@itmill.com>2011-09-29 12:44:21 +0000
commitc4b62e478ac9ab8f66c3ca4289619b0f9c8ee958 (patch)
tree3b4ca56faecf6f65e8cd308d8f0cdcdd822c2886 /tests/testbench/com/vaadin/tests/components/abstractfield
parentcceb9d3f2bf475037e6a40b591968ef80c4878b8 (diff)
downloadvaadin-framework-c4b62e478ac9ab8f66c3ca4289619b0f9c8ee958.tar.gz
vaadin-framework-c4b62e478ac9ab8f66c3ca4289619b0f9c8ee958.zip
Restructure test source directories and packages #7385
svn changeset:21440/svn branch:6.7
Diffstat (limited to 'tests/testbench/com/vaadin/tests/components/abstractfield')
-rw-r--r--tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldCommitWithInvalidValues.html62
-rw-r--r--tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldCommitWithInvalidValues.java67
-rw-r--r--tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldDataSourceReadOnly.html42
-rw-r--r--tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldDataSourceReadOnly.java60
-rw-r--r--tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldTest.java234
-rw-r--r--tests/testbench/com/vaadin/tests/components/abstractfield/AbstractTextFieldTest.java241
-rw-r--r--tests/testbench/com/vaadin/tests/components/abstractfield/ShortcutAddAndRemove.html209
-rw-r--r--tests/testbench/com/vaadin/tests/components/abstractfield/ShortcutAddAndRemove.java64
8 files changed, 979 insertions, 0 deletions
diff --git a/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldCommitWithInvalidValues.html b/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldCommitWithInvalidValues.html
new file mode 100644
index 0000000000..6a47032545
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldCommitWithInvalidValues.html
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>AbstractFieldCommitWithInvalidValues</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">AbstractFieldCommitWithInvalidValues</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.abstractfield.AbstractFieldCommitWithInvalidValues</td>
+ <td></td>
+</tr>
+<tr>
+ <td>waitForVaadin</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
+ <td>focus</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldAbstractFieldCommitWithInvalidValues::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTextField[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldAbstractFieldCommitWithInvalidValues::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
+ <td>clickAt</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldAbstractFieldCommitWithInvalidValues::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTextField[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>type</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldAbstractFieldCommitWithInvalidValues::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTextField[0]</td>
+ <td>long</td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldAbstractFieldCommitWithInvalidValues::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td></td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldCommitWithInvalidValues.java b/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldCommitWithInvalidValues.java
new file mode 100644
index 0000000000..a08f8999a6
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldCommitWithInvalidValues.java
@@ -0,0 +1,67 @@
+package com.vaadin.tests.components.abstractfield;
+
+import com.vaadin.data.util.ObjectProperty;
+import com.vaadin.data.validator.StringLengthValidator;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.Window.Notification;
+
+public class AbstractFieldCommitWithInvalidValues extends TestBase {
+
+ private TextField tf;
+
+ @Override
+ protected String getDescription() {
+ return "Commiting a field with invalid values should throw an exception";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 2532;
+ }
+
+ @Override
+ protected void setup() {
+ tf = new TextField("A field, must contain 1-2 chars",
+ new ObjectProperty<String>("a"));
+ tf.addValidator(new StringLengthValidator("Invalid length", 1, 2, false));
+ tf.setWriteThrough(false);
+ tf.setRequired(true);
+
+ Button b = new Button("Commit", new ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ try {
+ tf.commit();
+ if (tf.isValid()) {
+ getMainWindow().showNotification(
+ "OK! Form validated and no error was thrown",
+ Notification.TYPE_HUMANIZED_MESSAGE);
+ } else {
+ getMainWindow().showNotification(
+ "Form is invalid but no exception was thrown",
+ Notification.TYPE_ERROR_MESSAGE);
+ }
+ } catch (Exception e) {
+ if (tf.isValid()) {
+ getMainWindow().showNotification(
+ "Form is valid but an exception was thrown",
+ Notification.TYPE_ERROR_MESSAGE);
+ } else {
+ getMainWindow().showNotification(
+ "OK! Error was thrown for an invalid input",
+ Notification.TYPE_HUMANIZED_MESSAGE);
+
+ }
+ }
+ }
+
+ });
+
+ addComponent(tf);
+ addComponent(b);
+ }
+}
diff --git a/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldDataSourceReadOnly.html b/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldDataSourceReadOnly.html
new file mode 100644
index 0000000000..f99bdea946
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldDataSourceReadOnly.html
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8888/run/com.vaadin.tests.components.abstractfield.AbstractFieldDataSourceReadOnly" />
+<title>AbstractFieldDataSourceReadOnly</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">AbstractFieldDataSourceReadOnly</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.abstractfield.AbstractFieldDataSourceReadOnly</td>
+ <td></td>
+</tr>
+<tr>
+ <td>waitForVaadin</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldAbstractFieldDataSourceReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VButton[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>waitForVaadin</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td></td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldDataSourceReadOnly.java b/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldDataSourceReadOnly.java
new file mode 100644
index 0000000000..2a2fc0153a
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldDataSourceReadOnly.java
@@ -0,0 +1,60 @@
+package com.vaadin.tests.components.abstractfield;
+
+import com.vaadin.data.util.ObjectProperty;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Component.Event;
+import com.vaadin.ui.Component.Listener;
+import com.vaadin.ui.TextField;
+
+public class AbstractFieldDataSourceReadOnly extends TestBase {
+
+ private static class StateHolder {
+ private ObjectProperty<String> textField = new ObjectProperty<String>(
+ "");
+
+ public ObjectProperty<String> getTextField() {
+ return textField;
+ }
+
+ @SuppressWarnings("unused")
+ public void setTextField(ObjectProperty<String> textField) {
+ this.textField = textField;
+ }
+
+ public void buttonClicked() {
+ textField.setReadOnly(true);
+ }
+ }
+
+ @Override
+ protected void setup() {
+ final StateHolder stateHolder = new StateHolder();
+
+ // Button
+ Button button = new Button("Make data source read-only");
+ button.addListener(new Listener() {
+ public void componentEvent(Event event) {
+ stateHolder.buttonClicked();
+ }
+ });
+
+ // Input field
+ TextField input = new TextField("Field");
+ input.setPropertyDataSource(stateHolder.getTextField());
+
+ addComponent(button);
+ addComponent(input);
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Read-only status changes in data sources are not rendered immediately";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 5013;
+ }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldTest.java b/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldTest.java
new file mode 100644
index 0000000000..1c8e728908
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractFieldTest.java
@@ -0,0 +1,234 @@
+package com.vaadin.tests.components.abstractfield;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ReadOnlyStatusChangeEvent;
+import com.vaadin.data.Property.ReadOnlyStatusChangeListener;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.event.FieldEvents.BlurEvent;
+import com.vaadin.event.FieldEvents.BlurListener;
+import com.vaadin.event.FieldEvents.BlurNotifier;
+import com.vaadin.event.FieldEvents.FocusEvent;
+import com.vaadin.event.FieldEvents.FocusListener;
+import com.vaadin.event.FieldEvents.FocusNotifier;
+import com.vaadin.tests.components.AbstractComponentTest;
+import com.vaadin.ui.AbstractField;
+import com.vaadin.ui.MenuBar;
+import com.vaadin.ui.MenuBar.MenuItem;
+
+public abstract class AbstractFieldTest<T extends AbstractField> extends
+ AbstractComponentTest<T> implements ValueChangeListener,
+ ReadOnlyStatusChangeListener, FocusListener, BlurListener {
+
+ @Override
+ protected void createActions() {
+ super.createActions();
+ createBooleanAction("Required", CATEGORY_STATE, false, requiredCommand);
+ createRequiredErrorSelect(CATEGORY_DECORATIONS);
+
+ createValueChangeListener(CATEGORY_LISTENERS);
+ createReadOnlyStatusChangeListener(CATEGORY_LISTENERS);
+
+ // * invalidcommitted
+ // * commit()
+ // * discard()
+ // * writethrough
+ // * readthrough
+ // * addvalidator
+ // * isvalid
+ // * invalidallowed
+ // * error indicator
+ //
+ // * tabindex
+ // * validation visible
+ // * ShortcutListener
+
+ }
+
+ @Override
+ protected void populateSettingsMenu(MenuItem settingsMenu) {
+ super.populateSettingsMenu(settingsMenu);
+
+ if (AbstractField.class.isAssignableFrom(getTestClass())) {
+ MenuItem abstractField = settingsMenu
+ .addItem("AbstractField", null);
+ abstractField.addItem("Show value", new MenuBar.Command() {
+
+ public void menuSelected(MenuItem selectedItem) {
+ for (T a : getTestComponents()) {
+ log(a.getClass().getSimpleName() + " value: "
+ + getValue(a));
+ }
+ }
+ });
+ }
+ }
+
+ private void createRequiredErrorSelect(String category) {
+ LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
+ options.put("-", null);
+ options.put(TEXT_SHORT, TEXT_SHORT);
+ options.put("Medium", TEXT_MEDIUM);
+ options.put("Long", TEXT_LONG);
+ options.put("Very long", TEXT_VERY_LONG);
+ createSelectAction("Required error message", category, options, "-",
+ requiredErrorMessageCommand);
+
+ if (FocusNotifier.class.isAssignableFrom(getTestClass())) {
+ createFocusListener(CATEGORY_LISTENERS);
+ }
+
+ if (BlurNotifier.class.isAssignableFrom(getTestClass())) {
+ createBlurListener(CATEGORY_LISTENERS);
+ }
+
+ }
+
+ private void createValueChangeListener(String category) {
+
+ createBooleanAction("Value change listener", category, false,
+ valueChangeListenerCommand);
+ }
+
+ private void createReadOnlyStatusChangeListener(String category) {
+
+ createBooleanAction("Read only status change listener", category,
+ false, readonlyStatusChangeListenerCommand);
+ }
+
+ private void createFocusListener(String category) {
+ createBooleanAction("Focus listener", category, false,
+ focusListenerCommand);
+
+ }
+
+ private void createBlurListener(String category) {
+ createBooleanAction("Blur listener", category, false,
+ blurListenerCommand);
+
+ }
+
+ protected Command<T, Boolean> valueChangeListenerCommand = new Command<T, Boolean>() {
+
+ public void execute(T c, Boolean value, Object data) {
+ if (value) {
+ c.addListener((ValueChangeListener) AbstractFieldTest.this);
+ } else {
+ c.removeListener((ValueChangeListener) AbstractFieldTest.this);
+ }
+ }
+ };
+ protected Command<T, Boolean> readonlyStatusChangeListenerCommand = new Command<T, Boolean>() {
+
+ public void execute(T c, Boolean value, Object data) {
+ if (value) {
+ c.addListener((ReadOnlyStatusChangeListener) AbstractFieldTest.this);
+ } else {
+ c.removeListener((ReadOnlyStatusChangeListener) AbstractFieldTest.this);
+ }
+ }
+ };
+ protected Command<T, Boolean> focusListenerCommand = new Command<T, Boolean>() {
+
+ public void execute(T c, Boolean value, Object data) {
+ if (value) {
+ ((FocusNotifier) c).addListener(AbstractFieldTest.this);
+ } else {
+ ((FocusNotifier) c).removeListener(AbstractFieldTest.this);
+ }
+ }
+ };
+ protected Command<T, Boolean> blurListenerCommand = new Command<T, Boolean>() {
+
+ public void execute(T c, Boolean value, Object data) {
+ if (value) {
+ ((BlurNotifier) c).addListener(AbstractFieldTest.this);
+ } else {
+ ((BlurNotifier) c).removeListener(AbstractFieldTest.this);
+ }
+ }
+ };
+ protected Command<T, Object> setValueCommand = new Command<T, Object>() {
+
+ public void execute(T c, Object value, Object data) {
+ c.setValue(value);
+ }
+ };
+
+ public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
+ log(event.getClass().getSimpleName() + ", new value: "
+ + getValue(event.getProperty()));
+ };
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private String getValue(Property property) {
+ Object o = property.getValue();
+ if (o instanceof Collection) {
+ // Sort collections to avoid problems with values printed in
+ // different order
+ try {
+ ArrayList<Comparable> c = new ArrayList<Comparable>(
+ (Collection) o);
+ Collections.sort(c);
+ o = c;
+ } catch (Exception e) {
+ // continue with unsorted if sorting fails for some reason
+ log("Exception while sorting value: " + e.getMessage());
+ }
+ }
+
+ // Distinguish between null and 'null'
+ String value = "null";
+ if (o != null) {
+ if (o instanceof Date) {
+ Date d = (Date) o;
+ // Dec 31, 2068 23:09:26.531
+ String pattern = "MMM d, yyyy HH:mm:ss.SSS";
+ SimpleDateFormat format = new SimpleDateFormat(pattern,
+ new Locale("en", "US"));
+ value = format.format(d);
+ } else {
+ value = "'" + o.toString() + "'";
+ }
+ }
+
+ return value;
+
+ }
+
+ public void readOnlyStatusChange(ReadOnlyStatusChangeEvent event) {
+ log(event.getClass().getSimpleName());
+ }
+
+ public void focus(FocusEvent event) {
+ log(event.getClass().getSimpleName());
+ }
+
+ public void blur(BlurEvent event) {
+ log(event.getClass().getSimpleName());
+ }
+
+ protected void createSetTextValueAction(String category) {
+ String subCategory = "Set text value";
+ createCategory(subCategory, category);
+ List<String> values = new ArrayList<String>();
+ values.add("Test");
+ values.add("A little longer value");
+ values.add("A very long value with very much text. All in all it is 74 characters long");
+
+ createClickAction("(empty string)", subCategory, setValueCommand, "");
+ createClickAction("(null)", subCategory, setValueCommand, null);
+ for (String value : values) {
+ createClickAction(value, subCategory, setValueCommand, value);
+ }
+ }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractTextFieldTest.java b/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractTextFieldTest.java
new file mode 100644
index 0000000000..eb9adef8d2
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/components/abstractfield/AbstractTextFieldTest.java
@@ -0,0 +1,241 @@
+package com.vaadin.tests.components.abstractfield;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+import com.vaadin.event.FieldEvents.TextChangeEvent;
+import com.vaadin.event.FieldEvents.TextChangeListener;
+import com.vaadin.ui.AbstractTextField;
+import com.vaadin.ui.AbstractTextField.TextChangeEventMode;
+
+public abstract class AbstractTextFieldTest<T extends AbstractTextField>
+ extends AbstractFieldTest<T> implements TextChangeListener {
+
+ private Command<T, Integer> maxlengthCommand = new Command<T, Integer>() {
+
+ public void execute(T c, Integer value, Object data) {
+ c.setMaxLength(value);
+ }
+ };
+ private Command<T, Boolean> nullSelectionAllowedCommand = new Command<T, Boolean>() {
+
+ public void execute(T c, Boolean value, Object data) {
+ c.setNullSettingAllowed(value);
+
+ }
+ };
+ private Command<T, String> nullRepresentationCommand = new Command<T, String>() {
+
+ public void execute(T c, String value, Object data) {
+ c.setNullRepresentation(value);
+ }
+ };
+
+ private Command<T, String> inputPromptCommand = new Command<T, String>() {
+ public void execute(T c, String value, Object data) {
+ c.setInputPrompt(value);
+ }
+ };
+
+ private Command<T, Boolean> textChangeListenerCommand = new Command<T, Boolean>() {
+ public void execute(T c, Boolean value, Object data) {
+ if (value) {
+ c.addListener((TextChangeListener) AbstractTextFieldTest.this);
+ } else {
+ c.removeListener((TextChangeListener) AbstractTextFieldTest.this);
+ }
+ }
+ };
+
+ private Command<T, Integer> colsCommand = new Command<T, Integer>() {
+ public void execute(T c, Integer value, Object data) {
+ c.setColumns(value);
+ }
+ };
+
+ private Command<T, TextChangeEventMode> textChangeEventModeCommand = new Command<T, TextChangeEventMode>() {
+ public void execute(T c, TextChangeEventMode value, Object data) {
+ c.setTextChangeEventMode(value);
+ }
+ };
+
+ private Command<T, Integer> textChangeTimeoutCommand = new Command<T, Integer>() {
+ public void execute(T c, Integer value, Object data) {
+ c.setTextChangeTimeout(value);
+ }
+ };
+
+ private Command<T, Range> selectionRangeCommand = new Command<T, Range>() {
+ public void execute(T c, Range value, Object data) {
+ c.setSelectionRange(value.getStart(),
+ value.getEnd() - value.getStart());
+
+ }
+ };
+ private Command<T, Object> selectAllCommand = new Command<T, Object>() {
+ public void execute(T c, Object value, Object data) {
+ c.selectAll();
+ }
+ };
+
+ private Command<T, Integer> setCursorPositionCommand = new Command<T, Integer>() {
+
+ public void execute(T c, Integer value, Object data) {
+ c.setCursorPosition(value);
+ }
+ };
+
+ @Override
+ protected void createActions() {
+ super.createActions();
+
+ createSetTextValueAction(CATEGORY_ACTIONS);
+
+ createNullSettingAllowedAction(CATEGORY_FEATURES);
+ createNullRepresentationAction(CATEGORY_FEATURES);
+ createMaxLengthAction(CATEGORY_FEATURES);
+
+ createInputPromptAction(CATEGORY_FEATURES);
+ createColsAction(CATEGORY_STATE);
+
+ createTextChangeListener(CATEGORY_LISTENERS);
+ createTextChangeEventModeAction(CATEGORY_FEATURES);
+ createTextChangeEventTimeoutAction(CATEGORY_FEATURES);
+
+ createSetTextValueAction(CATEGORY_ACTIONS);
+ createCursorPositionAction(CATEGORY_ACTIONS);
+ createSelectionRangeAction(CATEGORY_ACTIONS);
+
+ }
+
+ private void createNullSettingAllowedAction(String category) {
+ createBooleanAction("Null selection allowed", category, true,
+ nullSelectionAllowedCommand);
+ }
+
+ private void createNullRepresentationAction(String category) {
+ LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
+ options.put("-", null);
+ options.put("null", "null");
+ options.put("This is empty", "This is empty");
+ options.put("- Nothing -", "- Nothing -");
+ createSelectAction("Null representation", category, options, "null",
+ nullRepresentationCommand);
+ }
+
+ private void createMaxLengthAction(String category) {
+ LinkedHashMap<String, Integer> options = createIntegerOptions(100);
+ options.put("-", -1);
+ createSelectAction("Max length", category, options, "-",
+ maxlengthCommand);
+
+ }
+
+ public class Range {
+ private int start;
+ private int end;
+
+ public Range(int start, int end) {
+ this.start = start;
+ this.end = end;
+ }
+
+ public int getStart() {
+ return start;
+ }
+
+ public int getEnd() {
+ return end;
+ }
+
+ @Override
+ public String toString() {
+ return start + "-" + end;
+ }
+ }
+
+ private void createSelectionRangeAction(String category) {
+ List<Range> options = new ArrayList<Range>();
+ options.add(new Range(0, 10));
+ options.add(new Range(0, 1));
+ options.add(new Range(0, 2));
+ options.add(new Range(1, 2));
+ options.add(new Range(2, 5));
+ options.add(new Range(5, 10));
+
+ createCategory("Select range", category);
+
+ createClickAction("All", "Select range", selectAllCommand, null);
+ for (Range range : options) {
+ createClickAction(range.toString(), "Select range",
+ selectionRangeCommand, range);
+ }
+
+ }
+
+ private void createCursorPositionAction(String category) {
+ String subCategory = "Set cursor position";
+ createCategory(subCategory, category);
+ for (int i = 0; i < 20; i++) {
+ createClickAction(String.valueOf(i), subCategory,
+ setCursorPositionCommand, Integer.valueOf(i));
+ }
+
+ }
+
+ private void createTextChangeEventTimeoutAction(String category) {
+ LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
+ options.put("0", 0);
+ options.put("100ms", 100);
+ options.put("500ms", 500);
+ options.put("1s", 1000);
+ options.put("2s", 2000);
+ options.put("5s", 5000);
+
+ createSelectAction("TextChange timeout", category, options, "0",
+ textChangeTimeoutCommand);
+ }
+
+ private void createTextChangeEventModeAction(String category) {
+ LinkedHashMap<String, TextChangeEventMode> options = new LinkedHashMap<String, AbstractTextField.TextChangeEventMode>();
+ for (TextChangeEventMode m : TextChangeEventMode.values()) {
+ options.put(m.toString(), m);
+ }
+
+ createSelectAction("TextChange event mode", category, options,
+ TextChangeEventMode.EAGER.toString(),
+ textChangeEventModeCommand);
+
+ }
+
+ private void createTextChangeListener(String category) {
+ createBooleanAction("Text change listener", category, false,
+ textChangeListenerCommand);
+
+ }
+
+ private void createColsAction(String category) {
+ LinkedHashMap<String, Integer> options = createIntegerOptions(20);
+ createSelectAction("Columns", category, options, "0", colsCommand);
+ }
+
+ private void createInputPromptAction(String category) {
+ LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
+ options.put("-", null);
+ options.put("Enter a value", "Enter a value");
+ options.put("- Click here -", "- Click here -");
+ createSelectAction("Input prompt", category, options, "-",
+ inputPromptCommand);
+
+ }
+
+ public void textChange(TextChangeEvent event) {
+ AbstractTextField tf = (AbstractTextField) event.getComponent();
+ log("TextChangeEvent: text='" + event.getText() + "', cursor position="
+ + event.getCursorPosition() + " (field cursor pos: "
+ + tf.getCursorPosition() + ")");
+
+ }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/components/abstractfield/ShortcutAddAndRemove.html b/tests/testbench/com/vaadin/tests/components/abstractfield/ShortcutAddAndRemove.html
new file mode 100644
index 0000000000..e61f227939
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/components/abstractfield/ShortcutAddAndRemove.html
@@ -0,0 +1,209 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://artur-laptop.office.itmill.com:8888/" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.abstractfield.ShortcutAddAndRemove?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/domChild[0]/domChild[1]</td>
+ <td>316,58</td>
+</tr>
+<!--Enter on background - should cause event-->
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::</td>
+ <td>enter</td>
+</tr>
+<tr>
+ <td>waitForVaadin</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
+ <td>1. Log button was clicked</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>102,51</td>
+</tr>
+<!--Enter in textfield - should cause event-->
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>enter</td>
+</tr>
+<tr>
+ <td>waitForVaadin</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
+ <td>2. Log button was clicked</td>
+</tr>
+<!--Remove shortcut-->
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>110,62</td>
+</tr>
+<!--Enter in field - should not cause event-->
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>97,26</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>up</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>enterCharacter</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>row1</td>
+</tr>
+<tr>
+ <td>keyPress</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>13</td>
+</tr>
+<tr>
+ <td>keyPress</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>r</td>
+</tr>
+<tr>
+ <td>keyPress</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>o</td>
+</tr>
+<tr>
+ <td>keyPress</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>w</td>
+</tr>
+<tr>
+ <td>keyPress</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>2</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
+ <td>2. Log button was clicked</td>
+</tr>
+<!-- Commented out because TestBench does not enter the text correctly using keyPress in any browser except Firefox -->
+<!-- <tr>
+ <td>assertValue</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>row1<br />row2</td>
+</tr>-->
+<!--Add shortcut again-->
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VButton[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>85,46</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VTextArea[0]</td>
+ <td>enter</td>
+</tr>
+<tr>
+ <td>waitForVaadin</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
+ <td>3. Log button was clicked</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/domChild[0]/domChild[2]/domChild[0]</td>
+ <td>625,2</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::</td>
+ <td>enter</td>
+</tr>
+<tr>
+ <td>waitForVaadin</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
+ <td>4. Log button was clicked</td>
+</tr>
+<!--Remove shortcut once more-->
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/domChild[0]/domChild[2]</td>
+ <td>631,52</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/domChild[0]/domChild[2]</td>
+ <td>597,57</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::</td>
+ <td>enter</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractfieldShortcutAddAndRemove::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
+ <td>4. Log button was clicked</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/testbench/com/vaadin/tests/components/abstractfield/ShortcutAddAndRemove.java b/tests/testbench/com/vaadin/tests/components/abstractfield/ShortcutAddAndRemove.java
new file mode 100644
index 0000000000..837256ff65
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/components/abstractfield/ShortcutAddAndRemove.java
@@ -0,0 +1,64 @@
+package com.vaadin.tests.components.abstractfield;
+
+import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.tests.util.Log;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.TextArea;
+
+public class ShortcutAddAndRemove extends TestBase {
+
+ private Log log;
+ private TextArea textArea;
+
+ @Override
+ protected void setup() {
+ log = new Log(4);
+
+ final Button logButton = new Button("Log a row (enter shortcut)");
+ logButton.setClickShortcut(KeyCode.ENTER);
+ logButton.addListener(new ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ log.log("Log button was clicked");
+ }
+ });
+
+ final Button removeShortcut = new Button("Remove shortcut");
+ removeShortcut.addListener(new ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ logButton.removeClickShortcut();
+ logButton.setCaption("Log a row (no shortcut)");
+ }
+ });
+ final Button addShortcut = new Button("Add shortcut");
+ addShortcut.addListener(new ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ logButton.setClickShortcut(KeyCode.ENTER);
+ logButton.setCaption("Log a row (enter shortcut)");
+ }
+ });
+ addComponent(log);
+ addComponent(logButton);
+ textArea = new TextArea("Enter key does not break lines ...");
+ textArea.setRows(5);
+ textArea.setColumns(20);
+ addComponent(textArea);
+ addComponent(removeShortcut);
+ addComponent(addShortcut);
+
+ }
+
+ @Override
+ protected String getDescription() {
+ return null;
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}