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