Path: blob/master/test/jdk/java/awt/List/FocusEmptyListTest/FocusEmptyListTest.java
41153 views
/*1* Copyright (c) 2007, 2020, 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 638727527@summary List: the focus is at the top of the first item, XAWT28@requires os.family == "linux"29@modules java.desktop/sun.awt30java.desktop/java.awt.peer31java.desktop/sun.awt.X11:open32@run main FocusEmptyListTest33*/3435import java.awt.*;36import java.lang.reflect.*;37import java.awt.peer.ListPeer;3839import sun.awt.AWTAccessor;4041public class FocusEmptyListTest extends Frame {4243public static void main(final String[] args) {44FocusEmptyListTest app = new FocusEmptyListTest();45app.start();46}4748public void start() {49boolean isXToolkit = Toolkit.getDefaultToolkit()50.getClass().getName().equals("sun.awt.X11.XToolkit");51if (!isXToolkit) {52System.out.println("The test is XAWT-only.");53return;54}5556List list = new List();57Object isIndexDisplayed = null;58setLayout(new FlowLayout());5960getToolkit().addAWTEventListener(System.out::println,61AWTEvent.FOCUS_EVENT_MASK | AWTEvent.WINDOW_FOCUS_EVENT_MASK);6263add(list);64list.add("item1");6566setSize(200, 200);67setUndecorated(true);68setLocationRelativeTo(null);69setVisible(true);70validate();7172list.removeAll();7374try {7576// peer = List.getPeer()77ListPeer peer = AWTAccessor.getComponentAccessor().getPeer(list);78System.out.println("peer = " + peer);79Class peerClass = peer.getClass();80System.out.println("peer's class = " + peerClass);8182// isIndexDisplayed = peer.isIndexDisplayed(-1)83Method isIndexDisplayedM84= peerClass.getDeclaredMethod("isIndexDisplayed", Integer.TYPE);85System.out.println("method = " + isIndexDisplayedM);86isIndexDisplayedM.setAccessible(true);87isIndexDisplayed = isIndexDisplayedM.invoke(peer, -1);88System.out.println("isIndexDisplayed=" + isIndexDisplayed);8990} catch (Throwable thr) {91throw new RuntimeException("TEST FAILED: " + thr);92}9394if ((Boolean) isIndexDisplayed) {95throw new RuntimeException("TEST FAILED: -1 should be"96+ " invisible index");97}9899}// start()100101}// class AutomaticAppletTest102103104