RFR: 8276058: Some swing test fails on specific CI macos system

Phil Race prr at openjdk.java.net
Wed Oct 27 17:58:10 UTC 2021


On Wed, 27 Oct 2021 17:39:04 GMT, Alexander Zvegintsev <azvegint at openjdk.org> wrote:

>> test/jdk/javax/swing/JButton/8151303/PressedIconTest.java line 88:
>> 
>>> 86:         robot.waitForIdle();
>>> 87:         Color color = robot.getPixelColor(centerX-10, centerY-10);
>>> 88: 
>> 
>> 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 ..
>
> Robot doesn't capture a cursor, we have a `Robot#createScreenCapture` spec which clearly says that:
> 
>> Creates an image containing pixels read from the screen.  
>> **This image does not include the mouse cursor.**
> 
> Both `Robot#createScreenCapture` and `Robot#getPixelColor` are using the same `CRobot#nativeGetScreenPixels` method for getting pixel data.
> 
> 
> <details>
>   <summary>So the mouse cursor should not affect `Robot#getPixelColor`, this is easy to check on practice</summary>  
> 
> 
> import javax.imageio.ImageIO;
> import java.awt.AWTException;
> import java.awt.Color;
> import java.awt.Frame;
> import java.awt.Rectangle;
> import java.awt.Robot;
> import java.awt.image.BufferedImage;
> import java.io.File;
> import java.io.IOException;
> 
> public class CursorTest {
>     public static void main(String[] args) throws AWTException, IOException {
>         Robot robot = new Robot();
> 
>         Frame frame = new Frame();
>         frame.setBackground(Color.red);
>         frame.setUndecorated(true);
> 
>         Rectangle rectangle = new Rectangle(100,100,50,50);
>         frame.setBounds(rectangle);
>         frame.setVisible(true);
> 
>         robot.waitForIdle();
>         robot.delay(1000);
>         robot.mouseMove(rectangle.x + 5, rectangle.y + 5);
>         robot.waitForIdle();
> 
>         System.err.println("Moved");
>         robot.waitForIdle();
>         robot.delay(3000);
> 
>         System.err.println("Starting");
> 
>         BufferedImage screenCapture = robot.createScreenCapture(rectangle);
>         ImageIO.write(screenCapture, "png", new File("/tmp/out.png"));
> 
>         for (int i = rectangle.x; i < rectangle.x + rectangle.width; i++) {
>             for (int j = rectangle.y; j < rectangle.y + rectangle.height; j++) {
>                 Color pixelColor = robot.getPixelColor(i, j);
>                 if (!pixelColor.equals(Color.red)) {
>                     System.err.println(pixelColor);
>                     frame.dispose();
>                     throw new RuntimeException("Unexpected pixel color " + pixelColor);
>                 }
>             }
>         }
> 
>         System.err.println("Finished");
>         frame.dispose();
>     }
> }
> 
>   
> </details>

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."

-------------

PR: https://git.openjdk.java.net/jdk/pull/6140



More information about the client-libs-dev mailing list