Skip to content

Commit 8c89fb9

Browse files
committed
8355179: Reinstate javax/swing/JScrollBar/4865918/bug4865918.java headful and macos run
Reviewed-by: abhiscxk, serb
1 parent bc518a6 commit 8c89fb9

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

test/jdk/javax/swing/JScrollBar/4865918/bug4865918.java

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@
2424
/*
2525
* @test
2626
* @bug 4865918
27-
* @requires (os.family != "mac")
27+
* @key headful
2828
* @summary REGRESSION:JCK1.4a-runtime api/javax_swing/interactive/JScrollBarTests.html#JScrollBar
2929
* @run main bug4865918
3030
*/
3131

3232
import java.awt.Dimension;
33+
import java.awt.Robot;
3334
import java.awt.event.MouseAdapter;
3435
import java.awt.event.MouseEvent;
36+
import javax.swing.JFrame;
3537
import javax.swing.JScrollBar;
3638
import javax.swing.SwingUtilities;
3739
import java.util.concurrent.CountDownLatch;
@@ -41,24 +43,33 @@
4143

4244
public class bug4865918 {
4345

46+
private static JFrame frame;
4447
private static TestScrollBar sbar;
4548
private static final CountDownLatch mousePressLatch = new CountDownLatch(1);
4649

4750
public static void main(String[] argv) throws Exception {
48-
String osName = System.getProperty("os.name");
49-
if (osName.toLowerCase().contains("os x")) {
50-
System.out.println("This test is not for MacOS, considered passed.");
51-
return;
52-
}
53-
SwingUtilities.invokeAndWait(() -> setupTest());
51+
try {
52+
Robot robot = new Robot();
53+
SwingUtilities.invokeAndWait(() -> createAndShowGUI());
5454

55-
SwingUtilities.invokeAndWait(() -> sbar.pressMouse());
56-
if (!mousePressLatch.await(2, TimeUnit.SECONDS)) {
57-
throw new RuntimeException("Timed out waiting for mouse press");
58-
}
55+
robot.waitForIdle();
56+
robot.delay(1000);
57+
58+
SwingUtilities.invokeAndWait(() -> sbar.pressMouse());
59+
if (!mousePressLatch.await(2, TimeUnit.SECONDS)) {
60+
throw new RuntimeException("Timed out waiting for mouse press");
61+
}
5962

60-
if (getValue() != 9) {
61-
throw new RuntimeException("The scrollbar block increment is incorrect");
63+
if (getValue() != 9) {
64+
throw new RuntimeException("The scrollbar block increment " +
65+
getValue() + " is incorrect");
66+
}
67+
} finally {
68+
SwingUtilities.invokeAndWait(() -> {
69+
if (frame != null) {
70+
frame.dispose();
71+
}
72+
});
6273
}
6374
}
6475

@@ -73,8 +84,8 @@ private static int getValue() throws Exception {
7384
return result[0];
7485
}
7586

76-
private static void setupTest() {
77-
87+
private static void createAndShowGUI() {
88+
frame = new JFrame("bug4865918");
7889
sbar = new TestScrollBar(JScrollBar.HORIZONTAL, -1, 10, -100, 100);
7990
sbar.setPreferredSize(new Dimension(200, 20));
8091
sbar.setBlockIncrement(10);
@@ -83,7 +94,11 @@ public void mousePressed(MouseEvent e) {
8394
mousePressLatch.countDown();
8495
}
8596
});
86-
97+
frame.getContentPane().add(sbar);
98+
frame.pack();
99+
frame.setLocationRelativeTo(null);
100+
frame.setVisible(true);
101+
frame.toFront();
87102
}
88103

89104
static class TestScrollBar extends JScrollBar {

0 commit comments

Comments
 (0)