Skip to content

Commit

Permalink
8168388: GetMousePositionTest fails with the message "Mouse position …
Browse files Browse the repository at this point in the history
…should not be null"

Reviewed-by: psadhukhan, serb
  • Loading branch information
Alexander Zuev committed Oct 21, 2021
1 parent 09f5235 commit 0c3eaea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ java/awt/Mixing/AWT_Mixing/JToggleButtonInGlassPaneOverlapping.java 8158801 wind
java/awt/Mixing/AWT_Mixing/JToggleButtonOverlapping.java 8158801 windows-all
java/awt/Mixing/MixingOnDialog.java 8225777 linux-all
java/awt/Mixing/NonOpaqueInternalFrame.java 7124549 macosx-all
java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java 8168388 linux-all
java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowRetaining.java 6829264 generic-all
java/awt/datatransfer/DragImage/MultiResolutionDragImageTest.java 8080982 generic-all
java/awt/datatransfer/SystemFlavorMap/AddFlavorTest.java 8079268 linux-all
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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 All @@ -25,6 +25,7 @@
import java.awt.Point;
import java.awt.Robot;
import java.awt.Rectangle;
import javax.swing.SwingUtilities;

/*
* @test
Expand All @@ -42,23 +43,21 @@ public class GetMousePositionWithOverlay {

public static void main(String[] args) throws Throwable {
robot = new Robot();
robot.setAutoDelay(100);

try{
constructTestUI();
} catch (Exception e) {
try {
SwingUtilities.invokeAndWait(GetMousePositionWithOverlay::constructTestUI);
doTest();
} finally {
dispose();
throw new RuntimeException("Unexpected Exception!");
}

robot.waitForIdle();

doTest();
dispose();
}

private static void doTest() {

frontFrame.toFront();
private static void doTest() throws Exception {
SwingUtilities.invokeAndWait(() -> frontFrame.toFront());
robot.waitForIdle();

Rectangle bounds = new Rectangle(frontFrame.getLocationOnScreen(), frontFrame.getSize());
Expand All @@ -67,45 +66,44 @@ private static void doTest() {

Point pos = backFrame.getMousePosition();
if (pos != null) {
dispose();
throw new RuntimeException("Test failed. Mouse position should be null but was " + pos);
}

pos = frontFrame.getMousePosition();
if (pos == null) {
dispose();
throw new RuntimeException("Test failed. Mouse position should not be null");
}

robot.mouseMove(189, 189);
robot.mouseMove(bounds.x + bounds.width + 5, bounds.y + bounds.height + 5);
robot.waitForIdle();

pos = backFrame.getMousePosition();
if (pos == null) {
dispose();
throw new RuntimeException("Test failed. Mouse position should not be null");
}

}

private static void dispose() {

if (backFrame != null) {
backFrame.dispose();
}
private static void dispose() throws Exception {
SwingUtilities.invokeAndWait(() -> {
if (backFrame != null) {
backFrame.dispose();
}

if (frontFrame != null) {
frontFrame.dispose();
}
if (frontFrame != null) {
frontFrame.dispose();
}
});
}

private static void constructTestUI() {
backFrame = new Frame();
backFrame.setUndecorated(true);
backFrame.setBounds(100, 100, 100, 100);
backFrame.setResizable(false);
backFrame.setVisible(true);

frontFrame = new Frame();
frontFrame.setUndecorated(true);
frontFrame.setBounds(120, 120, 60, 60);
frontFrame.setResizable(false);
frontFrame.setVisible(true);
Expand Down

1 comment on commit 0c3eaea

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.