From a8553904cfdfac28ca301f193e728a41af2ce42c Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Thu, 23 Apr 2015 13:53:17 +0300 Subject: Fix MenuBar keyboard navigation and selecting (#17076) This patch also changes old TB2 test to TB4. Change-Id: I7a2ba20267d2db99e29003b764530d65a4eab955 --- client/src/com/vaadin/client/ui/VMenuBar.java | 18 ++- .../components/menubar/MenuBarNavigation.java | 34 ++-- .../menubar/MenuBarNavigationKeyboardTest.java | 95 +++++++++++ .../menubar/MenuBarNavigationKeyboard.html | 178 --------------------- 4 files changed, 124 insertions(+), 201 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/menubar/MenuBarNavigationKeyboardTest.java delete mode 100644 uitest/tb2/com/vaadin/tests/components/menubar/MenuBarNavigationKeyboard.html diff --git a/client/src/com/vaadin/client/ui/VMenuBar.java b/client/src/com/vaadin/client/ui/VMenuBar.java index 823861534d..c6c4b444e5 100644 --- a/client/src/com/vaadin/client/ui/VMenuBar.java +++ b/client/src/com/vaadin/client/ui/VMenuBar.java @@ -1509,13 +1509,23 @@ public class VMenuBar extends SimpleFocusablePanel implements // selection there openMenuAndFocusFirstIfPossible(getSelected()); } else { - Command command = getSelected().getCommand(); - if (command != null) { - command.execute(); - } + final Command command = getSelected().getCommand(); setSelected(null); hideParents(true); + + // #17076 keyboard selected menuitem without children: do + // not leave menu to visible ("hover open") mode + menuVisible = false; + + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + if (command != null) { + command.execute(); + } + } + }); } } diff --git a/uitest/src/com/vaadin/tests/components/menubar/MenuBarNavigation.java b/uitest/src/com/vaadin/tests/components/menubar/MenuBarNavigation.java index 3af07645d6..b4e24c60d9 100644 --- a/uitest/src/com/vaadin/tests/components/menubar/MenuBarNavigation.java +++ b/uitest/src/com/vaadin/tests/components/menubar/MenuBarNavigation.java @@ -1,20 +1,29 @@ package com.vaadin.tests.components.menubar; -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.MenuBar; import com.vaadin.ui.MenuBar.Command; import com.vaadin.ui.MenuBar.MenuItem; -public class MenuBarNavigation extends TestBase implements Command { +public class MenuBarNavigation extends AbstractTestUIWithLog implements Command { private MenuItem edit; private MenuItem file; - private Log log; private MenuItem export; @Override - protected void setup() { + public String getDescription() { + return "Test case for mouse and keyboard navigation in MenuBar"; + } + + @Override + public Integer getTicketNumber() { + return 5174; + } + + @Override + protected void setup(VaadinRequest request) { MenuBar mb = new MenuBar(); file = mb.addItem("File", null); file.addItem("Open", this); @@ -32,24 +41,11 @@ public class MenuBarNavigation extends TestBase implements Command { mb.addItem("Help", this); addComponent(mb); - - log = new Log(5); - addComponent(log); - } - - @Override - protected String getDescription() { - return "Test case for mouse and keyboard navigation in MenuBar"; - } - - @Override - protected Integer getTicketNumber() { - return 5174; } @Override public void menuSelected(MenuItem selectedItem) { - log.log("MenuItem " + getName(selectedItem) + " selected"); + log("MenuItem " + getName(selectedItem) + " selected"); } private String getName(MenuItem selectedItem) { diff --git a/uitest/src/com/vaadin/tests/components/menubar/MenuBarNavigationKeyboardTest.java b/uitest/src/com/vaadin/tests/components/menubar/MenuBarNavigationKeyboardTest.java new file mode 100644 index 0000000000..8737ba054e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/menubar/MenuBarNavigationKeyboardTest.java @@ -0,0 +1,95 @@ +package com.vaadin.tests.components.menubar; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.MenuBarElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class MenuBarNavigationKeyboardTest extends MultiBrowserTest { + + @Override + protected Class getUIClass() { + return com.vaadin.tests.components.menubar.MenuBarNavigation.class; + } + + @Override + protected boolean requireWindowFocusForIE() { + return true; + } + + @Override + protected boolean usePersistentHoverForIE() { + return false; + } + + @Test + public void testKeyboardNavigation() throws Exception { + openTestURL(); + + openMenu("File"); + getMenuBar().sendKeys(Keys.DOWN, Keys.DOWN, Keys.DOWN, Keys.DOWN, + Keys.RIGHT, Keys.ENTER); + Assert.assertEquals("1. MenuItem File/Export../As PDF... selected", + getLogRow(0)); + + openMenu("File"); + getMenuBar().sendKeys(Keys.RIGHT, Keys.RIGHT, Keys.RIGHT, Keys.ENTER); + Assert.assertEquals("2. MenuItem Help selected", getLogRow(0)); + + openMenu("Edit"); + getMenuBar().sendKeys(Keys.LEFT, Keys.DOWN, Keys.DOWN, Keys.ENTER); + Assert.assertEquals("3. MenuItem Edit/Cut selected", getLogRow(0)); + + openMenu("Edit"); + getMenuBar().sendKeys(Keys.ENTER); + Assert.assertEquals("3. MenuItem Edit/Cut selected", getLogRow(0)); + + getMenuBar().sendKeys(Keys.ENTER); + Assert.assertEquals("4. MenuItem Edit/Copy selected", getLogRow(0)); + + /* Enter while menubar has focus but no selection should focus "File" */ + getMenuBar().sendKeys(Keys.ENTER); + Assert.assertEquals("4. MenuItem Edit/Copy selected", getLogRow(0)); + + /* Enter again should open File and focus Open */ + getMenuBar().sendKeys(Keys.ENTER); + Assert.assertEquals("4. MenuItem Edit/Copy selected", getLogRow(0)); + + getMenuBar().sendKeys(Keys.ENTER); + Assert.assertEquals("5. MenuItem File/Open selected", getLogRow(0)); + } + + @Test + public void testMenuSelectWithKeyboardStateClearedCorrectly() + throws InterruptedException { + openTestURL(); + + openMenu("File"); + + getMenuBar().sendKeys(Keys.ARROW_RIGHT, Keys.ARROW_RIGHT, + Keys.ARROW_RIGHT, Keys.ENTER); + + assertTrue("Help menu was not selected", + logContainsText("MenuItem Help selected")); + + new Actions(driver).moveToElement(getMenuBar(), 10, 10).perform(); + + assertFalse("Unexpected MenuBar popup is visible", + isElementPresent(By.className("v-menubar-popup"))); + } + + public MenuBarElement getMenuBar() { + return $(MenuBarElement.class).first(); + } + + public void openMenu(String name) { + getMenuBar().clickItem(name); + } +} diff --git a/uitest/tb2/com/vaadin/tests/components/menubar/MenuBarNavigationKeyboard.html b/uitest/tb2/com/vaadin/tests/components/menubar/MenuBarNavigationKeyboard.html deleted file mode 100644 index a3d7700dae..0000000000 --- a/uitest/tb2/com/vaadin/tests/components/menubar/MenuBarNavigationKeyboard.html +++ /dev/null @@ -1,178 +0,0 @@ - - - - - - -New Test - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
New Test
open/run/com.vaadin.tests.components.menubar.MenuBarNavigation?restartApplication
mouseClickvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]#menu03,10
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]down
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]down
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]down
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]down
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]right
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]enter
assertTextvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]1. MenuItem File/Export../As PDF... selected
mouseClickvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]#menu00,7
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]right
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]right
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]right
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]enter
assertTextvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]2. MenuItem Help selected
mouseClickvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]#menu14,7
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]left
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]down
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]down
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]enter
assertTextvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]3. MenuItem Edit/Cut selected
mouseClickvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]#menu14,7
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]enter
assertTextvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::PID_SLog_row_03. MenuItem Edit/Cut selected
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]enter
assertTextvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::PID_SLog_row_04. MenuItem Edit/Copy selected
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]enter
assertTextvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::PID_SLog_row_04. MenuItem Edit/Copy selected
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]enter
assertTextvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::PID_SLog_row_04. MenuItem Edit/Copy selected
pressSpecialKeyvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]enter
assertTextvaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::PID_SLog_row_05. MenuItem File/Open selected
- - -- cgit v1.2.3