Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/accessibility/AccessibleName/GetAccessibleNameTest.java
41149 views
1
/*
2
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
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
import javax.accessibility.AccessibleContext;
25
import javax.swing.JButton;
26
import javax.swing.JCheckBox;
27
import javax.swing.JCheckBoxMenuItem;
28
import javax.swing.JComponent;
29
import javax.swing.JLabel;
30
import javax.swing.JMenu;
31
import javax.swing.JMenuItem;
32
import javax.swing.JRadioButton;
33
import javax.swing.JRadioButtonMenuItem;
34
import javax.swing.JToggleButton;
35
import javax.swing.SwingUtilities;
36
import java.lang.reflect.Constructor;
37
import java.lang.reflect.InvocationTargetException;
38
39
/*
40
* @test
41
* @bug 4949105
42
* @summary Access Bridge lacks html tags parsing
43
* @run main GetAccessibleNameTest
44
*/
45
46
public class GetAccessibleNameTest {
47
48
public static void main(String[] args) throws Exception {
49
testConstructor();
50
testSetText();
51
testAccessibleProperty();
52
}
53
54
private static void testConstructor() {
55
Class[] testClass = new Class[] {
56
JLabel.class, JButton.class, JMenuItem.class,
57
JMenu.class, JCheckBoxMenuItem.class, JRadioButtonMenuItem.class,
58
JToggleButton.class, JRadioButton.class, JCheckBox.class };
59
60
Class[] ctorArg = new Class[1];
61
ctorArg[0] = String.class;
62
String expectedText = "bold italic em mark del small big sup sub ins strong code strike";
63
String inputText = "<html><style>{color:#FF0000;}</style><body>" +
64
"<b>bold</b> <i>italic</i> <em>em</em> <mark>mark</mark> <del>del</del> " +
65
"<small>small</small> <big>big</big> <sup>sup</sup> <sub>sub</sub> <ins>ins</ins> " +
66
"<strong>strong</strong> <code>code</code> <strike>strike</strike>" +
67
"</body></html>";
68
69
for (Class aClass : testClass) {
70
try {
71
Constructor constructor = aClass.getDeclaredConstructor(ctorArg);
72
JComponent comp = (JComponent) constructor.newInstance(inputText);
73
if (!expectedText.equals(comp.getAccessibleContext().getAccessibleName())) {
74
throw new RuntimeException("AccessibleName of " + aClass.getName() + " is incorrect." +
75
" Expected: " + expectedText +
76
" Actual: " + comp.getAccessibleContext().getAccessibleName());
77
}
78
} catch (NoSuchMethodException e) {
79
throw new RuntimeException(aClass.getName() + " does not have a constructor accepting" +
80
"String parameter.", e.getCause());
81
} catch (InstantiationException e) {
82
throw new RuntimeException(aClass.getName() + " could not be instantiated.",
83
e.getCause());
84
} catch (IllegalAccessException e) {
85
throw new RuntimeException(aClass.getName() + " constructor cannot be accessed.",
86
e.getCause());
87
} catch (InvocationTargetException e) {
88
throw new RuntimeException(aClass.getName() + " constructor cannot be invoked.",
89
e.getCause());
90
}
91
}
92
}
93
94
private static void testSetText() {
95
String text = "html text";
96
JLabel testLabel = new JLabel("<html>" + text + "</html>");
97
if (!text.equals(testLabel.getAccessibleContext().getAccessibleName())) {
98
throw new RuntimeException("Incorrect AccessibleName," +
99
" Expected: " + text +
100
" Actual: " + testLabel.getAccessibleContext().getAccessibleName());
101
}
102
103
text = "Non html text";
104
testLabel.setText(text);
105
if (!text.equals(testLabel.getAccessibleContext().getAccessibleName())) {
106
throw new RuntimeException("Incorrect AccessibleName," +
107
" Expected: " + text +
108
" Actual: " + testLabel.getAccessibleContext().getAccessibleName());
109
}
110
}
111
112
private static void testAccessibleProperty() {
113
String text = "html text";
114
JLabel testLabel = new JLabel("<html>" + text + "</html>");
115
if (!text.equals(testLabel.getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY))) {
116
throw new RuntimeException("Incorrect ACCESSIBLE_NAME_PROPERTY," +
117
" Expected: " + text +
118
" Actual: " + testLabel.getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY));
119
}
120
121
String namePropertyText = "name property";
122
testLabel.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, namePropertyText);
123
if (!namePropertyText.equals(testLabel.getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY))) {
124
throw new RuntimeException("Incorrect ACCESSIBLE_NAME_PROPERTY," +
125
" Expected: " + namePropertyText +
126
" Actual: " + testLabel.getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY));
127
}
128
129
text = "different html text";
130
testLabel.setText("<html>" + text + "</html>");
131
if (!namePropertyText.equals(testLabel.getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY))) {
132
throw new RuntimeException("Incorrect ACCESSIBLE_NAME_PROPERTY," +
133
" Expected: " + namePropertyText +
134
" Actual: " + testLabel.getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY));
135
}
136
}
137
}
138
139