Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/FileDialog/ISCthrownByFileListTest/ISCthrownByFileListTest.java
38828 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@summary REG: File Dialog throws ArrayIndexOutOfBounds Exception on XToolkit with b4527@author Dmitry Cherepanov: area=awt.filedialog28@run main/othervm -Dsun.awt.disableGtkFileDialogs=true ISCthrownByFileListTest29*/3031import java.awt.*;32import java.awt.event.*;33import java.lang.reflect.*;3435/*36Since the "sun.awt.exception.handler" property will be removed in a future release37this test will be rewritten using new future API. (<<< Done).38It's important that the bug 6304979 is reproducible if the bug 6299853 is reproducible.39*/4041public class ISCthrownByFileListTest42{43private static Frame frame = null;44private static FileDialog fd = null;4546// The handler load the class and instantiate this class47// so the 'passed' variable is static48static boolean passed = true;4950public static final void main(String args[]) {51// It's not true that the native file dialog will be focused on Motif & Windows52boolean isXToolkit = Toolkit.getDefaultToolkit().getClass().getName().equals("sun.awt.X11.XToolkit");53if (!isXToolkit){54return;55}5657frame = new Frame("frame");58frame.setLayout (new FlowLayout ());59frame.setBounds(100, 100, 100, 100);60frame.setVisible(true);6162fd = new FileDialog(frame, "file dialog", FileDialog.LOAD);6364// In order to handle all uncaught exceptions in the EDT65final Thread.UncaughtExceptionHandler eh = new Thread.UncaughtExceptionHandler()66{67@Override68public void uncaughtException(Thread t, Throwable e)69{70e.printStackTrace();71ISCthrownByFileListTest.passed = false;72}73};7475test();76}// start()7778private static void test (){79Robot r;8081try {82r = new Robot();83} catch(AWTException e) {84throw new RuntimeException(e.getMessage());85}8687r.delay(500);88new Thread(new Runnable() {89public void run() {90// The bug 6299853 is reproducible only if the file list is not empty91// since else the focus will be set to the directory list.92// But the focus index of the directory list equals 0.93// So goto the source directory (the file list is non empty)94fd.setDirectory(System.getProperty("test.src", "."));95fd.setVisible(true);96}97}).start();98r.delay(2000);99r.waitForIdle();100101Component focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();102if (focusedWindow != fd) {103throw new RuntimeException("Test failed - the file dialog isn't focused window, owner: " + focusedWindow);104}105r.waitForIdle();106107r.keyPress(KeyEvent.VK_SPACE);108r.delay(50);109r.keyRelease(KeyEvent.VK_SPACE);110r.delay(1000);111fd.setVisible(false);112r.delay(1000);113r.waitForIdle();114115if (!ISCthrownByFileListTest.passed){116throw new RuntimeException("Test failed.");117}118119}// test()120}// class ISCthrownByFileListTest121122123