From 60c3f0b64ae427231f7ec05087714c4aa379f2a8 Mon Sep 17 00:00:00 2001 From: Tejesh R Date: Fri, 5 May 2023 12:56:34 +0530 Subject: [PATCH 1/9] Open source few Applet test --- .../jdk/java/awt/Panel/SetForegroundTest.java | 57 ++++++ .../java/awt/Robot/RobotMoveMultiscreen.java | 94 ++++++++++ .../java/awt/Scrollbar/PageIncrementTest.java | 85 +++++++++ .../Scrollbar/ScrollbarKeyControlTest.java | 173 ++++++++++++++++++ 4 files changed, 409 insertions(+) create mode 100644 test/jdk/java/awt/Panel/SetForegroundTest.java create mode 100644 test/jdk/java/awt/Robot/RobotMoveMultiscreen.java create mode 100644 test/jdk/java/awt/Scrollbar/PageIncrementTest.java create mode 100644 test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java diff --git a/test/jdk/java/awt/Panel/SetForegroundTest.java b/test/jdk/java/awt/Panel/SetForegroundTest.java new file mode 100644 index 0000000000000..b63bffcaf3a46 --- /dev/null +++ b/test/jdk/java/awt/Panel/SetForegroundTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2004, 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. + */ +/* + @test + @bug 4994151 + @summary REGRESSION: Bug when setting the foreground of a JWindow + @key headful +*/ + +import java.awt.EventQueue; +import java.awt.Color; + +import javax.swing.JWindow; +public class SetForegroundTest { + static JWindow jwindow; + public static void main(String[] args) throws Exception { + try { + EventQueue.invokeAndWait(() -> { + jwindow = new JWindow(); + jwindow.pack(); + try { + jwindow.setForeground(Color.BLACK); + System.out.println("TEST PASSED"); + } catch (ClassCastException cce) { + System.out.println("TEST FAILED"); + throw new RuntimeException("Test failed.", cce); + } + }); + } finally { + EventQueue.invokeAndWait(() -> { + if(jwindow != null) { + jwindow.dispose(); + } + }); + } + } +} diff --git a/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java b/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java new file mode 100644 index 0000000000000..f02d1a3540436 --- /dev/null +++ b/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 1999, 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. + */ +/* + @test + @bug 4288230 + @summary Tests that Robot can move mouse to another screen + @key headful +*/ + +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.Rectangle; +import java.awt.Robot; + +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionAdapter; + +public class RobotMoveMultiscreen { + static int x_dest = 20; + static int y_dest = 20; + static Frame frame; + static volatile Boolean testCondition = false; + + public static void main(String[] args) throws Exception { + GraphicsDevice[] devs = + GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); + + if (devs.length <= 1) { + System.out.println("Minimum 2 display screens are required" + + " for the test, Found " + devs.length); + return; + } + try { + EventQueue.invokeAndWait(() -> { + GraphicsDevice workDev = devs[devs.length - 1]; + GraphicsConfiguration config = workDev.getDefaultConfiguration(); + Rectangle bounds = config.getBounds(); + x_dest = bounds.x + bounds.width / 2; + y_dest = bounds.y + bounds.height / 2; + frame = new Frame("Listening frame"); + frame.addMouseMotionListener(new MouseMotionAdapter() { + public void mouseMoved(MouseEvent e) { + testCondition = true; + } + }); + frame.setLocation(x_dest,y_dest); + frame.setSize(100,100); + frame.setVisible(true); + }); + + Robot robot = new Robot(); + robot.delay(1000); + robot.waitForIdle(); + robot.mouseMove(x_dest+50, y_dest+50); + robot.delay(1000); + robot.waitForIdle(); + + if(testCondition == false) { + throw new RuntimeException("Can't move to another display"); + } + + System.out.println("Test Pass!!"); + } finally { + EventQueue.invokeAndWait(() -> { + if (frame != null) { + frame.dispose(); + } + }); + } + } +} diff --git a/test/jdk/java/awt/Scrollbar/PageIncrementTest.java b/test/jdk/java/awt/Scrollbar/PageIncrementTest.java new file mode 100644 index 0000000000000..daead1c18b207 --- /dev/null +++ b/test/jdk/java/awt/Scrollbar/PageIncrementTest.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2003, 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. + */ + +/* + @test + @bug 4677084 + @summary Tests that the PageIncrement (BlockIncrement) and + LineIncrement (UnitIncrement) cannot be < 1 + @key headful +*/ + +import java.awt.EventQueue; +import java.awt.Scrollbar; + +public class PageIncrementTest { + static Scrollbar sb; + + public static void main(String[] args) throws Exception { + EventQueue.invokeAndWait(() -> { + sb = new Scrollbar(); + sb.setBlockIncrement(0); + sb.setUnitIncrement(0); + + if (sb.getBlockIncrement() < 1) { + String msg = "Failed: getBlockIncrement() == " + sb.getBlockIncrement(); + System.out.println(msg); + throw new RuntimeException(msg); + } + if (sb.getUnitIncrement() < 1) { + String msg = "Failed: getLineIncrement() == " + sb.getUnitIncrement(); + System.out.println(msg); + throw new RuntimeException(msg); + } + + sb.setBlockIncrement(-1); + sb.setUnitIncrement(-1); + + if (sb.getBlockIncrement() < 1) { + String msg = "Failed: getBlockIncrement() == " + sb.getBlockIncrement(); + System.out.println(msg); + throw new RuntimeException(msg); + } + if (sb.getUnitIncrement() < 1) { + String msg = "Failed: getLineIncrement() == " + sb.getUnitIncrement(); + System.out.println(msg); + throw new RuntimeException(msg); + } + + sb.setBlockIncrement(2); + sb.setUnitIncrement(2); + + if (sb.getBlockIncrement() != 2) { + String msg = "Failed: getBlockIncrement() == " + sb.getBlockIncrement(); + System.out.println(msg); + throw new RuntimeException(msg); + } + if (sb.getUnitIncrement() != 2) { + String msg = "Failed: getLineIncrement() == " + sb.getUnitIncrement(); + System.out.println(msg); + throw new RuntimeException(msg); + } + System.out.println("Test Pass!!"); + }); + } +} diff --git a/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java b/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java new file mode 100644 index 0000000000000..960b7dadcf058 --- /dev/null +++ b/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2003, 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. + */ + +/* + @test + @bug 4943277 + @requires (os.family == "linux") + @summary XAWT: Scrollbar can't be controlled by keyboard + @key headful +*/ + +import java.awt.AWTException; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.Robot; +import java.awt.Scrollbar; +import java.awt.Toolkit; + +import java.awt.event.AdjustmentListener; +import java.awt.event.AdjustmentEvent; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +public class ScrollbarKeyControlTest implements AdjustmentListener, KeyListener { + Scrollbar scrollbarV; + Scrollbar scrollbarH; + volatile int changesTotal = 0; + Robot robot; + Object LOCK = new Object(); + Frame frame; + + public static void main(String[] args) throws Exception { + + final boolean isXAWT = Toolkit.getDefaultToolkit().getClass().getName(). + equals("sun.awt.X11.XToolkit"); + + if (!isXAWT) { + System.out.println("This test is for XAWT only."); + return; + } + ScrollbarKeyControlTest scrollbarKeyControlTest = new ScrollbarKeyControlTest(); + scrollbarKeyControlTest.init(); + } + + public void init() throws Exception { + try { + EventQueue.invokeAndWait(() -> { + frame = new Frame("Scrollbar Test"); + + scrollbarV = new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, 255); + scrollbarH = new Scrollbar(Scrollbar.HORIZONTAL, 0, 60, 0, 300); + + scrollbarH.addAdjustmentListener(this); + scrollbarH.addKeyListener(this); + scrollbarV.addAdjustmentListener(this); + scrollbarV.addKeyListener(this); + + frame.add("South", scrollbarH); + frame.add("East", scrollbarV); + + frame.setSize(200, 200); + frame.setVisible(true); + frame.validate(); + frame.toFront(); + }); + try { + robot = new Robot(); + testOneScrollbar(scrollbarV); + if (changesTotal != 9) { //one by mouse click and six by keys + throw new RuntimeException("Test failed. Not all adjustment " + + "events received by vertical scrollbar (" + changesTotal + " of 9)"); + } + changesTotal = 0; + testOneScrollbar(scrollbarH); + if (changesTotal != 9) { //one by mouse click and six by keys + throw new RuntimeException("Test failed. Not all adjustment " + + "events received by horizontal scrollbar (" + changesTotal + " of 9)"); + } + } catch (AWTException e) { + throw new RuntimeException("Test interrupted.", e); + } + System.out.println("Test passed. Adjustment Event called " + + changesTotal + " times for each scrollbar"); + + } finally { + EventQueue.invokeAndWait(() -> { + if (frame != null) { + frame.dispose(); + } + }); + } + } + + public void testOneScrollbar(Scrollbar sb) { + robot.waitForIdle(); + robot.mouseMove(sb.getLocationOnScreen().x + sb.getWidth() / 2, + sb.getLocationOnScreen().y + sb.getHeight() / 2); + try { + synchronized (LOCK) { + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + LOCK.wait(2000); + robot.keyPress(KeyEvent.VK_DOWN); + robot.keyRelease(KeyEvent.VK_DOWN); + LOCK.wait(2000); + robot.keyPress(KeyEvent.VK_PAGE_DOWN); + robot.keyRelease(KeyEvent.VK_PAGE_DOWN); + LOCK.wait(2000); + robot.keyPress(KeyEvent.VK_UP); + robot.keyRelease(KeyEvent.VK_UP); + LOCK.wait(2000); + robot.keyPress(KeyEvent.VK_PAGE_UP); + robot.keyRelease(KeyEvent.VK_PAGE_UP); + LOCK.wait(2000); + robot.keyPress(KeyEvent.VK_RIGHT); + robot.keyRelease(KeyEvent.VK_RIGHT); + LOCK.wait(2000); + robot.keyPress(KeyEvent.VK_LEFT); + robot.keyRelease(KeyEvent.VK_LEFT); + LOCK.wait(2000); + robot.keyPress(KeyEvent.VK_HOME); + robot.keyRelease(KeyEvent.VK_HOME); + LOCK.wait(2000); + robot.keyPress(KeyEvent.VK_END); + robot.keyRelease(KeyEvent.VK_END); + LOCK.wait(2000); + } + } catch (InterruptedException e) { + throw new RuntimeException("Test interrupted while keys being pressed.", e); + } + } + + public void adjustmentValueChanged(AdjustmentEvent e) { + changesTotal++; + synchronized (LOCK) { + LOCK.notify(); + } + System.out.println("Adjustment Event called "); + } + + public void keyPressed(KeyEvent e) { + System.out.println("KeyPressed called"); + } + + public void keyReleased(KeyEvent e) { + System.out.println("in keyReleased"); + } + + public void keyTyped(KeyEvent e) { + System.out.println("in keyTyped"); + } +} From e396cbfa7be225a110ded52ee90a9a245c301959 Mon Sep 17 00:00:00 2001 From: Tejesh R Date: Fri, 5 May 2023 12:57:26 +0530 Subject: [PATCH 2/9] Open source few Applet test --- .../java/awt/PopupMenu/PopupMenuStayOpen.java | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java diff --git a/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java b/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java new file mode 100644 index 0000000000000..26b93bb722d80 --- /dev/null +++ b/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2003, 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. + */ +/* + @test + @bug 4791953 + @requires (os.family == "linux" | os.family == "mac") + @summary Checks that popup menu stay open after a triggering click. + @key headful + @run main/othervm -Dsun.java2d.uiScale=1 PopupMenuStayOpen +*/ + +import java.awt.Component; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.Point; +import java.awt.PopupMenu; +import java.awt.Robot; +import java.awt.Toolkit; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.InputEvent; + +public class PopupMenuStayOpen { + public static final int MAX_COUNT = 100; + public static boolean wasActionFired = false; + static Frame frame; + static PopupMenu pom; + volatile static Point point; + + public static void main(String[] args) throws Exception { + + String nm = Toolkit.getDefaultToolkit().getClass().getName(); + + try { + EventQueue.invokeAndWait(() -> { + frame = new Frame("Click-to-see-Popup"); + pom = new PopupMenu(); + frame.setTitle(nm); + frame.setSize(300, 300); + frame.setLocation(20, 300); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + pom.add("A long enough line"); + + pom.getItem(0).addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + wasActionFired = true; + } + }); + + frame.add(pom); + frame.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent me) { + pom.show(frame, me.getX(), me.getY()); + } + }); + }); + + Robot robot = new Robot(); + robot.delay(1000); + robot.waitForIdle(); + + EventQueue.invokeAndWait(() -> { + point = getLocation(frame); + }); + + robot.mouseMove(point.x + 50, point.y + 100); + robot.mousePress(InputEvent.BUTTON2_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON2_DOWN_MASK); + + robot.delay(1000); + robot.waitForIdle(); + + robot.mouseMove(point.x + 50 + 30, point.y + 100 + 15); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.delay(500); + + if (!wasActionFired) { + throw new RuntimeException("Popup not visible or has no focus"); + } + System.out.println("Test Pass!!"); + } finally { + EventQueue.invokeAndWait(() -> { + if (frame != null) { + frame.dispose(); + } + }); + } + } + + public static Point getLocation(Component co) throws RuntimeException { + Point pt = null; + boolean bFound = false; + int count = 0; + while (!bFound) { + try { + pt = co.getLocationOnScreen(); + bFound = true; + } catch (Exception ex) { + bFound = false; + count++; + } + if (!bFound && count > MAX_COUNT) { + throw new RuntimeException("don't see a component to get location"); + } + } + return pt; + } +} From e7d0a3ac2a0d7491fe2706a73b3bdc0190053e16 Mon Sep 17 00:00:00 2001 From: Tejesh R Date: Mon, 8 May 2023 23:29:49 +0530 Subject: [PATCH 3/9] Updated based on review comments --- .../jdk/java/awt/Panel/SetForegroundTest.java | 3 +- .../java/awt/Scrollbar/PageIncrementTest.java | 81 +++++++++---------- .../Scrollbar/ScrollbarKeyControlTest.java | 6 +- 3 files changed, 42 insertions(+), 48 deletions(-) diff --git a/test/jdk/java/awt/Panel/SetForegroundTest.java b/test/jdk/java/awt/Panel/SetForegroundTest.java index b63bffcaf3a46..f9a448b7bf8a2 100644 --- a/test/jdk/java/awt/Panel/SetForegroundTest.java +++ b/test/jdk/java/awt/Panel/SetForegroundTest.java @@ -31,6 +31,7 @@ import java.awt.Color; import javax.swing.JWindow; + public class SetForegroundTest { static JWindow jwindow; public static void main(String[] args) throws Exception { @@ -48,7 +49,7 @@ public static void main(String[] args) throws Exception { }); } finally { EventQueue.invokeAndWait(() -> { - if(jwindow != null) { + if (jwindow != null) { jwindow.dispose(); } }); diff --git a/test/jdk/java/awt/Scrollbar/PageIncrementTest.java b/test/jdk/java/awt/Scrollbar/PageIncrementTest.java index daead1c18b207..6bc7c955ed1cf 100644 --- a/test/jdk/java/awt/Scrollbar/PageIncrementTest.java +++ b/test/jdk/java/awt/Scrollbar/PageIncrementTest.java @@ -29,57 +29,54 @@ @key headful */ -import java.awt.EventQueue; import java.awt.Scrollbar; public class PageIncrementTest { static Scrollbar sb; - public static void main(String[] args) throws Exception { - EventQueue.invokeAndWait(() -> { - sb = new Scrollbar(); - sb.setBlockIncrement(0); - sb.setUnitIncrement(0); + public static void main(String[] args) { + sb = new Scrollbar(); + sb.setBlockIncrement(0); + sb.setUnitIncrement(0); - if (sb.getBlockIncrement() < 1) { - String msg = "Failed: getBlockIncrement() == " + sb.getBlockIncrement(); - System.out.println(msg); - throw new RuntimeException(msg); - } - if (sb.getUnitIncrement() < 1) { - String msg = "Failed: getLineIncrement() == " + sb.getUnitIncrement(); - System.out.println(msg); - throw new RuntimeException(msg); - } + if (sb.getBlockIncrement() < 1) { + String msg = "Failed: getBlockIncrement() == " + sb.getBlockIncrement(); + System.out.println(msg); + throw new RuntimeException(msg); + } + if (sb.getUnitIncrement() < 1) { + String msg = "Failed: getLineIncrement() == " + sb.getUnitIncrement(); + System.out.println(msg); + throw new RuntimeException(msg); + } - sb.setBlockIncrement(-1); - sb.setUnitIncrement(-1); + sb.setBlockIncrement(-1); + sb.setUnitIncrement(-1); - if (sb.getBlockIncrement() < 1) { - String msg = "Failed: getBlockIncrement() == " + sb.getBlockIncrement(); - System.out.println(msg); - throw new RuntimeException(msg); - } - if (sb.getUnitIncrement() < 1) { - String msg = "Failed: getLineIncrement() == " + sb.getUnitIncrement(); - System.out.println(msg); - throw new RuntimeException(msg); - } + if (sb.getBlockIncrement() < 1) { + String msg = "Failed: getBlockIncrement() == " + sb.getBlockIncrement(); + System.out.println(msg); + throw new RuntimeException(msg); + } + if (sb.getUnitIncrement() < 1) { + String msg = "Failed: getLineIncrement() == " + sb.getUnitIncrement(); + System.out.println(msg); + throw new RuntimeException(msg); + } - sb.setBlockIncrement(2); - sb.setUnitIncrement(2); + sb.setBlockIncrement(2); + sb.setUnitIncrement(2); - if (sb.getBlockIncrement() != 2) { - String msg = "Failed: getBlockIncrement() == " + sb.getBlockIncrement(); - System.out.println(msg); - throw new RuntimeException(msg); - } - if (sb.getUnitIncrement() != 2) { - String msg = "Failed: getLineIncrement() == " + sb.getUnitIncrement(); - System.out.println(msg); - throw new RuntimeException(msg); - } - System.out.println("Test Pass!!"); - }); + if (sb.getBlockIncrement() != 2) { + String msg = "Failed: getBlockIncrement() == " + sb.getBlockIncrement(); + System.out.println(msg); + throw new RuntimeException(msg); + } + if (sb.getUnitIncrement() != 2) { + String msg = "Failed: getLineIncrement() == " + sb.getUnitIncrement(); + System.out.println(msg); + throw new RuntimeException(msg); + } + System.out.println("Test Pass!!"); } } diff --git a/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java b/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java index 960b7dadcf058..f7c97374748aa 100644 --- a/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java +++ b/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java @@ -51,11 +51,7 @@ public class ScrollbarKeyControlTest implements AdjustmentListener, KeyListener Frame frame; public static void main(String[] args) throws Exception { - - final boolean isXAWT = Toolkit.getDefaultToolkit().getClass().getName(). - equals("sun.awt.X11.XToolkit"); - - if (!isXAWT) { + if (!System.getProperty("os.name").startsWith("Linux")) { System.out.println("This test is for XAWT only."); return; } From a93f0ddfaddcb9585ff03d671970d6dc6db1a4f8 Mon Sep 17 00:00:00 2001 From: Tejesh R Date: Thu, 11 May 2023 10:40:12 +0530 Subject: [PATCH 4/9] Updated based on review comments --- test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java | 7 +++++-- test/jdk/java/awt/Robot/RobotMoveMultiscreen.java | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java b/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java index 26b93bb722d80..254d422174afc 100644 --- a/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java +++ b/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java @@ -20,6 +20,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ + /* @test @bug 4791953 @@ -99,8 +100,10 @@ public void mousePressed(MouseEvent me) { robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); robot.delay(500); - if (!wasActionFired) { - throw new RuntimeException("Popup not visible or has no focus"); + EventQueue.invokeAndWait(() -> { + if (!wasActionFired) { + throw new RuntimeException("Popup not visible or has no focus"); + } } System.out.println("Test Pass!!"); } finally { diff --git a/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java b/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java index f02d1a3540436..4a3f212363e0f 100644 --- a/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java +++ b/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java @@ -20,6 +20,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ + /* @test @bug 4288230 @@ -78,7 +79,7 @@ public void mouseMoved(MouseEvent e) { robot.delay(1000); robot.waitForIdle(); - if(testCondition == false) { + if (testCondition == false) { throw new RuntimeException("Can't move to another display"); } From 1ba7c25f90921af5792f0a156c597275257c2998 Mon Sep 17 00:00:00 2001 From: Tejesh R Date: Thu, 11 May 2023 10:52:36 +0530 Subject: [PATCH 5/9] Updated based on review comments --- test/jdk/java/awt/Panel/SetForegroundTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/test/jdk/java/awt/Panel/SetForegroundTest.java b/test/jdk/java/awt/Panel/SetForegroundTest.java index f9a448b7bf8a2..ce7c7d0f0ed16 100644 --- a/test/jdk/java/awt/Panel/SetForegroundTest.java +++ b/test/jdk/java/awt/Panel/SetForegroundTest.java @@ -20,6 +20,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ + /* @test @bug 4994151 From c102c912dc99a67802d7c481e09c4f5be38c2254 Mon Sep 17 00:00:00 2001 From: Tejesh R Date: Fri, 12 May 2023 10:54:44 +0530 Subject: [PATCH 6/9] Updated based on review comments --- .../jdk/java/awt/Panel/SetForegroundTest.java | 10 +++---- .../Scrollbar/ScrollbarKeyControlTest.java | 26 ++++++++----------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/test/jdk/java/awt/Panel/SetForegroundTest.java b/test/jdk/java/awt/Panel/SetForegroundTest.java index ce7c7d0f0ed16..8601efc526bd5 100644 --- a/test/jdk/java/awt/Panel/SetForegroundTest.java +++ b/test/jdk/java/awt/Panel/SetForegroundTest.java @@ -35,18 +35,14 @@ public class SetForegroundTest { static JWindow jwindow; + public static void main(String[] args) throws Exception { try { EventQueue.invokeAndWait(() -> { jwindow = new JWindow(); jwindow.pack(); - try { - jwindow.setForeground(Color.BLACK); - System.out.println("TEST PASSED"); - } catch (ClassCastException cce) { - System.out.println("TEST FAILED"); - throw new RuntimeException("Test failed.", cce); - } + jwindow.setForeground(Color.BLACK); + System.out.println("TEST PASSED"); }); } finally { EventQueue.invokeAndWait(() -> { diff --git a/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java b/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java index f7c97374748aa..7d60c97e3540e 100644 --- a/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java +++ b/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java @@ -80,21 +80,17 @@ public void init() throws Exception { frame.validate(); frame.toFront(); }); - try { - robot = new Robot(); - testOneScrollbar(scrollbarV); - if (changesTotal != 9) { //one by mouse click and six by keys - throw new RuntimeException("Test failed. Not all adjustment " + - "events received by vertical scrollbar (" + changesTotal + " of 9)"); - } - changesTotal = 0; - testOneScrollbar(scrollbarH); - if (changesTotal != 9) { //one by mouse click and six by keys - throw new RuntimeException("Test failed. Not all adjustment " + - "events received by horizontal scrollbar (" + changesTotal + " of 9)"); - } - } catch (AWTException e) { - throw new RuntimeException("Test interrupted.", e); + robot = new Robot(); + testOneScrollbar(scrollbarV); + if (changesTotal != 9) { //one by mouse click and six by keys + throw new RuntimeException("Test failed. Not all adjustment " + + "events received by vertical scrollbar (" + changesTotal + " of 9)"); + } + changesTotal = 0; + testOneScrollbar(scrollbarH); + if (changesTotal != 9) { //one by mouse click and six by keys + throw new RuntimeException("Test failed. Not all adjustment " + + "events received by horizontal scrollbar (" + changesTotal + " of 9)"); } System.out.println("Test passed. Adjustment Event called " + changesTotal + " times for each scrollbar"); From bb9356ec952fd140ed0fd05e387787e7cf877ab3 Mon Sep 17 00:00:00 2001 From: Tejesh R Date: Wed, 24 May 2023 09:10:26 +0530 Subject: [PATCH 7/9] Updated based on review comments --- test/jdk/java/awt/Robot/RobotMoveMultiscreen.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java b/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java index 4a3f212363e0f..2795364b9c5cb 100644 --- a/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java +++ b/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java @@ -78,10 +78,11 @@ public void mouseMoved(MouseEvent e) { robot.mouseMove(x_dest+50, y_dest+50); robot.delay(1000); robot.waitForIdle(); - - if (testCondition == false) { - throw new RuntimeException("Can't move to another display"); - } + EventQueue.invokeAndWait(() -> { + if (testCondition == false) { + throw new RuntimeException("Can't move to another display"); + } + }); System.out.println("Test Pass!!"); } finally { From beb200e2ee3d9fe7691939eeb371d07ac2e9e64b Mon Sep 17 00:00:00 2001 From: Tejesh R Date: Fri, 26 May 2023 12:48:01 +0530 Subject: [PATCH 8/9] Updated based on review comments --- .../java/awt/PopupMenu/PopupMenuStayOpen.java | 26 +++---------------- .../java/awt/Robot/RobotMoveMultiscreen.java | 5 ++-- .../Scrollbar/ScrollbarKeyControlTest.java | 3 +++ 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java b/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java index 254d422174afc..548919078782a 100644 --- a/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java +++ b/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java @@ -46,7 +46,7 @@ public class PopupMenuStayOpen { public static final int MAX_COUNT = 100; - public static boolean wasActionFired = false; + public volatile static boolean wasActionFired = false; static Frame frame; static PopupMenu pom; volatile static Point point; @@ -62,7 +62,6 @@ public static void main(String[] args) throws Exception { frame.setTitle(nm); frame.setSize(300, 300); frame.setLocation(20, 300); - frame.setLocationRelativeTo(null); frame.setVisible(true); pom.add("A long enough line"); @@ -85,7 +84,7 @@ public void mousePressed(MouseEvent me) { robot.waitForIdle(); EventQueue.invokeAndWait(() -> { - point = getLocation(frame); + point = frame.getLocationOnScreen(); }); robot.mouseMove(point.x + 50, point.y + 100); @@ -104,7 +103,7 @@ public void mousePressed(MouseEvent me) { if (!wasActionFired) { throw new RuntimeException("Popup not visible or has no focus"); } - } + }); System.out.println("Test Pass!!"); } finally { EventQueue.invokeAndWait(() -> { @@ -114,23 +113,4 @@ public void mousePressed(MouseEvent me) { }); } } - - public static Point getLocation(Component co) throws RuntimeException { - Point pt = null; - boolean bFound = false; - int count = 0; - while (!bFound) { - try { - pt = co.getLocationOnScreen(); - bFound = true; - } catch (Exception ex) { - bFound = false; - count++; - } - if (!bFound && count > MAX_COUNT) { - throw new RuntimeException("don't see a component to get location"); - } - } - return pt; - } } diff --git a/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java b/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java index 2795364b9c5cb..05de2e1e0adb5 100644 --- a/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java +++ b/test/jdk/java/awt/Robot/RobotMoveMultiscreen.java @@ -40,8 +40,8 @@ import java.awt.event.MouseMotionAdapter; public class RobotMoveMultiscreen { - static int x_dest = 20; - static int y_dest = 20; + static volatile int x_dest = 20; + static volatile int y_dest = 20; static Frame frame; static volatile Boolean testCondition = false; @@ -76,7 +76,6 @@ public void mouseMoved(MouseEvent e) { robot.delay(1000); robot.waitForIdle(); robot.mouseMove(x_dest+50, y_dest+50); - robot.delay(1000); robot.waitForIdle(); EventQueue.invokeAndWait(() -> { if (testCondition == false) { diff --git a/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java b/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java index 7d60c97e3540e..06c0b87e9d790 100644 --- a/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java +++ b/test/jdk/java/awt/Scrollbar/ScrollbarKeyControlTest.java @@ -81,6 +81,9 @@ public void init() throws Exception { frame.toFront(); }); robot = new Robot(); + robot.delay(1000); + robot.waitForIdle(); + testOneScrollbar(scrollbarV); if (changesTotal != 9) { //one by mouse click and six by keys throw new RuntimeException("Test failed. Not all adjustment " + From 515726a54ef80c7dc5af3a4e70d6c46083cae0cd Mon Sep 17 00:00:00 2001 From: Tejesh R Date: Fri, 26 May 2023 13:47:14 +0530 Subject: [PATCH 9/9] Updated based on review comments --- test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java b/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java index 548919078782a..334a3e4ea5fa7 100644 --- a/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java +++ b/test/jdk/java/awt/PopupMenu/PopupMenuStayOpen.java @@ -61,7 +61,7 @@ public static void main(String[] args) throws Exception { pom = new PopupMenu(); frame.setTitle(nm); frame.setSize(300, 300); - frame.setLocation(20, 300); + frame.setLocationRelativeTo(null); frame.setVisible(true); pom.add("A long enough line"); @@ -99,11 +99,10 @@ public void mousePressed(MouseEvent me) { robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); robot.delay(500); - EventQueue.invokeAndWait(() -> { - if (!wasActionFired) { - throw new RuntimeException("Popup not visible or has no focus"); - } - }); + + if (!wasActionFired) { + throw new RuntimeException("Popup not visible or has no focus"); + } System.out.println("Test Pass!!"); } finally { EventQueue.invokeAndWait(() -> {