test/jdk/javax/swing/JInternalFrame/8145896/TestJInternalFrameMaximize.java
changeset 58318 f39420849ae9
parent 47216 71c04702a3d5
equal deleted inserted replaced
58317:ddd26bd764e8 58318:f39420849ae9
     1 /*
     1 /*
     2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @key headful
    26  * @key headful
    27  * @bug 8145896
    27  * @bug 8145896 8194944
    28  * @summary JInternalFrame setMaximum before adding to desktop throws null pointer exception
    28  * @summary JInternalFrame setMaximum before adding to desktop throws null pointer exception
    29  * @library ../../regtesthelpers
    29  * @library ../../regtesthelpers
    30  * @build Util
    30  * @build Util
    31  * @run main TestJInternalFrameMaximize
    31  * @run main TestJInternalFrameMaximize
    32  */
    32  */
       
    33 
    33 import java.awt.Point;
    34 import java.awt.Point;
    34 import java.awt.Robot;
    35 import java.awt.Robot;
    35 import java.awt.event.ActionEvent;
    36 import java.awt.event.ActionEvent;
    36 import java.awt.event.InputEvent;
    37 import java.awt.event.InputEvent;
    37 import java.beans.PropertyVetoException;
    38 import java.beans.PropertyVetoException;
    53     private static JMenu menu;
    54     private static JMenu menu;
    54     private static JMenuBar menuBar;
    55     private static JMenuBar menuBar;
    55     private static JMenuItem menuItem;
    56     private static JMenuItem menuItem;
    56     private static Robot robot;
    57     private static Robot robot;
    57     private static volatile String errorMessage = "";
    58     private static volatile String errorMessage = "";
       
    59     private static volatile boolean isFrameShowing;
    58 
    60 
    59     public static void main(String[] args) throws Exception {
    61     public static void main(String[] args) throws Exception {
    60         robot = new Robot();
    62         robot = new Robot();
       
    63         robot.setAutoDelay(100);
    61         UIManager.LookAndFeelInfo[] lookAndFeelArray
    64         UIManager.LookAndFeelInfo[] lookAndFeelArray
    62                 = UIManager.getInstalledLookAndFeels();
    65                 = UIManager.getInstalledLookAndFeels();
    63         for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) {
    66         for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) {
    64             String lookAndFeelString = lookAndFeelItem.getClassName();
    67             try {
    65             if (tryLookAndFeel(lookAndFeelString)) {
    68                 String lookAndFeelString = lookAndFeelItem.getClassName();
    66                 createUI();
    69                 if (tryLookAndFeel(lookAndFeelString)) {
       
    70                     createUI();
       
    71                     robot.waitForIdle();
       
    72                     blockTillDisplayed(frame);
       
    73                     executeTest();
       
    74                     robot.delay(1000);
       
    75                 }
       
    76             } finally {
       
    77                 frame.dispose();
       
    78                 isFrameShowing = false;
    67                 robot.waitForIdle();
    79                 robot.waitForIdle();
    68                 executeTest();
       
    69                 robot.delay(1000);
       
    70             }
    80             }
    71         }
    81         }
    72         if (!"".equals(errorMessage)) {
    82         if (!"".equals(errorMessage)) {
    73             throw new RuntimeException(errorMessage);
    83             throw new RuntimeException(errorMessage);
    74         }
    84         }
   111                     desktopPane.add(f);
   121                     desktopPane.add(f);
   112                     f.setVisible(true);
   122                     f.setVisible(true);
   113                 } catch (PropertyVetoException ex) {
   123                 } catch (PropertyVetoException ex) {
   114                 } catch (RuntimeException ex) {
   124                 } catch (RuntimeException ex) {
   115                     errorMessage = "Test Failed";
   125                     errorMessage = "Test Failed";
   116                 } finally {
       
   117                     frame.dispose();
       
   118                 }
   126                 }
   119             });
   127             });
   120             menu.add(menuItem);
   128             menu.add(menuItem);
   121             frame.setSize(500, 500);
   129             frame.setSize(500, 500);
   122             frame.setLocationRelativeTo(null);
   130             frame.setLocationRelativeTo(null);
   123             frame.setVisible(true);
   131             frame.setVisible(true);
   124         });
   132         });
   125     }
   133     }
   126 
   134 
       
   135     private static void blockTillDisplayed(JFrame frame) throws Exception {
       
   136         while (!isFrameShowing) {
       
   137             try {
       
   138                 SwingUtilities.invokeAndWait(()-> isFrameShowing = frame.isShowing());
       
   139                 if (!isFrameShowing) {
       
   140                     Thread.sleep(1000);
       
   141                 }
       
   142             } catch (InterruptedException ex) {
       
   143             } catch (Exception ex) {
       
   144                 throw new RuntimeException(ex);
       
   145             }
       
   146         }
       
   147     }
       
   148 
   127     private static void executeTest() throws Exception {
   149     private static void executeTest() throws Exception {
   128 
       
   129         Point point = Util.getCenterPoint(menu);
   150         Point point = Util.getCenterPoint(menu);
   130         performMouseOperations(point);
   151         performMouseOperations(point);
   131         point = Util.getCenterPoint(menuItem);
   152         point = Util.getCenterPoint(menuItem);
   132         performMouseOperations(point);
   153         performMouseOperations(point);
   133     }
   154     }