Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Dialog/ValidateOnShow/ValidateOnShow.java
38828 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@bug 702701326@summary Dialog.show() should validate the window unconditionally27@author [email protected]: area=awt.toplevel28@run main ValidateOnShow29*/3031import java.awt.*;3233public class ValidateOnShow {34private static Dialog dialog = new Dialog((Frame)null);35private static Panel panel = new Panel() {36@Override37public boolean isValidateRoot() {38return true;39}40};41private static Button button = new Button("Test");4243private static void sleep() {44try { Thread.sleep(500); } catch (Exception e) {}45}4647private static void test() {48System.out.println("Before showing: panel.isValid=" + panel.isValid() + " dialog.isValid=" + dialog.isValid());49dialog.setVisible(true);50sleep();51System.out.println("After showing: panel.isValid=" + panel.isValid() + " dialog.isValid=" + dialog.isValid());5253if (!panel.isValid()) {54dialog.dispose();55throw new RuntimeException("The panel hasn't been validated upon showing the dialog");56}5758dialog.setVisible(false);59sleep();60}6162public static void main(String[] args) {63// setup64dialog.add(panel);65panel.add(button);6667dialog.setBounds(200, 200, 300, 200);6869// The first test should always succeed since the dialog is invalid initially70test();7172// now invalidate the button and the panel73button.setBounds(1, 1, 30, 30);74sleep();75// since the panel is a validate root, the dialog is still valid7677// w/o a fix this would fail78test();7980// cleanup81dialog.dispose();82}83}848586