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.

InputTextFrameTest.java 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.ui_swing.components.frames;
  23. import com.dmdirc.Main;
  24. import com.dmdirc.commandparser.parsers.GlobalCommandParser;
  25. import com.dmdirc.config.ConfigManager;
  26. import com.dmdirc.config.IdentityManager;
  27. import com.dmdirc.config.InvalidIdentityFileException;
  28. import com.dmdirc.harness.TestConfigManagerMap;
  29. import com.dmdirc.harness.TestWritableFrameContainer;
  30. import com.dmdirc.harness.ui.ClassFinder;
  31. import com.dmdirc.ui.WindowManager;
  32. import com.dmdirc.addons.ui_swing.SwingController;
  33. import com.dmdirc.addons.ui_swing.UIUtilities;
  34. import com.dmdirc.addons.ui_swing.components.TextAreaInputField;
  35. import com.dmdirc.plugins.PluginManager;
  36. import java.awt.event.KeyEvent;
  37. import org.fest.swing.core.KeyPressInfo;
  38. import org.fest.swing.core.matcher.DialogMatcher;
  39. import org.fest.swing.core.matcher.JButtonMatcher;
  40. import org.fest.swing.fixture.DialogFixture;
  41. import org.fest.swing.fixture.FrameFixture;
  42. import org.fest.swing.fixture.JInternalFrameFixture;
  43. import org.junit.After;
  44. import org.junit.Before;
  45. import org.junit.BeforeClass;
  46. import org.junit.Test;
  47. public class InputTextFrameTest {
  48. static FrameFixture mainframe;
  49. static JInternalFrameFixture window;
  50. static TestConfigManagerMap cmmap;
  51. static TestWritableFrameContainer owner;
  52. static SwingController controller;
  53. @BeforeClass
  54. public static void setUpClass() throws InvalidIdentityFileException {
  55. IdentityManager.load();
  56. IdentityManager.getAddonIdentity().setOption("test", "windowMenuItems", "1");
  57. IdentityManager.getAddonIdentity().setOption("test", "windowMenuScrollInterval", "1");
  58. IdentityManager.getAddonIdentity().setOption("test", "debugEDT", "false");
  59. IdentityManager.getAddonIdentity().setOption("test", "textpanebackground", "");
  60. IdentityManager.getAddonIdentity().setOption("test", "desktopbackground", "");
  61. controller = new SwingController();
  62. controller.setDomain("test");
  63. controller.onLoad();
  64. Main.ensureExists(PluginManager.getPluginManager(), "tabcompletion");
  65. UIUtilities.initUISettings();
  66. mainframe = new FrameFixture(controller.getMainWindow());
  67. }
  68. @Before
  69. public void setUp() {
  70. cmmap = new TestConfigManagerMap();
  71. cmmap.settings.put("ui.pasteProtectionLimit", "1");
  72. owner = new TestWritableFrameContainer(512, cmmap);
  73. setupWindow(cmmap);
  74. }
  75. @After
  76. public void tearDown() {
  77. window.close();
  78. owner.window.close();
  79. WindowManager.removeWindow(owner.window);
  80. }
  81. @Test
  82. public void testPasteDialogContents() throws InterruptedException {
  83. ((InputTextFrame) window.target).doPaste("line1\nline2");
  84. final DialogFixture dlg = mainframe.dialog(DialogMatcher
  85. .withTitle("Multi-line paste").andShowing());
  86. dlg.requireVisible().button(JButtonMatcher.withText("Edit")).click();
  87. dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
  88. .requireText("line1\nline2");
  89. dlg.target.dispose();
  90. }
  91. @Test
  92. public void testPasteDialogWithTextBefore() throws InterruptedException {
  93. window.textBox().enterText("testing:");
  94. ((InputTextFrame) window.target).doPaste("line1\nline2");
  95. final DialogFixture dlg = mainframe.dialog(DialogMatcher
  96. .withTitle("Multi-line paste").andShowing());
  97. dlg.requireVisible().button(JButtonMatcher.withText("Edit")).click();
  98. dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
  99. .requireText("testing:line1\nline2");
  100. dlg.target.dispose();
  101. }
  102. @Test
  103. public void testPasteDialogWithTextAfter() throws InterruptedException {
  104. window.textBox().enterText("<- testing").pressAndReleaseKey(
  105. KeyPressInfo.keyCode(KeyEvent.VK_HOME));
  106. ((InputTextFrame) window.target).doPaste("line1\nline2");
  107. final DialogFixture dlg = mainframe.dialog(DialogMatcher
  108. .withTitle("Multi-line paste").andShowing());
  109. dlg.requireVisible().button(JButtonMatcher.withText("Edit")).click();
  110. dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
  111. .requireText("line1\nline2<- testing");
  112. dlg.target.dispose();
  113. }
  114. @Test
  115. public void testPasteDialogWithTextAround() throws InterruptedException {
  116. window.textBox().enterText("testing:<- testing").selectText(8, 8);
  117. ((InputTextFrame) window.target).doPaste("line1\nline2");
  118. final DialogFixture dlg = mainframe.dialog(DialogMatcher
  119. .withTitle("Multi-line paste").andShowing());
  120. dlg.requireVisible().button(JButtonMatcher.withText("Edit")).click();
  121. dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
  122. .requireText("testing:line1\nline2<- testing");
  123. dlg.target.dispose();
  124. }
  125. protected void setupWindow(final ConfigManager configManager) {
  126. final CustomInputFrame titf = new CustomInputFrame(owner,
  127. GlobalCommandParser.getGlobalCommandParser(), controller);
  128. titf.setTitle("testing123");
  129. owner.window = titf;
  130. WindowManager.addWindow(titf);
  131. titf.open();
  132. window = new JInternalFrameFixture(mainframe.robot, titf);
  133. window.robot.settings().eventPostingDelay(250);
  134. }
  135. }