changeset 8838:85dc748aa403

8029024: [TEST_BUG] java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java fails Reviewed-by: malenkov, alexsch
author serb
date Wed, 27 Nov 2013 20:45:10 +0400
parents f99277913d40
children 2bcdf1e05642 3aab01f03bb7
files test/java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java
diffstat 1 files changed, 26 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java	Wed Nov 27 11:41:55 2013 +0400
+++ b/test/java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java	Wed Nov 27 20:45:10 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,15 +28,16 @@
 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
  * @run main ModalDialogOrderingTest
  */
-
 public class ModalDialogOrderingTest {
 
     private static final Color DIALOG_COLOR = Color.GREEN;
@@ -45,13 +46,13 @@
     public static void main(String[] args) {
 
         final Frame frame = new Frame("Test");
-        frame.setSize(100, 100);
+        frame.setSize(400, 400);
         frame.setBackground(FRAME_COLOR);
         frame.setVisible(true);
 
-        final Dialog modalDialog = new Dialog((Frame) null, true);
+        final Dialog modalDialog = new Dialog(null, true);
         modalDialog.setTitle("Modal Dialog");
-        modalDialog.setSize(50, 50);
+        modalDialog.setSize(400, 200);
         modalDialog.setBackground(DIALOG_COLOR);
         modalDialog.setModal(true);
 
@@ -68,40 +69,35 @@
 
     private static void runTest(Dialog dialog, Frame frame) {
         try {
-            SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
             Robot robot = new Robot();
-            robot.setAutoDelay(15);
+            robot.setAutoDelay(50);
             robot.mouseMove(300, 300);
 
             while (!dialog.isVisible()) {
-                toolkit.realSync();
+                sleep();
             }
 
             Rectangle dialogBounds = dialog.getBounds();
             Rectangle frameBounds = frame.getBounds();
 
-            double x0 = dialogBounds.getX();
-            double y0 = dialogBounds.getY();
-            double x1 = dialogBounds.getX() + dialogBounds.getWidth();
-            double y1 = dialogBounds.getY() + dialogBounds.getHeight();
-            double x2 = frameBounds.getX() + frameBounds.getWidth();
-            double y2 = frameBounds.getY() + frameBounds.getHeight();
+            int y1 = dialogBounds.y + dialogBounds.height;
+            int y2 = frameBounds.y + frameBounds.height;
 
-            int clickX = (int) ((x2 + x1) / 2);
-            int clickY = (int) ((y2 + y1) / 2);
+            int clickX = frameBounds.x + frameBounds.width / 2;
+            int clickY = y1 + (y2 - y1) / 2;
 
             robot.mouseMove(clickX, clickY);
             robot.mousePress(InputEvent.BUTTON1_MASK);
             robot.mouseRelease(InputEvent.BUTTON1_MASK);
-            toolkit.realSync();
+            sleep();
 
-            int colorX = (int) ((x0 + x1) / 2);
-            int colorY = (int) ((y0 + y1) / 2);
+            int colorX = dialogBounds.x + dialogBounds.width / 2;
+            int colorY = dialogBounds.y + dialogBounds.height / 2;
 
             Color color = robot.getPixelColor(colorX, colorY);
 
-            dialog.setVisible(false);
-            frame.setVisible(false);
+            dialog.dispose();
+            frame.dispose();
 
             if (!DIALOG_COLOR.equals(color)) {
                 throw new RuntimeException("The frame is on top"
@@ -111,4 +107,12 @@
             throw new RuntimeException(ex);
         }
     }
+
+    private static void sleep() {
+        try {
+            Thread.sleep(1000);
+        } catch (InterruptedException ignored) {
+        }
+        ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
+    }
 }