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.

WindowDeclarativeTest.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package com.vaadin.tests.server.component.window;
  2. import static org.junit.Assert.fail;
  3. import org.junit.Test;
  4. import com.vaadin.event.ShortcutAction.KeyCode;
  5. import com.vaadin.event.ShortcutAction.ModifierKey;
  6. import com.vaadin.shared.ui.window.WindowMode;
  7. import com.vaadin.shared.ui.window.WindowRole;
  8. import com.vaadin.tests.design.DeclarativeTestBase;
  9. import com.vaadin.ui.Button;
  10. import com.vaadin.ui.Label;
  11. import com.vaadin.ui.Window;
  12. import com.vaadin.ui.declarative.DesignException;
  13. /**
  14. * Tests declarative support for implementations of {@link Window}.
  15. *
  16. * @author Vaadin Ltd
  17. */
  18. public class WindowDeclarativeTest extends DeclarativeTestBase<Window> {
  19. @Test
  20. public void testDefault() {
  21. String design = "<vaadin-window>";
  22. Window expected = new Window();
  23. testRead(design, expected);
  24. testWrite(design, expected);
  25. }
  26. @Test
  27. public void testFeatures() {
  28. String design = "<vaadin-window position='100,100' window-mode='maximized' "
  29. + "center modal resizable=false resize-lazy closable=false draggable=false "
  30. + "close-shortcut='ctrl-alt-escape' "
  31. + "assistive-prefix='Hello' assistive-postfix='World' assistive-role='alertdialog' "
  32. + "tab-stop-enabled "
  33. + "tab-stop-top-assistive-text='Do not move above the window' "
  34. + "tab-stop-bottom-assistive-text='End of window'>"
  35. + "</vaadin-window>";
  36. Window expected = new Window();
  37. expected.setPositionX(100);
  38. expected.setPositionY(100);
  39. expected.setWindowMode(WindowMode.MAXIMIZED);
  40. expected.center();
  41. expected.setModal(!expected.isModal());
  42. expected.setResizable(!expected.isResizable());
  43. expected.setResizeLazy(!expected.isResizeLazy());
  44. expected.setClosable(!expected.isClosable());
  45. expected.setDraggable(!expected.isDraggable());
  46. expected.removeAllCloseShortcuts();
  47. expected.addCloseShortcut(KeyCode.ESCAPE, ModifierKey.ALT,
  48. ModifierKey.CTRL);
  49. expected.setAssistivePrefix("Hello");
  50. expected.setAssistivePostfix("World");
  51. expected.setAssistiveRole(WindowRole.ALERTDIALOG);
  52. expected.setTabStopEnabled(!expected.isTabStopEnabled());
  53. expected.setTabStopTopAssistiveText("Do not move above the window");
  54. expected.setTabStopBottomAssistiveText("End of window");
  55. testRead(design, expected);
  56. testWrite(design, expected);
  57. }
  58. @Test
  59. public void testMultiCloseShortcuts() {
  60. Window expected = new Window();
  61. // Add two shortcuts - should now contain three (default escape + two
  62. // added)
  63. expected.addCloseShortcut(KeyCode.SPACEBAR);
  64. expected.addCloseShortcut(KeyCode.ARROW_LEFT, ModifierKey.ALT,
  65. ModifierKey.CTRL);
  66. // Try to add the same shortcut again, should be no-op
  67. expected.addCloseShortcut(KeyCode.ARROW_LEFT, ModifierKey.CTRL,
  68. ModifierKey.ALT);
  69. // Add a third shortcut, should total four (default escape + three
  70. // added)
  71. expected.addCloseShortcut(KeyCode.ARROW_RIGHT, ModifierKey.CTRL);
  72. // Test validity
  73. String design = "<vaadin-window close-shortcut='escape spacebar ctrl-alt-left ctrl-right' />";
  74. testRead(design, expected);
  75. testWrite(design, expected);
  76. // Try removing the spacebar shortcut
  77. expected.removeCloseShortcut(KeyCode.SPACEBAR);
  78. // Test again
  79. design = "<vaadin-window close-shortcut='escape ctrl-alt-left ctrl-right' />";
  80. testRead(design, expected);
  81. testWrite(design, expected);
  82. }
  83. @Test
  84. public void testInvalidPosition() {
  85. assertInvalidPosition("");
  86. assertInvalidPosition("1");
  87. assertInvalidPosition("100,100.1");
  88. assertInvalidPosition("x");
  89. assertInvalidPosition("2,foo");
  90. // Should be invalid, not checked currently
  91. // assertInvalidPosition("1,2,3");
  92. }
  93. protected void assertInvalidPosition(String position) {
  94. try {
  95. read("<vaadin-window position='" + position + "'>");
  96. fail("Invalid position '" + position + "' should throw");
  97. } catch (Exception e) {
  98. // expected
  99. }
  100. }
  101. @Test
  102. public void testChildContent() {
  103. String design = "<vaadin-window>" + createElement(new Button("OK"))
  104. + "</vaadin-window>";
  105. Window expected = new Window();
  106. expected.setContent(new Button("OK"));
  107. testRead(design, expected);
  108. testWrite(design, expected);
  109. }
  110. @Test(expected = DesignException.class)
  111. public void testMultipleContentChildren() {
  112. String design = "<vaadin-window>" + createElement(new Label("Hello"))
  113. + createElement(new Button("OK")) + "</vaadin-window>";
  114. read(design);
  115. }
  116. @Test
  117. public void testAssistiveDescription() {
  118. Label assistive1 = new Label("Assistive text");
  119. Label assistive2 = new Label("More assistive text");
  120. String design = "<vaadin-window>"
  121. + createElement(assistive1).attr(":assistive-description", true)
  122. + createElement(new Button("OK")) + createElement(assistive2)
  123. .attr(":assistive-description", true);
  124. Window expected = new Window();
  125. expected.setContent(new Button("OK"));
  126. expected.setAssistiveDescription(assistive1, assistive2);
  127. testRead(design, expected);
  128. String written = "<vaadin-window>" + createElement(new Button("OK"))
  129. + createElement(assistive1).attr(":assistive-description", true)
  130. + createElement(assistive2).attr(":assistive-description",
  131. true);
  132. testWrite(written, expected);
  133. }
  134. }