forked from openjdk/jdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8341373: Open source closed frame tests # 4
- Loading branch information
Showing
5 changed files
with
477 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
Oops, something went wrong.