1
|
|
package abbot.editor.recorder;
|
2
|
|
|
3
|
|
import java.awt.*;
|
4
|
|
import java.awt.event.*;
|
5
|
|
|
6
|
|
import javax.swing.*;
|
7
|
|
import javax.swing.table.JTableHeader;
|
8
|
|
|
9
|
|
import junit.extensions.abbot.*;
|
10
|
|
import junit.extensions.abbot.Timer;
|
11
|
|
|
12
|
|
import abbot.Log;
|
13
|
|
import abbot.Platform;
|
14
|
|
import abbot.script.*;
|
15
|
|
import abbot.tester.*;
|
16
|
|
import abbot.tester.Robot;
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
|
public class CaptureDragDropTest
|
22
|
|
extends AbstractSemanticRecorderFixture {
|
23
|
|
|
24
|
|
|
25
|
5
|
public CaptureDragDropTest(String name) {
|
26
|
5
|
super(name);
|
27
|
|
}
|
28
|
|
|
29
|
34
|
protected SemanticRecorder createSemanticRecorder(Resolver r) {
|
30
|
34
|
return new ComponentRecorder(r);
|
31
|
|
}
|
32
|
|
|
33
|
|
private ComponentTester tester;
|
34
|
5
|
protected void setUp() {
|
35
|
5
|
tester = new ComponentTester();
|
36
|
|
}
|
37
|
|
private Frame frame;
|
38
|
5
|
protected Frame showFrame(Component c) {
|
39
|
5
|
return frame = super.showFrame(c);
|
40
|
|
}
|
41
|
5
|
protected void tearDown() throws Exception {
|
42
|
5
|
if (frame != null) {
|
43
|
|
|
44
|
5
|
Log.log("DnD cleanup");
|
45
|
5
|
tester.click(frame);
|
46
|
5
|
frame = null;
|
47
|
|
}
|
48
|
5
|
tester = null;
|
49
|
|
}
|
50
|
|
|
51
|
|
|
52
|
1
|
public void testCaptureTableHeaderDragDrop() {
|
53
|
|
|
54
|
|
|
55
|
|
|
56
|
1
|
Object[][] values = {
|
57
|
|
{ "green", "ugly" },
|
58
|
|
{ "red", "beautiful" },
|
59
|
|
};
|
60
|
1
|
Object[] names = { "Color", "Type" };
|
61
|
1
|
JTable table = new JTable(values, names);
|
62
|
1
|
showFrame(new JScrollPane(table));
|
63
|
1
|
JTableHeader header = table.getTableHeader();
|
64
|
1
|
startRecording();
|
65
|
1
|
int width = header.getSize().width;
|
66
|
1
|
tester.actionDrag(header, 1, 1);
|
67
|
1
|
assertStep("Drag");
|
68
|
1
|
tester.actionDrop(header, width * 3 / 4, 1);
|
69
|
1
|
assertStep("Drop");
|
70
|
1
|
assertEquals("Column header not moved",
|
71
|
|
1, table.convertColumnIndexToView(0));
|
72
|
|
}
|
73
|
|
|
74
|
|
|
75
|
|
|
76
|
|
|
77
|
|
|
78
|
1
|
public void testCaptureLabelDragDrop() {
|
79
|
1
|
DropLabel drop = new DropLabel("drop");
|
80
|
1
|
DragLabel drag = new DragLabel("drag");
|
81
|
1
|
JPanel pane = new JPanel();
|
82
|
1
|
pane.add(drag);
|
83
|
1
|
pane.add(drop);
|
84
|
1
|
showFrame(pane);
|
85
|
|
|
86
|
1
|
startRecording();
|
87
|
1
|
tester.actionDrag(drag);
|
88
|
1
|
assertStep("Drag\\(DragLabel");
|
89
|
|
|
90
|
1
|
tester.dragOver(pane, pane.getWidth() + 1, pane.getHeight() + 1);
|
91
|
1
|
tester.actionDrop(drop);
|
92
|
1
|
assertStep("Drop\\(DropLabel");
|
93
|
|
}
|
94
|
|
|
95
|
|
|
96
|
1
|
public void testCaptureDragDropToJTree() {
|
97
|
1
|
DragLabel drag = new DragLabel("drag");
|
98
|
1
|
DropTree drop = new DropTree();
|
99
|
1
|
JPanel pane = new JPanel();
|
100
|
1
|
pane.add(drag);
|
101
|
1
|
pane.add(drop);
|
102
|
1
|
showFrame(pane);
|
103
|
1
|
startRecording();
|
104
|
1
|
tester.actionDrag(drag);
|
105
|
1
|
assertStep("Drag\\(DragLabel");
|
106
|
1
|
tester.dragOver(pane, pane.getWidth() + 1, pane.getHeight() + 1);
|
107
|
1
|
tester.actionDrop(drop, new JTreeLocation(2));
|
108
|
1
|
assertStep("Drop\\(DropTree,\"\\[.*\\]\"");
|
109
|
|
}
|
110
|
|
|
111
|
|
|
112
|
1
|
public void testCaptureDragDropToJTable() {
|
113
|
1
|
DragLabel drag = new DragLabel("drag");
|
114
|
1
|
DropTable drop = new DropTable();
|
115
|
1
|
JPanel pane = new JPanel();
|
116
|
1
|
pane.add(drag);
|
117
|
1
|
pane.add(drop);
|
118
|
1
|
showFrame(pane);
|
119
|
1
|
startRecording();
|
120
|
1
|
tester.actionDrag(drag);
|
121
|
1
|
assertStep("Drag\\(DragLabel");
|
122
|
1
|
tester.dragOver(pane, pane.getWidth() + 1, pane.getHeight() + 1);
|
123
|
1
|
tester.actionDrop(drop, new JTableLocation(1, 1));
|
124
|
1
|
assertStep("Drop\\(DropTable,\"" + drop.getValueAt(1, 1) + "\"");
|
125
|
|
}
|
126
|
|
|
127
|
1
|
public void testCaptureNoDrag() {
|
128
|
1
|
JButton button = new JButton(getName());
|
129
|
1
|
showFrame(button);
|
130
|
1
|
startRecording();
|
131
|
1
|
tester.mousePress(button, button.getWidth()/2, button.getHeight()/2);
|
132
|
1
|
tester.mouseMove(button, button.getWidth()/2+4, button.getHeight()/2);
|
133
|
1
|
tester.mouseRelease();
|
134
|
1
|
tester.waitForIdle();
|
135
|
1
|
assertStep("Click");
|
136
|
|
}
|
137
|
|
|
138
|
0
|
public static void main(String[] args) {
|
139
|
0
|
RepeatHelper.runTests(args, CaptureDragDropTest.class);
|
140
|
|
}
|
141
|
|
}
|
142
|
|
|