1 /*
   2  * Copyright (c) 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 /*
  25   @test
  26   @bug 8020443
  27   @summary Frame is not created on the specified GraphicsDevice with two
  28 monitors
  29   @author Oleg Pekhovskiy
  30   @library ../../../../lib/testlibrary
  31   @build jdk.testlibrary.OSInfo
  32   @run main MultiScreenInsetsTest
  33  */
  34 
  35 import java.awt.Frame;
  36 import java.awt.GraphicsConfiguration;
  37 import java.awt.GraphicsDevice;
  38 import java.awt.GraphicsEnvironment;
  39 import java.awt.Insets;
  40 import java.awt.Rectangle;
  41 import java.awt.Toolkit;
  42 import jdk.testlibrary.OSInfo;
  43 
  44 public class MultiScreenInsetsTest {
  45     private static final int SIZE = 100;
  46 
  47     public static void main(String[] args) throws InterruptedException {
  48         OSInfo.OSType type = OSInfo.getOSType();
  49         if (type != OSInfo.OSType.LINUX && type != OSInfo.OSType.SOLARIS) {
  50             System.out.println("This test is for Solaris and Linux only..." +
  51                                "skipping!");
  52             return;
  53         }
  54 
  55         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  56         GraphicsDevice[] gds = ge.getScreenDevices();
  57         if (gds.length < 2) {
  58             System.out.println("It's a multi-screen test... skipping!");
  59             return;
  60         }
  61 
  62         for (int screen = 0; screen < gds.length; ++screen) {
  63             GraphicsDevice gd = gds[screen];
  64             GraphicsConfiguration gc = gd.getDefaultConfiguration();
  65             Rectangle bounds = gc.getBounds();
  66             Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
  67 
  68             Frame frame = new Frame(gc);
  69             frame.setLocation(bounds.x + (bounds.width - SIZE) / 2,
  70                               bounds.y + (bounds.height - SIZE) / 2);
  71             frame.setSize(SIZE, SIZE);
  72             frame.setUndecorated(true);
  73             frame.setVisible(true);
  74 
  75             // Maximize Frame to reach the struts
  76             frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
  77             Thread.sleep(2000);
  78 
  79             Rectangle frameBounds = frame.getBounds();
  80             frame.dispose();
  81             if (bounds.x + insets.left != frameBounds.x
  82                 || bounds.y + insets.top != frameBounds.y
  83                 || bounds.width - insets.right - insets.left != frameBounds.width
  84                 || bounds.height - insets.bottom - insets.top != frameBounds.height) {
  85                 throw new RuntimeException("Test FAILED! Wrong screen #" +
  86                                            screen + " insets: " + insets);
  87             }
  88         }
  89         System.out.println("Test PASSED!");
  90     }
  91 }