01: package abbot.editor.recorder;
02:
03: import java.awt.*;
04: import javax.swing.*;
05: import javax.swing.plaf.*;
06:
07: import junit.extensions.abbot.RepeatHelper;
08: import abbot.Platform;
09: import abbot.script.Resolver;
10: import abbot.tester.*;
11: import abbot.util.AWT;
12:
13: /**
14: * Unit test to verify proper capture of user semantic events on a JTabbedPane.
15: */
16: public class JTabbedPaneRecorderTest extends
17: AbstractSemanticRecorderFixture {
18:
19: private JTabbedPaneTester tester;
20: private JTabbedPane tabbedPane;
21: private static final int MAX_ENTRIES = 10;
22:
23: public JTabbedPaneRecorderTest(String name) {
24: super (name);
25: }
26:
27: protected SemanticRecorder createSemanticRecorder(Resolver r) {
28: return new JTabbedPaneRecorder(r);
29: }
30:
31: private void showTabbedPane() {
32: tabbedPane = new JTabbedPane();
33: for (int i = 0; i < MAX_ENTRIES; i++) {
34: tabbedPane.addTab("Tab " + i, new JLabel("This is pane #"
35: + i) {
36: public Dimension getPreferredSize() {
37: return new Dimension(300, 175);
38: }
39: });
40: }
41: tester = (JTabbedPaneTester) ComponentTester
42: .getTester(tabbedPane);
43: showFrame(tabbedPane);
44: }
45:
46: public void testCaptureSelection() {
47: showTabbedPane();
48: startRecording();
49: TabbedPaneUI ui = tabbedPane.getUI();
50: Rectangle tab0 = ui.getTabBounds(tabbedPane, 0);
51: for (int i = MAX_ENTRIES - 1; i >= 0; i--) {
52: JTabbedPaneLocation loc = new JTabbedPaneLocation(i);
53: try {
54: loc.getPoint(tabbedPane);
55: tester.actionSelectTab(tabbedPane, loc);
56: } catch (LocationUnavailableException e) {
57: if (!Platform.isOSX()) {
58: throw e;
59: }
60: // Select from the popup menu
61: Point where = new Point(tabbedPane.getWidth() - tab0.x
62: - tab0.height / 2, tab0.height / 2);
63: tester.actionClick(tabbedPane, where.x, where.y);
64: JPopupMenu menu = AWT.getActivePopupMenu();
65: Component c = menu.getComponent(i);
66: tester.actionSelectMenuItem(c);
67:
68: }
69: assertStep("SelectTab\\(.*,\"Tab " + i + "\"\\)");
70: }
71: }
72:
73: /*
74: public void testCaptureSelectionBug() {
75: showTabbedPane();
76: startRecording();
77: tester.mouseMove(tabbedPane, 20, 20);
78: tester.delay(1000);
79: tester.mousePress(InputEvent.BUTTON1_MASK);
80: tester.delay(1000);
81: assertStep("SelectTab\\(.*,Tab 4\\)", false);
82: }
83: */
84:
85: public static void main(String[] args) {
86: RepeatHelper.runTests(args, JTabbedPaneRecorderTest.class);
87: }
88: }
|