jdk/test/javax/swing/JList/8161483/Bug8161483.java
author vromero
Thu, 05 Jan 2017 11:16:39 -0800
changeset 43033 c37b643739a7
parent 40439 acd9a7547e59
child 46151 5fa789776f7d
permissions -rw-r--r--
8148100: Convert lambda most specific positive tests to check runtime behavior Reviewed-by: mcimadamore Contributed-by: bsrbnd@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40439
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
     1
/*
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
     4
 *
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
     7
 * published by the Free Software Foundation.
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
     8
 *
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    13
 * accompanied this code).
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    14
 *
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    18
 *
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    21
 * questions.
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    22
 */
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    23
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    24
/*
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    25
 * @test
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    26
 * @bug 8161483
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    27
 * @summary Implement AccessibleAction in JList.AccessibleJList.AccessibleJListChild
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    28
 * @run main Bug8161483
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    29
 */
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    30
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    31
import javax.accessibility.Accessible;
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    32
import javax.accessibility.AccessibleAction;
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    33
import javax.accessibility.AccessibleContext;
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    34
import javax.accessibility.AccessibleSelection;
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    35
import javax.swing.DefaultListModel;
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    36
import javax.swing.JFrame;
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    37
import javax.swing.JList;
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    38
import javax.swing.SwingUtilities;
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    39
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    40
public class Bug8161483 extends JFrame {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    41
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    42
    private static JFrame frame;
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    43
    private static volatile Exception exception = null;
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    44
    private JList<String> countryList;
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    45
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    46
    public static void main(String args[]) throws Exception {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    47
        try {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    48
            SwingUtilities.invokeAndWait(() -> {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    49
                DefaultListModel<String> listModel = new DefaultListModel<>();
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    50
                listModel.addElement("one");
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    51
                listModel.addElement("two");
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    52
                listModel.addElement("three");
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    53
                JList<String> list = new JList<>(listModel);
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    54
                frame = new JFrame();
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    55
                frame.add(list);
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    56
                frame.pack();
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    57
                try {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    58
                    AccessibleContext acList = list.getAccessibleContext();
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    59
                    Accessible accChild = acList.getAccessibleChild(1);
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    60
                    AccessibleContext acChild = accChild.getAccessibleContext();
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    61
                    AccessibleAction aa = acChild.getAccessibleAction();
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    62
                    int c = aa.getAccessibleActionCount();
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    63
                    if (c != 1) {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    64
                        throw new RuntimeException("getAccessibleActionCount is not 1");
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    65
                    }
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    66
                    String s = aa.getAccessibleActionDescription(0);
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    67
                    if (!s.equals("click")) {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    68
                        throw new RuntimeException("getAccessibleActionDescription is not click");
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    69
                    }
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    70
                    boolean b = aa.doAccessibleAction(0);
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    71
                    if (!b) {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    72
                        throw new RuntimeException("doAccessibleAction did not return true");
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    73
                    }
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    74
                    AccessibleSelection as = acList.getAccessibleSelection();
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    75
                    int asc = as.getAccessibleSelectionCount();
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    76
                    if (asc != 1) {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    77
                        throw new RuntimeException("getAccessibleSelectionCount is not 1");
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    78
                    }
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    79
                    boolean isSelected = as.isAccessibleChildSelected(0);
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    80
                    if (isSelected) {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    81
                        throw new RuntimeException("isAccessibleChildSelected(0) did not return false");
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    82
                    }
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    83
                    isSelected = as.isAccessibleChildSelected(1);
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    84
                    if (!isSelected) {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    85
                        throw new RuntimeException("isAccessibleChildSelected(1) did not return true");
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    86
                    }
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    87
                } catch (Exception e) {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    88
                    exception = e;
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    89
                }
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    90
            });
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    91
            if (exception != null) {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    92
                System.out.println("Test failed: " + exception.getMessage());
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    93
                throw exception;
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    94
            } else {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    95
                System.out.println("Test passed.");
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    96
            }
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    97
        } finally {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    98
            SwingUtilities.invokeAndWait(() -> {
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
    99
                frame.dispose();
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
   100
            });
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
   101
        }
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
   102
    }
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
   103
acd9a7547e59 8161483: Implement AccessibleAction interface in JList.AccessibleJList.AccessibleJListChild
ptbrunet
parents:
diff changeset
   104
}