FirstItemRemoveTest.java revision 10730:07156012ab78
1221828Sgrehan/* 2221828Sgrehan * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3260167Sneel * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4221828Sgrehan * 5221828Sgrehan * This code is free software; you can redistribute it and/or modify it 6221828Sgrehan * under the terms of the GNU General Public License version 2 only, as 7221828Sgrehan * published by the Free Software Foundation. 8221828Sgrehan * 9221828Sgrehan * This code is distributed in the hope that it will be useful, but WITHOUT 10221828Sgrehan * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11221828Sgrehan * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12221828Sgrehan * version 2 for more details (a copy is included in the LICENSE file that 13221828Sgrehan * accompanied this code). 14221828Sgrehan * 15221828Sgrehan * You should have received a copy of the GNU General Public License version 16221828Sgrehan * 2 along with this work; if not, write to the Free Software Foundation, 17221828Sgrehan * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18221828Sgrehan * 19221828Sgrehan * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20221828Sgrehan * or visit www.oracle.com if you need additional information or have any 21221828Sgrehan * questions. 22221828Sgrehan */ 23221828Sgrehan 24221828Sgrehan/* 25221828Sgrehan test 26221828Sgrehan @bug 6299858 7124338 27221828Sgrehan @summary PIT. Focused border not shown on List if selected item is removed, XToolkit 28221828Sgrehan @author Dmitry.Cherepanov@SUN.COM area=awt.list 29221828Sgrehan @run applet FirstItemRemoveTest.html 30221828Sgrehan*/ 31221828Sgrehan 32273214Simpimport java.applet.Applet; 33221828Sgrehanimport java.awt.*; 34256072Sneelimport java.awt.event.*; 35256072Sneel 36256072Sneelpublic class FirstItemRemoveTest extends Applet 37256072Sneel{ 38256072Sneel List list = new List(4, false); 39256072Sneel Panel panel = new Panel(); 40266390Sgrehan 41266390Sgrehan public void init() 42266390Sgrehan { 43266390Sgrehan list.add("000"); 44221828Sgrehan list.add("111"); 45222112Sneel list.add("222"); 46222112Sneel list.add("333"); 47222112Sneel list.add("444"); 48222112Sneel list.add("555"); 49222112Sneel 50222112Sneel panel.setLayout(new FlowLayout ()); 51222112Sneel panel.add(list); 52222112Sneel 53221828Sgrehan this.add(panel); 54221828Sgrehan this.setLayout (new FlowLayout ()); 55222112Sneel }//End init() 56221828Sgrehan 57221828Sgrehan public void start () 58221828Sgrehan { 59221828Sgrehan setSize (200,200); 60221828Sgrehan setVisible(true); 61221828Sgrehan validate(); 62221828Sgrehan 63221828Sgrehan test(); 64221828Sgrehan }// start() 65221828Sgrehan 66221828Sgrehan private void test(){ 67221828Sgrehan 68221828Sgrehan if (jdk.testlibrary.OSInfo.getOSType() == jdk.testlibrary.OSInfo.OSType.MACOSX) { 69221828Sgrehan System.err.println("Skipped. This test is not for OS X."); 70221828Sgrehan return; 71221828Sgrehan } 72221828Sgrehan 73221828Sgrehan Robot r; 74256072Sneel try { 75260167Sneel r = new Robot(); 76260167Sneel } catch(AWTException e) { 77260167Sneel throw new RuntimeException(e.getMessage()); 78256072Sneel } 79264353Sneel 80260167Sneel // Removing first item in order to reproduce incorrect behaviour 81260167Sneel r.delay(1000); 82260167Sneel list.remove(0); 83260167Sneel r.delay(1000); 84260167Sneel 85260167Sneel // Request focus to list 86260167Sneel Point loc = this.getLocationOnScreen(); 87221828Sgrehan r.delay(1000); 88264353Sneel 89260167Sneel r.mouseMove(loc.x+10, loc.y+10); 90260167Sneel r.delay(10); 91260167Sneel r.mousePress(InputEvent.BUTTON1_MASK); 92260167Sneel r.delay(10); 93260167Sneel r.mouseRelease(InputEvent.BUTTON1_MASK); 94260167Sneel r.delay(1000); 95260167Sneel 96260167Sneel list.requestFocusInWindow(); 97256072Sneel r.delay(1000); 98260167Sneel r.waitForIdle(); 99260167Sneel if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != list){ 100261453Sneel throw new RuntimeException("Test failed - list isn't focus owner."); 101261453Sneel } 102260167Sneel 103256072Sneel // The focus index should be set to first item after removing 104260167Sneel // So if we press VK_SPACE then the selected item will be equals 0. 105266390Sgrehan r.delay(100); 106260167Sneel r.keyPress(KeyEvent.VK_SPACE); 107260167Sneel r.delay(10); 108260167Sneel r.keyRelease(KeyEvent.VK_SPACE); 109264353Sneel r.delay(1000); 110260167Sneel r.waitForIdle(); 111260167Sneel 112260167Sneel int selectedIndex = list.getSelectedIndex(); 113260167Sneel if (selectedIndex != 0){ 114260167Sneel throw new RuntimeException("Test failed. list.getSelectedIndex() = "+selectedIndex); 115260167Sneel } 116256072Sneel 117256072Sneel } 118260167Sneel 119261453Sneel}// class AutomaticAppletTest 120260167Sneel