3333import java .awt .geom .Area ;
3434import java .awt .geom .Ellipse2D ;
3535import java .awt .geom .Rectangle2D ;
36+ import java .awt .image .BufferedImage ;
3637import java .io .File ;
3738import java .io .IOException ;
3839import javax .imageio .ImageIO ;
4243 * @key headful
4344 * @bug 6988428
4445 * @summary Tests whether shape is always set
45- * @run main/othervm -Dsun.java2d.uiScale=1 ShapeNotSetSometimes
46+ * @run main/othervm/timeout=300 -Dsun.java2d.uiScale=1 ShapeNotSetSometimes
4647 */
4748
4849public class ShapeNotSetSometimes {
@@ -147,15 +148,20 @@ private void doTest() throws Exception {
147148 robot .waitForIdle ();
148149 robot .delay (500 );
149150
151+ Rectangle screenBounds = window .getGraphicsConfiguration ().getBounds ();
152+ BufferedImage screenCapture = robot .createScreenCapture (screenBounds );
150153 try {
151- colorCheck (innerPoint .x , innerPoint .y , SHAPE_COLOR , true );
154+ colorCheck (innerPoint .x , innerPoint .y , SHAPE_COLOR ,
155+ true , screenCapture );
152156
153157 for (Point point : pointsOutsideToCheck ) {
154- colorCheck (point .x , point .y , BACKGROUND_COLOR , true );
158+ colorCheck (point .x , point .y , BACKGROUND_COLOR ,
159+ true , screenCapture );
155160 }
156161
157162 for (Point point : shadedPointsToCheck ) {
158- colorCheck (point .x , point .y , SHAPE_COLOR , false );
163+ colorCheck (point .x , point .y , SHAPE_COLOR ,
164+ false , screenCapture );
159165 }
160166 } finally {
161167 EventQueue .invokeAndWait (() -> {
@@ -169,15 +175,12 @@ private void doTest() throws Exception {
169175 }
170176 }
171177
172- private void colorCheck (int x , int y , Color expectedColor , boolean mustBeExpectedColor ) {
178+ private void colorCheck (int x , int y , Color expectedColor ,
179+ boolean mustBeExpectedColor , BufferedImage screenCapture ) {
173180 int screenX = window .getX () + x ;
174181 int screenY = window .getY () + y ;
175182
176- robot .mouseMove (screenX , screenY );
177- robot .waitForIdle ();
178- robot .delay (50 );
179-
180- Color actualColor = robot .getPixelColor (screenX , screenY );
183+ Color actualColor = new Color (screenCapture .getRGB (screenX , screenY ));
181184
182185 System .out .printf (
183186 "Checking %3d, %3d, %35s should %sbe %35s\n " ,
0 commit comments