Skip to content

Commit

Permalink
JBR-5579 Update mouse location checks, set window always on top for A…
Browse files Browse the repository at this point in the history
…ctionListenerTest
  • Loading branch information
Sergey Shelomentsev committed May 29, 2023
1 parent 7b2806d commit c229e13
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions test/jdk/jb/java/awt/CustomTitleBar/ActionListenerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
*/

import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TaskResult;
import util.TestUtils;
import util.*;

import javax.swing.*;
import java.awt.*;
Expand Down Expand Up @@ -85,11 +82,12 @@ public void customizeWindow() {
actionListenerGotEvent = true;
});
window.add(button);
window.setAlwaysOnTop(true);
}

@Override
public void test() throws AWTException {
doClick(button.getLocationOnScreen(), button.getWidth(), button.getHeight());
doClick(window, button.getLocationOnScreen(), button.getWidth(), button.getHeight());

if (!actionListenerGotEvent) {
err("button didn't get event by action listener");
Expand Down Expand Up @@ -121,34 +119,32 @@ public void customizeWindow() {
actionListenerGotEvent = true;
});
window.add(button);
window.setAlwaysOnTop(true);
}

@Override
public void test() throws AWTException {
doClick(button.getLocationOnScreen(), button.getWidth(), button.getHeight());
doClick(window, button.getLocationOnScreen(), button.getWidth(), button.getHeight());

if (!actionListenerGotEvent) {
err("button didn't get event by action listener");
}
}
};

private static void doClick(Point location, int w, int h) throws AWTException {
private static void doClick(Window window, Point location, int w, int h) throws AWTException {
Robot robot = new Robot();
robot.waitForIdle();
int x = location.x + w / 2;
int y = location.y + h / 2;
System.out.println("Click at (" + x + ", " + y + ")");
robot.mouseMove(x, y);
robot.waitForIdle();
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

MouseUtils.verifyLocationAndMove(robot, window, x, y);
MouseUtils.verifyLocationAndClick(robot, window, x, y, InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
MouseUtils.verifyLocationAndClick(robot, window, x, y, InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
MouseUtils.verifyLocationAndClick(robot, window, x, y, InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();
}

Expand Down

0 comments on commit c229e13

Please sign in to comment.