--- /dev/null 2015-07-13 17:38:58.000000000 +0300 +++ new/test/java/awt/FileDialog/ModalFocus/FileDialogModalFocusTest.java 2015-07-13 17:38:57.533472700 +0300 @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* @test + @bug 8025815 + @summary Child FileDialog of modal dialog does not get focus on Gnome + @author Semyon Sadetsky + */ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.image.BufferedImage; +import java.lang.reflect.InvocationTargetException; + +public class FileDialogModalFocusTest { + public static void main(String[] args) throws Exception { + Frame frame = new Frame(); + FileDialog fileDialog = new FileDialog((Frame) null); + test(frame, fileDialog); + frame = new Frame(); + fileDialog = new FileDialog(frame); + test(frame, fileDialog); + System.out.println("ok"); + } + + private static void test(final Frame frame, final FileDialog fileDialog) + throws InterruptedException, InvocationTargetException, + AWTException { + Button button = new Button(); + button.setBackground(Color.RED); + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + fileDialog.setVisible(true); + } + }); + frame.add(button); + frame.setSize(200, 200); + EventQueue.invokeAndWait(new Runnable() { + @Override + public void run() { + frame.setVisible(true); + } + }); + Robot robot = new Robot(); + robot.setAutoDelay(200); + robot.waitForIdle(); + Point point = button.getLocationOnScreen(); + point.translate(100, 100); + robot.mouseMove(point.x, point.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + int delay = 0; + while (frame.isFocused() && delay < 2000) { + robot.delay(50); + delay += 50; + } + EventQueue.invokeAndWait(new Runnable() { + @Override + public void run() { + frame.setSize(Toolkit.getDefaultToolkit().getScreenSize()); + button.requestFocus(); + } + }); + robot.waitForIdle(); + Point p = new Point(100, 100); + SwingUtilities.convertPointToScreen(p, button); + BufferedImage image = robot.createScreenCapture( + new Rectangle(p, + new Dimension(button.getWidth() - 200, + button.getHeight() - 200))); + boolean found = false; + for (int x = 0; x < image.getWidth(); x+=50) { + for (int y = 0; y < image.getHeight(); y+=50) { + if( (image.getRGB(x, y) & 0x00FFFF) != 0 ) { + found = true; + break; + }; + } + } + fileDialog.dispose(); + frame.dispose(); + if(!found) { + throw new RuntimeException("file chooser is underneath"); + } + } +} \ No newline at end of file