1 /*
   2  * Copyright (c) 2016, 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 8169589
  27  * @summary Activating a dialog puts to back another dialog owned by the same frame
  28  * @author Dmitry Markov
  29  * @library ../../regtesthelpers
  30  * @build Util
  31  * @run main DialogAboveFrameTest
  32  */
  33 
  34 import java.awt.Color;
  35 import java.awt.Dialog;
  36 import java.awt.Frame;
  37 import java.awt.Point;
  38 import java.awt.Robot;
  39 
  40 import test.java.awt.regtesthelpers.Util;
  41 
  42 public class DialogAboveFrameTest {
  43     public static void main(String[] args) {
  44         Robot robot = Util.createRobot();
  45 
  46         Frame frame = new Frame("Frame");
  47         frame.setBackground(Color.BLUE);
  48         frame.setBounds(200, 50, 300, 300);
  49         frame.setVisible(true);
  50 
  51         Dialog dialog1 = new Dialog(frame, "Dialog 1", false);
  52         dialog1.setBackground(Color.RED);
  53         dialog1.setBounds(100, 100, 200, 200);
  54         dialog1.setVisible(true);
  55 
  56         Dialog dialog2 = new Dialog(frame, "Dialog 2", false);
  57         dialog2.setBackground(Color.GREEN);
  58         dialog2.setBounds(400, 100, 200, 200);
  59         dialog2.setVisible(true);
  60 
  61         Util.waitForIdle(robot);
  62 
  63         Util.clickOnComp(dialog2, robot);
  64         Util.waitForIdle(robot);
  65 
  66         Point point = dialog1.getLocationOnScreen();
  67         int x = point.x + (int)(dialog1.getWidth() * 0.9);
  68         int y = point.y + (int)(dialog1.getHeight() * 0.9);
  69 
  70         try {
  71             if (!robot.getPixelColor(x, y).equals(dialog1.getBackground())) {
  72                 throw new RuntimeException("Test FAILED: Dialog is behind the frame");
  73             }
  74         } finally {
  75             frame.dispose();
  76             dialog1.dispose();
  77             dialog2.dispose();
  78         }
  79     }
  80 }
  81