You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TextAreaEventPropagationTest.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.ui;
  17. import static org.junit.Assert.assertEquals;
  18. import org.junit.Test;
  19. import org.openqa.selenium.Keys;
  20. import org.openqa.selenium.WebElement;
  21. import org.openqa.selenium.interactions.Actions;
  22. import com.vaadin.tests.tb3.MultiBrowserTest;
  23. /**
  24. * Tests that the TextArea widget correctly stops ENTER events from propagating.
  25. *
  26. * @author Vaadin Ltd
  27. */
  28. public class TextAreaEventPropagationTest extends MultiBrowserTest {
  29. private final String baseLayoutSelector = "/VVerticalLayout[0]/Slot[2]"
  30. + "/VVerticalLayout[0]/Slot[0]/VFormLayout[0]/VFormLayout$VFormLayoutTable[0]";
  31. @Test
  32. public void testTextAreaEnterEventPropagation() throws InterruptedException {
  33. openTestURL();
  34. WebElement textArea = vaadinElement(baseLayoutSelector
  35. + "/VTextArea[0]");
  36. Actions builder = new Actions(driver);
  37. builder.click(textArea);
  38. builder.sendKeys(textArea, "first line asdf");
  39. builder.sendKeys(Keys.ENTER);
  40. builder.sendKeys(textArea, "second line jkl;");
  41. builder.perform();
  42. WebElement enterLabel = vaadinElementById("enterButtonLabel");
  43. String text = enterLabel.getText();
  44. assertEquals(TextAreaEventPropagation.NO_BUTTON_PRESSED, text);
  45. WebElement textField = vaadinElement(baseLayoutSelector
  46. + "/VTextField[0]");
  47. Actions builder2 = new Actions(driver);
  48. builder2.click(textField);
  49. builder2.sendKeys("third line");
  50. builder2.sendKeys(Keys.ENTER);
  51. builder2.perform();
  52. text = enterLabel.getText();
  53. assertEquals(TextAreaEventPropagation.BUTTON_PRESSED, text);
  54. }
  55. @Test
  56. public void testTextAreaEscapeEventPropagation()
  57. throws InterruptedException {
  58. openTestURL();
  59. WebElement textArea = vaadinElement(baseLayoutSelector
  60. + "/VTextArea[0]");
  61. Actions builder = new Actions(driver);
  62. builder.click(textArea);
  63. builder.sendKeys(textArea, "first line asdf");
  64. builder.sendKeys(Keys.ENTER);
  65. builder.sendKeys(textArea, "second line jkl;");
  66. builder.sendKeys(Keys.ESCAPE);
  67. builder.perform();
  68. WebElement enterLabel = vaadinElementById("enterButtonLabel");
  69. String text = enterLabel.getText();
  70. assertEquals(TextAreaEventPropagation.NO_BUTTON_PRESSED, text);
  71. WebElement escapeLabel = vaadinElementById("escapeButtonLabel");
  72. text = escapeLabel.getText();
  73. assertEquals(TextAreaEventPropagation.BUTTON_PRESSED, text);
  74. }
  75. @Test
  76. public void testTextFieldEscapeEventPropagation()
  77. throws InterruptedException {
  78. openTestURL();
  79. WebElement textArea = vaadinElement(baseLayoutSelector
  80. + "/VTextArea[0]");
  81. Actions builder = new Actions(driver);
  82. builder.click(textArea);
  83. builder.sendKeys(textArea, "first line asdf");
  84. builder.sendKeys(Keys.ENTER);
  85. builder.sendKeys(textArea, "second line jkl;");
  86. builder.perform();
  87. WebElement enterLabel = vaadinElementById("enterButtonLabel");
  88. String text = enterLabel.getText();
  89. assertEquals(TextAreaEventPropagation.NO_BUTTON_PRESSED, text);
  90. WebElement escapeLabel = vaadinElementById("escapeButtonLabel");
  91. WebElement textField = vaadinElement(baseLayoutSelector
  92. + "/VTextField[0]");
  93. Actions builder2 = new Actions(driver);
  94. builder2.click(textField);
  95. builder2.sendKeys("third line");
  96. builder2.sendKeys(Keys.ENTER);
  97. builder2.sendKeys(Keys.ESCAPE);
  98. builder2.perform();
  99. text = enterLabel.getText();
  100. assertEquals(TextAreaEventPropagation.BUTTON_PRESSED, text);
  101. text = escapeLabel.getText();
  102. assertEquals(TextAreaEventPropagation.BUTTON_PRESSED, text);
  103. }
  104. }