Skip to content

Commit cbfddf4

Browse files
committed
8317287: [macos14] InterJVMGetDropSuccessTest.java: Child VM: abnormal termination
Reviewed-by: honkar, aivanov, shurailine
1 parent 57fad67 commit cbfddf4

File tree

1 file changed

+66
-64
lines changed

1 file changed

+66
-64
lines changed

test/jdk/java/awt/dnd/InterJVMGetDropSuccessTest/InterJVMGetDropSuccessTest.java

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,16 +29,37 @@
2929
@run main InterJVMGetDropSuccessTest
3030
*/
3131

32-
import java.awt.*;
33-
import java.awt.datatransfer.*;
34-
import java.awt.dnd.*;
35-
import java.awt.event.*;
36-
import java.io.*;
32+
import java.awt.AWTEvent;
33+
import java.awt.Component;
34+
import java.awt.Dimension;
35+
import java.awt.EventQueue;
36+
import java.awt.Frame;
37+
import java.awt.Point;
38+
import java.awt.Robot;
39+
import java.awt.Toolkit;
40+
import java.awt.datatransfer.StringSelection;
41+
import java.awt.datatransfer.Transferable;
42+
import java.awt.dnd.DnDConstants;
43+
import java.awt.dnd.DragGestureEvent;
44+
import java.awt.dnd.DragGestureListener;
45+
import java.awt.dnd.DragGestureRecognizer;
46+
import java.awt.dnd.DragSource;
47+
import java.awt.dnd.DragSourceAdapter;
48+
import java.awt.dnd.DragSourceDropEvent;
49+
import java.awt.dnd.DropTarget;
50+
import java.awt.dnd.DropTargetAdapter;
51+
import java.awt.dnd.DropTargetDropEvent;
52+
import java.awt.dnd.DropTargetListener;
53+
import java.awt.event.AWTEventListener;
54+
import java.awt.event.InputEvent;
55+
import java.awt.event.MouseEvent;
56+
import java.io.File;
57+
import java.io.InputStream;
3758

3859
public class InterJVMGetDropSuccessTest {
3960

4061
private int returnCode = Util.CODE_NOT_RETURNED;
41-
private boolean successCodes[] = { true, false };
62+
private final boolean[] successCodes = { true, false };
4263
private int dropCount = 0;
4364

4465
final Frame frame = new Frame("Target Frame");
@@ -68,7 +89,9 @@ public void start() {
6889
frame.setVisible(true);
6990

7091
try {
71-
Thread.sleep(Util.FRAME_ACTIVATION_TIMEOUT);
92+
Robot robot = new Robot();
93+
robot.waitForIdle();
94+
robot.delay(Util.FRAME_ACTIVATION_TIMEOUT);
7295

7396
Point p = frame.getLocationOnScreen();
7497
Dimension d = frame.getSize();
@@ -136,10 +159,9 @@ final class Util implements AWTEventListener {
136159
public static final int CODE_SECOND_SUCCESS = 0x2;
137160
public static final int CODE_FAILURE = 0x1;
138161

139-
public static final int FRAME_ACTIVATION_TIMEOUT = 3000;
162+
public static final int FRAME_ACTIVATION_TIMEOUT = 1000;
140163

141164
static final Object SYNC_LOCK = new Object();
142-
static final int MOUSE_RELEASE_TIMEOUT = 1000;
143165

144166
static final Util theInstance = new Util();
145167

@@ -158,45 +180,13 @@ public static int sign(int n) {
158180
return n < 0 ? -1 : n == 0 ? 0 : 1;
159181
}
160182

161-
private Component clickedComponent = null;
162-
163-
private void reset() {
164-
clickedComponent = null;
165-
}
166-
167183
public void eventDispatched(AWTEvent e) {
168184
if (e.getID() == MouseEvent.MOUSE_RELEASED) {
169-
clickedComponent = (Component)e.getSource();
170185
synchronized (SYNC_LOCK) {
171186
SYNC_LOCK.notifyAll();
172187
}
173188
}
174189
}
175-
176-
public static boolean pointInComponent(Robot robot, Point p, Component comp)
177-
throws InterruptedException {
178-
return theInstance.pointInComponentImpl(robot, p, comp);
179-
}
180-
181-
private boolean pointInComponentImpl(Robot robot, Point p, Component comp)
182-
throws InterruptedException {
183-
robot.waitForIdle();
184-
reset();
185-
robot.mouseMove(p.x, p.y);
186-
robot.mousePress(InputEvent.BUTTON1_MASK);
187-
synchronized (SYNC_LOCK) {
188-
robot.mouseRelease(InputEvent.BUTTON1_MASK);
189-
SYNC_LOCK.wait(MOUSE_RELEASE_TIMEOUT);
190-
}
191-
192-
Component c = clickedComponent;
193-
194-
while (c != null && c != comp) {
195-
c = c.getParent();
196-
}
197-
198-
return c == comp;
199-
}
200190
}
201191

202192
class Child {
@@ -226,6 +216,9 @@ public void dragDropEnd(DragSourceDropEvent dsde) {
226216
}
227217
}
228218

219+
private volatile boolean success1 = false;
220+
private volatile boolean success2 = false;
221+
229222
final Frame frame = new Frame("Source Frame");
230223
final DragSource dragSource = DragSource.getDefaultDragSource();
231224
final DragSourceDropListener dragSourceListener = new DragSourceDropListener();
@@ -258,53 +251,62 @@ public void run(String[] args) {
258251
frame.setBounds(300, 200, 150, 150);
259252
frame.setVisible(true);
260253

261-
Thread.sleep(Util.FRAME_ACTIVATION_TIMEOUT);
254+
Robot robot = new Robot();
255+
robot.waitForIdle();
256+
robot.delay(Util.FRAME_ACTIVATION_TIMEOUT);
262257

263258
Point sourcePoint = Util.getCenterLocationOnScreen(frame);
264-
265259
Point targetPoint = new Point(x + w / 2, y + h / 2);
266260

267-
Robot robot = new Robot();
268261
robot.mouseMove(sourcePoint.x, sourcePoint.y);
269-
robot.mousePress(InputEvent.BUTTON1_MASK);
262+
robot.waitForIdle();
263+
robot.delay(50);
264+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
270265
for (Point p = new Point(sourcePoint); !p.equals(targetPoint);
271-
p.translate(Util.sign(targetPoint.x - p.x),
272-
Util.sign(targetPoint.y - p.y))) {
266+
p.translate(Util.sign(targetPoint.x - p.x),
267+
Util.sign(targetPoint.y - p.y))) {
273268
robot.mouseMove(p.x, p.y);
274-
Thread.sleep(50);
269+
robot.delay(5);
275270
}
276271

277272
synchronized (Util.SYNC_LOCK) {
278-
robot.mouseRelease(InputEvent.BUTTON1_MASK);
273+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
279274
Util.SYNC_LOCK.wait(Util.FRAME_ACTIVATION_TIMEOUT);
280275
}
281276

282-
if (!dragSourceListener.isDropFinished()) {
283-
throw new RuntimeException("Drop not finished");
284-
}
277+
EventQueue.invokeAndWait(() -> {
278+
if (!dragSourceListener.isDropFinished()) {
279+
throw new RuntimeException("Drop not finished");
280+
}
281+
success1 = dragSourceListener.getDropSuccess();
282+
dragSourceListener.reset();
283+
});
285284

286-
boolean success1 = dragSourceListener.getDropSuccess();
287285

288-
dragSourceListener.reset();
289286
robot.mouseMove(sourcePoint.x, sourcePoint.y);
290-
robot.mousePress(InputEvent.BUTTON1_MASK);
287+
robot.waitForIdle();
288+
robot.delay(50);
289+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
291290
for (Point p = new Point(sourcePoint); !p.equals(targetPoint);
292-
p.translate(Util.sign(targetPoint.x - p.x),
293-
Util.sign(targetPoint.y - p.y))) {
291+
p.translate(Util.sign(targetPoint.x - p.x),
292+
Util.sign(targetPoint.y - p.y))) {
294293
robot.mouseMove(p.x, p.y);
295-
Thread.sleep(50);
294+
robot.delay(5);
296295
}
297296

298297
synchronized (Util.SYNC_LOCK) {
299-
robot.mouseRelease(InputEvent.BUTTON1_MASK);
298+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
300299
Util.SYNC_LOCK.wait(Util.FRAME_ACTIVATION_TIMEOUT);
301300
}
302301

303-
if (!dragSourceListener.isDropFinished()) {
304-
throw new RuntimeException("Drop not finished");
305-
}
302+
EventQueue.invokeAndWait(() -> {
303+
if (!dragSourceListener.isDropFinished()) {
304+
throw new RuntimeException("Drop not finished");
305+
}
306+
success2 = dragSourceListener.getDropSuccess();
307+
dragSourceListener.reset();
308+
});
306309

307-
boolean success2 = dragSourceListener.getDropSuccess();
308310
int retCode = 0;
309311

310312
if (success1) {

0 commit comments

Comments
 (0)