Path: blob/master/test/jdk/java/awt/Dialog/ValidateOnShow/ValidateOnShow.java
41154 views
/*1* Copyright (c) 2011, 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 702701327@summary Dialog.show() should validate the window unconditionally28@author [email protected]: area=awt.toplevel29@run main ValidateOnShow30*/3132import java.awt.*;3334public class ValidateOnShow {35private static Dialog dialog = new Dialog((Frame)null);36private static Panel panel = new Panel() {37@Override38public boolean isValidateRoot() {39return true;40}41};42private static Button button = new Button("Test");4344private static void sleep() {45try { Thread.sleep(500); } catch (Exception e) {}46}4748private static void test() {49System.out.println("Before showing: panel.isValid=" + panel.isValid() + " dialog.isValid=" + dialog.isValid());50dialog.setVisible(true);51sleep();52System.out.println("After showing: panel.isValid=" + panel.isValid() + " dialog.isValid=" + dialog.isValid());5354if (!panel.isValid()) {55dialog.dispose();56throw new RuntimeException("The panel hasn't been validated upon showing the dialog");57}5859dialog.setVisible(false);60sleep();61}6263public static void main(String[] args) {64// setup65dialog.add(panel);66panel.add(button);6768dialog.setBounds(200, 200, 300, 200);6970// The first test should always succeed since the dialog is invalid initially71test();7273// now invalidate the button and the panel74button.setBounds(1, 1, 30, 30);75sleep();76// since the panel is a validate root, the dialog is still valid7778// w/o a fix this would fail79test();8081// cleanup82dialog.dispose();83}84}858687