test/jdk/javax/accessibility/8017112/AccessibleIndexInParentTest.java
author serb
Tue, 27 Aug 2019 04:43:01 -0700
changeset 58315 07556f8cd819
parent 47216 71c04702a3d5
permissions -rw-r--r--
8146238: [macosx] Java2D Queue Flusher crash on OSX after switching between user accounts Reviewed-by: prr, avu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38390
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
     1
/*
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
     4
 *
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
     7
 * published by the Free Software Foundation.
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
     8
 *
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    13
 * accompanied this code).
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    14
 *
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    18
 *
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    21
 * questions.
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    22
 */
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    23
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    24
import java.awt.Component;
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    25
import javax.swing.JLabel;
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    26
import javax.swing.JTabbedPane;
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    27
import javax.swing.SwingUtilities;
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    28
import javax.accessibility.Accessible;
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    29
import javax.accessibility.AccessibleContext;
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    30
/*
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    31
 * @test
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    32
 * @bug 8017112
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    33
 * @summary JTabbedPane components have inconsistent accessibility tree
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    34
 * @run main AccessibleIndexInParentTest
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    35
 */
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    36
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    37
public class AccessibleIndexInParentTest {
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    38
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    40
        SwingUtilities.invokeAndWait(AccessibleIndexInParentTest::test);
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    41
    }
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    42
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    43
    private static void test() {
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    44
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    45
        int N = 5;
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    46
        JTabbedPane tabbedPane = new JTabbedPane();
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    47
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    48
        for (int i = 0; i < N; i++) {
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    49
            tabbedPane.addTab("Title: " + i, new JLabel("Component: " + i));
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    50
        }
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    51
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    52
        for (int i = 0; i < tabbedPane.getTabCount(); i++) {
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    53
            Component child = tabbedPane.getComponentAt(i);
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    54
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    55
            AccessibleContext ac = child.getAccessibleContext();
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    56
            if (ac == null) {
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    57
                throw new RuntimeException("Accessible Context is null!");
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    58
            }
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    59
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    60
            int index = ac.getAccessibleIndexInParent();
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    61
            Accessible parent = ac.getAccessibleParent();
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    62
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    63
            if (parent.getAccessibleContext().getAccessibleChild(index) != child) {
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    64
                throw new RuntimeException("Wrong getAccessibleIndexInParent!");
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    65
            }
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    66
        }
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    67
    }
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents:
diff changeset
    68
}