Skip to content

Commit fa64c0e

Browse files
author
Andrew Lu
committedAug 14, 2024
8316285: Opensource JButton manual tests
Backport-of: 9f5d2b947f7d70babba663e16882e480b8a973f2
1 parent 3f2d6f0 commit fa64c0e

File tree

3 files changed

+292
-0
lines changed

3 files changed

+292
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 1999, 2023, 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 4234034
27+
* @summary Tests NullPointerException when ToolTip invoked via keyboard
28+
* @key headful
29+
* @run main bug4234034
30+
*/
31+
32+
import java.awt.Robot;
33+
import java.awt.event.KeyEvent;
34+
import javax.swing.JButton;
35+
import javax.swing.JFrame;
36+
import javax.swing.SwingUtilities;
37+
38+
public class bug4234034 {
39+
static JFrame frame;
40+
static JButton button;
41+
42+
public static void main(String args[]) throws Exception {
43+
Robot robot = new Robot();
44+
robot.setAutoDelay(100);
45+
try {
46+
SwingUtilities.invokeAndWait(() -> {
47+
frame = new JFrame("bug4323121");
48+
button = new JButton("Press tab, then Ctrl+F1");
49+
button.setToolTipText("Tooltip for button");
50+
frame.getContentPane().add(button);
51+
frame.pack();
52+
frame.setLocationRelativeTo(null);
53+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
54+
frame.setVisible(true);
55+
});
56+
robot.waitForIdle();
57+
robot.delay(1000);
58+
robot.keyPress(KeyEvent.VK_TAB);
59+
robot.keyRelease(KeyEvent.VK_TAB);
60+
robot.keyPress(KeyEvent.VK_CONTROL);
61+
robot.keyPress(KeyEvent.VK_F1);
62+
robot.keyRelease(KeyEvent.VK_F1);
63+
robot.keyRelease(KeyEvent.VK_CONTROL);
64+
} finally {
65+
SwingUtilities.invokeAndWait(() -> {
66+
if (frame != null) {
67+
frame.dispose();
68+
}
69+
});
70+
}
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Copyright (c) 2000, 2023, 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 4323121
27+
* @summary Tests whether any button that extends JButton always
28+
returns true for isArmed()
29+
* @key headful
30+
* @run main bug4323121
31+
*/
32+
33+
import java.awt.Graphics;
34+
import java.awt.Point;
35+
import java.awt.Robot;
36+
import java.awt.event.MouseEvent;
37+
import java.awt.event.MouseListener;
38+
import java.awt.event.MouseMotionListener;
39+
import javax.swing.JButton;
40+
import javax.swing.JFrame;
41+
import javax.swing.SwingUtilities;
42+
43+
public class bug4323121 {
44+
45+
static JFrame frame;
46+
static testButton button;
47+
static volatile Point pt;
48+
static volatile int buttonW;
49+
static volatile int buttonH;
50+
static volatile boolean failed = false;
51+
52+
public static void main(String[] args) throws Exception {
53+
Robot robot = new Robot();
54+
robot.setAutoDelay(100);
55+
try {
56+
SwingUtilities.invokeAndWait(() -> {
57+
frame = new JFrame("bug4323121");
58+
button = new testButton("gotcha");
59+
frame.getContentPane().add(button);
60+
frame.pack();
61+
frame.setLocationRelativeTo(null);
62+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
63+
frame.setVisible(true);
64+
});
65+
robot.waitForIdle();
66+
robot.delay(1000);
67+
SwingUtilities.invokeAndWait(() -> {
68+
pt = button.getLocationOnScreen();
69+
buttonW = button.getSize().width;
70+
buttonH = button.getSize().height;
71+
});
72+
robot.mouseMove(pt.x + buttonW / 2, pt.y + buttonH / 2);
73+
robot.waitForIdle();
74+
if (failed) {
75+
throw new RuntimeException("Any created button returns " +
76+
"true for isArmed()");
77+
}
78+
} finally {
79+
SwingUtilities.invokeAndWait(() -> {
80+
if (frame != null) {
81+
frame.dispose();
82+
}
83+
});
84+
}
85+
}
86+
87+
static class testButton extends JButton implements MouseMotionListener, MouseListener {
88+
public testButton(String label) {
89+
super(label);
90+
addMouseMotionListener(this);
91+
addMouseListener(this);
92+
}
93+
94+
protected void paintComponent(Graphics g) {
95+
super.paintComponent(g);
96+
}
97+
98+
protected void paintBorder(Graphics g) {
99+
}
100+
101+
public void mousePressed(MouseEvent e) {
102+
}
103+
104+
public void mouseDragged(MouseEvent e) {
105+
}
106+
107+
public void mouseMoved(MouseEvent e) {
108+
}
109+
110+
public void mouseReleased(MouseEvent e) {
111+
}
112+
113+
public void mouseEntered(MouseEvent e) {
114+
if (getModel().isArmed()) {
115+
failed = true;
116+
}
117+
}
118+
119+
public void mouseExited(MouseEvent e) {
120+
}
121+
122+
public void mouseClicked(MouseEvent e) {
123+
}
124+
}
125+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (c) 2002, 2023, 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 4490179
27+
* @summary Tests that JButton only responds to left mouse clicks.
28+
* @key headful
29+
* @run main bug4490179
30+
*/
31+
32+
import java.awt.Point;
33+
import java.awt.Robot;
34+
import java.awt.event.ActionEvent;
35+
import java.awt.event.ActionListener;
36+
import java.awt.event.InputEvent;
37+
import javax.swing.JButton;
38+
import javax.swing.JFrame;
39+
import javax.swing.SwingUtilities;
40+
41+
public class bug4490179 {
42+
static JFrame frame;
43+
static JButton button;
44+
static volatile Point pt;
45+
static volatile int buttonW;
46+
static volatile int buttonH;
47+
static volatile boolean passed = true;
48+
49+
public static void main(String[] args) throws Exception {
50+
Robot robot = new Robot();
51+
robot.setAutoDelay(100);
52+
try {
53+
SwingUtilities.invokeAndWait(() -> {
54+
frame = new JFrame("bug4490179");
55+
button = new JButton("Button");
56+
frame.getContentPane().add(button);
57+
button.addActionListener(new ActionListener() {
58+
public void actionPerformed(ActionEvent e) {
59+
passed = false;
60+
}
61+
});
62+
frame.pack();
63+
frame.setLocationRelativeTo(null);
64+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
65+
frame.setVisible(true);
66+
});
67+
robot.waitForIdle();
68+
robot.delay(1000);
69+
SwingUtilities.invokeAndWait(() -> {
70+
pt = button.getLocationOnScreen();
71+
buttonW = button.getSize().width;
72+
buttonH = button.getSize().height;
73+
});
74+
75+
robot.mouseMove(pt.x + buttonW / 2, pt.y + buttonH / 2);
76+
robot.waitForIdle();
77+
robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
78+
robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
79+
80+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
81+
robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
82+
robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
83+
84+
if (!passed) {
85+
throw new RuntimeException("Test Failed");
86+
}
87+
} finally {
88+
SwingUtilities.invokeAndWait(() -> {
89+
if (frame != null) {
90+
frame.dispose();
91+
}
92+
});
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)
Please sign in to comment.