Skip to content

Commit 307d548

Browse files
author
Satyen Subramaniam
committed
8355429: Open source ProgressMonitor test
Backport-of: 3b7f43f95e061274020deaa1eecdb8182a6b64e1
1 parent dd495ab commit 307d548

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2001, 2025, 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+
* @test
26+
* @bug 4401480
27+
* @summary Tests that closing ProgressMonitor dialog cancels it
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4401480
31+
*/
32+
33+
import java.lang.reflect.InvocationTargetException;
34+
import javax.swing.JButton;
35+
import javax.swing.JPanel;
36+
import javax.swing.ProgressMonitor;
37+
import javax.swing.SwingUtilities;
38+
39+
public class bug4401480 {
40+
private static ProgressMonitor monitor;
41+
private static volatile boolean cancelled = false;
42+
43+
private static final String INSTRUCTIONS = """
44+
This is a semi-automated test which automatically
45+
passes if closing the JProgressBar dialog cancels it.
46+
Read the following test instructions and when ready
47+
click on the Start button below.
48+
49+
After clicking on Start button wait for few seconds for
50+
progress monitor (a dialog with progress bar) to appear.
51+
Close it by clicking on the window close button.
52+
DO NOT click on Cancel button.
53+
54+
NOTE:
55+
Ensure to click on the window close button before
56+
progress bar reaches its max limit.
57+
""";
58+
59+
public static void main(String[] args) throws Exception {
60+
PassFailJFrame.builder()
61+
.title("JProgress Monitor Instructions")
62+
.instructions(INSTRUCTIONS)
63+
.columns(35)
64+
.splitUIBottom(bug4401480::createTestUI)
65+
.build()
66+
.awaitAndCheck();
67+
}
68+
69+
private static JPanel createTestUI() {
70+
JPanel panel = new JPanel();
71+
JButton startButton = new JButton("Start");
72+
startButton.addActionListener(e -> {
73+
monitor = new ProgressMonitor(null, "Progress", "Running ...", 0, 10);
74+
monitor.setProgress(0);
75+
76+
new Thread(() -> {
77+
for (int i = 0; i < 10; i++) {
78+
int count = i;
79+
try {
80+
SwingUtilities.invokeAndWait(() ->
81+
monitor.setProgress(count));
82+
Thread.sleep(2000);
83+
SwingUtilities.invokeAndWait(() ->
84+
cancelled = monitor.isCanceled());
85+
} catch (InterruptedException
86+
| InvocationTargetException ex) {
87+
throw new RuntimeException(ex);
88+
}
89+
if (cancelled) {
90+
break;
91+
}
92+
}
93+
94+
if (cancelled) {
95+
PassFailJFrame.forcePass();
96+
} else {
97+
PassFailJFrame.forceFail("Test Failed! JProgress Monitor"
98+
+ " was not cancelled");
99+
}
100+
}).start();
101+
});
102+
panel.add(startButton);
103+
return panel;
104+
}
105+
}

0 commit comments

Comments
 (0)