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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 = "<v-window>";
  38. Window expected = new Window();
  39. testRead(design, expected);
  40. testWrite(design, expected);
  41. }
  42. @Test
  43. public void testFeatures() {
  44. String design = "<v-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. + "</v-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.setCloseShortcut(KeyCode.ESCAPE, ModifierKey.CTRL,
  63. ModifierKey.ALT);
  64. expected.setAssistivePrefix("Hello");
  65. expected.setAssistivePostfix("World");
  66. expected.setAssistiveRole(WindowRole.ALERTDIALOG);
  67. expected.setTabStopEnabled(!expected.isTabStopEnabled());
  68. expected.setTabStopTopAssistiveText("Do not move above the window");
  69. expected.setTabStopBottomAssistiveText("End of window");
  70. testRead(design, expected);
  71. testWrite(design, expected);
  72. }
  73. @Test
  74. public void testInvalidPosition() {
  75. assertInvalidPosition("");
  76. assertInvalidPosition("1");
  77. assertInvalidPosition("100,100.1");
  78. assertInvalidPosition("x");
  79. assertInvalidPosition("2,foo");
  80. // Should be invalid, not checked currently
  81. // assertInvalidPosition("1,2,3");
  82. }
  83. protected void assertInvalidPosition(String position) {
  84. try {
  85. read("<v-window position='" + position + "'>");
  86. Assert.fail("Invalid position '" + position + "' should throw");
  87. } catch (Exception e) {
  88. // expected
  89. }
  90. }
  91. @Test
  92. public void testChildContent() {
  93. String design = "<v-window>" + createElement(new Button("OK"))
  94. + "</v-window>";
  95. Window expected = new Window();
  96. expected.setContent(new Button("OK"));
  97. testRead(design, expected);
  98. testWrite(design, expected);
  99. }
  100. @Test(expected = DesignException.class)
  101. public void testMultipleContentChildren() {
  102. String design = "<v-window>" + createElement(new Label("Hello"))
  103. + createElement(new Button("OK")) + "</v-window>";
  104. read(design);
  105. }
  106. @Test
  107. public void testAssistiveDescription() {
  108. Label assistive1 = new Label("Assistive text");
  109. Label assistive2 = new Label("More assistive text");
  110. String design = "<v-window>"
  111. + createElement(assistive1).attr(":assistive-description", "")
  112. + createElement(new Button("OK"))
  113. + createElement(assistive2).attr(":assistive-description", "");
  114. Window expected = new Window();
  115. expected.setContent(new Button("OK"));
  116. expected.setAssistiveDescription(assistive1, assistive2);
  117. testRead(design, expected);
  118. String written = "<v-window>" + createElement(new Button("OK"))
  119. + createElement(assistive1).attr(":assistive-description", "")
  120. + createElement(assistive2).attr(":assistive-description", "");
  121. testWrite(written, expected);
  122. }
  123. }