New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8276058: Some swing test fails on specific CI macos system #6140
Changes from all commits
5035532
cf3fc29
5986b59
077eb52
115455c
67ee7b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,9 @@ | |
import java.awt.Dimension; | ||
import java.awt.Graphics; | ||
import java.awt.Point; | ||
import java.awt.Rectangle; | ||
import java.awt.Robot; | ||
import java.awt.Toolkit; | ||
import java.awt.event.InputEvent; | ||
import java.awt.image.BaseMultiResolutionImage; | ||
import java.awt.image.BufferedImage; | ||
|
@@ -56,37 +58,56 @@ public class PressedIconTest { | |
private static volatile double scale = -1; | ||
private static volatile int centerX; | ||
private static volatile int centerY; | ||
private static volatile Point location; | ||
// move away from cursor | ||
private final static int OFFSET_X = -20; | ||
private final static int OFFSET_Y = -20; | ||
|
||
public static void main(String[] args) throws Exception { | ||
Robot robot = new Robot(); | ||
robot.setAutoDelay(50); | ||
robot.setAutoDelay(100); | ||
|
||
SwingUtilities.invokeAndWait(() -> createAndShowGUI()); | ||
robot.waitForIdle(); | ||
robot.delay(1000); | ||
|
||
SwingUtilities.invokeAndWait(() -> { | ||
scale = frame.getGraphicsConfiguration().getDefaultTransform() | ||
.getScaleX(); | ||
Point location = frame.getLocation(); | ||
location = frame.getLocation(); | ||
Dimension size = frame.getSize(); | ||
centerX = location.x + size.width / 2; | ||
centerY = location.y + size.height / 2; | ||
}); | ||
robot.waitForIdle(); | ||
|
||
System.out.println("scale " + scale); | ||
|
||
robot.mouseMove(centerX, centerY); | ||
robot.mousePress(InputEvent.BUTTON1_MASK); | ||
robot.waitForIdle(); | ||
Thread.sleep(100); | ||
Color color = robot.getPixelColor(centerX, centerY); | ||
robot.mouseRelease(InputEvent.BUTTON1_MASK); | ||
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); | ||
robot.waitForIdle(); | ||
Color color = robot.getPixelColor(centerX - OFFSET_X, centerY - OFFSET_Y); | ||
|
||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); | ||
Rectangle screen = new Rectangle(0, 0, (int) screenSize.getWidth(), (int) screenSize.getHeight()); | ||
BufferedImage img = robot.createScreenCapture(screen); | ||
javax.imageio.ImageIO.write(img, "png", new java.io.File("image.png")); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we writing the image or any other type of file in the CWD in other tests ? |
||
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); | ||
|
||
|
||
SwingUtilities.invokeAndWait(() -> frame.dispose()); | ||
|
||
if ((scale == 1 && !similar(color, COLOR_1X)) | ||
|| (scale == 2 && !similar(color, COLOR_2X))) { | ||
throw new RuntimeException("Colors are different!"); | ||
if (scale == 1 && !similar(color, COLOR_1X)) { | ||
System.out.println("color " + color + " COLOR_1X " + COLOR_1X); | ||
throw new RuntimeException("Colors is different for scale=1!"); | ||
} | ||
if (scale == 2 && !similar(color, COLOR_2X)) { | ||
System.out.println("color " + color + " COLOR_2X " + COLOR_2X); | ||
throw new RuntimeException("Colors is different for scale=2!"); | ||
} | ||
System.out.println("Test Passed"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm .. the test tags are What if the default scale is 2 ? If you are going to explicitly test for 1 and 2 here, shouldn't we explicitly set it ? And if you aren't then the test here needs to do something based on the actual scale. |
||
} | ||
|
||
private static void createAndShowGUI() { | ||
|
@@ -108,6 +129,8 @@ private static void createAndShowGUI() { | |
panel.add(button, BorderLayout.CENTER); | ||
|
||
frame.getContentPane().add(panel); | ||
frame.setUndecorated(true); | ||
frame.setLocationRelativeTo(null); | ||
frame.setVisible(true); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the problematic pattern is a mouse move to the location from which you subsequently capture a pixel?
I can see how on a compositing window manager that might be an issue as the cursor is part of the window
whereas on old X11 it isn't part of the root window .. but why isn't this ALWAYS an issue on macOS ?
I wonder how many other tests have the same issue ?
And is an offset of 10 enough ? Its a bit arbitrary and cursors could be a larger shape or different orientation ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Robot doesn't capture a cursor, we have a
Robot#createScreenCapture
spec which clearly says that:Both
Robot#createScreenCapture
andRobot#getPixelColor
are using the sameCRobot#nativeGetScreenPixels
method for getting pixel data.So the mouse cursor should not affect `Robot#getPixelColor`, this is easy to check on practice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok .. yet Prasanta said it did ..
"The png image generated at failure also did not reveal anything abnormal apart from presence of mouse cursor around the same area where the getPixelColor location is pointing to."