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 6.4KB

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