jdk/test/java/awt/TextArea/TextAreaCaretVisibilityTest/bug7129742.java
author alanb
Thu, 01 Dec 2016 08:57:53 +0000
changeset 42338 a60f280f803c
parent 40128 e635645d2a8a
permissions -rw-r--r--
8169069: Module system implementation refresh (11/2016) Reviewed-by: plevart, chegar, psandoz, mchung, alanb, dfuchs, naoto, coffeys, weijun Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, claes.redestad@oracle.com, mark.reinhold@oracle.com
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
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 39541
diff changeset
    29
/*
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 39541
diff changeset
    30
 * @test
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 39541
diff changeset
    31
 * @key headful
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    32
 * @bug 7129742
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    33
 * @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
    34
 * @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
    35
 * @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
    36
 *          java.desktop/java.awt.peer
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40128
diff changeset
    37
 *          java.desktop/sun.awt.X11:open
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    38
 * @author Sean Chou
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    39
 */
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    40
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    41
import java.awt.FlowLayout;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    42
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
    43
import java.awt.Robot;
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    44
import java.lang.reflect.Field;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    45
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    46
import javax.swing.JFrame;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    47
import javax.swing.JTextArea;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    48
import javax.swing.SwingUtilities;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    49
import javax.swing.text.DefaultCaret;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    50
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    51
import sun.awt.AWTAccessor;
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    52
import sun.awt.AWTAccessor.ComponentAccessor;
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    53
12523
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 class bug7129742 {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    56
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    57
    public static DefaultCaret caret = null;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    58
    public static JFrame frame = null;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    59
    public static boolean fastreturn = false;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    60
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    61
    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
    62
        Robot robot = new Robot();
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    63
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    64
        SwingUtilities.invokeAndWait(new Runnable() {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    65
            @Override
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    66
            public void run() {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    67
                frame = new JFrame("Test");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    68
                TextArea textArea = new TextArea("Non-editable textArea");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    69
                textArea.setEditable(false);
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    70
                frame.setLayout(new FlowLayout());
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    71
                frame.add(textArea);
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    72
                frame.pack();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    73
                frame.setVisible(true);
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    74
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    75
                try {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    76
                    ComponentAccessor acc = AWTAccessor.getComponentAccessor();
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    77
                    Class XTextAreaPeerClzz = acc.getPeer(textArea).getClass();
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    78
                    System.out.println(XTextAreaPeerClzz.getName());
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    79
                    if (!XTextAreaPeerClzz.getName().equals("sun.awt.X11.XTextAreaPeer")) {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    80
                        fastreturn = true;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    81
                        return;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    82
                    }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    83
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    84
                    Field jtextField = XTextAreaPeerClzz.getDeclaredField("jtext");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    85
                    jtextField.setAccessible(true);
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    86
                    JTextArea jtext = (JTextArea)jtextField.get(acc.getPeer(textArea));
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    87
                    caret = (DefaultCaret) jtext.getCaret();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    88
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    89
                    textArea.requestFocusInWindow();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    90
                } catch (NoSuchFieldException | SecurityException
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    91
                         | IllegalArgumentException | IllegalAccessException e) {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    92
                    /* These exceptions mean the implementation of XTextAreaPeer is
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    93
                     * 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
    94
                     */
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    95
                    frame.dispose();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    96
                    throw new RuntimeException("This testcase is not valid any more!");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    97
                }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    98
            }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    99
        });
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
   100
        robot.waitForIdle();
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   101
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   102
        SwingUtilities.invokeAndWait(new Runnable() {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   103
            @Override
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   104
            public void run() {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   105
                try{
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   106
                    if (fastreturn) {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   107
                        return;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   108
                    }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   109
                    boolean passed = caret.isActive();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   110
                    System.out.println("is caret visible : " + passed);
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   111
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   112
                    if (!passed) {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   113
                        throw new RuntimeException("The test for bug 71297422 failed");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   114
                    }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   115
                } finally {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   116
                    frame.dispose();
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
    }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   121
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   122
}