Skip to content
Permalink
Browse files
8274597: Some of the dnd tests time out and fail intermittently
8028998: [TEST_BUG] [macosx] java/awt/dnd/DropTargetEnterExitTest/MissedDragExitTest.java failed

Reviewed-by: serb
  • Loading branch information
Manukumar V S authored and Abdul Kolarkunnu committed Apr 29, 2022
1 parent 269eae6 commit 669ac611b269bbda5c53d84173e5c9d0eb4ce919
Showing 4 changed files with 147 additions and 52 deletions.
@@ -35,22 +35,44 @@

import test.java.awt.regtesthelpers.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetAdapter;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.event.InputEvent;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.imageio.ImageIO;
import javax.swing.SwingUtilities;

public class AcceptDropMultipleTimes {

private static final int FRAME_SIZE = 100;
private static final int FRAME_LOCATION = 100;
private static CountDownLatch dropCompleteLatch = new CountDownLatch(1);

private static volatile Frame f;

private static void initAndShowUI() {
f = new Frame("Test frame");
f.setBounds(FRAME_LOCATION, FRAME_LOCATION, FRAME_SIZE, FRAME_SIZE);
f.setSize(FRAME_SIZE, FRAME_SIZE);
f.setLocationRelativeTo(null);
f.setUndecorated(true);

final DraggablePanel dragSource = new DraggablePanel();
dragSource.setBackground(Color.yellow);
@@ -63,11 +85,12 @@ private static void initAndShowUI() {
dtde.acceptDrop(DnDConstants.ACTION_MOVE);

dtde.dropComplete(true);
dropCompleteLatch.countDown();
}
});
dragSource.setDropTarget(dt);
f.add(dragSource);

f.setAlwaysOnTop(true);
f.setVisible(true);
}

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

Robot r = new Robot();
r.setAutoDelay(50);
Util.waitForIdle(r);
final AtomicReference<Point> frameLoc = new AtomicReference<>();
SwingUtilities.invokeAndWait(() -> frameLoc.set(f.getLocationOnScreen()));
Point loc = frameLoc.get();
Util.drag(r,
new Point(FRAME_LOCATION + FRAME_SIZE / 3, FRAME_LOCATION + FRAME_SIZE / 3),
new Point(FRAME_LOCATION + FRAME_SIZE / 3 * 2, FRAME_LOCATION + FRAME_SIZE / 3 * 2),
InputEvent.BUTTON1_MASK);
new Point(loc.x + FRAME_SIZE / 3, loc.y + FRAME_SIZE / 3),
new Point(loc.x + FRAME_SIZE / 3 * 2, loc.y + FRAME_SIZE / 3 * 2),
InputEvent.BUTTON1_DOWN_MASK);
Util.waitForIdle(r);
if(!dropCompleteLatch.await(10, TimeUnit.SECONDS)) {
captureScreen(r);
throw new RuntimeException("Waited too long, but the drop is not completed");
}
} finally {
if (f != null) {
f.dispose();
}
}
}

private static void captureScreen(Robot r) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
try {
ImageIO.write(
r.createScreenCapture(new Rectangle(0, 0, screenSize.width, screenSize.height)),
"png",
new File("FailedScreenImage.png")
);
} catch (IOException ignore) {
}
}
private static class DraggablePanel extends Panel implements DragGestureListener {

public DraggablePanel() {
@@ -35,8 +35,13 @@

import test.java.awt.regtesthelpers.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Robot;
import java.awt.datatransfer.StringSelection;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
@@ -47,23 +52,27 @@
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.event.InputEvent;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.SwingUtilities;

public class ExtraDragEnterTest {

private static final int FRAME_SIZE = 100;
private static final int FRAME_LOCATION = 100;

private static AtomicInteger dragEnterCalled = new AtomicInteger(0);

private static volatile Panel mainPanel;
private static volatile Frame f;
private static CountDownLatch dropCompleteLatch = new CountDownLatch(1);

private static void initAndShowUI() {
f = new Frame("Test frame");
f.setBounds(FRAME_LOCATION,FRAME_LOCATION,FRAME_SIZE,FRAME_SIZE);
f.setLocationRelativeTo(null);
f.setSize(FRAME_SIZE,FRAME_SIZE);
mainPanel = new Panel();
mainPanel.setBounds(0, 0, FRAME_SIZE, FRAME_SIZE);
mainPanel.setSize(FRAME_SIZE, FRAME_SIZE);
mainPanel.setBackground(Color.black);
mainPanel.setLayout(new GridLayout(2, 1));

@@ -75,7 +84,10 @@ private static void initAndShowUI() {
Panel dropTarget = new Panel();
dropTarget.setBackground(Color.red);
DropTarget dt = new DropTarget(dropTarget, new DropTargetAdapter() {
@Override public void drop(DropTargetDropEvent dtde) { }
@Override public void drop(DropTargetDropEvent dtde) {
System.out.println("Drop complete");
dropCompleteLatch.countDown();
}

@Override
public void dragEnter(DropTargetDragEvent dtde) {
@@ -86,6 +98,7 @@ public void dragEnter(DropTargetDragEvent dtde) {
mainPanel.add(dropTarget);

f.add(mainPanel);
f.setAlwaysOnTop(true);
f.setVisible(true);
}

@@ -113,6 +126,9 @@ public void run() {
if (called != 1) {
throw new RuntimeException("Failed. Drag enter called " + called + " times. Expected 1" );
}
if(!dropCompleteLatch.await(10, TimeUnit.SECONDS)) {
throw new RuntimeException("Waited too long, but the drop is not completed");
}
} finally {
if (f != null) {
f.dispose();
@@ -35,8 +35,12 @@

import test.java.awt.regtesthelpers.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Robot;
import java.awt.datatransfer.StringSelection;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
@@ -48,15 +52,17 @@
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.event.InputEvent;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.swing.SwingUtilities;

public class MissedDragExitTest {

private static final int FRAME_SIZE = 100;
private static final int FRAME_LOCATION = 100;

private static volatile boolean dragExitCalled = false;

private static volatile Frame f;
private static CountDownLatch dragLatch = new CountDownLatch(2);

private static void initAndShowUI() {
f = new Frame("Test frame");
@@ -70,21 +76,30 @@ private static void initAndShowUI() {

@Override
public void dragExit(DropTargetEvent dte) {
dragExitCalled = true;
System.out.println("Drag Exit");
dragLatch.countDown();
}

@Override
public void dragOver(DropTargetDragEvent dtde) {
Panel newDropTarget = new Panel();
newDropTarget.setDropTarget(new DropTarget());
newDropTarget.setBackground(Color.red);
newDropTarget.setBounds(0, 0, FRAME_SIZE, FRAME_SIZE);
dragSource.add(newDropTarget);
Panel newDropTargetPanel = new Panel();
final DropTarget dropTarget = new DropTarget(null,new DropTargetAdapter() {
@Override
public void drop(DropTargetDropEvent dtde) {
System.out.println("Drop complete");
dragLatch.countDown();
}
});
newDropTargetPanel.setDropTarget(dropTarget);
newDropTargetPanel.setBackground(Color.red);
newDropTargetPanel.setSize(FRAME_SIZE, FRAME_SIZE);
dragSource.add(newDropTargetPanel);
}
});
dragSource.setDropTarget(dt);
f.add(dragSource);

f.setAlwaysOnTop(true);
f.setVisible(true);
}

@@ -105,8 +120,7 @@ public void run() {
new Point(FRAME_LOCATION + FRAME_SIZE / 3 * 2, FRAME_LOCATION + FRAME_SIZE / 3 * 2),
InputEvent.BUTTON1_DOWN_MASK);
Util.waitForIdle(r);

if (!dragExitCalled) {
if(!dragLatch.await(10, TimeUnit.SECONDS)) {
throw new RuntimeException("Failed. Drag exit was not called" );
}
} finally {

3 comments on commit 669ac61

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 669ac61 Apr 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 669ac61 Jun 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 669ac61 Jun 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch GoeLin-backport-669ac611 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 669ac611 from the openjdk/jdk repository.

The commit being backported was authored by Manukumar V S on 29 Apr 2022 and was reviewed by Sergey Bylokhov.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-669ac611:GoeLin-backport-669ac611
$ git checkout GoeLin-backport-669ac611
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-669ac611

Please sign in to comment.