8341373: Open source closed frame tests # 4
Reviewed-by: prr
This commit is contained in:
parent
3359518986
commit
d0c5e4bc50
120
test/jdk/java/awt/Frame/AddRemoveMenuBarTest_5.java
Normal file
120
test/jdk/java/awt/Frame/AddRemoveMenuBarTest_5.java
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Menu;
|
||||
import java.awt.MenuBar;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 4159883
|
||||
* @summary Adding/Removing a menu causes frame to unexpected small size
|
||||
* @requires (os.family == "linux" | os.family == "windows")
|
||||
*/
|
||||
|
||||
public class AddRemoveMenuBarTest_5 {
|
||||
|
||||
static Frame frame;
|
||||
static MenuBar menu;
|
||||
static Button btnAdd, btnRemove;
|
||||
static Dimension oldSize;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Robot robot = new Robot();
|
||||
try {
|
||||
EventQueue.invokeAndWait(AddRemoveMenuBarTest_5::initAndShowGui);
|
||||
robot.waitForIdle();
|
||||
robot.delay(500);
|
||||
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
oldSize = frame.getSize();
|
||||
changeMenubar(true);
|
||||
});
|
||||
robot.waitForIdle();
|
||||
robot.delay(500);
|
||||
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
checkSize();
|
||||
changeMenubar(false);
|
||||
});
|
||||
robot.waitForIdle();
|
||||
robot.delay(500);
|
||||
|
||||
EventQueue.invokeAndWait(AddRemoveMenuBarTest_5::checkSize);
|
||||
} finally {
|
||||
EventQueue.invokeAndWait(frame::dispose);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initAndShowGui() {
|
||||
frame = new Frame();
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowOpened(WindowEvent e) {
|
||||
System.out.println("Frame size:" + frame.getSize().toString());
|
||||
System.out.println("Button size:" + btnAdd.getSize().toString());
|
||||
}
|
||||
});
|
||||
frame.add("West", btnAdd = new Button("TRY:ADD"));
|
||||
frame.add("East", btnRemove = new Button("TRY:REMOVE"));
|
||||
|
||||
|
||||
btnAdd.addActionListener((e) -> changeMenubar(true));
|
||||
btnRemove.addActionListener((e) -> changeMenubar(false));
|
||||
frame.setSize(500, 100);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
private static void changeMenubar(boolean enable) {
|
||||
if (enable) {
|
||||
menu = new MenuBar();
|
||||
menu.add(new Menu("BAAAAAAAAAAAAAAA"));
|
||||
menu.add(new Menu("BZZZZZZZZZZZZZZZ"));
|
||||
menu.add(new Menu("BXXXXXXXXXXXXXXX"));
|
||||
} else {
|
||||
menu = null;
|
||||
}
|
||||
frame.setMenuBar(menu);
|
||||
frame.invalidate();
|
||||
frame.validate();
|
||||
|
||||
System.out.println("Frame size:" + frame.getSize().toString());
|
||||
System.out.println("Button size:" + btnAdd.getSize().toString());
|
||||
}
|
||||
|
||||
private static void checkSize() {
|
||||
Dimension newSize = frame.getSize();
|
||||
if (!oldSize.equals(newSize)) {
|
||||
throw new RuntimeException("Frame size changed: old %s new %s"
|
||||
.formatted(oldSize, newSize));
|
||||
}
|
||||
}
|
||||
}
|
97
test/jdk/java/awt/Frame/FrameResizableTest.java
Normal file
97
test/jdk/java/awt/Frame/FrameResizableTest.java
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Label;
|
||||
import java.awt.Panel;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 1231233
|
||||
* @summary Tests whether the resizable property of a Frame is
|
||||
* respected after it is set.
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual FrameResizableTest
|
||||
*/
|
||||
|
||||
public class FrameResizableTest {
|
||||
private static final String INSTRUCTIONS = """
|
||||
There is a frame with two buttons and a label. The label
|
||||
reads 'true' or 'false' to indicate whether the frame can be
|
||||
resized or not.
|
||||
|
||||
When the first button, 'Set Resizable', is
|
||||
clicked, you should be able to resize the frame.
|
||||
When the second button, 'UnSet Resizable', is clicked, you should
|
||||
not be able to resize the frame.
|
||||
|
||||
A frame is resized in a way which depends upon the window manager (WM) running.
|
||||
You may resize the frame by dragging the corner resize handles or the borders,
|
||||
or you may use the title bar's resize menu items and buttons.
|
||||
|
||||
Upon test completion, click Pass or Fail appropriately.
|
||||
""";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PassFailJFrame.builder()
|
||||
.title("FrameResizableTest Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(50)
|
||||
.testUI(FrameResizable::new)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
private static class FrameResizable extends Frame {
|
||||
Label label;
|
||||
Button buttonResizable;
|
||||
Button buttonNotResizable;
|
||||
|
||||
public FrameResizable() {
|
||||
super("FrameResizable");
|
||||
setResizable(false);
|
||||
Panel panel = new Panel();
|
||||
|
||||
add("North", panel);
|
||||
ActionListener actionListener = (e) -> {
|
||||
if (e.getSource() == buttonResizable) {
|
||||
setResizable(true);
|
||||
} else if (e.getSource() == buttonNotResizable) {
|
||||
setResizable(false);
|
||||
}
|
||||
label.setText("Resizable: " + isResizable());
|
||||
};
|
||||
|
||||
panel.add(buttonResizable = new Button("Set Resizable"));
|
||||
panel.add(buttonNotResizable = new Button("UnSet Resizable"));
|
||||
panel.add(label = new Label("Resizable: " + isResizable()));
|
||||
buttonResizable.addActionListener(actionListener);
|
||||
buttonNotResizable.addActionListener(actionListener);
|
||||
|
||||
setSize(400, 200);
|
||||
}
|
||||
}
|
||||
}
|
65
test/jdk/java/awt/Frame/I18NTitle.java
Normal file
65
test/jdk/java/awt/Frame/I18NTitle.java
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Label;
|
||||
import java.awt.Window;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6269884 4929291
|
||||
* @summary Tests that title which contains mix of non-English characters is displayed correctly
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual I18NTitle
|
||||
*/
|
||||
|
||||
public class I18NTitle {
|
||||
private static final String INSTRUCTIONS = """
|
||||
You will see a frame with some title (S. Chinese, Cyrillic and German).
|
||||
Please check if non-English characters are visible and compare
|
||||
the visible title with the same string shown in the label
|
||||
(it should not look worse than the label).
|
||||
""";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PassFailJFrame.builder()
|
||||
.title("I18NTitle Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(50)
|
||||
.testUI(I18NTitle::createAndShowGUI)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
private static Window createAndShowGUI() {
|
||||
String s = "\u4e2d\u6587\u6d4b\u8bd5 \u0420\u0443\u0441\u0441\u043a\u0438\u0439 Zur\u00FCck";
|
||||
Frame frame = new Frame(s);
|
||||
frame.setLayout(new BorderLayout());
|
||||
Label l = new Label(s);
|
||||
frame.add(l);
|
||||
frame.setSize(400, 100);
|
||||
return frame;
|
||||
}
|
||||
}
|
81
test/jdk/java/awt/Frame/MenuBarOffsetTest.java
Normal file
81
test/jdk/java/awt/Frame/MenuBarOffsetTest.java
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Menu;
|
||||
import java.awt.MenuBar;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4180577
|
||||
* @summary offset problems with menus in frames: (2 * 1) should be (2 * menuBarBorderSize)
|
||||
* @requires (os.family == "linux" | os.family == "windows")
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual MenuBarOffsetTest
|
||||
*/
|
||||
|
||||
public class MenuBarOffsetTest {
|
||||
private static final String INSTRUCTIONS = """
|
||||
If a menubar containing a menubar item labeled Test appears.
|
||||
in a frame, and fits within the frame, press Pass, else press Fail.
|
||||
""";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PassFailJFrame.builder()
|
||||
.title("MenuBarOffsetTest Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(45)
|
||||
.testUI(FrameTest::new)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
private static class FrameTest extends Frame {
|
||||
public FrameTest() {
|
||||
super("MenuBarOffsetTest FrameTest");
|
||||
MenuBar m = new MenuBar();
|
||||
setMenuBar(m);
|
||||
Menu test = m.add(new Menu("Test"));
|
||||
test.add("1");
|
||||
test.add("2");
|
||||
setSize(100, 100);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
setForeground(Color.red);
|
||||
Insets i = getInsets();
|
||||
Dimension d = getSize();
|
||||
System.err.println(getBounds());
|
||||
System.err.println("" + i);
|
||||
|
||||
g.drawRect(i.left, i.top,
|
||||
d.width - i.left - i.right - 1,
|
||||
d.height - i.top - i.bottom - 1);
|
||||
}
|
||||
}
|
||||
}
|
114
test/jdk/java/awt/Frame/MinimumSizeTest.java
Normal file
114
test/jdk/java/awt/Frame/MinimumSizeTest.java
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 1256759
|
||||
* @summary Checks that Frames with a very small size don't cause Motif
|
||||
* to generate VendorShells which consume the entire desktop.
|
||||
*/
|
||||
|
||||
public class MinimumSizeTest {
|
||||
|
||||
private static final Color BG_COLOR = Color.RED;
|
||||
private static Frame backgroundFrame;
|
||||
private static Frame testedFrame;
|
||||
|
||||
private static Robot robot;
|
||||
private static final Point location = new Point(200, 200);
|
||||
private static final Point[] testPointLocations = {
|
||||
new Point(100, 200),
|
||||
new Point(200, 100),
|
||||
new Point(450, 210),
|
||||
new Point(210, 350),
|
||||
};
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
robot = new Robot();
|
||||
|
||||
try {
|
||||
EventQueue.invokeAndWait(MinimumSizeTest::initAndShowGui);
|
||||
robot.waitForIdle();
|
||||
robot.delay(500);
|
||||
test();
|
||||
System.out.println("Test passed.");
|
||||
} finally {
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
backgroundFrame.dispose();
|
||||
testedFrame.dispose();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void test() {
|
||||
for (Point testLocation : testPointLocations) {
|
||||
Color pixelColor = robot.getPixelColor(testLocation.x, testLocation.y);
|
||||
|
||||
if (!pixelColor.equals(BG_COLOR)) {
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
BufferedImage screenCapture = robot.createScreenCapture(new Rectangle(screenSize));
|
||||
try {
|
||||
ImageIO.write(screenCapture, "png", new File("failure.png"));
|
||||
} catch (IOException ignored) {}
|
||||
throw new RuntimeException("Pixel color does not match expected color %s at %s"
|
||||
.formatted(pixelColor, testLocation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void initAndShowGui() {
|
||||
backgroundFrame = new Frame("MinimumSizeTest background");
|
||||
backgroundFrame.setUndecorated(true);
|
||||
backgroundFrame.setBackground(BG_COLOR);
|
||||
backgroundFrame.setBounds(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
|
||||
backgroundFrame.setVisible(true);
|
||||
|
||||
testedFrame = new MinimumSizeTestFrame();
|
||||
testedFrame.setVisible(true);
|
||||
}
|
||||
|
||||
private static class MinimumSizeTestFrame extends Frame {
|
||||
public MinimumSizeTestFrame() {
|
||||
super("MinimumSizeTest");
|
||||
setVisible(true);
|
||||
setBackground(Color.BLUE);
|
||||
setSize(0, 0);
|
||||
setLocation(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user