Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/List/FirstItemRemoveTest/FirstItemRemoveTest.java
38828 views
/*1* Copyright (c) 2013, 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/*24test25@bug 6299858 712433826@summary PIT. Focused border not shown on List if selected item is removed, XToolkit27@author [email protected] area=awt.list28@run applet FirstItemRemoveTest.html29*/3031import java.applet.Applet;32import java.awt.*;33import java.awt.event.*;3435public class FirstItemRemoveTest extends Applet36{37List list = new List(4, false);38Panel panel = new Panel();3940public void init()41{42list.add("000");43list.add("111");44list.add("222");45list.add("333");46list.add("444");47list.add("555");4849panel.setLayout(new FlowLayout ());50panel.add(list);5152this.add(panel);53this.setLayout (new FlowLayout ());54}//End init()5556public void start ()57{58setSize (200,200);59setVisible(true);60validate();6162test();63}// start()6465private void test(){6667if (sun.awt.OSInfo.getOSType() == sun.awt.OSInfo.OSType.MACOSX) {68System.err.println("Skipped. This test is not for OS X.");69return;70}7172Robot r;73try {74r = new Robot();75} catch(AWTException e) {76throw new RuntimeException(e.getMessage());77}7879// Removing first item in order to reproduce incorrect behaviour80r.delay(1000);81list.remove(0);82r.delay(1000);8384// Request focus to list85Point loc = this.getLocationOnScreen();86r.delay(1000);8788r.mouseMove(loc.x+10, loc.y+10);89r.delay(10);90r.mousePress(InputEvent.BUTTON1_MASK);91r.delay(10);92r.mouseRelease(InputEvent.BUTTON1_MASK);93r.delay(1000);9495list.requestFocusInWindow();96r.delay(1000);97r.waitForIdle();98if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != list){99throw new RuntimeException("Test failed - list isn't focus owner.");100}101102// The focus index should be set to first item after removing103// So if we press VK_SPACE then the selected item will be equals 0.104r.delay(100);105r.keyPress(KeyEvent.VK_SPACE);106r.delay(10);107r.keyRelease(KeyEvent.VK_SPACE);108r.delay(1000);109r.waitForIdle();110111int selectedIndex = list.getSelectedIndex();112if (selectedIndex != 0){113throw new RuntimeException("Test failed. list.getSelectedIndex() = "+selectedIndex);114}115116}117118}// class AutomaticAppletTest119120121