1
1
/*
2
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
22
22
*/
23
23
24
24
import java .awt .Color ;
25
+ import java .awt .Dimension ;
25
26
import java .awt .Frame ;
26
27
import java .awt .Point ;
28
+ import java .awt .Rectangle ;
27
29
import java .awt .Robot ;
30
+ import java .awt .Toolkit ;
31
+ import java .awt .image .BufferedImage ;
32
+ import java .io .File ;
33
+ import java .io .IOException ;
28
34
import java .util .List ;
29
35
36
+ import javax .imageio .ImageIO ;
37
+
30
38
/**
31
39
* @test
32
40
* @key headful
@@ -58,6 +66,7 @@ private static void test() {
58
66
Color .GREEN , Color .MAGENTA , Color .CYAN ,
59
67
Color .BLUE )) {
60
68
frame .dispose ();
69
+ robot .waitForIdle ();
61
70
frame .setBackground (color );
62
71
frame .setVisible (true );
63
72
checkPixels (color );
@@ -68,14 +77,25 @@ private static void checkPixels(final Color color) {
68
77
int attempt = 0 ;
69
78
while (true ) {
70
79
Point p = frame .getLocationOnScreen ();
71
- Color pixel = robot . getPixelColor ( p . x + frame .getWidth () / 2 ,
72
- p . y + frame . getHeight () / 2 );
80
+ p . translate ( frame . getWidth () / 2 , frame .getHeight () / 2 );
81
+ Color pixel = robot . getPixelColor ( p . x , p . y );
73
82
if (color .equals (pixel )) {
74
83
return ;
75
84
}
76
- if (attempt > 10 ) {
85
+ frame .repaint ();
86
+ if (attempt > 11 ) {
77
87
System .err .println ("Expected: " + color );
78
88
System .err .println ("Actual: " + pixel );
89
+ System .err .println ("Point: " + p );
90
+ Dimension screenSize =
91
+ Toolkit .getDefaultToolkit ().getScreenSize ();
92
+ BufferedImage screen = robot .createScreenCapture (
93
+ new Rectangle (screenSize ));
94
+ try {
95
+ File output = new File ("ScreenCapture.png" );
96
+ System .err .println ("Dump screen to: " + output );
97
+ ImageIO .write (screen , "png" , output );
98
+ } catch (IOException ex ) {}
79
99
throw new RuntimeException ("Too many attempts: " + attempt );
80
100
}
81
101
// skip Robot.waitForIdle to speedup the common case, but also take
0 commit comments