01: package abbot.editor.recorder;
02:
03: import java.awt.Toolkit;
04: import java.awt.event.KeyEvent;
05:
06: import javax.swing.*;
07:
08: import junit.extensions.abbot.RepeatHelper;
09: import abbot.script.Resolver;
10: import abbot.tester.*;
11:
12: /** Test recording of JComponent-specific events. */
13: public class JComponentRecorderTest extends
14: AbstractSemanticRecorderFixture {
15:
16: private JComponentTester tester;
17:
18: protected void setUp() throws Exception {
19: super .setUp();
20: tester = new JComponentTester();
21: }
22:
23: public void testCaptureActionMap() {
24: JTextField tf = new JTextField("Operate here");
25: showFrame(tf);
26: tester.actionFocus(tf);
27: startRecording();
28:
29: int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
30: tester.key(KeyEvent.VK_A, mask);
31: assertStep("ActionMap\\(.*,select-all\\)");
32: assertNoStep();
33: assertNoTrailingEvents();
34: }
35:
36: public void testSwallowKeyTyped() {
37: JTextField tf = new JTextField("Press Enter");
38: showFrame(tf);
39: tester.actionFocus(tf);
40: startRecording();
41:
42: tester.key(KeyEvent.VK_ENTER);
43: assertStep("ActionMap\\(.*,notify-field-accept\\)");
44: assertNoStep();
45: assertNoTrailingEvents();
46: }
47:
48: public void testCaptureUnnamedActions() {
49: JTree tree = new JTree();
50: showFrame(tree);
51: tester.actionFocus(tree);
52: startRecording();
53: // FIXME ensure the action is unnamed; LAFs may differ
54: tester.key(KeyEvent.VK_LEFT);
55: assertStep("ActionMap\\(.*,(selectParent|aquaCollapseNode)\\)");
56: }
57:
58: /** Create a new test case with the given name. */
59: public JComponentRecorderTest(String name) {
60: super (name);
61: }
62:
63: protected SemanticRecorder createSemanticRecorder(Resolver r) {
64: return new JComponentRecorder(r);
65: }
66:
67: public static void main(String[] args) {
68: RepeatHelper.runTests(args, JComponentRecorderTest.class);
69: }
70: }
|