summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-07-27 13:41:17 +0300
committerHenri Sara <henri.sara@gmail.com>2017-07-27 13:41:17 +0300
commit390fd31dc18d026a60a89e9b5cba040859cc3393 (patch)
tree734b3de37b021f541ef209d9b72fb567ec0cdd66 /uitest
parent410965ddca3e601343f8b759e1a27a2c1b0d0f29 (diff)
downloadvaadin-framework-390fd31dc18d026a60a89e9b5cba040859cc3393.tar.gz
vaadin-framework-390fd31dc18d026a60a89e9b5cba040859cc3393.zip
Implement GWT Focusable so tab indexes work correctly in MenuBar (#9733)
Fixes #9550
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/fields/TabIndexes.java91
-rw-r--r--uitest/src/test/java/com/vaadin/tests/fields/TabIndexesTest.java153
2 files changed, 98 insertions, 146 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/fields/TabIndexes.java b/uitest/src/main/java/com/vaadin/tests/fields/TabIndexes.java
index 83183c7b27..18a2d2766e 100644
--- a/uitest/src/main/java/com/vaadin/tests/fields/TabIndexes.java
+++ b/uitest/src/main/java/com/vaadin/tests/fields/TabIndexes.java
@@ -3,37 +3,60 @@ package com.vaadin.tests.fields;
import java.util.ArrayList;
import java.util.List;
+import com.vaadin.annotations.Widgetset;
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;
import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.DateField;
-import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.InlineDateField;
+import com.vaadin.ui.ListSelect;
+import com.vaadin.ui.MenuBar;
+import com.vaadin.ui.NativeSelect;
+import com.vaadin.ui.PasswordField;
import com.vaadin.ui.RichTextArea;
import com.vaadin.ui.Slider;
-import com.vaadin.v7.ui.ComboBox;
-import com.vaadin.v7.ui.ListSelect;
-import com.vaadin.v7.ui.NativeSelect;
-import com.vaadin.v7.ui.OptionGroup;
-import com.vaadin.v7.ui.PasswordField;
-import com.vaadin.v7.ui.Table;
-import com.vaadin.v7.ui.TextArea;
-import com.vaadin.v7.ui.TextField;
-import com.vaadin.v7.ui.Tree;
-import com.vaadin.v7.ui.TreeTable;
-import com.vaadin.v7.ui.TwinColSelect;
+import com.vaadin.ui.TextArea;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.TreeGrid;
+import com.vaadin.ui.TwinColSelect;
+import com.vaadin.ui.VerticalLayout;
+@Widgetset("com.vaadin.DefaultWidgetSet")
public class TabIndexes extends AbstractTestUIWithLog {
- private List<Focusable> fields;
+ public static final String FIELD_CONTAINER_ID = "field-container";
+ private List<Focusable> fields = new ArrayList<>();
@Override
protected void setup(VaadinRequest request) {
+ fields.add(new ComboBox());
+ fields.add(new NativeSelect());
+ fields.add(new ListSelect());
+ fields.add(new TextField());
+ fields.add(new DateField());
+ fields.add(new InlineDateField());
+ TreeGrid<String> tt = new TreeGrid<>();
+ tt.addColumn(s -> s);
+ tt.setItems("Foo", "Bar");
+
+ fields.add(tt);
+ fields.add(new TwinColSelect<String>());
+ fields.add(new PasswordField());
+ fields.add(new TextArea());
+ fields.add(new RichTextArea());
+ fields.add(new CheckBox());
+ fields.add(new Slider());
+ MenuBar menubar = new MenuBar();
+ menubar.addItem("foo", item -> {
+ });
+ fields.add(menubar);
+
HorizontalLayout buttonLayout = new HorizontalLayout();
addComponent(buttonLayout);
Button clearTabIndexes = new Button("Set all tab indexes to 0");
@@ -87,51 +110,19 @@ public class TabIndexes extends AbstractTestUIWithLog {
updateCaptions();
}
});
- fields = new ArrayList<>();
- Table t = new Table();
- t.setSelectable(true);
- t.addContainerProperty("foo", String.class, "bar");
- t.addItem();
- fields.add(t);
- fields.add(new ComboBox());
- fields.add(new NativeSelect());
- fields.add(new ListSelect());
- fields.add(new TextField());
- fields.add(new DateField());
- fields.add(new InlineDateField());
- OptionGroup og = new OptionGroup();
- og.addItem("Item 1");
- og.addItem("Item 2");
- fields.add(og);
- TreeTable tt = new TreeTable();
- tt.setSelectable(true);
- tt.addContainerProperty("foo", String.class, "bar");
- tt.addItem();
-
- fields.add(tt);
- Tree tree = new Tree();
- tree.addItem("Item 1");
- fields.add(tree);
- fields.add(new TwinColSelect());
- fields.add(new PasswordField());
- fields.add(new TextField());
- fields.add(new TextArea());
- fields.add(new RichTextArea());
- fields.add(new CheckBox());
- fields.add(new Slider());
clearTabIndexes.click();
buttonLayout.addComponents(clearTabIndexes, setTabIndexesToOne,
setTabIndexesInOrder, setTabIndexesInReverseOrder);
- int fieldId = 1;
- GridLayout gl = new GridLayout(4, 4);
+ VerticalLayout vl = new VerticalLayout();
+ vl.setId(FIELD_CONTAINER_ID);
for (Component f : fields) {
- f.setId("field-" + fieldId++);
- gl.addComponent(f);
+ f.setId("field-" + f.getClass().getSimpleName());
+ vl.addComponent(f);
}
- addComponent(gl);
+ addComponent(vl);
}
diff --git a/uitest/src/test/java/com/vaadin/tests/fields/TabIndexesTest.java b/uitest/src/test/java/com/vaadin/tests/fields/TabIndexesTest.java
index a642a1207a..16ea0d051f 100644
--- a/uitest/src/test/java/com/vaadin/tests/fields/TabIndexesTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/fields/TabIndexesTest.java
@@ -7,10 +7,26 @@ import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.WebElement;
+import com.vaadin.testbench.elements.AbstractComponentElement;
import com.vaadin.testbench.elements.ButtonElement;
-import com.vaadin.tests.tb3.MultiBrowserTest;
-
-public class TabIndexesTest extends MultiBrowserTest {
+import com.vaadin.testbench.elements.CheckBoxElement;
+import com.vaadin.testbench.elements.ComboBoxElement;
+import com.vaadin.testbench.elements.DateFieldElement;
+import com.vaadin.testbench.elements.InlineDateFieldElement;
+import com.vaadin.testbench.elements.ListSelectElement;
+import com.vaadin.testbench.elements.MenuBarElement;
+import com.vaadin.testbench.elements.NativeSelectElement;
+import com.vaadin.testbench.elements.PasswordFieldElement;
+import com.vaadin.testbench.elements.RichTextAreaElement;
+import com.vaadin.testbench.elements.SliderElement;
+import com.vaadin.testbench.elements.TextAreaElement;
+import com.vaadin.testbench.elements.TextFieldElement;
+import com.vaadin.testbench.elements.TreeGridElement;
+import com.vaadin.testbench.elements.TwinColSelectElement;
+import com.vaadin.testbench.elements.VerticalLayoutElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class TabIndexesTest extends SingleBrowserTest {
@Override
public void setup() throws Exception {
@@ -22,7 +38,7 @@ public class TabIndexesTest extends MultiBrowserTest {
public void testTabIndexesSetToZero() {
// clicked by default
assertLogText("1. Setting tab indexes to 0");
- for (WebElement element : getFieldElements()) {
+ for (WebElement element : getFocusElements()) {
assertTabIndex("0", element);
}
}
@@ -30,7 +46,7 @@ public class TabIndexesTest extends MultiBrowserTest {
@Test
public void testTabIndexesSetToOne() {
setTabIndexesTo("1");
- for (WebElement element : getFieldElements()) {
+ for (WebElement element : getFocusElements()) {
assertTabIndex("1", element);
}
}
@@ -39,7 +55,7 @@ public class TabIndexesTest extends MultiBrowserTest {
public void testTabIndexesSetToOneThroughN() {
setTabIndexesTo("1..N");
int counter = 0;
- for (WebElement element : getFieldElements()) {
+ for (WebElement element : getFocusElements()) {
++counter;
assertTabIndex(String.valueOf(counter), element);
}
@@ -48,7 +64,7 @@ public class TabIndexesTest extends MultiBrowserTest {
@Test
public void testTabIndexesSetToNThroughOne() {
setTabIndexesTo("N..1");
- List<WebElement> fieldElements = getFieldElements();
+ List<WebElement> fieldElements = getFocusElements();
int counter = fieldElements.size();
for (WebElement element : fieldElements) {
assertTabIndex(String.valueOf(counter), element);
@@ -68,97 +84,42 @@ public class TabIndexesTest extends MultiBrowserTest {
}
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<>();
- 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]");
+ if (!expected.equals(element.getAttribute("tabIndex"))) {
+ Assert.assertEquals(
+ "Unexpected tab index for element "
+ + element.getAttribute("outerHTML"),
+ expected, element.getAttribute("tabIndex"));
+ }
}
- private WebElement getElement16() {
- return vaadinElement("PID_Sfield-16/domChild[0]");
+ private List<WebElement> getFocusElements() {
+ List<WebElement> focusElements = new ArrayList<>();
+
+ focusElements.add($(ComboBoxElement.class).first().getInputField());
+ focusElements
+ .add($(NativeSelectElement.class).first().getSelectElement());
+ focusElements
+ .add($(ListSelectElement.class).first().getSelectElement());
+ focusElements.add($(TextFieldElement.class).first());
+ focusElements.add($(DateFieldElement.class).first().getInputElement());
+ focusElements
+ .add($(InlineDateFieldElement.class).first().getFocusElement());
+ focusElements.add($(TreeGridElement.class).first());
+ focusElements
+ .add($(TwinColSelectElement.class).first().getOptionsElement());
+ focusElements.add($(PasswordFieldElement.class).first());
+ focusElements.add($(TextAreaElement.class).first());
+ focusElements
+ .add($(RichTextAreaElement.class).first().getEditorIframe());
+ focusElements.add($(CheckBoxElement.class).first().getInputElement());
+ focusElements.add($(SliderElement.class).first());
+ focusElements.add($(MenuBarElement.class).first());
+
+ List<AbstractComponentElement> components = $(
+ VerticalLayoutElement.class).id(TabIndexes.FIELD_CONTAINER_ID)
+ .$(AbstractComponentElement.class).all();
+ Assert.assertEquals(components.size(), focusElements.size());
+ return focusElements;
}
- private WebElement getElement17() {
- return vaadinElement("PID_Sfield-17");
- }
}