jdk/test/java/awt/TextArea/TextAreaCaretVisibilityTest/bug7129742.java
author yan
Fri, 03 Jul 2015 17:37:40 +0300
changeset 31660 1a4e2e5c15e1
parent 30469 bac0a7ff7e1e
child 32286 5ffa8d8b4a2d
permissions -rw-r--r--
8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update Reviewed-by: serb, alexsch
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.
31660
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents: 30469
diff changeset
    32
 * @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
    33
 *          java.desktop/java.awt.peer
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    34
 * @author Sean Chou
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    35
 */
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    36
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    37
import java.awt.FlowLayout;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    38
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
    39
import java.awt.Robot;
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    40
import java.lang.reflect.Field;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    41
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    42
import javax.swing.JFrame;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    43
import javax.swing.JTextArea;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    44
import javax.swing.SwingUtilities;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    45
import javax.swing.text.DefaultCaret;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    46
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    47
import sun.awt.AWTAccessor;
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    48
import sun.awt.AWTAccessor.ComponentAccessor;
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    49
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    50
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    51
public class bug7129742 {
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 static DefaultCaret caret = null;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    54
    public static JFrame frame = null;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    55
    public static boolean fastreturn = false;
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 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
    58
        Robot robot = new Robot();
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    59
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    60
        SwingUtilities.invokeAndWait(new Runnable() {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    61
            @Override
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    62
            public void run() {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    63
                frame = new JFrame("Test");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    64
                TextArea textArea = new TextArea("Non-editable textArea");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    65
                textArea.setEditable(false);
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    66
                frame.setLayout(new FlowLayout());
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    67
                frame.add(textArea);
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    68
                frame.pack();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    69
                frame.setVisible(true);
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    70
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    71
                try {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    72
                    ComponentAccessor acc = AWTAccessor.getComponentAccessor();
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    73
                    Class XTextAreaPeerClzz = acc.getPeer(textArea).getClass();
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    74
                    System.out.println(XTextAreaPeerClzz.getName());
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    75
                    if (!XTextAreaPeerClzz.getName().equals("sun.awt.X11.XTextAreaPeer")) {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    76
                        fastreturn = true;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    77
                        return;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    78
                    }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    79
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    80
                    Field jtextField = XTextAreaPeerClzz.getDeclaredField("jtext");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    81
                    jtextField.setAccessible(true);
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 27763
diff changeset
    82
                    JTextArea jtext = (JTextArea)jtextField.get(acc.getPeer(textArea));
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    83
                    caret = (DefaultCaret) jtext.getCaret();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    84
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    85
                    textArea.requestFocusInWindow();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    86
                } catch (NoSuchFieldException | SecurityException
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    87
                         | IllegalArgumentException | IllegalAccessException e) {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    88
                    /* These exceptions mean the implementation of XTextAreaPeer is
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    89
                     * 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
    90
                     */
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    91
                    frame.dispose();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    92
                    throw new RuntimeException("This testcase is not valid any more!");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    93
                }
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
        });
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    96
        robot.waitForIdle();
12523
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
        SwingUtilities.invokeAndWait(new Runnable() {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
    99
            @Override
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   100
            public void run() {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   101
                try{
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   102
                    if (fastreturn) {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   103
                        return;
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   104
                    }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   105
                    boolean passed = caret.isActive();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   106
                    System.out.println("is caret visible : " + passed);
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   107
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   108
                    if (!passed) {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   109
                        throw new RuntimeException("The test for bug 71297422 failed");
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   110
                    }
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   111
                } finally {
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   112
                    frame.dispose();
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
diff changeset
   113
                }
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
        });
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
}