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/3343813> [JavaJDK16] J2SE50R4DP7: setMaximizedBounds size should not be used as the maximum size
  27  @summary com.apple.junit.java.awt.Frame;
  28  @library ../../regtesthelpers
  29  @build VisibilityValidator
  30  @build Waypoint
  31  @run main MaximizedBoundsTest
  32  */
  33 
  34 import junit.framework.*;
  35 
  36 import java.awt.*;
  37 import java.awt.event.ComponentEvent;
  38 
  39 import test.java.awt.regtesthelpers.VisibilityValidator;
  40 import test.java.awt.regtesthelpers.Waypoint;
  41 
  42 public class MaximizedBoundsTest extends TestCase {
  43     Waypoint waypoint = new Waypoint();
  44 
  45     public void testMaximizedBounds() {
  46         Frame f = new Frame("Maximized bounds test");
  47         Rectangle bounds = new Rectangle( 200, 200, 600, 400 );
  48         try {
  49             f.setLayout(null);
  50             f.setSize(300,175);
  51             f.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(ComponentEvent e) {
  52                 waypoint.clear();
  53             }});
  54 
  55             f.setMaximizedBounds(bounds);
  56 
  57             VisibilityValidator vis = new VisibilityValidator(f);
  58             f.setVisible(true);
  59             vis.requireVisible();
  60 
  61             waypoint.reset();
  62             f.setExtendedState(Frame.MAXIMIZED_BOTH);
  63             try { EventQueue.invokeAndWait(new Runnable() { public void run() {}}); } catch(Exception e) {}
  64             waypoint.requireClear("Didn't get resize event after zoom");
  65             assertTrue("Maximized bounds should be " + bounds +", but is instead " + f.getBounds(), f.getBounds().equals(bounds));
  66         } finally {
  67             f.setVisible(false);
  68             f.dispose();
  69             f = null;
  70         }
  71     }
  72 
  73     public static Test suite() {
  74         return new TestSuite(MaximizedBoundsTest.class);
  75     }
  76 
  77     public static void main (String[] args) throws RuntimeException {
  78         TestResult tr = junit.textui.TestRunner.run(suite());
  79         if((tr.errorCount() != 0) || (tr.failureCount() != 0)) {
  80             throw new RuntimeException("### Unexpected JUnit errors or failures.");
  81         }
  82     }
  83 }