選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

InputTextFrameTest.java 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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.addons.ui_swing.components.*;
  24. import com.dmdirc.Main;
  25. import com.dmdirc.commandparser.parsers.GlobalCommandParser;
  26. import com.dmdirc.config.ConfigManager;
  27. import com.dmdirc.config.IdentityManager;
  28. import com.dmdirc.config.InvalidIdentityFileException;
  29. import com.dmdirc.harness.TestConfigManagerMap;
  30. import com.dmdirc.harness.TestWritableFrameContainer;
  31. import com.dmdirc.harness.ui.ClassFinder;
  32. import com.dmdirc.harness.ui.UIClassTestRunner;
  33. import com.dmdirc.harness.ui.UITestIface;
  34. import com.dmdirc.ui.WindowManager;
  35. import com.dmdirc.addons.ui_swing.SwingController;
  36. import com.dmdirc.addons.ui_swing.UIUtilities;
  37. import com.dmdirc.plugins.PluginManager;
  38. import java.awt.event.KeyEvent;
  39. import org.fest.swing.core.EventMode;
  40. import org.fest.swing.core.KeyPressInfo;
  41. import org.fest.swing.core.matcher.DialogByTitleMatcher;
  42. import org.fest.swing.core.matcher.JButtonByTextMatcher;
  43. import org.fest.swing.fixture.DialogFixture;
  44. import org.fest.swing.fixture.FrameFixture;
  45. import org.fest.swing.fixture.JInternalFrameFixture;
  46. import org.junit.After;
  47. import org.junit.Before;
  48. import org.junit.BeforeClass;
  49. import org.junit.Ignore;
  50. import org.junit.Test;
  51. import org.junit.runner.RunWith;
  52. @RunWith(UIClassTestRunner.class)
  53. public class InputTextFrameTest implements UITestIface {
  54. static FrameFixture mainframe;
  55. static JInternalFrameFixture window;
  56. static TestConfigManagerMap cmmap;
  57. static TestWritableFrameContainer owner;
  58. static SwingController controller;
  59. @BeforeClass
  60. public static void setUpClass() throws InvalidIdentityFileException {
  61. IdentityManager.load();
  62. controller = new SwingController();
  63. controller.onLoad();
  64. Main.setUI(controller);
  65. Main.ensureExists(PluginManager.getPluginManager(), "tabcompletion");
  66. }
  67. @Before
  68. public void setUp() {
  69. cmmap = new TestConfigManagerMap();
  70. cmmap.settings.put("ui.pasteProtectionLimit", "1");
  71. if (window == null) {
  72. owner = new TestWritableFrameContainer(512, cmmap);
  73. setupWindow(cmmap);
  74. }
  75. }
  76. @After
  77. public void tearDown() {
  78. // ??
  79. }
  80. @Test
  81. public void testPasteDialogContents() throws InterruptedException {
  82. ((InputTextFrame) window.target).doPaste("line1\nline2");
  83. final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
  84. .withTitleAndShowing("Multi-line paste"));
  85. dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
  86. dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
  87. .requireText("line1\nline2");
  88. dlg.target.dispose();
  89. }
  90. @Test @Ignore
  91. public void testPasteDialogWithTextBefore() throws InterruptedException {
  92. window.textBox().enterText("testing:");
  93. ((InputTextFrame) window.target).doPaste("line1\nline2");
  94. final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
  95. .withTitleAndShowing("Multi-line paste"));
  96. dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
  97. dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
  98. .requireText("testing:line1\nline2");
  99. dlg.target.dispose();
  100. }
  101. @Test @Ignore
  102. public void testPasteDialogWithTextAfter() throws InterruptedException {
  103. window.textBox().enterText("<- testing").pressAndReleaseKey(
  104. KeyPressInfo.keyCode(KeyEvent.VK_HOME));
  105. ((InputTextFrame) window.target).doPaste("line1\nline2");
  106. final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
  107. .withTitleAndShowing("Multi-line paste"));
  108. dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
  109. dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
  110. .requireText("line1\nline2<- testing");
  111. dlg.target.dispose();
  112. }
  113. @Test @Ignore
  114. public void testPasteDialogWithTextAround() throws InterruptedException {
  115. window.textBox().enterText("testing:<- testing").selectText(8, 8);
  116. ((InputTextFrame) window.target).doPaste("line1\nline2");
  117. final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
  118. .withTitleAndShowing("Multi-line paste"));
  119. dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
  120. dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
  121. .requireText("testing:line1\nline2<- testing");
  122. dlg.target.dispose();
  123. }
  124. protected void setupWindow(final ConfigManager configManager) {
  125. UIUtilities.initUISettings();
  126. mainframe = new FrameFixture(controller.getMainWindow());
  127. mainframe.robot.settings().eventMode(EventMode.AWT);
  128. final CustomInputFrame titf = new CustomInputFrame(owner,
  129. GlobalCommandParser.getGlobalCommandParser(), controller);
  130. titf.setTitle("testing123");
  131. owner.window = titf;
  132. WindowManager.addWindow(titf);
  133. titf.open();
  134. window = new JInternalFrameFixture(mainframe.robot, titf);
  135. }
  136. }