Skip to content

Commit

Permalink
8317287: [macos14] InterJVMGetDropSuccessTest.java: Child VM: abnorma…
Browse files Browse the repository at this point in the history
…l termination

Reviewed-by: honkar, aivanov, shurailine
  • Loading branch information
songpv-imt committed Jan 18, 2024
1 parent 57fad67 commit cbfddf4
Showing 1 changed file with 66 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -29,16 +29,37 @@
@run main InterJVMGetDropSuccessTest
*/

import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.awt.event.*;
import java.io.*;
import java.awt.AWTEvent;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Point;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceAdapter;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetAdapter;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetListener;
import java.awt.event.AWTEventListener;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.InputStream;

public class InterJVMGetDropSuccessTest {

private int returnCode = Util.CODE_NOT_RETURNED;
private boolean successCodes[] = { true, false };
private final boolean[] successCodes = { true, false };
private int dropCount = 0;

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

try {
Thread.sleep(Util.FRAME_ACTIVATION_TIMEOUT);
Robot robot = new Robot();
robot.waitForIdle();
robot.delay(Util.FRAME_ACTIVATION_TIMEOUT);

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

public static final int FRAME_ACTIVATION_TIMEOUT = 3000;
public static final int FRAME_ACTIVATION_TIMEOUT = 1000;

static final Object SYNC_LOCK = new Object();
static final int MOUSE_RELEASE_TIMEOUT = 1000;

static final Util theInstance = new Util();

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

private Component clickedComponent = null;

private void reset() {
clickedComponent = null;
}

public void eventDispatched(AWTEvent e) {
if (e.getID() == MouseEvent.MOUSE_RELEASED) {
clickedComponent = (Component)e.getSource();
synchronized (SYNC_LOCK) {
SYNC_LOCK.notifyAll();
}
}
}

public static boolean pointInComponent(Robot robot, Point p, Component comp)
throws InterruptedException {
return theInstance.pointInComponentImpl(robot, p, comp);
}

private boolean pointInComponentImpl(Robot robot, Point p, Component comp)
throws InterruptedException {
robot.waitForIdle();
reset();
robot.mouseMove(p.x, p.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
synchronized (SYNC_LOCK) {
robot.mouseRelease(InputEvent.BUTTON1_MASK);
SYNC_LOCK.wait(MOUSE_RELEASE_TIMEOUT);
}

Component c = clickedComponent;

while (c != null && c != comp) {
c = c.getParent();
}

return c == comp;
}
}

class Child {
Expand Down Expand Up @@ -226,6 +216,9 @@ public void dragDropEnd(DragSourceDropEvent dsde) {
}
}

private volatile boolean success1 = false;
private volatile boolean success2 = false;

final Frame frame = new Frame("Source Frame");
final DragSource dragSource = DragSource.getDefaultDragSource();
final DragSourceDropListener dragSourceListener = new DragSourceDropListener();
Expand Down Expand Up @@ -258,53 +251,62 @@ public void run(String[] args) {
frame.setBounds(300, 200, 150, 150);
frame.setVisible(true);

Thread.sleep(Util.FRAME_ACTIVATION_TIMEOUT);
Robot robot = new Robot();
robot.waitForIdle();
robot.delay(Util.FRAME_ACTIVATION_TIMEOUT);

Point sourcePoint = Util.getCenterLocationOnScreen(frame);

Point targetPoint = new Point(x + w / 2, y + h / 2);

Robot robot = new Robot();
robot.mouseMove(sourcePoint.x, sourcePoint.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.waitForIdle();
robot.delay(50);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
for (Point p = new Point(sourcePoint); !p.equals(targetPoint);
p.translate(Util.sign(targetPoint.x - p.x),
Util.sign(targetPoint.y - p.y))) {
p.translate(Util.sign(targetPoint.x - p.x),
Util.sign(targetPoint.y - p.y))) {
robot.mouseMove(p.x, p.y);
Thread.sleep(50);
robot.delay(5);
}

synchronized (Util.SYNC_LOCK) {
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
Util.SYNC_LOCK.wait(Util.FRAME_ACTIVATION_TIMEOUT);
}

if (!dragSourceListener.isDropFinished()) {
throw new RuntimeException("Drop not finished");
}
EventQueue.invokeAndWait(() -> {
if (!dragSourceListener.isDropFinished()) {
throw new RuntimeException("Drop not finished");
}
success1 = dragSourceListener.getDropSuccess();
dragSourceListener.reset();
});

boolean success1 = dragSourceListener.getDropSuccess();

dragSourceListener.reset();
robot.mouseMove(sourcePoint.x, sourcePoint.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.waitForIdle();
robot.delay(50);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
for (Point p = new Point(sourcePoint); !p.equals(targetPoint);
p.translate(Util.sign(targetPoint.x - p.x),
Util.sign(targetPoint.y - p.y))) {
p.translate(Util.sign(targetPoint.x - p.x),
Util.sign(targetPoint.y - p.y))) {
robot.mouseMove(p.x, p.y);
Thread.sleep(50);
robot.delay(5);
}

synchronized (Util.SYNC_LOCK) {
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
Util.SYNC_LOCK.wait(Util.FRAME_ACTIVATION_TIMEOUT);
}

if (!dragSourceListener.isDropFinished()) {
throw new RuntimeException("Drop not finished");
}
EventQueue.invokeAndWait(() -> {
if (!dragSourceListener.isDropFinished()) {
throw new RuntimeException("Drop not finished");
}
success2 = dragSourceListener.getDropSuccess();
dragSourceListener.reset();
});

boolean success2 = dragSourceListener.getDropSuccess();
int retCode = 0;

if (success1) {
Expand Down

0 comments on commit cbfddf4

Please sign in to comment.