Skip to content

Commit 9592af7

Browse files
author
Satyen Subramaniam
committed
8352686: Opensource JInternalFrame tests - series3
Backport-of: 27c8d9d635eaa0aac722c1b1eba8591fd291c077
1 parent 943251d commit 9592af7

File tree

4 files changed

+428
-0
lines changed

4 files changed

+428
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2003, 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 4151444
27+
* @summary The maximize button acts like the restore button
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4151444
31+
*/
32+
33+
import javax.swing.JDesktopPane;
34+
import javax.swing.JFrame;
35+
import javax.swing.JInternalFrame;
36+
import javax.swing.JLayeredPane;
37+
import javax.swing.UIManager;
38+
39+
40+
public class bug4151444 {
41+
42+
private static JFrame frame;
43+
private static JInternalFrame interFrame;
44+
45+
private static final String INSTRUCTIONS = """
46+
- maximize the internal frame
47+
- then minimize the internal frame
48+
- then maximize the internal frame again
49+
- Check whether internal frame is maximized
50+
- Test will fail automatically even if "Pass" is pressed
51+
if internal frame is not maximized.""";
52+
53+
public static void main(String[] args) throws Exception {
54+
55+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
56+
57+
PassFailJFrame pfj = PassFailJFrame.builder()
58+
.title("bug4151444 Instructions")
59+
.instructions(INSTRUCTIONS)
60+
.columns(45)
61+
.testUI(bug4151444::createTestUI)
62+
.build();
63+
try {
64+
pfj.awaitAndCheck();
65+
} finally {
66+
if (!interFrame.isMaximum()) {
67+
throw new RuntimeException ("Test failed. The maximize button acts like the restore button");
68+
}
69+
}
70+
}
71+
72+
private static JFrame createTestUI() {
73+
JFrame frame = new JFrame("bug4151444 frame");
74+
JDesktopPane desktop = new JDesktopPane();
75+
frame.setContentPane(desktop);
76+
interFrame = new JInternalFrame(
77+
"Internal frame", true, true, true, true);
78+
desktop.add(interFrame, JLayeredPane.DEFAULT_LAYER);
79+
interFrame.setBounds(0, 0, 200, 100);
80+
interFrame.setVisible(true);
81+
frame.setSize(300, 200);
82+
return frame;
83+
}
84+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (c) 2000, 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 4215380
27+
* @summary Internal Frame should get focus
28+
* @key headful
29+
* @run main bug4215380
30+
*/
31+
32+
import java.awt.BorderLayout;
33+
import java.awt.Dimension;
34+
import java.awt.event.InputEvent;
35+
import java.awt.Point;
36+
import java.awt.Robot;
37+
38+
import javax.swing.JButton;
39+
import javax.swing.JDesktopPane;
40+
import javax.swing.JFrame;
41+
import javax.swing.JInternalFrame;
42+
import javax.swing.JLayeredPane;
43+
import javax.swing.JPanel;
44+
import javax.swing.SwingUtilities;
45+
46+
public class bug4215380 {
47+
48+
private static String button;
49+
private static JButton b;
50+
private static JFrame frame;
51+
private static JInternalFrame jif;
52+
private static volatile Point loc;
53+
private static volatile Dimension size;
54+
55+
public static void main(String[] args) throws Exception {
56+
Robot robot = new Robot();
57+
try {
58+
SwingUtilities.invokeAndWait(() -> {
59+
frame = new JFrame("bug4215380");
60+
JDesktopPane desktop = new JDesktopPane();
61+
frame.add(desktop, BorderLayout.CENTER);
62+
63+
jif = iFrame(1);
64+
desktop.add(jif, JLayeredPane.DEFAULT_LAYER);
65+
desktop.add(iFrame(2), JLayeredPane.DEFAULT_LAYER);
66+
frame.setSize(200, 200);
67+
frame.setLocationRelativeTo(null);
68+
frame.setVisible(true);
69+
});
70+
robot.waitForIdle();
71+
robot.delay(1000);
72+
SwingUtilities.invokeAndWait(() -> {
73+
loc = b.getLocationOnScreen();
74+
size = b.getSize();
75+
});
76+
robot.mouseMove(loc.x + size.width / 2, loc.y + size.height / 2);
77+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
78+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
79+
robot.waitForIdle();
80+
robot.delay(500);
81+
if (!(jif.isSelected()) && !button.equals("Frame 1")) {
82+
throw new RuntimeException("Internal frame \"Frame 1\" should be selected...");
83+
}
84+
} finally {
85+
SwingUtilities.invokeAndWait(() -> {
86+
if (frame != null) {
87+
frame.dispose();
88+
}
89+
});
90+
}
91+
}
92+
93+
private static JInternalFrame iFrame(int i) {
94+
JInternalFrame frame = new JInternalFrame("Frame " + i);
95+
JPanel panel = new JPanel();
96+
JButton bt = new JButton("Button " + i);
97+
if (i == 1) {
98+
b = bt;
99+
}
100+
bt.addActionListener(e -> button = ((JButton)e.getSource()).getText());
101+
102+
panel.add(bt);
103+
104+
frame.getContentPane().add(panel);
105+
frame.setBounds(10, i * 80 - 70, 120, 90);
106+
frame.setVisible(true);
107+
return frame;
108+
}
109+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright (c) 2000, 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 4321312
27+
* @summary Verifies no Exception thrown from BasicInternalFrameUI$BorderListener
28+
* @key headful
29+
* @run main bug4321312
30+
*/
31+
32+
import java.awt.Dimension;
33+
import java.awt.event.InputEvent;
34+
import java.awt.event.MouseEvent;
35+
import java.awt.Point;
36+
import java.awt.Robot;
37+
38+
import javax.swing.JDesktopPane;
39+
import javax.swing.JFrame;
40+
import javax.swing.JInternalFrame;
41+
import javax.swing.SwingUtilities;
42+
import javax.swing.UIManager;
43+
import javax.swing.UnsupportedLookAndFeelException;
44+
45+
public class bug4321312 {
46+
47+
private static JFrame frame;
48+
private static MyInternalFrame jif;
49+
private static volatile Point loc;
50+
private static volatile Dimension size;
51+
52+
static boolean fails;
53+
static Exception exc;
54+
55+
private static synchronized boolean isFails() {
56+
return fails;
57+
}
58+
59+
private static synchronized void setFails(Exception e) {
60+
fails = true;
61+
exc = e;
62+
}
63+
64+
public static void main(String[] args) throws Exception {
65+
Robot robot = new Robot();
66+
try {
67+
SwingUtilities.invokeAndWait(() -> {
68+
try {
69+
UIManager.setLookAndFeel(
70+
"com.sun.java.swing.plaf.motif.MotifLookAndFeel");
71+
} catch (ClassNotFoundException | InstantiationException
72+
| UnsupportedLookAndFeelException
73+
| IllegalAccessException e) {
74+
throw new RuntimeException(e);
75+
}
76+
77+
frame = new JFrame("bug4321312");
78+
JDesktopPane jdp = new JDesktopPane();
79+
frame.add(jdp);
80+
81+
jif = new MyInternalFrame("Internal Frame", true);
82+
jdp.add(jif);
83+
jif.setSize(150, 150);
84+
jif.setVisible(true);
85+
86+
frame.setSize(200, 200);
87+
frame.setLocationRelativeTo(null);
88+
frame.setVisible(true);
89+
});
90+
robot.waitForIdle();
91+
robot.delay(1000);
92+
SwingUtilities.invokeAndWait(() -> {
93+
loc = jif.getLocationOnScreen();
94+
size = jif.getSize();
95+
});
96+
robot.mouseMove(loc.x + size.width / 2, loc.y + size.height / 2);
97+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
98+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
99+
robot.waitForIdle();
100+
robot.delay(200);
101+
if (isFails()) {
102+
throw new RuntimeException(exc);
103+
}
104+
} finally {
105+
SwingUtilities.invokeAndWait(() -> {
106+
if (frame != null) {
107+
frame.dispose();
108+
}
109+
});
110+
}
111+
}
112+
113+
static class MyInternalFrame extends JInternalFrame {
114+
MyInternalFrame(String str, boolean b) {
115+
super(str, b);
116+
}
117+
118+
protected void processMouseEvent(MouseEvent e) {
119+
try {
120+
super.processMouseEvent(e);
121+
} catch (Exception exc) {
122+
setFails(exc);
123+
}
124+
}
125+
}
126+
}

0 commit comments

Comments
 (0)