Path: blob/master/test/jdk/javax/swing/JList/8161483/Bug8161483.java
41153 views
/*1* Copyright (c) 2016, 2017, 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 816148327* @summary Implement AccessibleAction in JList.AccessibleJList.AccessibleJListChild28* @run main Bug816148329*/3031import javax.accessibility.Accessible;32import javax.accessibility.AccessibleAction;33import javax.accessibility.AccessibleContext;34import javax.accessibility.AccessibleSelection;35import javax.swing.DefaultListModel;36import javax.swing.JFrame;37import javax.swing.JList;38import javax.swing.SwingUtilities;3940public class Bug8161483 extends JFrame {4142private static JFrame frame = null;43private static volatile Exception exception = null;44private JList<String> countryList;4546public static void main(String args[]) throws Exception {47try {48SwingUtilities.invokeAndWait(() -> {49DefaultListModel<String> listModel = new DefaultListModel<>();50listModel.addElement("one");51listModel.addElement("two");52listModel.addElement("three");53JList<String> list = new JList<>(listModel);54frame = new JFrame();55frame.add(list);56frame.pack();57try {58AccessibleContext acList = list.getAccessibleContext();59Accessible accChild = acList.getAccessibleChild(1);60AccessibleContext acChild = accChild.getAccessibleContext();61AccessibleAction aa = acChild.getAccessibleAction();62int c = aa.getAccessibleActionCount();63if (c != 1) {64throw new RuntimeException("getAccessibleActionCount is not 1");65}66String s = aa.getAccessibleActionDescription(0);67if (!s.equals("click")) {68throw new RuntimeException("getAccessibleActionDescription is not click");69}70boolean b = aa.doAccessibleAction(0);71if (!b) {72throw new RuntimeException("doAccessibleAction did not return true");73}74AccessibleSelection as = acList.getAccessibleSelection();75int asc = as.getAccessibleSelectionCount();76if (asc != 1) {77throw new RuntimeException("getAccessibleSelectionCount is not 1");78}79boolean isSelected = as.isAccessibleChildSelected(0);80if (isSelected) {81throw new RuntimeException("isAccessibleChildSelected(0) did not return false");82}83isSelected = as.isAccessibleChildSelected(1);84if (!isSelected) {85throw new RuntimeException("isAccessibleChildSelected(1) did not return true");86}87} catch (Exception e) {88exception = e;89}90});91if (exception != null) {92System.out.println("Test failed: " + exception.getMessage());93throw exception;94} else {95System.out.println("Test passed.");96}97} finally {98SwingUtilities.invokeAndWait(() -> {99if (frame != null) { frame.dispose(); }100});101}102}103104}105106107