|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| RobotVerifier.java | 62.5% | 89.2% | 66.7% | 83.3% |
|
||||||||||||||
| 1 |
package abbot.tester;
|
|
| 2 |
|
|
| 3 |
import java.awt.*;
|
|
| 4 |
import java.awt.event.*;
|
|
| 5 |
import javax.swing.event.*;
|
|
| 6 |
|
|
| 7 |
import abbot.Platform;
|
|
| 8 |
import abbot.util.Bugs;
|
|
| 9 |
|
|
| 10 |
/** Provides methods to verify that the robot on the current platform works
|
|
| 11 |
* properly.
|
|
| 12 |
*/
|
|
| 13 |
public class RobotVerifier { |
|
| 14 |
// No instantiations
|
|
| 15 | 0 |
private RobotVerifier() { }
|
| 16 |
|
|
| 17 |
private static final String WINDOW_NAME = "Abbot Robot Verification"; |
|
| 18 |
|
|
| 19 |
/** Auto-detect whether the robot actually works.
|
|
| 20 |
Use this to tell whether we're in w32 pseudo-headless mode, such as
|
|
| 21 |
when in a remote shell (ssh) or running as a service. This is also
|
|
| 22 |
used as a delay mechanism to ensure the AWT subsystem is running
|
|
| 23 |
before continuing (particularly a problem on early OSX 1.4 VM
|
|
| 24 |
versions).
|
|
| 25 |
@return false if the robot fails.
|
|
| 26 |
*/
|
|
| 27 | 96 |
public static boolean verify(java.awt.Robot robot) { |
| 28 | 96 |
if (!Bugs.needsRobotVerification())
|
| 29 | 0 |
return true; |
| 30 |
|
|
| 31 |
class Flag { volatile boolean flag = false; } |
|
| 32 | 96 |
final Flag flag = new Flag();
|
| 33 | 96 |
final int SIZE = 4;
|
| 34 | 96 |
Window w; |
| 35 | 96 |
Frame f = new Frame(WINDOW_NAME);
|
| 36 | 96 |
f.setName(WINDOW_NAME); |
| 37 | 96 |
if (Bugs.hasMissingWindowMouseMotion()) {
|
| 38 |
// so use an undecorated dialog instead.
|
|
| 39 | 0 |
w = new Dialog(f);
|
| 40 | 0 |
try {
|
| 41 |
// setUndecorated is 1.4+ only
|
|
| 42 | 0 |
w.getClass(). |
| 43 |
getDeclaredMethod("setUndecorated",
|
|
| 44 |
new Class[] { boolean.class }). |
|
| 45 |
invoke(w, new Object[] { Boolean.TRUE });
|
|
| 46 |
} |
|
| 47 |
catch(Exception e) { }
|
|
| 48 |
} |
|
| 49 |
else {
|
|
| 50 | 96 |
w = new Window(f);
|
| 51 |
} |
|
| 52 | 96 |
w.setName(WINDOW_NAME); |
| 53 | 96 |
w.pack(); |
| 54 | 96 |
w.setSize(SIZE, SIZE); |
| 55 | 96 |
w.setLocation(100, 100); |
| 56 | 96 |
w.addMouseMotionListener(new MouseInputAdapter() {
|
| 57 | 393 |
public void mouseMoved(MouseEvent e) { |
| 58 | 393 |
synchronized(flag) {
|
| 59 | 393 |
flag.flag = true;
|
| 60 | 393 |
flag.notifyAll(); |
| 61 |
} |
|
| 62 |
} |
|
| 63 |
}); |
|
| 64 | 96 |
w.show(); |
| 65 | 96 |
robot.waitForIdle(); |
| 66 | 96 |
WindowTracker tracker = WindowTracker.getTracker(); |
| 67 | 96 |
while (!tracker.isWindowReady(w)) {
|
| 68 | 96 |
robot.delay(20); |
| 69 |
} |
|
| 70 |
// Bail if we get no response after 30s
|
|
| 71 | 96 |
final int AWT_WAIT_TIMEOUT = 30000;
|
| 72 | 96 |
long start = System.currentTimeMillis();
|
| 73 | 96 |
try {
|
| 74 | 96 |
do {
|
| 75 | 96 |
w.toFront(); |
| 76 | 96 |
synchronized(flag) {
|
| 77 | 96 |
robot.mouseMove(w.getX(), |
| 78 |
w.getY() + w.getHeight() - 1); |
|
| 79 | 96 |
robot.mouseMove(w.getX() + 1, |
| 80 |
w.getY() + w.getHeight() - 2); |
|
| 81 | 96 |
try {
|
| 82 | 96 |
flag.wait(500); |
| 83 |
} |
|
| 84 |
catch(InterruptedException e) {
|
|
| 85 |
} |
|
| 86 |
} |
|
| 87 | 96 |
} while (!flag.flag
|
| 88 |
&& System.currentTimeMillis() - start < AWT_WAIT_TIMEOUT); |
|
| 89 |
} |
|
| 90 |
finally {
|
|
| 91 | 96 |
w.dispose(); |
| 92 |
} |
|
| 93 | 96 |
return flag.flag;
|
| 94 |
} |
|
| 95 |
} |
|
| 96 |
|
|
||||||||||