Skip to content

Commit

Permalink
8316389: Open source few AWT applet tests
Browse files Browse the repository at this point in the history
Reviewed-by: dnguyen, abhiscxk, aivanov
  • Loading branch information
Alexander Zvegintsev committed Sep 26, 2023
1 parent 788e6e1 commit 65227a3
Show file tree
Hide file tree
Showing 4 changed files with 577 additions and 0 deletions.
175 changes: 175 additions & 0 deletions test/jdk/java/awt/Frame/FrameRepackTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
* Copyright (c) 1998, 2023, 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.Color;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.Panel;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/*
* @test
* @key headful
* @summary Test dynamically changing frame component visibility and repacking
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual FrameRepackTest
*/

public class FrameRepackTest {

private static final String INSTRUCTIONS = """
There is a green frame with a menubar.
The menubar has one menu, labelled 'Flip'.
The menu has two items, labelled 'visible' and 'not visible'.
The frame also contains a red panel that contains two line labels,
'This panel is always displayed' and 'it is a test'.
If you select the menu item 'Flip->visible', then another panel is
added below the red panel.
The added panel is blue and has yellow horizontal and vertical scrollbars.
If you select menu item 'Flip->not visible', the second panel
is removed and the frame appears as it did originally.
You can repeatedly add and remove the second panel in this way.
After such an addition or removal, the frame's location on the screen
should not change, while the size changes to accommodate
either just the red panel or both the red and the blue panels.
If you resize the frame larger, the red panel remains at the
top of the frame with its height fixed and its width adjusted
to the width of the frame.
Similarly, if it is present, the blue panel and its yellow scroolbars
remain at the bottom of the frame with fixed height and width adjusted
to the size of the frame. But selecting 'visible' or 'not visible'
repacks the frame, thereby adjusting its size tightly to its panel(s).
Upon test completion, click Pass or Fail appropriately.
""";

public static void main(String[] args) throws Exception {
PassFailJFrame passFailJFrame = new PassFailJFrame.Builder()
.title("FrameRepackTest Instructions")
.instructions(INSTRUCTIONS)
.testTimeOut(5)
.rows(30)
.columns(45)
.build();

EventQueue.invokeAndWait(() -> {
FrameRepack frame = new FrameRepack();

PassFailJFrame.addTestWindow(frame);
PassFailJFrame.positionTestWindow(frame,
PassFailJFrame.Position.HORIZONTAL);

frame.setVisible(true);
});

passFailJFrame.awaitAndCheck();
}

}

class FrameRepack extends Frame implements ActionListener {

Panel south;

public FrameRepack() {
super("FrameRepack");

// create the menubar
MenuBar menubar = new MenuBar();
this.setMenuBar(menubar);
// create the options
Menu flip = new Menu("Flip");
MenuItem mi;
mi = new MenuItem("visible");
mi.addActionListener(this);
flip.add(mi);
mi = new MenuItem("not visible");
mi.addActionListener(this);
flip.add(mi);

menubar.add(flip);

setLayout(new BorderLayout(2, 2));
setBackground(Color.green);

// north panel is always displayed
Panel north = new Panel();
north.setBackground(Color.red);
north.setLayout(new BorderLayout(2, 2));
north.add("North", new Label("This panel is always displayed"));
north.add("Center", new Label("it is a test"));
north.setSize(200, 200);
add("North", north);

// south panel can be visible or not...
// The problem seems to occur when I put this panel not visible
south = new Panel();
south.setBackground(Color.white);
south.setLayout(new BorderLayout());

ScrollPane scroller = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
scroller.setBackground(Color.yellow);
Panel pan1 = new Panel();
pan1.setBackground(Color.blue);
pan1.setLayout(new BorderLayout());

pan1.setSize(400, 150);
scroller.add("Center", pan1);

south.add("South", scroller);

add("South", south);

south.setVisible(false);

setSize(350, 300);

pack();
}

@Override
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() instanceof MenuItem) {
if (evt.getActionCommand().equals("visible")) {
south.setVisible(true);
pack();
} else if (evt.getActionCommand().equals("not visible")) {
south.setVisible(false);
pack();
}
}
}
}
92 changes: 92 additions & 0 deletions test/jdk/java/awt/Frame/FrameResizeTest/FrameResizeTest_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) 1998, 2023, 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.Canvas;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Frame;

/*
* @test
* @bug 4041442
* @key headful
* @summary Test resizing a frame containing a canvas
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual FrameResizeTest_1
*/

public class FrameResizeTest_1 {

private static final String INSTRUCTIONS = """
To the right of this frame is an all-white 200x200 frame.
This is actually a white canvas component in the frame.
The frame itself is red.
The red should never show.
In particular, after you resize the frame, you should see all white and no red.
(During very fast window resizing, red color may appear briefly,
which is not a failure.)
Upon test completion, click Pass or Fail appropriately.
""";

public static void main(String[] args) throws Exception {
PassFailJFrame passFailJFrame = new PassFailJFrame.Builder()
.title("FrameResizeTest_1 Instructions")
.instructions(INSTRUCTIONS)
.testTimeOut(5)
.rows(12)
.columns(45)
.build();

EventQueue.invokeAndWait(() -> {
FrameResize_1 frame = new FrameResize_1();

PassFailJFrame.addTestWindow(frame);
PassFailJFrame.positionTestWindow(frame,
PassFailJFrame.Position.HORIZONTAL);

frame.setVisible(true);
});

passFailJFrame.awaitAndCheck();
}
}

class FrameResize_1 extends Frame {

FrameResize_1() {
super("FrameResize_1");
// Create a white canvas
Canvas canvas = new Canvas();
canvas.setBackground(Color.white);

setLayout(new BorderLayout());
add("Center", canvas);

setBackground(Color.red);
setSize(200,200);
}
}

1 comment on commit 65227a3

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.