jdk/test/java/awt/TextArea/TextAreaCaretVisibilityTest/bug7129742.java
author mcherkas
Thu, 30 Jun 2016 22:27:28 +0300
changeset 39541 2d0b64d48027
parent 32286 5ffa8d8b4a2d
child 40128 e635645d2a8a
permissions -rw-r--r--
8160650: Couple awt and swing tests have wrong require jtreg arguments Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
     1
/*
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
     2
 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
     4
 *
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
     8
 *
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    13
 * accompanied this code).
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    14
 *
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    18
 *
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    21
 * questions.
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    22
 */
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    23
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    24
/*
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    25
 * Portions Copyright (c) 2012 IBM Corporation
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    26
 */
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    27
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    28
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    29
/* @test
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    30
 * @bug 7129742
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    31
 * @summary Focus in non-editable TextArea is not shown on Linux.
39541
2d0b64d48027 8160650: Couple awt and swing tests have wrong require jtreg arguments
mcherkas
parents: 32286
diff changeset
    32
 * @requires (os.family == "linux" | os.family == "solaris")
31660
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents: 30469
diff changeset
    33
 * @modules java.desktop/sun.awt
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents: 30469
diff changeset
    34
 *          java.desktop/java.awt.peer
32286
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents: 31660
diff changeset
    35
 *          java.desktop/sun.awt.X11
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    36
 * @author Sean Chou
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    37
 */
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    38
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    39
import java.awt.FlowLayout;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    40
import java.awt.TextArea;
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    41
import java.awt.Robot;
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    42
import java.lang.reflect.Field;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    43
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    44
import javax.swing.JFrame;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    45
import javax.swing.JTextArea;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    46
import javax.swing.SwingUtilities;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    47
import javax.swing.text.DefaultCaret;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    48
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    49
import sun.awt.AWTAccessor;
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    50
import sun.awt.AWTAccessor.ComponentAccessor;
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    51
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    52
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    53
public class bug7129742 {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    54
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    55
    public static DefaultCaret caret = null;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    56
    public static JFrame frame = null;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    57
    public static boolean fastreturn = false;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    58
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    59
    public static void main(String[] args) throws Exception {
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    60
        Robot robot = new Robot();
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    61
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    62
        SwingUtilities.invokeAndWait(new Runnable() {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    63
            @Override
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    64
            public void run() {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    65
                frame = new JFrame("Test");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    66
                TextArea textArea = new TextArea("Non-editable textArea");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    67
                textArea.setEditable(false);
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    68
                frame.setLayout(new FlowLayout());
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    69
                frame.add(textArea);
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    70
                frame.pack();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    71
                frame.setVisible(true);
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    72
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    73
                try {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    74
                    ComponentAccessor acc = AWTAccessor.getComponentAccessor();
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    75
                    Class XTextAreaPeerClzz = acc.getPeer(textArea).getClass();
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    76
                    System.out.println(XTextAreaPeerClzz.getName());
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    77
                    if (!XTextAreaPeerClzz.getName().equals("sun.awt.X11.XTextAreaPeer")) {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    78
                        fastreturn = true;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    79
                        return;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    80
                    }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    81
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    82
                    Field jtextField = XTextAreaPeerClzz.getDeclaredField("jtext");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    83
                    jtextField.setAccessible(true);
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    84
                    JTextArea jtext = (JTextArea)jtextField.get(acc.getPeer(textArea));
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    85
                    caret = (DefaultCaret) jtext.getCaret();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    86
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    87
                    textArea.requestFocusInWindow();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    88
                } catch (NoSuchFieldException | SecurityException
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    89
                         | IllegalArgumentException | IllegalAccessException e) {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    90
                    /* These exceptions mean the implementation of XTextAreaPeer is
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    91
                     * changed, this testcase is not valid any more, fix it or remove.
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    92
                     */
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    93
                    frame.dispose();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    94
                    throw new RuntimeException("This testcase is not valid any more!");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    95
                }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    96
            }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    97
        });
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    98
        robot.waitForIdle();
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    99
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   100
        SwingUtilities.invokeAndWait(new Runnable() {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   101
            @Override
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   102
            public void run() {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   103
                try{
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   104
                    if (fastreturn) {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   105
                        return;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   106
                    }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   107
                    boolean passed = caret.isActive();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   108
                    System.out.println("is caret visible : " + passed);
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   109
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   110
                    if (!passed) {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   111
                        throw new RuntimeException("The test for bug 71297422 failed");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   112
                    }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   113
                } finally {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   114
                    frame.dispose();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   115
                }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   116
            }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   117
        });
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   118
    }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   119
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   120
}