Skip to content

Commit 65227a3

Browse files
author
Alexander Zvegintsev
committedSep 26, 2023
8316389: Open source few AWT applet tests
Reviewed-by: dnguyen, abhiscxk, aivanov
1 parent 788e6e1 commit 65227a3

File tree

4 files changed

+577
-0
lines changed

4 files changed

+577
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
* Copyright (c) 1998, 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+
import java.awt.BorderLayout;
25+
import java.awt.Color;
26+
import java.awt.EventQueue;
27+
import java.awt.Frame;
28+
import java.awt.Label;
29+
import java.awt.Menu;
30+
import java.awt.MenuBar;
31+
import java.awt.MenuItem;
32+
import java.awt.Panel;
33+
import java.awt.ScrollPane;
34+
import java.awt.event.ActionEvent;
35+
import java.awt.event.ActionListener;
36+
37+
/*
38+
* @test
39+
* @key headful
40+
* @summary Test dynamically changing frame component visibility and repacking
41+
* @library /java/awt/regtesthelpers
42+
* @build PassFailJFrame
43+
* @run main/manual FrameRepackTest
44+
*/
45+
46+
public class FrameRepackTest {
47+
48+
private static final String INSTRUCTIONS = """
49+
There is a green frame with a menubar.
50+
The menubar has one menu, labelled 'Flip'.
51+
The menu has two items, labelled 'visible' and 'not visible'.
52+
The frame also contains a red panel that contains two line labels,
53+
'This panel is always displayed' and 'it is a test'.
54+
55+
If you select the menu item 'Flip->visible', then another panel is
56+
added below the red panel.
57+
The added panel is blue and has yellow horizontal and vertical scrollbars.
58+
59+
If you select menu item 'Flip->not visible', the second panel
60+
is removed and the frame appears as it did originally.
61+
62+
You can repeatedly add and remove the second panel in this way.
63+
After such an addition or removal, the frame's location on the screen
64+
should not change, while the size changes to accommodate
65+
either just the red panel or both the red and the blue panels.
66+
67+
If you resize the frame larger, the red panel remains at the
68+
top of the frame with its height fixed and its width adjusted
69+
to the width of the frame.
70+
71+
Similarly, if it is present, the blue panel and its yellow scroolbars
72+
remain at the bottom of the frame with fixed height and width adjusted
73+
to the size of the frame. But selecting 'visible' or 'not visible'
74+
repacks the frame, thereby adjusting its size tightly to its panel(s).
75+
76+
Upon test completion, click Pass or Fail appropriately.
77+
""";
78+
79+
public static void main(String[] args) throws Exception {
80+
PassFailJFrame passFailJFrame = new PassFailJFrame.Builder()
81+
.title("FrameRepackTest Instructions")
82+
.instructions(INSTRUCTIONS)
83+
.testTimeOut(5)
84+
.rows(30)
85+
.columns(45)
86+
.build();
87+
88+
EventQueue.invokeAndWait(() -> {
89+
FrameRepack frame = new FrameRepack();
90+
91+
PassFailJFrame.addTestWindow(frame);
92+
PassFailJFrame.positionTestWindow(frame,
93+
PassFailJFrame.Position.HORIZONTAL);
94+
95+
frame.setVisible(true);
96+
});
97+
98+
passFailJFrame.awaitAndCheck();
99+
}
100+
101+
}
102+
103+
class FrameRepack extends Frame implements ActionListener {
104+
105+
Panel south;
106+
107+
public FrameRepack() {
108+
super("FrameRepack");
109+
110+
// create the menubar
111+
MenuBar menubar = new MenuBar();
112+
this.setMenuBar(menubar);
113+
// create the options
114+
Menu flip = new Menu("Flip");
115+
MenuItem mi;
116+
mi = new MenuItem("visible");
117+
mi.addActionListener(this);
118+
flip.add(mi);
119+
mi = new MenuItem("not visible");
120+
mi.addActionListener(this);
121+
flip.add(mi);
122+
123+
menubar.add(flip);
124+
125+
setLayout(new BorderLayout(2, 2));
126+
setBackground(Color.green);
127+
128+
// north panel is always displayed
129+
Panel north = new Panel();
130+
north.setBackground(Color.red);
131+
north.setLayout(new BorderLayout(2, 2));
132+
north.add("North", new Label("This panel is always displayed"));
133+
north.add("Center", new Label("it is a test"));
134+
north.setSize(200, 200);
135+
add("North", north);
136+
137+
// south panel can be visible or not...
138+
// The problem seems to occur when I put this panel not visible
139+
south = new Panel();
140+
south.setBackground(Color.white);
141+
south.setLayout(new BorderLayout());
142+
143+
ScrollPane scroller = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
144+
scroller.setBackground(Color.yellow);
145+
Panel pan1 = new Panel();
146+
pan1.setBackground(Color.blue);
147+
pan1.setLayout(new BorderLayout());
148+
149+
pan1.setSize(400, 150);
150+
scroller.add("Center", pan1);
151+
152+
south.add("South", scroller);
153+
154+
add("South", south);
155+
156+
south.setVisible(false);
157+
158+
setSize(350, 300);
159+
160+
pack();
161+
}
162+
163+
@Override
164+
public void actionPerformed(ActionEvent evt) {
165+
if (evt.getSource() instanceof MenuItem) {
166+
if (evt.getActionCommand().equals("visible")) {
167+
south.setVisible(true);
168+
pack();
169+
} else if (evt.getActionCommand().equals("not visible")) {
170+
south.setVisible(false);
171+
pack();
172+
}
173+
}
174+
}
175+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) 1998, 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+
import java.awt.BorderLayout;
25+
import java.awt.Canvas;
26+
import java.awt.Color;
27+
import java.awt.EventQueue;
28+
import java.awt.Frame;
29+
30+
/*
31+
* @test
32+
* @bug 4041442
33+
* @key headful
34+
* @summary Test resizing a frame containing a canvas
35+
* @library /java/awt/regtesthelpers
36+
* @build PassFailJFrame
37+
* @run main/manual FrameResizeTest_1
38+
*/
39+
40+
public class FrameResizeTest_1 {
41+
42+
private static final String INSTRUCTIONS = """
43+
To the right of this frame is an all-white 200x200 frame.
44+
45+
This is actually a white canvas component in the frame.
46+
The frame itself is red.
47+
The red should never show.
48+
In particular, after you resize the frame, you should see all white and no red.
49+
(During very fast window resizing, red color may appear briefly,
50+
which is not a failure.)
51+
52+
Upon test completion, click Pass or Fail appropriately.
53+
""";
54+
55+
public static void main(String[] args) throws Exception {
56+
PassFailJFrame passFailJFrame = new PassFailJFrame.Builder()
57+
.title("FrameResizeTest_1 Instructions")
58+
.instructions(INSTRUCTIONS)
59+
.testTimeOut(5)
60+
.rows(12)
61+
.columns(45)
62+
.build();
63+
64+
EventQueue.invokeAndWait(() -> {
65+
FrameResize_1 frame = new FrameResize_1();
66+
67+
PassFailJFrame.addTestWindow(frame);
68+
PassFailJFrame.positionTestWindow(frame,
69+
PassFailJFrame.Position.HORIZONTAL);
70+
71+
frame.setVisible(true);
72+
});
73+
74+
passFailJFrame.awaitAndCheck();
75+
}
76+
}
77+
78+
class FrameResize_1 extends Frame {
79+
80+
FrameResize_1() {
81+
super("FrameResize_1");
82+
// Create a white canvas
83+
Canvas canvas = new Canvas();
84+
canvas.setBackground(Color.white);
85+
86+
setLayout(new BorderLayout());
87+
add("Center", canvas);
88+
89+
setBackground(Color.red);
90+
setSize(200,200);
91+
}
92+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* Copyright (c) 1998, 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+
import java.awt.BorderLayout;
25+
import java.awt.Canvas;
26+
import java.awt.Color;
27+
import java.awt.Container;
28+
import java.awt.Dimension;
29+
import java.awt.EventQueue;
30+
import java.awt.Frame;
31+
import java.awt.Graphics;
32+
import java.awt.GridBagConstraints;
33+
import java.awt.GridBagLayout;
34+
import java.awt.Panel;
35+
36+
/*
37+
* @test
38+
* @bug 4065568
39+
* @key headful
40+
* @summary Test resizing a frame containing a canvas
41+
* @library /java/awt/regtesthelpers
42+
* @build PassFailJFrame
43+
* @run main/manual FrameResizeTest_2
44+
*/
45+
46+
public class FrameResizeTest_2 {
47+
private static final String INSTRUCTIONS = """
48+
There is a frame (size 300x300).
49+
The left half is red and the right half is blue.
50+
51+
When you resize the frame, it should still have a red left half
52+
and a blue right half.
53+
54+
In particular, no green should be visible after a resize.
55+
56+
Upon test completion, click Pass or Fail appropriately.
57+
""";
58+
59+
public static void main(String[] args) throws Exception {
60+
PassFailJFrame passFailJFrame = new PassFailJFrame.Builder()
61+
.title("FrameResizeTest_2 Instructions")
62+
.instructions(INSTRUCTIONS)
63+
.testTimeOut(5)
64+
.rows(10)
65+
.columns(45)
66+
.build();
67+
68+
EventQueue.invokeAndWait(() -> {
69+
FrameResize_2 frame = new FrameResize_2();
70+
71+
PassFailJFrame.addTestWindow(frame);
72+
PassFailJFrame.positionTestWindow(frame,
73+
PassFailJFrame.Position.HORIZONTAL);
74+
75+
frame.setVisible(true);
76+
});
77+
78+
passFailJFrame.awaitAndCheck();
79+
}
80+
}
81+
82+
class FrameResize_2 extends Frame {
83+
84+
FrameResize_2() {
85+
super("FrameResize_2");
86+
87+
setLayout(new GridBagLayout());
88+
89+
GridBagConstraints c = new GridBagConstraints();
90+
c.fill = GridBagConstraints.BOTH;
91+
c.weightx = 1;
92+
c.weighty = 1;
93+
94+
Container dumbContainer = new DumbContainer();
95+
add(dumbContainer, c);
96+
97+
Panel dumbPanel = new DumbPanel();
98+
add(dumbPanel, c);
99+
100+
setSize(300, 300);
101+
}
102+
}
103+
104+
105+
class Fake extends Canvas {
106+
public Fake(String name, Color what) {
107+
setBackground(what);
108+
setName(name);
109+
}
110+
111+
public void paint(Graphics g) {
112+
Dimension d = getSize();
113+
g.setColor(getBackground());
114+
g.fillRect(0, 0, d.width, d.height);
115+
}
116+
}
117+
118+
class DumbContainer extends Container {
119+
public DumbContainer() {
120+
setLayout(new BorderLayout());
121+
add("Center", new Fake("dumbc", Color.red));
122+
}
123+
124+
public void paint(Graphics g) {
125+
Dimension d = getSize();
126+
g.setColor(Color.green);
127+
g.fillRect(0, 0, d.width, d.height);
128+
super.paint(g);
129+
}
130+
}
131+
132+
class DumbPanel extends Panel {
133+
public DumbPanel() {
134+
setLayout(new BorderLayout());
135+
add("Center", new Fake("dumbp", Color.blue));
136+
}
137+
138+
public void paint(Graphics g) {
139+
Dimension d = getSize();
140+
g.setColor(Color.green);
141+
g.fillRect(0, 0, d.width, d.height);
142+
super.paint(g);
143+
}
144+
}
+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*
2+
* Copyright (c) 1998, 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+
import java.awt.Color;
25+
import java.awt.EventQueue;
26+
import java.awt.Frame;
27+
import java.awt.Rectangle;
28+
import java.awt.Robot;
29+
import java.awt.event.WindowEvent;
30+
import java.awt.event.WindowListener;
31+
import java.util.concurrent.CountDownLatch;
32+
import java.util.concurrent.TimeUnit;
33+
34+
/*
35+
* @test
36+
* @bug 4077874
37+
* @key headful
38+
* @summary Test window position at opening, closing, and closed for consistency
39+
*/
40+
41+
public class WindowMoveTest {
42+
43+
static WindowMove frame;
44+
public static void main(String[] args) throws Exception {
45+
Robot robot = new Robot();
46+
robot.setAutoDelay(50);
47+
robot.setAutoWaitForIdle(true);
48+
49+
EventQueue.invokeAndWait(() -> frame = new WindowMove());
50+
51+
robot.waitForIdle();
52+
robot.delay(1000);
53+
54+
EventQueue.invokeAndWait(() ->
55+
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)));
56+
57+
if (!WindowMove.latch.await(2, TimeUnit.SECONDS)) {
58+
throw new RuntimeException("Test timeout.");
59+
}
60+
61+
if (WindowMove.failMessage != null) {
62+
throw new RuntimeException(WindowMove.failMessage);
63+
}
64+
}
65+
}
66+
67+
class WindowMove extends Frame implements WindowListener {
68+
static final Rectangle expectedBounds =
69+
new Rectangle(100, 100, 300, 300);
70+
71+
static CountDownLatch latch = new CountDownLatch(1);
72+
static String failMessage = null;
73+
74+
private boolean layoutCheck;
75+
private boolean visibleCheck;
76+
private boolean openedCheck;
77+
private boolean closingCheck;
78+
private boolean closedCheck;
79+
80+
public WindowMove() {
81+
super("WindowMove");
82+
addWindowListener(this);
83+
84+
setSize(300, 300);
85+
setLocation(100, 100);
86+
setBackground(Color.white);
87+
88+
setLayout(null);
89+
if (checkBounds()) {
90+
layoutCheck = true;
91+
}
92+
System.out.println("setLayout bounds: " + getBounds());
93+
94+
setVisible(true);
95+
if (checkBounds()) {
96+
visibleCheck = true;
97+
}
98+
System.out.println("setVisible bounds: " + getBounds());
99+
}
100+
101+
private boolean checkBounds() {
102+
return getBounds().equals(expectedBounds);
103+
}
104+
105+
public void checkResult() {
106+
if (layoutCheck
107+
&& visibleCheck
108+
&& openedCheck
109+
&& closingCheck
110+
&& closedCheck) {
111+
System.out.println("Test passed.");
112+
} else {
113+
failMessage = """
114+
Some of the checks failed:
115+
layoutCheck %s
116+
visibleCheck %s
117+
openedCheck %s
118+
closingCheck %s
119+
closedCheck %s
120+
"""
121+
.formatted(
122+
layoutCheck,
123+
visibleCheck,
124+
openedCheck,
125+
closingCheck,
126+
closedCheck
127+
);
128+
}
129+
130+
latch.countDown();
131+
}
132+
133+
public void windowClosing(WindowEvent evt) {
134+
if (checkBounds()) {
135+
closingCheck = true;
136+
}
137+
System.out.println("Closing bounds: " + getBounds());
138+
139+
setVisible(false);
140+
dispose();
141+
}
142+
143+
public void windowClosed(WindowEvent evt) {
144+
if (checkBounds()) {
145+
closedCheck = true;
146+
}
147+
System.out.println("Closed bounds: " + getBounds());
148+
149+
checkResult();
150+
}
151+
152+
public void windowOpened(WindowEvent evt) {
153+
if (checkBounds()) {
154+
openedCheck = true;
155+
}
156+
System.out.println("Opening bounds: " + getBounds());
157+
}
158+
159+
public void windowActivated(WindowEvent evt) {}
160+
161+
public void windowIconified(WindowEvent evt) {}
162+
163+
public void windowDeactivated(WindowEvent evt) {}
164+
165+
public void windowDeiconified(WindowEvent evt) {}
166+
}

0 commit comments

Comments
 (0)
Please sign in to comment.