Skip to content

Commit

Permalink
8340458: Open source additional Component tests (part 2)
Browse files Browse the repository at this point in the history
Reviewed-by: psadhukhan
  • Loading branch information
Alexander Zuev committed Oct 1, 2024
1 parent 9a7817b commit 021bf63
Show file tree
Hide file tree
Showing 4 changed files with 502 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* 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.
*/

/*
* @test
* @bug 4148334
* @summary tests that background color is initially set correctly.
* @requires os.family == "windows"
* @key headful
* @run main InitialBackgroundSettingTest
*/
import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.List;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.Scrollbar;
import java.lang.reflect.InvocationTargetException;

public class InitialBackgroundSettingTest {
Frame frame;
TextField tf;
TextArea ta;
Choice choice;
List list;
Scrollbar bar;
Button button;

public static void main(String[] args) throws InterruptedException,
InvocationTargetException {
InitialBackgroundSettingTest test= new InitialBackgroundSettingTest();
try {
EventQueue.invokeAndWait(test::setupGUI);
EventQueue.invokeAndWait(test::test);
} finally {
EventQueue.invokeAndWait(test::dispose);
}
}

public void setupGUI () {
frame = new Frame("InitialBackgroundSettingTest frame");
tf = new TextField("I am the TextField");
ta = new TextArea("I am the TextArea");
choice = new Choice();
list = new List();
bar = new Scrollbar(Scrollbar.HORIZONTAL);
button = new Button("I am the button");
frame.setBackground(Color.red);
frame.setLayout(new GridLayout(7, 1));
frame.add(button);
frame.add(bar);
frame.add(choice);
frame.add(list);
frame.add(tf);
frame.add(ta);
frame.setVisible(true);
frame.setBounds (400, 0, 300, 300);
}

public void test() {
boolean passed = true;
System.out.println("Button background color is:" +
button.getBackground());
if (Color.red.equals(button.getBackground())) {
System.err.println("Button background is red");
passed = false;
}
System.out.println("Scrollbar background color is:" +
bar.getBackground());
if (Color.red.equals(bar.getBackground())) {
System.err.println("ScrollBar background is red");
passed = false;
}
System.out.println("Choice background color is:" +
choice.getBackground());
if (Color.red.equals(choice.getBackground())) {
System.err.println("Choice background is red");
passed = false;
}
System.out.println("List background color is:" +
list.getBackground());
if (Color.red.equals(list.getBackground())) {
System.err.println("List background is red");
passed = false;
}
System.out.println("TextField background color is:" +
tf.getBackground());
if (Color.red.equals(tf.getBackground())) {
System.err.println("TextField background is red");
passed = false;
}
System.out.println("TextArea background color is:" +
ta.getBackground());
if (Color.red.equals(ta.getBackground())) {
System.err.println("TextArea background is red");
passed = false;
}

if (!passed) {
throw new RuntimeException("One or more component inherited" +
" background from a Frame");
}
}

public void dispose() {
frame.dispose();
}
}
139 changes: 139 additions & 0 deletions test/jdk/java/awt/Component/FlickeringOnScroll/FlickeringOnScroll.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* 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.
*/

/*
* @test
* @bug 6347994
* @summary REG: Scrollbar, Choice, Checkbox flickers and grays out when scrolling, XToolkit
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual FlickeringOnScroll
*/

import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.MenuItem;
import java.awt.Panel;
import java.awt.PopupMenu;
import java.awt.Scrollbar;
import java.awt.TextArea;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.reflect.InvocationTargetException;

public class FlickeringOnScroll extends Frame {

static final String INSTRUCTIONS = """
There are five components in the frame:
Scrollbars(vertical and horizontal), a Choice,
a Checkbox and a TextArea
1) Drag the thumbs of each Scrollbar.
2) Do the same with Choice's scrollbar.
3) Focus on Checkbox and press left mouse button or SPACE repeatedly.
4) Right click inside TextArea and navigate through all menu items
in PopupMenu using the arrow keys.
If you notice some component or its scrollbar flickers on
key/mouse press or drag, press Fail. Otherwise press Pass.
""";

public FlickeringOnScroll() {
Choice ch = new Choice();
ch.add("Praveen");
ch.add("Mohan");
ch.add("Rakesh");
ch.add("Menon");
ch.add("Girish");
ch.add("Ramachandran");
ch.add("Elancheran");
ch.add("Subramanian");
ch.add("Raju");
ch.add("Pallath");
ch.add("Mayank");
ch.add("Joshi");
ch.add("Sundar");
ch.add("Srinivas");
ch.add("Mandalika");
Checkbox chb = new Checkbox ("Checkbox", false);
TextArea ta = new TextArea("Text Area");
Panel panel = new Panel();
PopupMenu popup = new PopupMenu("Popup");
MenuItem mi1 = new MenuItem("mi1");
MenuItem mi2 = new MenuItem("mi2");
MenuItem mi3 = new MenuItem("mi3");
MenuItem mi4 = new MenuItem("mi4");

setTitle("Flickering Scroll Area Testing Frame");
setLayout(new FlowLayout());
add(ch);
add(chb);
add(ta);

panel.setLayout(new BorderLayout());
panel.setPreferredSize(new Dimension(200, 200));
add(panel);
panel.add("Center",new java.awt.Label("Scrollbar flickering test..." ,java.awt.Label.CENTER));
panel.add("South",new Scrollbar(Scrollbar.HORIZONTAL, 0, 100, 0, 255));
panel.add("East",new Scrollbar(Scrollbar.VERTICAL, 0, 100, 0, 255));

ta.add(popup);
popup.add (mi1);
popup.add (mi2);
popup.add (mi3);
popup.add (mi4);

ta.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent me) {
if (me.isPopupTrigger()) {
if (popup != null) {
popup.show(me.getComponent(), me.getX(), me.getY());
}
}
}
public void mouseReleased(MouseEvent me) {
if (me.isPopupTrigger()) {
if (popup != null) {
popup.show(me.getComponent(), me.getX(), me.getY());
}
}
}
});

pack();
}

public static void main(String[] args) throws InterruptedException,
InvocationTargetException {
PassFailJFrame.builder()
.title("Scroll Area Flickering Repaint")
.testUI(FlickeringOnScroll::new)
.instructions(INSTRUCTIONS)
.columns(40)
.logArea()
.build()
.awaitAndCheck();
}
}
83 changes: 83 additions & 0 deletions test/jdk/java/awt/Component/FocusRepaintTest/FocusRepaintTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 1997, 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.
*/

/*
* @test
* @bug 4079435
* @summary Calling repaint() in focus handlers messes up the window.
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual FocusRepaintTest
*/

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.lang.reflect.InvocationTargetException;

public class FocusRepaintTest extends Frame implements FocusListener {
static final String INSTRUCTIONS = """
Hit the tab key repeatedly in the Test window.
If any of the buttons disappear press Fail, otherwise press Pass.
""";

public FocusRepaintTest() {
setTitle("Test");
setLayout(new FlowLayout());
setSize(200, 100);
Button b1 = new Button("Close");
Button b2 = new Button("Button");
add(b1);
add(b2);
b1.setSize(50, 30);
b2.setSize(50, 30);
b1.addFocusListener(this);
b2.addFocusListener(this);
}

public void focusGained(FocusEvent e) {
Button b = (Button) e.getSource();
PassFailJFrame.log("Focus gained for " + b.getLabel());
b.repaint();
}

public void focusLost(FocusEvent e) {
Button b = (Button) e.getSource();
PassFailJFrame.log("Focus lost for " + b.getLabel());
b.repaint();
}

public static void main(String[] args) throws InterruptedException,
InvocationTargetException {
PassFailJFrame.builder()
.title("Focus Repaint")
.testUI(FocusRepaintTest::new)
.instructions(INSTRUCTIONS)
.columns(40)
.logArea()
.build()
.awaitAndCheck();
}
}
Loading

1 comment on commit 021bf63

@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.