001: package abbot.editor.recorder;
002:
003: import java.awt.*;
004: import javax.swing.*;
005: import javax.swing.table.JTableHeader;
006:
007: import junit.extensions.abbot.*;
008: import abbot.Log;
009: import abbot.script.*;
010: import abbot.tester.*;
011:
012: /**
013: * Verify capture of various Drag/Drop operations.
014: */
015: public class CaptureDragDropTest extends
016: AbstractSemanticRecorderFixture {
017:
018: /** Create a new test case with the given name. */
019: public CaptureDragDropTest(String name) {
020: super (name);
021: }
022:
023: protected SemanticRecorder createSemanticRecorder(Resolver r) {
024: return new ComponentRecorder(r);
025: }
026:
027: private ComponentTester tester;
028:
029: protected void setUp() {
030: tester = new ComponentTester();
031: }
032:
033: private Frame frame;
034:
035: protected Frame showFrame(Component c) {
036: return frame = super .showFrame(c);
037: }
038:
039: protected void tearDown() throws Exception {
040: if (frame != null) {
041: // ensure DnD state gets reset
042: Log.log("DnD cleanup");
043: tester.click(frame);
044: frame = null;
045: }
046: tester = null;
047: }
048:
049: // FIXME sporadic linux failure (misses release)
050: public void testCaptureTableHeaderDragDrop() {
051: // Use a table with draggable headers as a default drag & drop test
052: // Drag the first column header over the second and verify they
053: // switched positions
054: Object[][] values = { { "green", "ugly" },
055: { "red", "beautiful" }, };
056: Object[] names = { "Color", "Type" };
057: JTable table = new JTable(values, names);
058: showFrame(new JScrollPane(table));
059: JTableHeader header = table.getTableHeader();
060: startRecording();
061: int width = header.getWidth();
062: int height = header.getHeight();
063: tester.actionDrag(header, width / 4, height / 2);
064: assertStep("Drag");
065: tester.actionDrop(header, width * 3 / 4, height / 2);
066: assertStep("Drop");
067: assertEquals("Column header not moved", 1, table
068: .convertColumnIndexToView(0));
069: }
070:
071: // This fails on 1.3, because we can't determine the drop location
072: public void testCaptureLabelDragDrop() {
073: DropLabel drop = new DropLabel("drop");
074: DragLabel drag = new DragLabel("drag");
075: JPanel pane = new JPanel();
076: pane.add(drag);
077: pane.add(drop);
078: showFrame(pane);
079:
080: startRecording();
081: tester.actionDrag(drag);
082: assertStep("Drag\\(DragLabel");
083: // ensure we ignore enter/exit events by dragging outside the pane
084: tester
085: .dragOver(pane, pane.getWidth() + 1,
086: pane.getHeight() + 1);
087: tester.actionDrop(drop);
088: assertStep("Drop\\(DropLabel");
089: }
090:
091: public void testCaptureDragDropToJTree() {
092: DragLabel drag = new DragLabel("drag");
093: DropTree drop = new DropTree();
094: JPanel pane = new JPanel();
095: pane.add(drag);
096: pane.add(drop);
097: showFrame(pane);
098: startRecording();
099: tester.actionDrag(drag);
100: assertStep("Drag\\(DragLabel");
101: tester
102: .dragOver(pane, pane.getWidth() + 1,
103: pane.getHeight() + 1);
104: tester.actionDrop(drop, new JTreeLocation(2));
105: assertStep("Drop\\(DropTree,\"\\[.*\\]\"");
106: }
107:
108: public void testCaptureDragDropToJTable() {
109: DragLabel drag = new DragLabel("drag");
110: DropTable drop = new DropTable();
111: JPanel pane = new JPanel();
112: pane.add(drag);
113: pane.add(drop);
114: showFrame(pane);
115: startRecording();
116: tester.actionDrag(drag);
117: assertStep("Drag\\(DragLabel");
118: tester
119: .dragOver(pane, pane.getWidth() + 1,
120: pane.getHeight() + 1);
121: tester.actionDrop(drop, new JTableLocation(1, 1));
122: assertStep("Drop\\(DropTable,\"" + drop.getValueAt(1, 1) + "\"");
123: }
124:
125: public void testCaptureNoDrag() {
126: JButton button = new JButton(getName());
127: showFrame(button);
128: startRecording();
129: tester.mousePress(button, button.getWidth() / 2, button
130: .getHeight() / 2);
131: tester.mouseMove(button, button.getWidth() / 2 + 4, button
132: .getHeight() / 2);
133: tester.mouseRelease();
134: tester.waitForIdle();
135: assertStep("Click");
136: }
137:
138: public static void main(String[] args) {
139: RepeatHelper.runTests(args, CaptureDragDropTest.class);
140: }
141: }
|