4883N/A/*
4883N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
4883N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4883N/A *
4883N/A * This code is free software; you can redistribute it and/or modify it
4883N/A * under the terms of the GNU General Public License version 2 only, as
4883N/A * published by the Free Software Foundation.
4883N/A *
4883N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4883N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4883N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4883N/A * version 2 for more details (a copy is included in the LICENSE file that
4883N/A * accompanied this code).
4883N/A *
4883N/A * You should have received a copy of the GNU General Public License version
4883N/A * 2 along with this work; if not, write to the Free Software Foundation,
4883N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4883N/A *
4883N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4883N/A * or visit www.oracle.com if you need additional information or have any
4883N/A * questions.
4883N/A */
4883N/A
4883N/A/*
4883N/A @test
4883N/A @bug 7154177
4883N/A @summary An invisible owner frame should never become visible
4883N/A @author anthony.petrov@oracle.com: area=awt.toplevel
4883N/A @library ../../regtesthelpers
4883N/A @build Util
4883N/A @run main InvisibleOwner
4883N/A*/
4883N/A
4883N/Aimport java.awt.*;
4883N/Aimport java.awt.event.*;
4883N/Aimport java.util.*;
4883N/Aimport test.java.awt.regtesthelpers.Util;
4883N/A
4883N/Apublic class InvisibleOwner {
4883N/A private static volatile boolean invisibleOwnerClicked = false;
4883N/A private static volatile boolean backgroundClicked = false;
4883N/A
4883N/A private static final int F_X = 40, F_Y = 40, F_W = 200, F_H = 200;
4883N/A
4883N/A public static void main(String[] args) throws AWTException {
4883N/A // A background frame to compare a pixel color against
4883N/A Frame helperFrame = new Frame("Background frame");
4883N/A helperFrame.setBackground(Color.BLUE);
4883N/A helperFrame.setBounds(F_X - 10, F_Y - 10, F_W + 20, F_H + 20);
4883N/A helperFrame.addMouseListener(new MouseAdapter() {
4883N/A @Override
4883N/A public void mouseClicked(MouseEvent ev) {
4883N/A backgroundClicked= true;
4883N/A }
4883N/A });
4883N/A helperFrame.setVisible(true);
4883N/A
4883N/A // An owner frame that should stay invisible
4883N/A Frame frame = new Frame("Invisible Frame");
4883N/A frame.setBackground(Color.GREEN);
4883N/A frame.setLocation(F_X, F_Y);
4883N/A frame.setSize(F_W, F_H);
4883N/A frame.addMouseListener(new MouseAdapter() {
4883N/A @Override
4883N/A public void mouseClicked(MouseEvent ev) {
4883N/A invisibleOwnerClicked = true;
4883N/A }
4883N/A });
4883N/A
4883N/A // An owned window
4883N/A final Window window = new Window(frame);
4883N/A window.setBackground(Color.RED);
4883N/A window.setSize(200, 200);
4883N/A window.setLocation(300, 300);
4883N/A window.setVisible(true);
4883N/A try { Thread.sleep(1000); } catch (Exception ex) {}
4883N/A
4883N/A Robot robot = new Robot();
4883N/A
4883N/A // Clicking the owned window shouldn't make its owner visible
4883N/A Util.clickOnComp(window, robot);
4883N/A try { Thread.sleep(500); } catch (Exception ex) {}
4883N/A
4883N/A
4883N/A // Assume the location and size are applied to the frame as expected.
4883N/A // This should work fine on the Mac. We can't call getLocationOnScreen()
4883N/A // since from Java perspective the frame is invisible anyway.
4883N/A
4883N/A // 1. Check the color at the center of the owner frame
4883N/A Color c = robot.getPixelColor(F_X + F_W / 2, F_Y + F_H / 2);
4883N/A System.err.println("Pixel color: " + c);
4883N/A if (c == null) {
4883N/A throw new RuntimeException("Robot.getPixelColor() failed");
4883N/A }
4883N/A if (c.equals(frame.getBackground())) {
4883N/A throw new RuntimeException("The invisible frame has become visible");
4883N/A }
4883N/A if (!c.equals(helperFrame.getBackground())) {
4883N/A throw new RuntimeException("The background helper frame has been covered by something unexpected");
4883N/A }
4883N/A
4883N/A // 2. Try to click it
4883N/A robot.mouseMove(F_X + F_W / 2, F_Y + F_H / 2);
4883N/A robot.mousePress(InputEvent.BUTTON1_MASK);
4883N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
4883N/A try { Thread.sleep(500); } catch (Exception ex) {}
4883N/A
4883N/A // Cleanup
4883N/A window.dispose();
4883N/A frame.dispose();
4883N/A helperFrame.dispose();
4883N/A
4883N/A // Final checks
4883N/A if (invisibleOwnerClicked) {
4883N/A throw new RuntimeException("An invisible owner frame got clicked. Looks like it became visible.");
4883N/A }
4883N/A if (!backgroundClicked) {
4883N/A throw new RuntimeException("The background helper frame hasn't been clciked");
4883N/A }
4883N/A }
4883N/A}