Skip to content

Commit abda9d8

Browse files
Taizo KurashigePaul Hohensee
authored andcommitted
8274597: Some of the dnd tests time out and fail intermittently
8028998: [TEST_BUG] [macosx] java/awt/dnd/DropTargetEnterExitTest/MissedDragExitTest.java failed Reviewed-by: phh Backport-of: 669ac611b269bbda5c53d84173e5c9d0eb4ce919
1 parent b4aa221 commit abda9d8

File tree

4 files changed

+147
-52
lines changed

4 files changed

+147
-52
lines changed

jdk/test/java/awt/dnd/AcceptDropMultipleTimes/AcceptDropMultipleTimes.java

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,44 @@
3434

3535
import test.java.awt.regtesthelpers.Util;
3636

37-
import javax.swing.*;
38-
import java.awt.*;
39-
import java.awt.datatransfer.*;
40-
import java.awt.dnd.*;
37+
import java.awt.Color;
38+
import java.awt.Cursor;
39+
import java.awt.Dimension;
40+
import java.awt.Frame;
41+
import java.awt.Panel;
42+
import java.awt.Point;
43+
import java.awt.Rectangle;
44+
import java.awt.Robot;
45+
import java.awt.Toolkit;
46+
import java.awt.datatransfer.StringSelection;
47+
import java.awt.dnd.DnDConstants;
48+
import java.awt.dnd.DragGestureEvent;
49+
import java.awt.dnd.DragGestureListener;
50+
import java.awt.dnd.DragSource;
51+
import java.awt.dnd.DropTarget;
52+
import java.awt.dnd.DropTargetAdapter;
53+
import java.awt.dnd.DropTargetDropEvent;
4154
import java.awt.event.InputEvent;
55+
import java.io.File;
56+
import java.io.IOException;
57+
import java.util.concurrent.CountDownLatch;
58+
import java.util.concurrent.TimeUnit;
59+
import java.util.concurrent.atomic.AtomicReference;
60+
import javax.imageio.ImageIO;
61+
import javax.swing.SwingUtilities;
4262

4363
public class AcceptDropMultipleTimes {
4464

4565
private static final int FRAME_SIZE = 100;
46-
private static final int FRAME_LOCATION = 100;
66+
private static CountDownLatch dropCompleteLatch = new CountDownLatch(1);
4767

4868
private static volatile Frame f;
4969

5070
private static void initAndShowUI() {
5171
f = new Frame("Test frame");
52-
f.setBounds(FRAME_LOCATION, FRAME_LOCATION, FRAME_SIZE, FRAME_SIZE);
72+
f.setSize(FRAME_SIZE, FRAME_SIZE);
73+
f.setLocationRelativeTo(null);
74+
f.setUndecorated(true);
5375

5476
final DraggablePanel dragSource = new DraggablePanel();
5577
dragSource.setBackground(Color.yellow);
@@ -62,11 +84,12 @@ private static void initAndShowUI() {
6284
dtde.acceptDrop(DnDConstants.ACTION_MOVE);
6385

6486
dtde.dropComplete(true);
87+
dropCompleteLatch.countDown();
6588
}
6689
});
6790
dragSource.setDropTarget(dt);
6891
f.add(dragSource);
69-
92+
f.setAlwaysOnTop(true);
7093
f.setVisible(true);
7194
}
7295

@@ -76,19 +99,37 @@ public static void main(String[] args) throws Throwable {
7699
SwingUtilities.invokeAndWait(() -> initAndShowUI());
77100

78101
Robot r = new Robot();
102+
r.setAutoDelay(50);
79103
Util.waitForIdle(r);
104+
final AtomicReference<Point> frameLoc = new AtomicReference<>();
105+
SwingUtilities.invokeAndWait(() -> frameLoc.set(f.getLocationOnScreen()));
106+
Point loc = frameLoc.get();
80107
Util.drag(r,
81-
new Point(FRAME_LOCATION + FRAME_SIZE / 3, FRAME_LOCATION + FRAME_SIZE / 3),
82-
new Point(FRAME_LOCATION + FRAME_SIZE / 3 * 2, FRAME_LOCATION + FRAME_SIZE / 3 * 2),
83-
InputEvent.BUTTON1_MASK);
108+
new Point(loc.x + FRAME_SIZE / 3, loc.y + FRAME_SIZE / 3),
109+
new Point(loc.x + FRAME_SIZE / 3 * 2, loc.y + FRAME_SIZE / 3 * 2),
110+
InputEvent.BUTTON1_DOWN_MASK);
84111
Util.waitForIdle(r);
112+
if(!dropCompleteLatch.await(10, TimeUnit.SECONDS)) {
113+
captureScreen(r);
114+
throw new RuntimeException("Waited too long, but the drop is not completed");
115+
}
85116
} finally {
86117
if (f != null) {
87118
f.dispose();
88119
}
89120
}
90121
}
91-
122+
private static void captureScreen(Robot r) {
123+
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
124+
try {
125+
ImageIO.write(
126+
r.createScreenCapture(new Rectangle(0, 0, screenSize.width, screenSize.height)),
127+
"png",
128+
new File("FailedScreenImage.png")
129+
);
130+
} catch (IOException ignore) {
131+
}
132+
}
92133
private static class DraggablePanel extends Panel implements DragGestureListener {
93134

94135
public DraggablePanel() {

jdk/test/java/awt/dnd/DropTargetEnterExitTest/ExtraDragEnterTest.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@
3434

3535
import test.java.awt.regtesthelpers.Util;
3636

37-
import javax.swing.*;
38-
import java.awt.*;
37+
import java.awt.Color;
38+
import java.awt.Cursor;
39+
import java.awt.Frame;
40+
import java.awt.GridLayout;
41+
import java.awt.Panel;
42+
import java.awt.Point;
43+
import java.awt.Robot;
3944
import java.awt.datatransfer.StringSelection;
4045
import java.awt.dnd.DnDConstants;
4146
import java.awt.dnd.DragGestureEvent;
@@ -46,23 +51,27 @@
4651
import java.awt.dnd.DropTargetDragEvent;
4752
import java.awt.dnd.DropTargetDropEvent;
4853
import java.awt.event.InputEvent;
54+
import java.util.concurrent.CountDownLatch;
55+
import java.util.concurrent.TimeUnit;
4956
import java.util.concurrent.atomic.AtomicInteger;
57+
import javax.swing.SwingUtilities;
5058

5159
public class ExtraDragEnterTest {
5260

5361
private static final int FRAME_SIZE = 100;
54-
private static final int FRAME_LOCATION = 100;
5562

5663
private static AtomicInteger dragEnterCalled = new AtomicInteger(0);
5764

5865
private static volatile Panel mainPanel;
5966
private static volatile Frame f;
67+
private static CountDownLatch dropCompleteLatch = new CountDownLatch(1);
6068

6169
private static void initAndShowUI() {
6270
f = new Frame("Test frame");
63-
f.setBounds(FRAME_LOCATION,FRAME_LOCATION,FRAME_SIZE,FRAME_SIZE);
71+
f.setLocationRelativeTo(null);
72+
f.setSize(FRAME_SIZE,FRAME_SIZE);
6473
mainPanel = new Panel();
65-
mainPanel.setBounds(0, 0, FRAME_SIZE, FRAME_SIZE);
74+
mainPanel.setSize(FRAME_SIZE, FRAME_SIZE);
6675
mainPanel.setBackground(Color.black);
6776
mainPanel.setLayout(new GridLayout(2, 1));
6877

@@ -74,7 +83,10 @@ private static void initAndShowUI() {
7483
Panel dropTarget = new Panel();
7584
dropTarget.setBackground(Color.red);
7685
DropTarget dt = new DropTarget(dropTarget, new DropTargetAdapter() {
77-
@Override public void drop(DropTargetDropEvent dtde) { }
86+
@Override public void drop(DropTargetDropEvent dtde) {
87+
System.out.println("Drop complete");
88+
dropCompleteLatch.countDown();
89+
}
7890

7991
@Override
8092
public void dragEnter(DropTargetDragEvent dtde) {
@@ -85,6 +97,7 @@ public void dragEnter(DropTargetDragEvent dtde) {
8597
mainPanel.add(dropTarget);
8698

8799
f.add(mainPanel);
100+
f.setAlwaysOnTop(true);
88101
f.setVisible(true);
89102
}
90103

@@ -112,6 +125,9 @@ public void run() {
112125
if (called != 1) {
113126
throw new RuntimeException("Failed. Drag enter called " + called + " times. Expected 1" );
114127
}
128+
if(!dropCompleteLatch.await(10, TimeUnit.SECONDS)) {
129+
throw new RuntimeException("Waited too long, but the drop is not completed");
130+
}
115131
} finally {
116132
if (f != null) {
117133
f.dispose();

jdk/test/java/awt/dnd/DropTargetEnterExitTest/MissedDragExitTest.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@
3434

3535
import test.java.awt.regtesthelpers.Util;
3636

37-
import javax.swing.*;
38-
import java.awt.*;
37+
import java.awt.Color;
38+
import java.awt.Cursor;
39+
import java.awt.Frame;
40+
import java.awt.Panel;
41+
import java.awt.Point;
42+
import java.awt.Robot;
3943
import java.awt.datatransfer.StringSelection;
4044
import java.awt.dnd.DnDConstants;
4145
import java.awt.dnd.DragGestureEvent;
@@ -47,15 +51,17 @@
4751
import java.awt.dnd.DropTargetDropEvent;
4852
import java.awt.dnd.DropTargetEvent;
4953
import java.awt.event.InputEvent;
54+
import java.util.concurrent.CountDownLatch;
55+
import java.util.concurrent.TimeUnit;
56+
import javax.swing.SwingUtilities;
5057

5158
public class MissedDragExitTest {
5259

5360
private static final int FRAME_SIZE = 100;
5461
private static final int FRAME_LOCATION = 100;
5562

56-
private static volatile boolean dragExitCalled = false;
57-
5863
private static volatile Frame f;
64+
private static CountDownLatch dragLatch = new CountDownLatch(2);
5965

6066
private static void initAndShowUI() {
6167
f = new Frame("Test frame");
@@ -69,21 +75,30 @@ private static void initAndShowUI() {
6975

7076
@Override
7177
public void dragExit(DropTargetEvent dte) {
72-
dragExitCalled = true;
78+
System.out.println("Drag Exit");
79+
dragLatch.countDown();
7380
}
7481

7582
@Override
7683
public void dragOver(DropTargetDragEvent dtde) {
77-
Panel newDropTarget = new Panel();
78-
newDropTarget.setDropTarget(new DropTarget());
79-
newDropTarget.setBackground(Color.red);
80-
newDropTarget.setBounds(0, 0, FRAME_SIZE, FRAME_SIZE);
81-
dragSource.add(newDropTarget);
84+
Panel newDropTargetPanel = new Panel();
85+
final DropTarget dropTarget = new DropTarget(null,new DropTargetAdapter() {
86+
@Override
87+
public void drop(DropTargetDropEvent dtde) {
88+
System.out.println("Drop complete");
89+
dragLatch.countDown();
90+
}
91+
});
92+
newDropTargetPanel.setDropTarget(dropTarget);
93+
newDropTargetPanel.setBackground(Color.red);
94+
newDropTargetPanel.setSize(FRAME_SIZE, FRAME_SIZE);
95+
dragSource.add(newDropTargetPanel);
8296
}
8397
});
8498
dragSource.setDropTarget(dt);
8599
f.add(dragSource);
86100

101+
f.setAlwaysOnTop(true);
87102
f.setVisible(true);
88103
}
89104

@@ -104,8 +119,7 @@ public void run() {
104119
new Point(FRAME_LOCATION + FRAME_SIZE / 3 * 2, FRAME_LOCATION + FRAME_SIZE / 3 * 2),
105120
InputEvent.BUTTON1_DOWN_MASK);
106121
Util.waitForIdle(r);
107-
108-
if (!dragExitCalled) {
122+
if(!dragLatch.await(10, TimeUnit.SECONDS)) {
109123
throw new RuntimeException("Failed. Drag exit was not called" );
110124
}
111125
} finally {

0 commit comments

Comments
 (0)