test/java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java
Print this page
@@ -27,17 +27,17 @@
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.InputEvent;
-import sun.awt.SunToolkit;
-
/**
* @test
* @bug 8008728
* @summary [macosx] Swing. JDialog. Modal dialog goes to background
* @author Alexandr Scherbatiy
+ * @library ../../../../lib/testlibrary
+ * @build ExtendedRobot
* @run main ModalDialogOrderingTest
*/
public class ModalDialogOrderingTest {
private static final Color DIALOG_COLOR = Color.GREEN;
@@ -67,16 +67,16 @@
modalDialog.setVisible(true);
}
private static void runTest(Dialog dialog, Frame frame) {
try {
- Robot robot = new Robot();
+ ExtendedRobot robot = new ExtendedRobot();
robot.setAutoDelay(50);
robot.mouseMove(300, 300);
while (!dialog.isVisible()) {
- sleep();
+ robot.waitForIdle(1000);
}
Rectangle dialogBounds = dialog.getBounds();
Rectangle frameBounds = frame.getBounds();
@@ -87,32 +87,25 @@
int clickY = y1 + (y2 - y1) / 2;
robot.mouseMove(clickX, clickY);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
- sleep();
+ robot.waitForIdle(1000);
int colorX = dialogBounds.x + dialogBounds.width / 2;
int colorY = dialogBounds.y + dialogBounds.height / 2;
Color color = robot.getPixelColor(colorX, colorY);
- dialog.dispose();
- frame.dispose();
if (!DIALOG_COLOR.equals(color)) {
throw new RuntimeException("The frame is on top"
+ " of the modal dialog!");
+ }else{
+ frame.dispose();
+ dialog.dispose();
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
-
- private static void sleep() {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ignored) {
- }
- ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
- }
}