Path: blob/master/test/jdk/java/awt/List/FirstItemRemoveTest/FirstItemRemoveTest.java
41153 views
/*1* Copyright (c) 2013, 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*/2223/*24@test25@key headful26@bug 629985827@summary PIT. Focused border not shown on List if selected item is removed, XToolkit28@library /test/lib29@build jdk.test.lib.Platform30@run main FirstItemRemoveTest31*/3233import jdk.test.lib.Platform;3435import java.awt.*;36import java.awt.event.*;3738public class FirstItemRemoveTest extends Frame39{40List list = new List(4, false);41Panel panel = new Panel();4243public static void main(final String[] args) {44FirstItemRemoveTest app = new FirstItemRemoveTest();45app.init();46app.start();47}4849public void init()50{51list.add("000");52list.add("111");53list.add("222");54list.add("333");55list.add("444");56list.add("555");5758panel.setLayout(new FlowLayout ());59panel.add(list);6061this.add(panel);62this.setLayout (new FlowLayout ());63}//End init()6465public void start ()66{67setSize (200,200);68setUndecorated(true);69setLocationRelativeTo(null);70setVisible(true);71validate();7273test();74}// start()7576private void test(){7778if (Platform.isOSX()) {79System.err.println("Skipped. This test is not for OS X.");80return;81}8283Robot r;84try {85r = new Robot();86} catch(AWTException e) {87throw new RuntimeException(e.getMessage());88}8990// Removing first item in order to reproduce incorrect behaviour91r.delay(1000);92list.remove(0);93r.delay(1000);9495// Request focus to list96Point loc = this.getLocationOnScreen();97r.delay(1000);9899r.mouseMove(loc.x+10, loc.y+10);100r.delay(10);101r.mousePress(InputEvent.BUTTON1_MASK);102r.delay(10);103r.mouseRelease(InputEvent.BUTTON1_MASK);104r.delay(1000);105106list.requestFocusInWindow();107r.delay(1000);108r.waitForIdle();109if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != list){110throw new RuntimeException("Test failed - list isn't focus owner.");111}112113// The focus index should be set to first item after removing114// So if we press VK_SPACE then the selected item will be equals 0.115r.delay(100);116r.keyPress(KeyEvent.VK_SPACE);117r.delay(10);118r.keyRelease(KeyEvent.VK_SPACE);119r.delay(1000);120r.waitForIdle();121122int selectedIndex = list.getSelectedIndex();123if (selectedIndex != 0){124throw new RuntimeException("Test failed. list.getSelectedIndex() = "+selectedIndex);125}126127}128129}// class AutomaticAppletTest130131132