Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Choice/ResizeAutoClosesChoice/ResizeAutoClosesChoice.java
47497 views
/*1* Copyright (c) 2006, 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*/22/*23@test24@bug 639967925@summary Choice is not invalidated when the frame gets resized programmatically when the drop-down is visible26@author andrei.dmitriev area=awt.choice27@library ../../../../lib/testlibrary28@build jdk.testlibrary.OSInfo29@run main ResizeAutoClosesChoice30*/3132import java.awt.*;33import java.awt.event.*;3435import jdk.testlibrary.OSInfo;3637public class ResizeAutoClosesChoice38{39static Frame frame = new Frame("Test Frame");40static Choice choice1 = new Choice();41static Robot robot;42static Point pt;43static String passed = null;44static Button button = new Button("This button causes Frame to be resized on pack()");45public static void main(String args[]) throws Exception46{47if(OSInfo.getOSType().equals(OSInfo.OSType.MACOSX)) {48System.out.println("Not for OS OX");49return;50}5152choice1.setForeground(Color.red);53choice1.setBackground(Color.red);5455frame.setLayout (new BorderLayout ());56for (int i = 1; i<10;i++){57choice1.add("item "+i);58}59frame.setSize(300, 300);60choice1.setLocation(50, 50);61choice1.setSize(70, 20);6263button.setLocation(150, 100);64button.setSize(150, 20);65frame.add(choice1, BorderLayout.SOUTH);66frame.pack();6768frame.validate();69frame.setVisible(true);7071robot = new Robot();72robot.waitForIdle();73pt = choice1.getLocationOnScreen();74robot.mouseMove(pt.x + choice1.getWidth()/10*9, pt.y + choice1.getHeight()/2);75robot.waitForIdle();76robot.mousePress(InputEvent.BUTTON1_MASK);77robot.delay(1000);78robot.mouseRelease(InputEvent.BUTTON1_MASK);7980Color color = robot.getPixelColor(pt.x + choice1.getWidth()/2,81pt.y + 3 * choice1.getHeight());82//should take a color on the point on the choice's menu83System.out.println("Choice opened. Color got : "+color);84if ( !color.equals(Color.red) ){85passed = "Choice wasn't opened with the mouse";86}8788Rectangle oldBounds = choice1.getBounds();89System.out.println("Choice's old bounds : "+oldBounds);9091frame.add(button, BorderLayout.NORTH);92// frame.setSize(500, 500);93frame.pack();94robot.waitForIdle();95System.out.println("Choice's new bounds : "+choice1.getBounds());9697if (!choice1.getBounds().equals(oldBounds)){98pt = choice1.getLocationOnScreen();99color = robot.getPixelColor(pt.x + choice1.getWidth()/2,100pt.y + 3 * choice1.getHeight());101System.out.println("Choice opened. Color got : "+color);102if (color.equals(Color.red) ){103passed = "Choice wasn't closed when toplevel repacked.";104}105} else {106System.out.println("frame.pack didn't changed Choice's size - dropdown menu should remain the same. Test passed.");107}108if (passed != null){109throw new RuntimeException(passed);110}111}112}113114115