From 35284e4667fe904bd2df42d625e769dfd98920d3 Mon Sep 17 00:00:00 2001 From: Prasanta Sadhukhan Date: Wed, 11 Nov 2020 08:05:20 +0000 Subject: [PATCH] 8255916: [macos] javax/swing/JInternalFrame/6647340/bug6647340.java timed out Reviewed-by: serb --- .../JInternalFrame/6647340/bug6647340.java | 97 ++++++++----------- 1 file changed, 43 insertions(+), 54 deletions(-) diff --git a/test/jdk/javax/swing/JInternalFrame/6647340/bug6647340.java b/test/jdk/javax/swing/JInternalFrame/6647340/bug6647340.java index e277cc83e10..15972c504fa 100644 --- a/test/jdk/javax/swing/JInternalFrame/6647340/bug6647340.java +++ b/test/jdk/javax/swing/JInternalFrame/6647340/bug6647340.java @@ -26,9 +26,6 @@ * @bug 6647340 * @summary Checks that iconified internal frame follows * the main frame borders properly. - * @author Mikhail Lapshin - * @library /lib/client/ - * @build ExtendedRobot * @run main bug6647340 */ @@ -38,22 +35,22 @@ public class bug6647340 { private JFrame frame; - private Point location; + private volatile Point location; + private volatile Point iconloc; private JInternalFrame jif; - private static ExtendedRobot robot = createRobot(); + private static Robot robot; public static void main(String[] args) throws Exception { + robot = new Robot(); final bug6647340 test = new bug6647340(); try { - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - test.setupUI(); - } - }); + SwingUtilities.invokeAndWait(() -> test.setupUI()); + robot.waitForIdle(); + robot.delay(1000); test.test(); } finally { if (test.frame != null) { - test.frame.dispose(); + SwingUtilities.invokeAndWait(() -> test.frame.dispose()); } } } @@ -77,77 +74,69 @@ private void setupUI() { } private void test() throws Exception { - sync(); test1(); - sync(); + + robot.waitForIdle(); + robot.delay(500); check1(); - sync(); + robot.waitForIdle(); + test2(); - sync(); + robot.waitForIdle(); + robot.delay(500); check2(); } private void test1() throws Exception { - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - setIcon(true); - location = jif.getDesktopIcon().getLocation(); - Dimension size = frame.getSize(); - frame.setSize(size.width + 100, size.height + 100); - } + SwingUtilities.invokeAndWait(() -> { + setIcon(true); + location = jif.getDesktopIcon().getLocation(); + Dimension size = frame.getSize(); + frame.setSize(size.width + 100, size.height + 100); }); } private void test2() throws Exception { - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - setIcon(false); - } + SwingUtilities.invokeAndWait(() -> { + setIcon(false); }); - sync(); - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - Dimension size = frame.getSize(); - frame.setSize(size.width - 100, size.height - 100); - } + robot.waitForIdle(); + robot.delay(500); + + SwingUtilities.invokeAndWait(() -> { + Dimension size = frame.getSize(); + frame.setSize(size.width - 100, size.height - 100); }); - sync(); - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - setIcon(true); - } + robot.waitForIdle(); + robot.delay(500); + + SwingUtilities.invokeAndWait(() -> { + setIcon(true); }); } - private void check1() { - if (!jif.getDesktopIcon().getLocation().equals(location)) { + private void check1() throws Exception { + SwingUtilities.invokeAndWait(() -> { + iconloc = jif.getDesktopIcon().getLocation(); + }); + if (!iconloc.equals(location)) { System.out.println("First test passed"); } else { throw new RuntimeException("Icon isn't shifted with the frame bounds"); } } - private void check2() { - if (jif.getDesktopIcon().getLocation().equals(location)) { + private void check2() throws Exception { + SwingUtilities.invokeAndWait(() -> { + iconloc = jif.getDesktopIcon().getLocation(); + }); + if (iconloc.equals(location)) { System.out.println("Second test passed"); } else { throw new RuntimeException("Icon isn't located near the frame bottom"); } } - private static void sync() { - robot.waitForIdle(); - } - private static ExtendedRobot createRobot() { - try { - ExtendedRobot robot = new ExtendedRobot(); - return robot; - }catch(Exception ex) { - ex.printStackTrace(); - throw new Error("Unexpected Failure"); - } - } - private void setIcon(boolean b) { try { jif.setIcon(b);