1 /*
   2  * Copyright (c) 2011, 2013, 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 /*
  25  * @test
  26  * @summary <rdar://problem/4555794> [JavaJDK16] Hiding / Showing owned (child) windows is not sufficiently recursive
  27  * @summary com.apple.junit.java.awt.Window
  28  * @library ../../regtesthelpers
  29  * @build RobotUtilities VisibilityValidator Waypoint
  30  * @run junit HideShowOwnedWindows
  31  */
  32 
  33 import test.java.awt.regtesthelpers.RobotUtilities;
  34 import test.java.awt.regtesthelpers.VisibilityValidator;
  35 import test.java.awt.regtesthelpers.Waypoint;
  36 import junit.framework.*;
  37 import java.awt.*;
  38 import java.awt.event.*;
  39 
  40 public class HideShowOwnedWindows extends TestCase {
  41     Waypoint waypoint = new Waypoint();
  42 
  43     public void testHideShowOwnedWindows() throws RuntimeException {
  44         Frame f = null;
  45         Dialog d1 = null;
  46         Dialog d2 = null;
  47         Dialog d3 = null;
  48         VisibilityValidator vis = null;
  49 
  50         try {
  51             f = new Frame("Frame");
  52             f.setBounds(50,50,450,450);
  53             vis = new VisibilityValidator(f);
  54             f.setVisible(true);
  55             vis.requireVisible();
  56 
  57             d1 = new Dialog(f, "1", false);
  58             d1.setBounds(100,100,100,100);
  59             vis = new VisibilityValidator(d1);
  60             d1.setVisible(true);
  61             vis.requireVisible();
  62 
  63             d2 = new Dialog(d1, "2", false);
  64             d2.setBounds(150,150,100,100);
  65             vis = new VisibilityValidator(d2);
  66             d2.setVisible(true);
  67             vis.requireVisible();
  68 
  69             d3 = new Dialog(d2, "3", false);
  70             d3.setBounds(200,200,100,100);
  71             Button b = new Button("b");
  72             b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
  73                 waypoint.clear();
  74             }});
  75             d3.add(b);
  76             vis = new VisibilityValidator(d3);
  77             d3.setVisible(true);
  78             vis.requireVisible();
  79 
  80             f.setVisible(false);
  81             // No inverse VisibilityValidator
  82             try { EventQueue.invokeAndWait(new Runnable() { public void run() {}}); } catch (Exception e) {}
  83 
  84             f.setVisible(true);
  85             // Can't use VisibilityValidator here since f has already been shown once.
  86             try { EventQueue.invokeAndWait(new Runnable() { public void run() {}}); } catch (Exception e) {}
  87 
  88             waypoint.reset();
  89             RobotUtilities.click(b);
  90             waypoint.requireClear("Owned dialog didn't come back after hide/show.");
  91         } finally {
  92             if (d3 != null) { d3.setVisible(false); d3.dispose(); d3 = null; }
  93             if (d2 != null) { d2.setVisible(false); d2.dispose(); d2 = null; }
  94             if (d1 != null) { d1.setVisible(false); d1.dispose(); d1 = null; }
  95             if (f != null) { f.setVisible(false); f.dispose(); f = null; }
  96         }
  97     }
  98 
  99 
 100     public static Test suite() {
 101         return new TestSuite(HideShowOwnedWindows.class);
 102     }
 103 
 104     public static void main (String[] args) throws RuntimeException {
 105         TestResult tr = junit.textui.TestRunner.run(suite());
 106         if ((tr.errorCount() != 0) || (tr.failureCount() != 0)) {
 107             throw new RuntimeException("### FAILED: unexpected JUnit errors or failures.");
 108         }
 109     }
 110 }