< prev index next >

test/java/awt/Frame/MaximizedByPlatform/MaximizedByPlatform.java

Print this page
rev 14565 : 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
Summary: Add new keyword 'printer'. Some minor test fixes to show headless exception. Add some @requires windows.
Reviewed-by: serb, mbaesken
   1 /*
   2  * Copyright (c) 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 /* @test


  25  * @bug 8026143
  26  * @summary [macosx] Maximized state could be inconsistent between peer and frame
  27  * @author Petr Pchelko
  28  * @library ../../../../lib/testlibrary
  29  * @build jdk.testlibrary.OSInfo
  30  * @run main MaximizedByPlatform
  31  */
  32 
  33 import jdk.testlibrary.OSInfo;
  34 
  35 import java.awt.*;
  36 
  37 public class MaximizedByPlatform {
  38     private static Frame frame;
  39     private static Rectangle availableScreenBounds;
  40 
  41     public static void main(String[] args) {
  42         if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
  43             // Test only for macosx. Pass
  44             return;


  53         }
  54         availableScreenBounds = getAvailableScreenBounds();
  55 
  56         // Test 1. The maximized state is set in setBounds
  57         try {
  58             frame = new Frame();
  59             frame.setBounds(100, 100, 100, 100);
  60             frame.setVisible(true);
  61 
  62             robot.waitForIdle();
  63 
  64             frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
  65                     availableScreenBounds.width, availableScreenBounds.height);
  66 
  67             robot.waitForIdle();
  68 
  69             if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) {
  70                 throw new RuntimeException("Maximized state was not set for frame in setBounds");
  71             }
  72         } finally {
  73             frame.dispose();
  74         }
  75 
  76 
  77         // Test 2. The maximized state is set in setVisible
  78         try {
  79             frame = new Frame();
  80             frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
  81                     availableScreenBounds.width + 100, availableScreenBounds.height);
  82             frame.setVisible(true);
  83 
  84             robot.waitForIdle();
  85 
  86             if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) {
  87                 throw new RuntimeException("Maximized state was not set for frame in setVisible");
  88             }
  89         } finally {
  90             frame.dispose();
  91         }
  92     }
  93 
  94     private static Rectangle getAvailableScreenBounds() {
  95         final Toolkit toolkit = Toolkit.getDefaultToolkit();
  96         final GraphicsEnvironment graphicsEnvironment =
  97                 GraphicsEnvironment.getLocalGraphicsEnvironment();
  98         final GraphicsDevice graphicsDevice =
  99                 graphicsEnvironment.getDefaultScreenDevice();
 100 
 101         final Dimension screenSize = toolkit.getScreenSize();
 102         final Insets screenInsets = toolkit.getScreenInsets(
 103                 graphicsDevice.getDefaultConfiguration());
 104 
 105         final Rectangle availableScreenBounds = new Rectangle(screenSize);
 106 
 107         availableScreenBounds.x += screenInsets.left;
 108         availableScreenBounds.y += screenInsets.top;
 109         availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
 110         availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);
   1 /*
   2  * Copyright (c) 2013, 2017, 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  * @key headful
  27  * @bug 8026143
  28  * @summary [macosx] Maximized state could be inconsistent between peer and frame
  29  * @author Petr Pchelko
  30  * @library ../../../../lib/testlibrary
  31  * @build jdk.testlibrary.OSInfo
  32  * @run main MaximizedByPlatform
  33  */
  34 
  35 import jdk.testlibrary.OSInfo;
  36 
  37 import java.awt.*;
  38 
  39 public class MaximizedByPlatform {
  40     private static Frame frame;
  41     private static Rectangle availableScreenBounds;
  42 
  43     public static void main(String[] args) {
  44         if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
  45             // Test only for macosx. Pass
  46             return;


  55         }
  56         availableScreenBounds = getAvailableScreenBounds();
  57 
  58         // Test 1. The maximized state is set in setBounds
  59         try {
  60             frame = new Frame();
  61             frame.setBounds(100, 100, 100, 100);
  62             frame.setVisible(true);
  63 
  64             robot.waitForIdle();
  65 
  66             frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
  67                     availableScreenBounds.width, availableScreenBounds.height);
  68 
  69             robot.waitForIdle();
  70 
  71             if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) {
  72                 throw new RuntimeException("Maximized state was not set for frame in setBounds");
  73             }
  74         } finally {
  75             if (frame != null) frame.dispose();
  76         }
  77 
  78 
  79         // Test 2. The maximized state is set in setVisible
  80         try {
  81             frame = new Frame();
  82             frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
  83                     availableScreenBounds.width + 100, availableScreenBounds.height);
  84             frame.setVisible(true);
  85 
  86             robot.waitForIdle();
  87 
  88             if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) {
  89                 throw new RuntimeException("Maximized state was not set for frame in setVisible");
  90             }
  91         } finally {
  92             if (frame != null) frame.dispose();
  93         }
  94     }
  95 
  96     private static Rectangle getAvailableScreenBounds() {
  97         final Toolkit toolkit = Toolkit.getDefaultToolkit();
  98         final GraphicsEnvironment graphicsEnvironment =
  99                 GraphicsEnvironment.getLocalGraphicsEnvironment();
 100         final GraphicsDevice graphicsDevice =
 101                 graphicsEnvironment.getDefaultScreenDevice();
 102 
 103         final Dimension screenSize = toolkit.getScreenSize();
 104         final Insets screenInsets = toolkit.getScreenInsets(
 105                 graphicsDevice.getDefaultConfiguration());
 106 
 107         final Rectangle availableScreenBounds = new Rectangle(screenSize);
 108 
 109         availableScreenBounds.x += screenInsets.left;
 110         availableScreenBounds.y += screenInsets.top;
 111         availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
 112         availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);
< prev index next >