jdk/test/javax/swing/plaf/basic/BasicSplitPaneUI/Test6657026.java
author psadhukhan
Fri, 27 Jan 2017 15:37:47 +0530
changeset 43516 f23912ce3308
parent 31448 1066345d2a8a
permissions -rw-r--r--
7190595: Nimbus: Test6657026 fails Reviewed-by: yan, jdv
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
     1
/*
43516
f23912ce3308 7190595: Nimbus: Test6657026 fails
psadhukhan
parents: 31448
diff changeset
     2
 * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
     4
 *
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
     8
 *
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    13
 * accompanied this code).
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    14
 *
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4199
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4199
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4199
diff changeset
    21
 * questions.
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    22
 */
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    23
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    24
/*
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    25
 * @test
43516
f23912ce3308 7190595: Nimbus: Test6657026 fails
psadhukhan
parents: 31448
diff changeset
    26
 * @bug 6657026 7190595
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    27
 * @summary Tests shared BasicSplitPaneUI in different application contexts
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    28
 * @author Sergey Malenkov
31448
1066345d2a8a 8076468: Add @modules to tests in jdk_desktop test group
yan
parents: 5506
diff changeset
    29
 * @modules java.desktop/sun.awt
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    30
 */
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    31
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    32
import sun.awt.SunToolkit;
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    33
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    34
import java.awt.event.ActionEvent;
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    35
import java.util.Set;
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    36
import javax.swing.JSplitPane;
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    37
import javax.swing.plaf.basic.BasicSplitPaneUI;
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    38
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    39
public class Test6657026 extends BasicSplitPaneUI implements Runnable {
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    40
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    41
    public static void main(String[] args) throws InterruptedException {
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    42
        if (new JSplitPane().getFocusTraversalKeys(0).isEmpty()){
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    43
            throw new Error("unexpected traversal keys");
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    44
        }
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    45
        new JSplitPane() {
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    46
            public void setFocusTraversalKeys(int id, Set keystrokes) {
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    47
                keystrokes.clear();
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    48
                super.setFocusTraversalKeys(id, keystrokes);
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    49
            }
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    50
        };
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    51
        if (new JSplitPane().getFocusTraversalKeys(0).isEmpty()) {
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    52
            throw new Error("shared traversal keys");
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    53
        }
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    54
        KEYBOARD_DIVIDER_MOVE_OFFSET = -KEYBOARD_DIVIDER_MOVE_OFFSET;
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    55
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    56
        ThreadGroup group = new ThreadGroup("$$$");
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    57
        Thread thread = new Thread(group, new Test6657026());
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    58
        thread.start();
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    59
        thread.join();
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    60
    }
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    61
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    62
    public void run() {
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    63
        SunToolkit.createNewAppContext();
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    64
        if (new JSplitPane().getFocusTraversalKeys(0).isEmpty()) {
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    65
            throw new Error("shared traversal keys");
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    66
        }
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    67
        JSplitPane pane = new JSplitPane();
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    68
        pane.setUI(this);
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    69
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    70
        createFocusListener().focusGained(null); // allows actions
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    71
        test(pane, "positiveIncrement", 3);
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    72
        test(pane, "negativeIncrement", 0);
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    73
    }
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    74
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    75
    private static void test(JSplitPane pane, String action, int expected) {
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    76
        ActionEvent event = new ActionEvent(pane, expected, action);
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    77
        pane.getActionMap().get(action).actionPerformed(event);
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    78
        int actual = pane.getDividerLocation();
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    79
        if (actual != expected) {
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    80
            throw new Error(actual + ", but expected " + expected);
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    81
        }
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    82
    }
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
diff changeset
    83
}