Path: blob/master/test/jdk/java/awt/FileDialog/ISCthrownByFileListTest/ISCthrownByFileListTest.java
41153 views
/*1* Copyright (c) 2005, 2014, 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@bug 630497926@key headful27@summary REG: File Dialog throws ArrayIndexOutOfBounds Exception on XToolkit with b4528@author Dmitry Cherepanov: area=awt.filedialog29@run main/othervm -Dsun.awt.disableGtkFileDialogs=true ISCthrownByFileListTest30*/3132import java.awt.*;33import java.awt.event.*;34import java.lang.reflect.*;3536/*37Since the "sun.awt.exception.handler" property will be removed in a future release38this test will be rewritten using new future API. (<<< Done).39It's important that the bug 6304979 is reproducible if the bug 6299853 is reproducible.40*/4142public class ISCthrownByFileListTest43{44private static Frame frame = null;45private static FileDialog fd = null;4647// The handler load the class and instantiate this class48// so the 'passed' variable is static49static boolean passed = true;5051public static final void main(String args[]) {52// It's not true that the native file dialog will be focused on Motif & Windows53boolean isXToolkit = Toolkit.getDefaultToolkit().getClass().getName().equals("sun.awt.X11.XToolkit");54if (!isXToolkit){55return;56}5758frame = new Frame("frame");59frame.setLayout (new FlowLayout ());60frame.setBounds(100, 100, 100, 100);61frame.setVisible(true);6263fd = new FileDialog(frame, "file dialog", FileDialog.LOAD);6465// In order to handle all uncaught exceptions in the EDT66final Thread.UncaughtExceptionHandler eh = new Thread.UncaughtExceptionHandler()67{68@Override69public void uncaughtException(Thread t, Throwable e)70{71e.printStackTrace();72ISCthrownByFileListTest.passed = false;73}74};7576test();77}// start()7879private static void test (){80Robot r;8182try {83r = new Robot();84} catch(AWTException e) {85throw new RuntimeException(e.getMessage());86}8788r.delay(500);89new Thread(new Runnable() {90public void run() {91// The bug 6299853 is reproducible only if the file list is not empty92// since else the focus will be set to the directory list.93// But the focus index of the directory list equals 0.94// So goto the source directory (the file list is non empty)95fd.setDirectory(System.getProperty("test.src", "."));96fd.setVisible(true);97}98}).start();99r.delay(2000);100r.waitForIdle();101102Component focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();103if (focusedWindow != fd) {104throw new RuntimeException("Test failed - the file dialog isn't focused window, owner: " + focusedWindow);105}106r.waitForIdle();107108r.keyPress(KeyEvent.VK_SPACE);109r.delay(50);110r.keyRelease(KeyEvent.VK_SPACE);111r.delay(1000);112fd.setVisible(false);113r.delay(1000);114r.waitForIdle();115116if (!ISCthrownByFileListTest.passed){117throw new RuntimeException("Test failed.");118}119120}// test()121}// class ISCthrownByFileListTest122123124