Path: blob/master/test/jdk/java/awt/Choice/ResizeAutoClosesChoice/ResizeAutoClosesChoice.java
41152 views
/*1* Copyright (c) 2006, 2018, 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@key headful25@bug 639967926@summary Choice is not invalidated when the frame gets resized programmatically when the drop-down is visible27@author andrei.dmitriev area=awt.choice28@library /test/lib29@build jdk.test.lib.Platform30@run main ResizeAutoClosesChoice31*/3233import java.awt.*;34import java.awt.event.*;3536import jdk.test.lib.Platform;3738public class ResizeAutoClosesChoice39{40static Frame frame = new Frame("Test Frame");41static Choice choice1 = new Choice();42static Robot robot;43static Point pt;44static String passed = null;45static Button button = new Button("This button causes Frame to be resized on pack()");46public static void main(String args[]) throws Exception47{48if (Platform.isOSX()) {49System.out.println("Not for OS OX");50return;51}5253choice1.setForeground(Color.red);54choice1.setBackground(Color.red);5556frame.setLayout (new BorderLayout ());57for (int i = 1; i<10;i++){58choice1.add("item "+i);59}60frame.setSize(300, 300);61choice1.setLocation(50, 50);62choice1.setSize(70, 20);6364button.setLocation(150, 100);65button.setSize(150, 20);66frame.add(choice1, BorderLayout.SOUTH);67frame.pack();6869frame.validate();70frame.setVisible(true);7172robot = new Robot();73robot.waitForIdle();74pt = choice1.getLocationOnScreen();75robot.mouseMove(pt.x + choice1.getWidth()/10*9, pt.y + choice1.getHeight()/2);76robot.waitForIdle();77robot.mousePress(InputEvent.BUTTON1_MASK);78robot.delay(1000);79robot.mouseRelease(InputEvent.BUTTON1_MASK);8081Color color = robot.getPixelColor(pt.x + choice1.getWidth()/2,82pt.y + 3 * choice1.getHeight());83//should take a color on the point on the choice's menu84System.out.println("Choice opened. Color got : "+color);85if ( !color.equals(Color.red) ){86passed = "Choice wasn't opened with the mouse";87}8889Rectangle oldBounds = choice1.getBounds();90System.out.println("Choice's old bounds : "+oldBounds);9192frame.add(button, BorderLayout.NORTH);93// frame.setSize(500, 500);94frame.pack();95robot.waitForIdle();96System.out.println("Choice's new bounds : "+choice1.getBounds());9798if (!choice1.getBounds().equals(oldBounds)){99pt = choice1.getLocationOnScreen();100color = robot.getPixelColor(pt.x + choice1.getWidth()/2,101pt.y + 3 * choice1.getHeight());102System.out.println("Choice opened. Color got : "+color);103if (color.equals(Color.red) ){104passed = "Choice wasn't closed when toplevel repacked.";105}106} else {107System.out.println("frame.pack didn't changed Choice's size - dropdown menu should remain the same. Test passed.");108}109if (passed != null){110throw new RuntimeException(passed);111}112}113}114115116