01: package abbot.editor.recorder;
02:
03: import java.awt.*;
04: import java.awt.event.*;
05:
06: import javax.swing.*;
07:
08: import junit.extensions.abbot.RepeatHelper;
09: import abbot.script.Resolver;
10: import abbot.tester.*;
11: import abbot.util.Bugs;
12:
13: /**
14: * Unit test to verify proper capture of user semantic events on a Choice.
15: */
16: public class ChoiceRecorderTest extends AbstractSemanticRecorderFixture {
17:
18: private Frame frame;
19: private Choice choice;
20: private static final int MAX_ENTRIES = 20;
21:
22: // FIXME linux gets duplicate ITEM_STATE_CHANGED events (VM bug)
23: public void testCaptureSelection() {
24: showChoice();
25: ChoiceTester tester = new ChoiceTester();
26:
27: startRecording();
28: int idx = MAX_ENTRIES - 1;
29: tester.actionSelectIndex(choice, idx);
30: tester.delay(500);
31: assertStep("SelectItem(.*,item " + idx + ")");
32: if (Bugs.hasChoiceLockupBug()) {
33: return;
34: }
35:
36: startRecording();
37: idx = MAX_ENTRIES / 2 - 1;
38: tester.actionSelectIndex(choice, idx);
39: tester.delay(500);
40: assertStep("SelectItem(.*,item " + idx + ")");
41:
42: startRecording();
43: tester.actionSelectIndex(choice, 0);
44: assertStep("SelectItem(.*,item 0)");
45: }
46:
47: public void testESCToCancelSelection() {
48: showChoice();
49: startRecording();
50: ComponentTester tester = ComponentTester
51: .getTester(Component.class);
52: tester.mousePress(choice);
53: tester.actionKeyStroke(KeyEvent.VK_ESCAPE);
54: assertNoStep();
55: }
56:
57: public void testClickToCancelSelection() {
58: showChoice();
59: startRecording();
60: ComponentTester tester = ComponentTester
61: .getTester(Component.class);
62: tester.mousePress(choice);
63: JPanel pane = (JPanel) ((JFrame) frame).getContentPane();
64: tester.actionClick(pane, 0, 0);
65: assertNoStep();
66: }
67:
68: protected SemanticRecorder createSemanticRecorder(Resolver r) {
69: return new ChoiceRecorder(r);
70: }
71:
72: private void showChoice() {
73: choice = new Choice();
74: for (int i = 0; i < MAX_ENTRIES; i++) {
75: choice.add("item " + i);
76: }
77: // Must have a listener or no events will be fired
78: choice.addItemListener(new ItemListener() {
79: public void itemStateChanged(ItemEvent e) {
80: }
81: });
82: frame = showFrame(choice);
83: }
84:
85: public static void main(String[] args) {
86: RepeatHelper.runTests(args, ChoiceRecorderTest.class);
87: }
88: }
|