Skip to content

Commit a1eb777

Browse files
author
Amos Shi
committed
8284316: Support accessibility ManualTestFrame.java for non SwingSet tests
Backport-of: 6a7c023796b0f39f54d0335f4723c1f06ff0032d
1 parent c0a6920 commit a1eb777

File tree

4 files changed

+207
-47
lines changed

4 files changed

+207
-47
lines changed
Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
/**
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
33
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
44
*/
55

66
import lib.ManualTestFrame;
77
import lib.TestResult;
88

9-
import javax.imageio.ImageIO;
10-
import java.io.File;
9+
import java.util.function.Consumer;
1110
import java.io.IOException;
1211
import java.lang.reflect.InvocationTargetException;
1312
import java.net.URL;
1413
import java.net.URLClassLoader;
15-
import java.nio.file.Files;
1614
import java.util.function.Supplier;
15+
import javax.swing.JEditorPane;
1716

1817
import static java.io.File.separator;
1918

@@ -22,10 +21,21 @@ public class SwingSetTest {
2221
public static void main(String[] args) throws IOException, InterruptedException,
2322
ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
2423
System.out.println("test image " + System.getenv("TEST_IMAGE_DIR"));
24+
25+
Consumer<JEditorPane> testInstructionProvider = e -> {
26+
try {
27+
e.setContentType("text/html");
28+
e.setPage(SwingSetTest.class.getResource(args[0] + ".html"));
29+
} catch (IOException exception) {
30+
exception.printStackTrace();
31+
}
32+
};
33+
2534
Supplier<TestResult> resultSupplier = ManualTestFrame.showUI(args[0],
2635
"Wait for SwingSet2 to load, follow the instructions, select pass or fail. " +
2736
"Do not close windows manually.",
28-
SwingSetTest.class.getResource(args[0] + ".html"));
37+
testInstructionProvider);
38+
2939
String swingSetJar = System.getenv("SWINGSET2_JAR");
3040
if (swingSetJar == null) {
3141
swingSetJar = "file://" + System.getProperty("java.home") +
@@ -37,23 +47,10 @@ public static void main(String[] args) throws IOException, InterruptedException,
3747
System.out.println("Loading SwingSet2 from " + swingSetJar);
3848
ClassLoader ss = new URLClassLoader(new URL[]{new URL(swingSetJar)});
3949
ss.loadClass("SwingSet2").getMethod("main", String[].class).invoke(null, (Object)new String[0]);
50+
4051
//this will block until user decision to pass or fail the test
4152
TestResult result = resultSupplier.get();
42-
if (result != null) {
43-
System.err.println("Failure reason: \n" + result.getFailureDescription());
44-
if (result.getScreenCapture() != null) {
45-
File screenDump = new File(System.getProperty("test.classes") + separator + args[0] + ".png");
46-
System.err.println("Saving screen image to " + screenDump.getAbsolutePath());
47-
ImageIO.write(result.getScreenCapture(), "png", screenDump);
48-
}
49-
Throwable e = result.getException();
50-
if (e != null) {
51-
throw new RuntimeException(e);
52-
} else {
53-
if (!result.getStatus()) throw new RuntimeException("Test failed!");
54-
}
55-
} else {
56-
throw new RuntimeException("No result returned!");
57-
}
53+
ManualTestFrame.handleResult(result, args[0]);
5854
}
59-
}
55+
}
56+
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 2022 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+
25+
/*
26+
@test
27+
@key headful
28+
@summary manual test for accessibility JProgressBar
29+
@run main/manual TestJProgressBarAccessibility
30+
*/
31+
32+
import java.awt.BorderLayout;
33+
import java.awt.event.MouseAdapter;
34+
import java.awt.event.MouseEvent;
35+
import java.io.IOException;
36+
import java.lang.reflect.InvocationTargetException;
37+
import java.util.function.Consumer;
38+
import java.util.function.Supplier;
39+
import javax.accessibility.AccessibleContext;
40+
import javax.swing.JEditorPane;
41+
import javax.swing.JFrame;
42+
import javax.swing.JProgressBar;
43+
import javax.swing.SwingUtilities;
44+
45+
import lib.ManualTestFrame;
46+
import lib.TestResult;
47+
48+
public class TestJProgressBarAccessibility {
49+
50+
private static JFrame frame;
51+
private static volatile int value = 10;
52+
private static final String instruction = """
53+
Aim : Check whether JProgressBar value is read in case of VoiceOver or
54+
Screen magnifier shows the magnified value in case of Screen magnifier is enabled
55+
1) Move the mouse pointer over the JProgressBar and if you
56+
hear the JProgressBar value in case of VoiceOver then the test pass else fail.
57+
2) Move the mouse pointer over the JProgressBar and if you see the magnified value
58+
when Screen magnifier is enabled then the test pass else fail.
59+
""";
60+
61+
private static void createTestUI() throws InterruptedException, InvocationTargetException {
62+
SwingUtilities.invokeAndWait(() -> {
63+
frame = new JFrame("Test JProgressBar accessibility");
64+
JProgressBar progressBar = new JProgressBar();
65+
progressBar.setValue(value);
66+
progressBar.setStringPainted(true);
67+
68+
progressBar.addMouseListener(new MouseAdapter() {
69+
@Override
70+
public void mouseClicked(MouseEvent e) {
71+
super.mouseClicked(e);
72+
if ( value == 100) {
73+
value = 0;
74+
} else {
75+
value += 5;
76+
}
77+
progressBar.setValue(value);
78+
}
79+
});
80+
81+
AccessibleContext accessibleContext =
82+
progressBar.getAccessibleContext();
83+
accessibleContext.setAccessibleName("JProgressBar accessibility name");
84+
accessibleContext.setAccessibleDescription("Jprogress accessibility " +
85+
"description");
86+
87+
frame.getContentPane().add(progressBar, BorderLayout.CENTER);
88+
89+
frame.setSize(200,200);
90+
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
91+
frame.setLocationRelativeTo(null);
92+
frame.setVisible(true);
93+
});
94+
}
95+
96+
public static void main(String[] args) throws InterruptedException,
97+
InvocationTargetException, IOException {
98+
99+
Consumer<JEditorPane> testInstProvider = e -> {
100+
e.setContentType("text/plain");
101+
e.setText(instruction);
102+
};
103+
104+
Supplier<TestResult> resultSupplier = ManualTestFrame.showUI(
105+
"JProgressBar " +
106+
"Accessibility Test", "Wait until the Test UI is " +
107+
"seen", testInstProvider);
108+
109+
// Create and show TestUI
110+
createTestUI();
111+
112+
//this will block until user decision to pass or fail the test
113+
TestResult testResult = resultSupplier.get();
114+
ManualTestFrame.handleResult(testResult,"TestJProgressBarAccessibility");
115+
}
116+
}
117+

test/jdk/javax/accessibility/manual/lib/DescriptionPane.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@
2020
* or visit www.oracle.com if you need additional information or have any
2121
* questions.
2222
*/
23+
2324
package lib;
2425

25-
import javax.swing.JEditorPane;
26-
import javax.swing.JPanel;
27-
import javax.swing.JScrollPane;
2826
import java.awt.BorderLayout;
2927
import java.awt.Dimension;
3028
import java.io.IOException;
31-
import java.net.URL;
29+
import java.util.function.Consumer;
30+
import javax.swing.JEditorPane;
31+
import javax.swing.JPanel;
32+
import javax.swing.JScrollPane;
3233

3334
/**
3435
* Displays instructions provided through a URL.
3536
*/
3637
class DescriptionPane extends JPanel {
3738

38-
DescriptionPane(URL instructions) throws IOException {
39+
DescriptionPane(Consumer<JEditorPane> instructions) {
3940
JEditorPane editorPane = new JEditorPane();
4041
editorPane.setFocusable(false);
41-
editorPane.setContentType("text/html");
42-
editorPane.setPage(instructions);
42+
instructions.accept(editorPane);
4343
editorPane.setEditable(false);
4444

4545
JScrollPane esp = new JScrollPane(editorPane);
@@ -51,3 +51,4 @@ class DescriptionPane extends JPanel {
5151
add(esp);
5252
}
5353
}
54+

test/jdk/javax/accessibility/manual/lib/ManualTestFrame.java

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,25 +22,31 @@
2222
*/
2323
package lib;
2424

25-
import javax.swing.BorderFactory;
26-
import javax.swing.JFrame;
27-
import javax.swing.JLabel;
28-
import javax.swing.JPanel;
29-
import javax.swing.JSplitPane;
30-
import javax.swing.JTextArea;
31-
import javax.swing.border.BevelBorder;
3225
import java.awt.BorderLayout;
3326
import java.awt.Dimension;
3427
import java.awt.GridLayout;
28+
import java.io.File;
3529
import java.io.IOException;
3630
import java.lang.reflect.InvocationTargetException;
37-
import java.net.URL;
3831
import java.util.concurrent.CountDownLatch;
32+
import java.util.concurrent.TimeUnit;
3933
import java.util.concurrent.atomic.AtomicReference;
4034
import java.util.function.Consumer;
4135
import java.util.function.Supplier;
36+
import javax.imageio.ImageIO;
37+
import javax.swing.BorderFactory;
38+
import javax.swing.JEditorPane;
39+
import javax.swing.JFrame;
40+
import javax.swing.JLabel;
41+
import javax.swing.JPanel;
42+
import javax.swing.JSplitPane;
43+
import javax.swing.JTextArea;
44+
import javax.swing.border.BevelBorder;
4245

43-
import static java.awt.BorderLayout.*;
46+
import static java.awt.BorderLayout.CENTER;
47+
import static java.awt.BorderLayout.NORTH;
48+
import static java.awt.BorderLayout.SOUTH;
49+
import static java.io.File.separator;
4450
import static javax.swing.SwingUtilities.invokeAndWait;
4551

4652
/**
@@ -51,7 +57,9 @@ public class ManualTestFrame extends JFrame {
5157

5258
private boolean alreadyFailed = false;
5359

54-
private ManualTestFrame(String testName, String headerText, URL instructions, Consumer<TestResult> listener) throws IOException {
60+
private ManualTestFrame(String testName, String headerText,
61+
Consumer<JEditorPane> instructions,
62+
Consumer<TestResult> listener) throws IOException {
5563

5664
super(testName);
5765

@@ -124,14 +132,17 @@ private ManualTestFrame(String testName, String headerText, URL instructions, Co
124132

125133
/**
126134
* Show a test control frame which allows a user to either pass or fail the test.
127-
* @param testName
128-
* @param headerText
129-
* @param instructions
135+
*
136+
* @param testName name of the testcase
137+
* @param headerText information to the user to wait for the test frame.
138+
* @param instructions test instruction for the user
130139
* @return Returning supplier blocks till the test is passed or failed by the user.
131-
* @throws InterruptedException
132-
* @throws InvocationTargetException
140+
* @throws InterruptedException exception
141+
* @throws InvocationTargetException exception
133142
*/
134-
public static Supplier<TestResult> showUI(String testName, String headerText, URL instructions)
143+
public static Supplier<TestResult> showUI(String testName,
144+
String headerText,
145+
Consumer<JEditorPane> instructions)
135146
throws InterruptedException, InvocationTargetException {
136147
AtomicReference<TestResult> resultContainer = new AtomicReference<>();
137148
CountDownLatch latch = new CountDownLatch(1);
@@ -148,12 +159,46 @@ public static Supplier<TestResult> showUI(String testName, String headerText, UR
148159
});
149160
return () -> {
150161
try {
151-
latch.await();
162+
int timeout = Integer.getInteger("timeout", 10);
163+
System.out.println("timeout value : " + timeout);
164+
if (!latch.await(timeout, TimeUnit.MINUTES)) {
165+
throw new RuntimeException("Timeout : User failed to " +
166+
"take decision on the test result.");
167+
}
152168
} catch (InterruptedException e) {
153169
return new TestResult(e);
154170
}
155171
return resultContainer.get();
156172
};
157173
}
158174

175+
/**
176+
* Checks the TestResult after user interacted with the manual TestFrame
177+
* and the test UI.
178+
*
179+
* @param result Instance of the TestResult
180+
* @param testName name of the testcase
181+
* @throws IOException exception
182+
*/
183+
public static void handleResult(TestResult result, String testName) throws IOException {
184+
if (result != null) {
185+
System.err.println("Failure reason: \n" + result.getFailureDescription());
186+
if (result.getScreenCapture() != null) {
187+
File screenDump = new File(System.getProperty("test.classes") + separator + testName + ".png");
188+
System.err.println("Saving screen image to " + screenDump.getAbsolutePath());
189+
ImageIO.write(result.getScreenCapture(), "png", screenDump);
190+
}
191+
Throwable e = result.getException();
192+
if (e != null) {
193+
throw new RuntimeException(e);
194+
} else {
195+
if (!result.getStatus())
196+
throw new RuntimeException("Test failed!");
197+
}
198+
} else {
199+
throw new RuntimeException("No result returned!");
200+
}
201+
}
202+
159203
}
204+

0 commit comments

Comments
 (0)