test/jdk/javax/accessibility/6192422/bug6192422.java
author serb
Sat, 16 Mar 2019 17:50:24 -0700
changeset 54242 132590e72765
permissions -rw-r--r--
7106851: Test should not use System.exit Reviewed-by: aivanov, psadhukhan, kaddepalli
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54242
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
     1
/*
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
     2
 * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
     4
 *
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
     8
 *
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    13
 * accompanied this code).
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    14
 *
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    18
 *
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    21
 * questions.
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    22
 */
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    23
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    24
import javax.accessibility.Accessible;
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    25
import javax.accessibility.AccessibleContext;
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    26
import javax.accessibility.AccessibleRole;
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    27
import javax.swing.JFrame;
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    28
import javax.swing.JMenu;
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    29
import javax.swing.JMenuBar;
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    30
import javax.swing.SwingUtilities;
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    31
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    32
/**
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    33
 * @test
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    34
 * @bug 6192422 7106851
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    35
 * @key headful
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    36
 * @summary Verifies fix for JMenuBar not being in the accessibility hierarchy
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    37
 */
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    38
public class bug6192422 {
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    39
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    40
    private static boolean foundJMenuBar = false;
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    41
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    42
    public static void main(String[] args) throws Throwable {
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    43
        SwingUtilities.invokeAndWait(new Runnable() {
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    44
            public void run() {
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    45
                if (!testIt()) {
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    46
                    throw new RuntimeException("JMenuBar was not found");
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    47
                }
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    48
            }
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    49
        });
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    50
    }
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    51
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    52
    /*
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    53
     * Test whether JMenuBar is in accessibility hierarchy
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    54
     */
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    55
    private static boolean testIt() {
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    56
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    57
        JFrame frame = new JFrame("bug6192422");
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    58
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    59
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    60
        /*
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    61
         * Add a menu bar to the frame using setJMenuBar. The setJMenuBar
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    62
         * method add the menu bar to the JLayeredPane.
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    63
         */
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    64
        JMenuBar menuBar = new JMenuBar();
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    65
        menuBar.add(new JMenu("foo"));
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    66
        menuBar.add(new JMenu("bar"));
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    67
        menuBar.add(new JMenu("baz"));
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    68
        frame.setJMenuBar(menuBar);
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    69
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    70
        findJMenuBar(frame.getAccessibleContext());
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    71
        return foundJMenuBar;
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    72
    }
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    73
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    74
    /*
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    75
     * Finds the JMenuBar in the Accessibility hierarchy
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    76
     */
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    77
    private static void findJMenuBar(AccessibleContext ac) {
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    78
        if (ac != null) {
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    79
            System.err.println("findJMenuBar: ac = "+ac.getClass());
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    80
            int num = ac.getAccessibleChildrenCount();
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    81
            System.err.println("  #children "+num);
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    82
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    83
            for (int i = 0; i < num; i++) {
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    84
                System.err.println("  child #"+i);
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    85
                Accessible a = ac.getAccessibleChild(i);
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    86
                AccessibleContext child = a.getAccessibleContext();
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    87
                AccessibleRole role = child.getAccessibleRole();
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    88
                System.err.println("  role "+role);
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    89
                if (role == AccessibleRole.MENU_BAR) {
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    90
                    foundJMenuBar = true;
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    91
                    return;
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    92
                }
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    93
                if (child.getAccessibleChildrenCount() > 0) {
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    94
                    findJMenuBar(child);
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    95
                }
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    96
            }
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    97
        }
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    98
    }
132590e72765 7106851: Test should not use System.exit
serb
parents:
diff changeset
    99
}