001: package abbot.editor.recorder;
002:
003: import java.awt.*;
004: import java.awt.event.*;
005: import java.util.Vector;
006:
007: import javax.swing.*;
008:
009: import junit.extensions.abbot.RepeatHelper;
010: import abbot.script.Resolver;
011: import abbot.tester.*;
012: import abbot.util.AWT;
013:
014: /**
015: * Unit test to verify proper capture of user semantic events on a JComboBox.
016: */
017: public class JComboBoxRecorderTest extends
018: AbstractSemanticRecorderFixture {
019:
020: private Frame frame;
021: private JComboBoxTester tester;
022: private JComboBox combo;
023: private static final int MAX_ENTRIES = 20;
024:
025: // FIXME sporadic failure on linux 1.4.1_02
026: public void testCaptureMousePressDragReleaseSelect() {
027: showComboBox();
028:
029: startRecording();
030: tester.drag(combo, combo.getWidth() / 2, combo.getHeight() / 2);
031: tester.waitForIdle();
032:
033: // FIXME this is just an estimate of the right position
034: tester.drop(combo, combo.getWidth() / 2,
035: combo.getHeight() * 3 / 2);
036: tester.waitForIdle();
037: assertStep("SelectItem\\(.*,item 1\\)");
038: }
039:
040: public void testCaptureClickMoveClickSelection() {
041: showComboBox();
042: startRecording();
043: tester.actionSelectIndex(combo, MAX_ENTRIES - 1);
044: assertStep("SelectItem(.*,item " + (MAX_ENTRIES - 1) + ")");
045: tester.actionSelectIndex(combo, MAX_ENTRIES / 2 - 1);
046: assertStep("SelectItem(.*,item " + (MAX_ENTRIES / 2 - 1) + ")");
047: tester.actionSelectIndex(combo, 0);
048: assertStep("SelectItem(.*,item 0)");
049: }
050:
051: public void testCaptureCanceledSelection() {
052: showComboBox();
053: startRecording();
054: tester.actionClick(combo);
055: tester.actionKeyStroke(KeyEvent.VK_ESCAPE);
056: assertNoStep();
057: }
058:
059: public void testCaptureSelectionWithExtraEvents() {
060: showComboBox();
061: startRecording();
062: tester.actionClick(combo);
063: Component popup = AWT.findActivePopupMenu();
064: assertNotNull(
065: "Combo should have an associated popup when active",
066: popup);
067: // FIXME need to add some intervening events
068: }
069:
070: public void testCaptureClickCancelSelection() {
071: showComboBox();
072: startRecording();
073: tester.actionClick(combo);
074: JPanel pane = (JPanel) ((JFrame) frame).getContentPane();
075: tester.actionClick(pane, 1, 1);
076: assertNoStep();
077: }
078:
079: public JComboBoxRecorderTest(String name) {
080: super (name);
081: }
082:
083: protected SemanticRecorder createSemanticRecorder(Resolver r) {
084: return new JComboBoxRecorder(r);
085: }
086:
087: private void showComboBox() {
088: Vector list = new Vector();
089: for (int i = 0; i < MAX_ENTRIES; i++) {
090: list.add("item " + i);
091: }
092: combo = new JComboBox(list);
093: tester = (JComboBoxTester) ComponentTester.getTester(combo);
094: frame = showFrame(combo);
095: }
096:
097: public static void main(String[] args) {
098: RepeatHelper.runTests(args, JComboBoxRecorderTest.class);
099: }
100: }
|