Path: blob/master/test/jdk/java/awt/FileDialog/FileDialogIconTest/FileDialogIconTest.java
41155 views
/*1* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @key headful26* @bug 8157163 815913227* @summary AWT FileDialog does not inherit icon image from parent Frame28* @requires os.family=="windows"29* @run main FileDialogIconTest30*/3132import java.awt.Color;33import java.awt.Dialog;34import java.awt.FileDialog;35import java.awt.Frame;36import java.awt.Graphics;37import java.awt.Point;38import java.awt.Robot;39import java.awt.Image;40import java.awt.image.BufferedImage;41import javax.swing.SwingUtilities;4243public class FileDialogIconTest {44private static Frame frame;45private static Dialog dialog;4647public static void main(final String[] args) throws Exception {48Robot robot;49Point p;50try {51frame = new Frame();52frame.setIconImage(createImage());53frame.setVisible(true);54robot = new Robot();55robot.waitForIdle();56robot.delay(200);5758dialog = new FileDialog(frame, "Dialog");59dialog.setModal(false);60dialog.setVisible(true);61robot.waitForIdle();62robot.delay(1000);6364p = new Point(20, 20);65SwingUtilities.convertPointToScreen(p, dialog);66Color color = robot.getPixelColor(p.x, p.y);67if (!Color.RED.equals(color)) {68throw new RuntimeException("Dialog icon was not inherited from " +69"owning window. Wrong color: " + color);70}71} finally {72if (dialog != null) { dialog.dispose(); }73if (frame != null) { frame.dispose(); }74}75}7677private static Image createImage() {78BufferedImage image = new BufferedImage(64, 64,79BufferedImage.TYPE_INT_ARGB);80Graphics g = image.getGraphics();81g.setColor(Color.RED);82g.fillRect(0, 0, image.getWidth(), image.getHeight());83g.dispose();84return image;85}8687}888990