|
@@ -23,22 +23,29 @@
|
23
|
23
|
package com.dmdirc.ui.swing.components;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.WritableFrameContainer;
|
|
26
|
+import com.dmdirc.commandparser.parsers.GlobalCommandParser;
|
26
|
27
|
import com.dmdirc.config.ConfigManager;
|
27
|
28
|
import com.dmdirc.config.IdentityManager;
|
28
|
29
|
import com.dmdirc.harness.TestConfigManagerMap;
|
29
|
30
|
import com.dmdirc.harness.TestWritableFrameContainer;
|
30
|
|
-import com.dmdirc.harness.ui.TestInputTextFrame;
|
|
31
|
+import com.dmdirc.harness.ui.ClassFinder;
|
31
|
32
|
import com.dmdirc.harness.ui.UIClassTestRunner;
|
32
|
33
|
import com.dmdirc.harness.ui.UITestIface;
|
33
|
34
|
|
34
|
35
|
import com.dmdirc.ui.WindowManager;
|
|
36
|
+import com.dmdirc.ui.interfaces.Window;
|
|
37
|
+import com.dmdirc.ui.swing.CustomInputFrame;
|
35
|
38
|
import com.dmdirc.ui.swing.SwingController;
|
|
39
|
+import com.dmdirc.ui.swing.UIUtilities;
|
36
|
40
|
import java.awt.Toolkit;
|
37
|
41
|
import java.awt.datatransfer.StringSelection;
|
38
|
42
|
import java.awt.event.KeyEvent;
|
|
43
|
+import javax.swing.text.JTextComponent;
|
39
|
44
|
import org.fest.swing.core.EventMode;
|
40
|
45
|
import org.fest.swing.core.KeyPressInfo;
|
41
|
46
|
import org.fest.swing.core.matcher.DialogByTitleMatcher;
|
|
47
|
+import org.fest.swing.core.matcher.JButtonByTextMatcher;
|
|
48
|
+import org.fest.swing.fixture.DialogFixture;
|
42
|
49
|
import org.fest.swing.fixture.FrameFixture;
|
43
|
50
|
import org.fest.swing.fixture.JInternalFrameFixture;
|
44
|
51
|
import org.fest.swing.util.Platform;
|
|
@@ -52,10 +59,10 @@ import static org.junit.Assert.*;
|
52
|
59
|
@RunWith(UIClassTestRunner.class)
|
53
|
60
|
public class InputTextFrameTest implements UITestIface {
|
54
|
61
|
|
55
|
|
- FrameFixture mainframe;
|
56
|
|
- JInternalFrameFixture window;
|
57
|
|
- TestConfigManagerMap cmmap;
|
58
|
|
- TestWritableFrameContainer owner;
|
|
62
|
+ static FrameFixture mainframe;
|
|
63
|
+ static JInternalFrameFixture window;
|
|
64
|
+ static TestConfigManagerMap cmmap;
|
|
65
|
+ static TestWritableFrameContainer owner;
|
59
|
66
|
|
60
|
67
|
@Before
|
61
|
68
|
public void setUp() {
|
|
@@ -64,36 +71,99 @@ public class InputTextFrameTest implements UITestIface {
|
64
|
71
|
cmmap = new TestConfigManagerMap();
|
65
|
72
|
cmmap.settings.put("ui.pasteProtectionLimit", "1");
|
66
|
73
|
|
67
|
|
- owner = new TestWritableFrameContainer(512, cmmap);
|
|
74
|
+ if (window == null) {
|
|
75
|
+ owner = new TestWritableFrameContainer(512, cmmap);
|
|
76
|
+
|
|
77
|
+ setupWindow(cmmap);
|
|
78
|
+ }
|
68
|
79
|
}
|
69
|
80
|
|
70
|
81
|
@After
|
71
|
82
|
public void tearDown() {
|
72
|
|
- if (window != null) {
|
73
|
|
- window.close();
|
74
|
|
- }
|
75
|
|
-
|
76
|
|
- if (mainframe != null) {
|
77
|
|
- mainframe.close();
|
78
|
|
- }
|
|
83
|
+ // ??
|
79
|
84
|
}
|
80
|
85
|
|
81
|
86
|
@Test
|
82
|
87
|
public void testPasteDialogAppearing() throws InterruptedException {
|
83
|
|
- setupWindow(cmmap);
|
|
88
|
+ Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
|
|
89
|
+ new StringSelection("line1\nline2"), null);
|
84
|
90
|
|
|
91
|
+ window.textBox().pressAndReleaseKey(KeyPressInfo.keyCode(KeyEvent.VK_V)
|
|
92
|
+ .modifiers(Platform.controlOrCommandMask()));
|
|
93
|
+ mainframe.dialog(DialogByTitleMatcher.withTitleAndShowing("Multi-line paste"))
|
|
94
|
+ .requireVisible().close();
|
|
95
|
+ }
|
|
96
|
+
|
|
97
|
+ @Test
|
|
98
|
+ public void testPasteDialogContents() throws InterruptedException {
|
85
|
99
|
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
|
86
|
100
|
new StringSelection("line1\nline2"), null);
|
87
|
101
|
|
88
|
|
- while (true) {
|
89
|
|
- Thread.yield();
|
90
|
|
- Thread.sleep(1000);
|
91
|
|
- }
|
|
102
|
+ window.textBox().pressAndReleaseKey(KeyPressInfo.keyCode(KeyEvent.VK_V)
|
|
103
|
+ .modifiers(Platform.controlOrCommandMask()));
|
|
104
|
+
|
|
105
|
+ final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
|
|
106
|
+ .withTitleAndShowing("Multi-line paste"));
|
92
|
107
|
|
93
|
|
- //window.textBox().pressAndReleaseKey(KeyPressInfo.keyCode(KeyEvent.VK_C)
|
94
|
|
- // .modifiers(Platform.controlOrCommandMask()));
|
95
|
|
- //mainframe.dialog(DialogByTitleMatcher.withTitle("Multi-line paste")).
|
96
|
|
- // requireVisible();
|
|
108
|
+ dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
|
|
109
|
+ dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
|
|
110
|
+ .requireText("line1\nline2");
|
|
111
|
+ dlg.close();
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ @Test
|
|
115
|
+ public void testPasteDialogWithTextBefore() throws InterruptedException {
|
|
116
|
+ Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
|
|
117
|
+ new StringSelection("line1\nline2"), null);
|
|
118
|
+
|
|
119
|
+ window.textBox().enterText("testing:");
|
|
120
|
+ window.textBox().pressAndReleaseKey(KeyPressInfo.keyCode(KeyEvent.VK_V)
|
|
121
|
+ .modifiers(Platform.controlOrCommandMask()));
|
|
122
|
+
|
|
123
|
+ final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
|
|
124
|
+ .withTitleAndShowing("Multi-line paste"));
|
|
125
|
+
|
|
126
|
+ dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
|
|
127
|
+ dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
|
|
128
|
+ .requireText("testing:line1\nline2");
|
|
129
|
+ dlg.close();
|
|
130
|
+ }
|
|
131
|
+
|
|
132
|
+ @Test
|
|
133
|
+ public void testPasteDialogWithTextAfter() throws InterruptedException {
|
|
134
|
+ Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
|
|
135
|
+ new StringSelection("line1\nline2"), null);
|
|
136
|
+
|
|
137
|
+ window.textBox().enterText("<- testing").pressAndReleaseKey(
|
|
138
|
+ KeyPressInfo.keyCode(KeyEvent.VK_HOME));
|
|
139
|
+ window.textBox().pressAndReleaseKey(KeyPressInfo.keyCode(KeyEvent.VK_V)
|
|
140
|
+ .modifiers(Platform.controlOrCommandMask()));
|
|
141
|
+
|
|
142
|
+ final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
|
|
143
|
+ .withTitleAndShowing("Multi-line paste"));
|
|
144
|
+
|
|
145
|
+ dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
|
|
146
|
+ dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
|
|
147
|
+ .requireText("line1\nline2<- testing");
|
|
148
|
+ dlg.close();
|
|
149
|
+ }
|
|
150
|
+
|
|
151
|
+ @Test
|
|
152
|
+ public void testPasteDialogWithTextAround() throws InterruptedException {
|
|
153
|
+ Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
|
|
154
|
+ new StringSelection("line1\nline2"), null);
|
|
155
|
+
|
|
156
|
+ window.textBox().enterText("testing:<- testing").selectText(8, 8);
|
|
157
|
+ window.textBox().pressAndReleaseKey(KeyPressInfo.keyCode(KeyEvent.VK_V)
|
|
158
|
+ .modifiers(Platform.controlOrCommandMask()));
|
|
159
|
+
|
|
160
|
+ final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
|
|
161
|
+ .withTitleAndShowing("Multi-line paste"));
|
|
162
|
+
|
|
163
|
+ dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
|
|
164
|
+ dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
|
|
165
|
+ .requireText("testing:line1\nline2<- testing");
|
|
166
|
+ dlg.close();
|
97
|
167
|
}
|
98
|
168
|
|
99
|
169
|
public static junit.framework.Test suite() {
|
|
@@ -101,10 +171,13 @@ public class InputTextFrameTest implements UITestIface {
|
101
|
171
|
}
|
102
|
172
|
|
103
|
173
|
protected void setupWindow(final ConfigManager configManager) {
|
|
174
|
+ UIUtilities.initUISettings();
|
|
175
|
+
|
104
|
176
|
mainframe = new FrameFixture(SwingController.getMainFrame());
|
105
|
177
|
mainframe.robot.settings().eventMode(EventMode.AWT);
|
106
|
178
|
|
107
|
|
- final TestInputTextFrame titf = new TestInputTextFrame(owner);
|
|
179
|
+ final CustomInputFrame titf = new CustomInputFrame(owner,
|
|
180
|
+ GlobalCommandParser.getGlobalCommandParser());
|
108
|
181
|
|
109
|
182
|
titf.setTitle("testing123");
|
110
|
183
|
|
|
@@ -113,7 +186,6 @@ public class InputTextFrameTest implements UITestIface {
|
113
|
186
|
WindowManager.addWindow(titf);
|
114
|
187
|
|
115
|
188
|
titf.open();
|
116
|
|
- titf.show();
|
117
|
189
|
|
118
|
190
|
window = new JInternalFrameFixture(mainframe.robot, titf);
|
119
|
191
|
}
|