jdk/test/java/awt/Modal/ModalBlockingTests/BlockingFDTest.java
changeset 25787 f1c606e8b3f8
equal deleted inserted replaced
25786:266ca40a0af2 25787:f1c606e8b3f8
       
     1 /*
       
     2  * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     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
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 import java.awt.*;
       
    25 import static jdk.testlibrary.Asserts.*;
       
    26 
       
    27 
       
    28 // FD: Frame -> Dialog
       
    29 
       
    30 public class BlockingFDTest {
       
    31 
       
    32     private TestFrame  frame;
       
    33     private TestDialog dialog;
       
    34 
       
    35     private static final int delay = 500;
       
    36     private final ExtendedRobot robot;
       
    37 
       
    38     private final Dialog.ModalityType modalityType;
       
    39     private final boolean setModal;
       
    40 
       
    41     private BlockingFDTest(Dialog.ModalityType modType, boolean modal) throws Exception {
       
    42 
       
    43         modalityType = modType;
       
    44         setModal = modal;
       
    45 
       
    46         robot = new ExtendedRobot();
       
    47         EventQueue.invokeLater(this::createGUI);
       
    48     }
       
    49 
       
    50     public BlockingFDTest(Dialog.ModalityType modType) throws Exception {
       
    51         this(modType, false);
       
    52     }
       
    53 
       
    54     public BlockingFDTest() throws Exception {
       
    55         this(null, true);
       
    56     }
       
    57 
       
    58     private void createGUI() {
       
    59 
       
    60         frame = new CustomFrame();
       
    61         frame.setLocation(50, 50);
       
    62         dialog = new TestDialog(frame);
       
    63         if (setModal) {
       
    64             dialog.setModal(true);
       
    65         } else if (modalityType != null) {
       
    66             dialog.setModalityType(modalityType);
       
    67         }
       
    68         dialog.setLocation(250, 50);
       
    69 
       
    70         frame.setVisible(true);
       
    71     }
       
    72 
       
    73     public void doTest() throws Exception {
       
    74 
       
    75         try {
       
    76 
       
    77             robot.waitForIdle(delay);
       
    78 
       
    79             frame.clickOpenButton(robot);
       
    80             robot.waitForIdle(delay);
       
    81 
       
    82             dialog.activated.waitForFlagTriggered();
       
    83             assertTrue(dialog.activated.flag(), "Dialog did not trigger " +
       
    84                 "Window Activated event when it became visible");
       
    85 
       
    86             dialog.closeGained.waitForFlagTriggered();
       
    87             assertTrue(dialog.closeGained.flag(), "the 1st Dialog button " +
       
    88                 "did not gain focus when it became visible");
       
    89 
       
    90             assertTrue(dialog.closeButton.hasFocus(), "the 1st Dialog button " +
       
    91                 "gained the focus but lost it afterwards");
       
    92 
       
    93             if ((modalityType == Dialog.ModalityType.APPLICATION_MODAL) ||
       
    94                 (modalityType == Dialog.ModalityType.DOCUMENT_MODAL) ||
       
    95                 (modalityType == Dialog.ModalityType.TOOLKIT_MODAL) ||
       
    96                 setModal)
       
    97             {
       
    98                 frame.checkBlockedFrame(robot,
       
    99                     "Frame is the parent of a visible " + modalityType + " Dialog.");
       
   100             } else {
       
   101                 frame.checkUnblockedFrame(robot,
       
   102                     "Frame is the parent of a visible " + modalityType + " Dialog.");
       
   103             }
       
   104             robot.waitForIdle(delay);
       
   105 
       
   106         } finally {
       
   107             EventQueue.invokeAndWait(this::closeAll);
       
   108         }
       
   109     }
       
   110 
       
   111     private void closeAll() {
       
   112         if (frame  != null) {  frame.dispose(); }
       
   113         if (dialog != null) { dialog.dispose(); }
       
   114     }
       
   115 
       
   116 
       
   117     class CustomFrame extends TestFrame {
       
   118 
       
   119         @Override
       
   120         public void doOpenAction() {
       
   121             if (dialog != null) { dialog.setVisible(true); }
       
   122         }
       
   123     }
       
   124 }