From ee95a2a1c40ab6d132b1063f87edb74cf6a40da9 Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Fri, 29 Nov 2013 11:08:52 +0400 Subject: [PATCH 1/9] 7152982: [TEST_BUG][macosx] Extremely unstable mouse modifiers test Reviewed-by: anthony, serb --- .../MouseModifiersUnitTest_Extra.java | 79 ++++++++++--------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/jdk/test/java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Extra.java b/jdk/test/java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Extra.java index 1ef1474b5ee..b5d59d0d7af 100644 --- a/jdk/test/java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Extra.java +++ b/jdk/test/java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Extra.java @@ -29,6 +29,8 @@ @run main MouseModifiersUnitTest_Extra */ +import sun.awt.OSInfo; + import java.awt.*; import java.awt.event.*; import java.util.Arrays; @@ -61,6 +63,17 @@ public class MouseModifiersUnitTest_Extra extends Frame { static int [] modifiersExStandardCTRL; static int [] modifiersExStandardALT; + private final static String SHIFT_MODIFIER = OSInfo.getOSType().equals(OSInfo.OSType.MACOSX) ? + "\u21e7" : "Shift"; + + private final static String ALT_MODIFIER = OSInfo.getOSType().equals(OSInfo.OSType.MACOSX) ? + "\u2325" : "Alt"; + + + private final static String CTRL_MODIFIER = OSInfo.getOSType().equals(OSInfo.OSType.MACOSX) ? + "\u2303" : "Ctrl"; + + // BUTTON1, 2, 3 press-release. final static int modifiersStandard = 0; //InputEvent.BUTTON_DOWN_MASK; @@ -77,7 +90,8 @@ public class MouseModifiersUnitTest_Extra extends Frame { if (modifiersEx != curStandardExModifiers[index]){ // System.out.println(">>>>>>>>>>>>>>> Pressed. modifiersEx "+modifiersEx +" : "+!= curStandardExModifiers"); - MessageLogger.reportError("Test failed : Pressed. modifiersEx != curStandardExModifiers. Got: " + modifiersEx + " , Expected: " + curStandardExModifiers[index]); + MessageLogger.reportError("Test failed : Pressed. modifiersEx != curStandardExModifiers. Got: " + + modifiersEx + " , Expected: " + curStandardExModifiers[index]); } //check event.paramString() output @@ -88,51 +102,54 @@ public class MouseModifiersUnitTest_Extra extends Frame { checkExtModifiersOnPress(testModifier, paramStringElements, button); } - public static void checkExtModifiersOnReleaseClick(int testModifier, HashMap h, int button){ + public static void checkExtModifiersOnReleaseClick(int testModifier, HashMap h, int button){ String ethalon = ""; switch (testModifier){ case SHIFT:{ - ethalon = "Shift"; + ethalon = SHIFT_MODIFIER; break; } case ALT:{ - ethalon = "Alt"; + ethalon = ALT_MODIFIER; break; } case CTRL:{ - ethalon = "Ctrl"; + ethalon = CTRL_MODIFIER; break; } } - // + if (h.get("extModifiers") == null){ h.put("extModifiers", ""); } + if (!ethalon.equals(h.get("extModifiers"))) { - MessageLogger.reportError("Test failed : Released/Clicked. extModifiers = " +h.get("extModifiers")+" instead of : "+ethalon); + MessageLogger.reportError("Test failed : Released/Clicked. extModifiers = " + + h.get("extModifiers") + " instead of : " + ethalon); } } - public static void checkExtModifiersOnPress(int testModifier, HashMap h, int button){ + public static void checkExtModifiersOnPress(int testModifier, HashMap h, int button){ String ethalon = ""; switch (testModifier){ case SHIFT:{ - ethalon = "Shift+"; + ethalon = SHIFT_MODIFIER + "+"; break; } case ALT:{ - ethalon = "Alt+"; + ethalon = ALT_MODIFIER + "+"; break; } case CTRL:{ - ethalon = "Ctrl+"; + ethalon = CTRL_MODIFIER + "+"; break; } } ethalon = ethalon + "Button" +button; if (!h.get("extModifiers").equals(ethalon)) { - MessageLogger.reportError("Test failed : Pressed. extModifiers = " +h.get("extModifiers")+" instead of : "+ethalon); + MessageLogger.reportError("Test failed : Pressed. extModifiers = " +h.get("extModifiers")+" instead of : " + + ethalon); } } @@ -152,7 +169,7 @@ public class MouseModifiersUnitTest_Extra extends Frame { } } public static HashMap tokenizeParamString(String param){ - HashMap params = new HashMap(); + HashMap params = new HashMap<>(); StringTokenizer st = new StringTokenizer(param, ",="); while (st.hasMoreTokens()){ String tmp = st.nextToken(); @@ -167,7 +184,7 @@ public class MouseModifiersUnitTest_Extra extends Frame { } public static Vector tokenizeModifiers(String modifierList){ - Vector modifiers = new Vector(); + Vector modifiers = new Vector<>(); StringTokenizer st = new StringTokenizer(modifierList, "+"); while (st.hasMoreTokens()){ String tmp = st.nextToken(); @@ -189,7 +206,8 @@ public class MouseModifiersUnitTest_Extra extends Frame { } if (modifiersEx != curStandardExModifiers[index]){ - MessageLogger.reportError("Test failed : Released. modifiersEx != curStandardExModifiers. Got: " + modifiersEx + " , Expected: " + curStandardExModifiers[index]); + MessageLogger.reportError("Test failed : Released. modifiersEx != curStandardExModifiers. Got: " + + modifiersEx + " , Expected: " + curStandardExModifiers[index]); } //check event.paramString() output @@ -212,7 +230,8 @@ public class MouseModifiersUnitTest_Extra extends Frame { } if (modifiersEx != curStandardExModifiers[index]){ - MessageLogger.reportError("Test failed : Clicked. modifiersEx != curStandardExModifiers. Got: " + modifiersEx + " , Expected: " + curStandardExModifiers[index]); + MessageLogger.reportError("Test failed : Clicked. modifiersEx != curStandardExModifiers. Got: " + + modifiersEx + " , Expected: " + curStandardExModifiers[index]); } //check event.paramString() output @@ -243,22 +262,10 @@ public class MouseModifiersUnitTest_Extra extends Frame { static Robot robot; public void init() { this.setLayout(new BorderLayout()); - - String[] instructions = - { - "This test should be used with the mouse having more then three buttons.", - "Currently, " + MouseInfo.getNumberOfButtons() +" buttons are available.", - "If there are less then three buttons, press PASS.", - "1. Press each extra mouse button.", - "2. For each mouse event its modifiers and ExModifiers will be printed.", - "3. Verify that they are correct.", - "4. Press Pass or Fail accordingly." - }; -// Sysout.createDialogWithInstructions( instructions ); - -// addMouseListener(adapterTest1); try { robot = new Robot(); + robot.setAutoDelay(100); + robot.setAutoWaitForIdle(true); } catch (Exception e) { MessageLogger.reportError("Test failed. "+e); } @@ -297,9 +304,8 @@ public class MouseModifiersUnitTest_Extra extends Frame { robot.delay(1000); robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2); for (int i = 3; i< mouseButtonDownMasks.length; i++){ - System.out.println("testNONE() => " +mouseButtonDownMasks[i] ); + System.out.println("testNONE() => " + mouseButtonDownMasks[i]); robot.mousePress(mouseButtonDownMasks[i]); - robot.delay(100); robot.mouseRelease(mouseButtonDownMasks[i]); } robot.delay(1000); @@ -312,9 +318,8 @@ public class MouseModifiersUnitTest_Extra extends Frame { robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2); for (int i = 3; i< mouseButtonDownMasks.length; i++){ robot.keyPress(KeyEvent.VK_SHIFT); - System.out.println("testSHIFT() => " +mouseButtonDownMasks[i] ); + System.out.println("testSHIFT() => " + mouseButtonDownMasks[i]); robot.mousePress(mouseButtonDownMasks[i]); - robot.delay(100); robot.mouseRelease(mouseButtonDownMasks[i]); robot.keyRelease(KeyEvent.VK_SHIFT); } @@ -328,9 +333,8 @@ public class MouseModifiersUnitTest_Extra extends Frame { robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2); for (int i = 3; i< mouseButtonDownMasks.length; i++){ robot.keyPress(KeyEvent.VK_CONTROL); - System.out.println("testCTRL() => " +mouseButtonDownMasks[i] ); + System.out.println("testCTRL() => " + mouseButtonDownMasks[i]); robot.mousePress(mouseButtonDownMasks[i]); - robot.delay(100); robot.mouseRelease(mouseButtonDownMasks[i]); robot.keyRelease(KeyEvent.VK_CONTROL); } @@ -344,9 +348,8 @@ public class MouseModifiersUnitTest_Extra extends Frame { robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2); for (int i = 3; i< mouseButtonDownMasks.length; i++){ robot.keyPress(KeyEvent.VK_ALT); - System.out.println("testALT() => " +mouseButtonDownMasks[i] ); + System.out.println("testALT() => " + mouseButtonDownMasks[i]); robot.mousePress(mouseButtonDownMasks[i]); - robot.delay(100); robot.mouseRelease(mouseButtonDownMasks[i]); robot.keyRelease(KeyEvent.VK_ALT); } From 8850d18abd9679034436a3bcb723ec6e1ab83154 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Fri, 29 Nov 2013 16:12:03 +0400 Subject: [PATCH 2/9] 8029010: [macosx] Need test for JDK-7124513 Reviewed-by: pchelko, alexsch --- .../NSTexturedJFrame/NSTexturedJFrame.java | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 jdk/test/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java diff --git a/jdk/test/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java b/jdk/test/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java new file mode 100644 index 00000000000..f3dd87cb335 --- /dev/null +++ b/jdk/test/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2013, 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.Rectangle; +import java.awt.Robot; +import java.awt.Toolkit; +import java.awt.image.BufferedImage; + +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import sun.awt.OSInfo; +import sun.awt.SunToolkit; + +/** + * @test + * @bug 7124513 + * @summary We should support NSTexturedBackgroundWindowMask style on OSX. + * @author Sergey Bylokhov + */ +public final class NSTexturedJFrame { + + private static final String BRUSH = "apple.awt.brushMetalLook"; + private static final String STYLE = "Window.style"; + private static final BufferedImage[] images = new BufferedImage[3]; + private static Rectangle bounds; + private static volatile int step; + private static JFrame frame; + + public static void main(final String[] args) throws Exception { + if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) { + System.out.println("This test is for OSX, considered passed."); + return; + } + // Default window appearance + showFrame(); + step++; + // apple.awt.brushMetalLook appearance + showFrame(); + step++; + // Window.style appearance + showFrame(); + + // images on step 1 and 2 should be same + testImages(images[1], images[2], false); + // images on step 1 and 2 should be different from default + testImages(images[0], images[1], true); + testImages(images[0], images[2], true); + } + + private static void testImages(BufferedImage img1, BufferedImage img2, + boolean shouldbeDifferent) { + boolean different = false; + for (int x = 0; x < img1.getWidth(); ++x) { + for (int y = 0; y < img1.getHeight(); ++y) { + if (img1.getRGB(x, y) != img2.getRGB(x, y)) { + different = true; + } + } + } + if (different != shouldbeDifferent) { + throw new RuntimeException("Textured property does not work"); + } + } + + private static void showFrame() throws Exception { + final Robot robot = new Robot(); + robot.setAutoDelay(50); + createUI(); + images[step] = robot.createScreenCapture(bounds); + SwingUtilities.invokeAndWait(frame::dispose); + sleep(); + } + + private static void createUI() throws Exception { + SwingUtilities.invokeAndWait(() -> { + frame = new JFrame(); + frame.setUndecorated(true); + frame.setSize(400, 400); + frame.setLocationRelativeTo(null); + switch (step) { + case 1: + frame.getRootPane().putClientProperty(BRUSH, true); + break; + case 2: + frame.getRootPane().putClientProperty(STYLE, "textured"); + } + frame.setVisible(true); + }); + sleep(); + SwingUtilities.invokeAndWait(() -> { + bounds = frame.getBounds(); + }); + sleep(); + } + + private static void sleep() throws InterruptedException { + ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + Thread.sleep(1000); + } +} From 72e44e870c61f4da99ca81842a34abaecb5a9734 Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Fri, 29 Nov 2013 16:43:22 +0400 Subject: [PATCH 3/9] 7178682: [TEST_BUG][macosx] Mouse Pressed event can't be monitored for DisabledComponentsTest.html Reviewed-by: anthony, serb --- .../DisabledComponentsTest.java | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 jdk/test/java/awt/event/MouseEvent/DisabledComponents/DisabledComponentsTest.java diff --git a/jdk/test/java/awt/event/MouseEvent/DisabledComponents/DisabledComponentsTest.java b/jdk/test/java/awt/event/MouseEvent/DisabledComponents/DisabledComponentsTest.java new file mode 100644 index 00000000000..3da25c6d9c0 --- /dev/null +++ b/jdk/test/java/awt/event/MouseEvent/DisabledComponents/DisabledComponentsTest.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2013 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 4173714 + @summary java.awt.button behaves differently under Win32/Solaris + @author tdv@sparc.spb.su + @library ../../../regtesthelpers + @build Util + @run main DisabledComponentsTest +*/ + +/** + * DisabledComponentsTest.java + * + * summary: java.awt.button behaves differently under Win32/Solaris + * Disabled component should not receive events. This is what this + * test checks out. + */ + +import java.awt.*; +import java.awt.event.*; +import java.util.concurrent.atomic.AtomicBoolean; + +import test.java.awt.regtesthelpers.Util; + +import javax.swing.*; + +public class DisabledComponentsTest { + + private static Frame frame; + private static Button b = new Button("Button"); + private static final AtomicBoolean pressed = new AtomicBoolean(false); + private static final AtomicBoolean entered = new AtomicBoolean(false); + + private static void init() { + frame = new Frame("Test"); + frame.setBounds(100, 100, 100, 100); + b = new Button("Test"); + b.setEnabled(false); + b.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + System.err.println("Mouse pressed. target=" + e.getSource()); + if (!b.isEnabled()) { + System.err.println("TEST FAILED: BUTTON RECEIVED AN EVENT WHEN DISABLED!"); + pressed.set(true); + } + } + public void mouseEntered(MouseEvent e) { + System.out.println("Mouse entered. target=" + e.getSource()); + if (!b.isEnabled()) + System.err.println("TEST FAILED: BUTTON RECEIVED AN EVENT WHEN DISABLED!"); + entered.set(true); + } + }); + frame.add(b); + frame.setVisible(true); + } + + public static void main(String[] args) throws Exception { + try { + Robot r = Util.createRobot(); + r.setAutoDelay(200); + r.setAutoWaitForIdle(true); + r.mouseMove(0, 0); + SwingUtilities.invokeAndWait(DisabledComponentsTest::init); + Util.waitForIdle(r); + Util.pointOnComp(b, r); + if (entered.get()) { + throw new RuntimeException("TEST FAILED: disabled button received MouseEntered event"); + } + Util.clickOnComp(b, r); + if (pressed.get()) { + throw new RuntimeException("TEST FAILED: disabled button received MousePressed event"); + } + } finally { + if (frame != null) { + frame.dispose(); + } + } + } +} From 0bb946b80ed22511be4be7331914f5b6a0f98080 Mon Sep 17 00:00:00 2001 From: Andrei Eremeev Date: Tue, 3 Dec 2013 15:18:52 +0400 Subject: [PATCH 4/9] 8023576: [TEST BUG] Compilation fails for java/awt/Choice/ChoiceMouseWheelTest/ChoiceMouseWheelTest.java Reviewed-by: anthony, serb --- .../Choice/ChoiceMouseWheelTest/ChoiceMouseWheelTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jdk/test/java/awt/Choice/ChoiceMouseWheelTest/ChoiceMouseWheelTest.java b/jdk/test/java/awt/Choice/ChoiceMouseWheelTest/ChoiceMouseWheelTest.java index e545b08fea0..a63e6c13175 100644 --- a/jdk/test/java/awt/Choice/ChoiceMouseWheelTest/ChoiceMouseWheelTest.java +++ b/jdk/test/java/awt/Choice/ChoiceMouseWheelTest/ChoiceMouseWheelTest.java @@ -25,7 +25,9 @@ @test @bug 7050935 @summary closed/java/awt/Choice/WheelEventsConsumed/WheelEventsConsumed.html fails on win32 + @library ../../regtesthelpers @author Oleg Pekhovskiy: area=awt-choice + @build Util @run main ChoiceMouseWheelTest */ @@ -142,8 +144,7 @@ public class ChoiceMouseWheelTest extends Frame { throw new RuntimeException("Mouse Wheel scroll position error!"); } - System.exit(0); - + dispose(); } catch (AWTException e) { throw new RuntimeException("AWTException occurred - problem creating robot!"); } From d78b1178098e1b4060ae49d8791f4e721b35eb4e Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Tue, 3 Dec 2013 15:31:07 +0400 Subject: [PATCH 5/9] 8029251: [TEST_BUG][macosx] Use safari browser, the ouput contain information that DataFlavor.allHtmlFlavor is not present in the system clipboard Reviewed-by: anthony, serb --- .../HTMLDataFlavors/ManualHTMLDataFlavorTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/jdk/test/java/awt/datatransfer/HTMLDataFlavors/ManualHTMLDataFlavorTest.java b/jdk/test/java/awt/datatransfer/HTMLDataFlavors/ManualHTMLDataFlavorTest.java index 156bbe4cb51..015d46f03b2 100644 --- a/jdk/test/java/awt/datatransfer/HTMLDataFlavors/ManualHTMLDataFlavorTest.java +++ b/jdk/test/java/awt/datatransfer/HTMLDataFlavors/ManualHTMLDataFlavorTest.java @@ -96,9 +96,7 @@ public class ManualHTMLDataFlavorTest extends Applet { Sysout.println(t.getTransferData(DataFlavor.fragmentHtmlFlavor).toString()); Sysout.println("SELECTION:"); Sysout.println(t.getTransferData(DataFlavor.selectionHtmlFlavor).toString()); - } catch (UnsupportedFlavorException e) { - e.printStackTrace(); - } catch (IOException e) { + } catch (UnsupportedFlavorException | IOException e) { e.printStackTrace(); } @@ -116,6 +114,7 @@ public class ManualHTMLDataFlavorTest extends Applet { " otherwise for instance iexplore can prohibit drag and drop from", " the browser to other applications because of", " the protected mode restrictions.", + " On Mac OS X do NOT use Safari, it does not provide the needed DataFlavor", "3) Check the data in the output area of this dialog", "5) The output should not contain information that any of", " flavors is not present in the system clipboard", From 0aa8a5ad09c85d19cd107b5975519ac1d4734321 Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Tue, 3 Dec 2013 19:33:05 +0400 Subject: [PATCH 6/9] 7124391: [TEST_BUG][macosx] MouseEvents are not dispatched when the mouse cursor leaves the component Reviewed-by: anthony, serb --- .../EnterAsGrabbedEvent.java | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 jdk/test/java/awt/event/MouseEvent/EnterAsGrabbedEvent/EnterAsGrabbedEvent.java diff --git a/jdk/test/java/awt/event/MouseEvent/EnterAsGrabbedEvent/EnterAsGrabbedEvent.java b/jdk/test/java/awt/event/MouseEvent/EnterAsGrabbedEvent/EnterAsGrabbedEvent.java new file mode 100644 index 00000000000..8f62e4ffd8a --- /dev/null +++ b/jdk/test/java/awt/event/MouseEvent/EnterAsGrabbedEvent/EnterAsGrabbedEvent.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2013, 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 6317481 8012325 + @summary REG:Pressing the mouse, dragging and releasing it outside the button triggers ActionEvent, XAWT + @author Dmitry.Cherepanov@SUN.COM area=awt.event + @run main EnterAsGrabbedEvent +*/ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class EnterAsGrabbedEvent +{ + //Declare things used in the test, like buttons and labels here + private static Frame frame; + private static Button button; + private static volatile boolean enterTriggered = false; + private static volatile boolean actionTriggered = false; + + private static void init() + { + frame = new Frame(); + frame.setLayout(new FlowLayout()); + button = new Button("button"); + button.addActionListener(actionEvent -> { + actionTriggered = true; + }); + frame.add(button); + frame.setBounds(100, 100, 200, 200); + frame.setVisible(true); + frame.validate(); + } + + public static void main(String[] args) throws Exception { + try { + Robot r = new Robot(); + r.setAutoDelay(200); + r.setAutoWaitForIdle(true); + SwingUtilities.invokeAndWait(EnterAsGrabbedEvent::init); + r.waitForIdle(); + + Point loc = button.getLocationOnScreen(); + r.mouseMove(loc.x+button.getWidth()/2, loc.y+button.getHeight()/2); + r.mousePress(InputEvent.BUTTON1_MASK); + + // in this case (drag mouse outside the button): + // NotifyEnter (->MouseEnter) should be dispatched to the top-level + // event if the grabbed window is the component (button) + frame.addMouseListener( + new MouseAdapter() { + public void mouseEntered(MouseEvent me) { + System.out.println(me); + enterTriggered = true; + } + + // Just for tracing + public void mouseExited(MouseEvent me) { + System.out.println(me); + } + }); + + // Just for tracing + button.addMouseListener( + new MouseAdapter(){ + public void mouseEntered(MouseEvent me){ + System.out.println(me); + } + public void mouseExited(MouseEvent me){ + System.out.println(me); + } + }); + + r.mouseMove(loc.x+button.getWidth() + 1, loc.y+button.getHeight()/2); + + r.mouseRelease(InputEvent.BUTTON1_MASK); + + if (!enterTriggered) { + throw new RuntimeException("Test failed. MouseEntered was not triggered"); + } + + if (actionTriggered) { + throw new RuntimeException("Test failed. ActionEvent triggered"); + } + } finally { + if (frame != null) { + frame.dispose(); + } + } + } +} From eef145dadafb6c06db619e4e6688e8ea3dcf1b5c Mon Sep 17 00:00:00 2001 From: Anton Litvinov Date: Wed, 4 Dec 2013 12:29:18 +0400 Subject: [PATCH 7/9] 8025775: JNI warnings in TryXShmAttach Reviewed-by: art, anthony --- .../classes/sun/awt/X11/XConstants.java | 5 -- .../classes/sun/awt/X11/XErrorHandler.java | 70 ------------------- .../sun/awt/X11/XErrorHandlerUtil.java | 14 ++-- .../solaris/native/sun/awt/awt_GraphicsEnv.c | 43 ++++++------ .../solaris/native/sun/awt/awt_GraphicsEnv.h | 3 +- jdk/src/solaris/native/sun/awt/awt_util.c | 5 ++ jdk/src/solaris/native/sun/awt/awt_util.h | 64 +++++------------ .../native/sun/java2d/opengl/GLXSurfaceData.c | 28 +++++--- .../native/sun/java2d/x11/X11SurfaceData.c | 10 +-- jdk/src/solaris/native/sun/xawt/XlibWrapper.c | 5 ++ 10 files changed, 82 insertions(+), 165 deletions(-) diff --git a/jdk/src/solaris/classes/sun/awt/X11/XConstants.java b/jdk/src/solaris/classes/sun/awt/X11/XConstants.java index e1903d81f40..91c533898b8 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XConstants.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XConstants.java @@ -674,9 +674,4 @@ final public class XConstants { public static final long XkbModifierMapMask = (1L<<2); public static final long XkbVirtualModsMask = (1L<<6); //server map - /***************************************************************** - * X SHARED MEMORY EXTENSION FUNCTIONS - *****************************************************************/ - - public static final int X_ShmAttach = 1; } diff --git a/jdk/src/solaris/classes/sun/awt/X11/XErrorHandler.java b/jdk/src/solaris/classes/sun/awt/X11/XErrorHandler.java index ec09cea5198..4fc6bd84249 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XErrorHandler.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XErrorHandler.java @@ -42,29 +42,6 @@ public abstract class XErrorHandler { } } - /** - * This is a base synthetic error handler containing a boolean flag which allows - * to show that an error is handled or not. - */ - public static class XErrorHandlerWithFlag extends XBaseErrorHandler { - private volatile boolean errorOccurred = false; - - public boolean getErrorOccurredFlag() { - return errorOccurred; - } - - /** - * Sets an internal boolean flag to a particular value. Should be always called with - * false value of the parameter errorOccurred before this - * error handler is set as current. - * @param errorOccurred true to indicate that an error was handled, - * false to reset the internal boolean flag - */ - public void setErrorOccurredFlag(boolean errorOccurred) { - this.errorOccurred = errorOccurred; - } - } - /* * Instead of validating window id, we simply call XGetWindowProperty, * but temporary install this function as the error handler to ignore @@ -99,51 +76,4 @@ public abstract class XErrorHandler { return theInstance; } } - - /** - * This is a synthetic error handler for errors generated by the native function - * XShmAttach. If an error is handled, an internal boolean flag of the - * handler is set to true. - */ - public static final class XShmAttachHandler extends XErrorHandlerWithFlag { - private XShmAttachHandler() {} - - @Override - public int handleError(long display, XErrorEvent err) { - if (err.get_minor_code() == XConstants.X_ShmAttach) { - setErrorOccurredFlag(true); - return 0; - } - return super.handleError(display, err); - } - - // Shared instance - private static XShmAttachHandler theInstance = new XShmAttachHandler(); - public static XShmAttachHandler getInstance() { - return theInstance; - } - } - - /** - * This is a synthetic error handler for BadAlloc errors generated by the - * native glX* functions. Its internal boolean flag is set to true, - * if an error is handled. - */ - public static final class GLXBadAllocHandler extends XErrorHandlerWithFlag { - private GLXBadAllocHandler() {} - - @Override - public int handleError(long display, XErrorEvent err) { - if (err.get_error_code() == XConstants.BadAlloc) { - setErrorOccurredFlag(true); - return 0; - } - return super.handleError(display, err); - } - - private static GLXBadAllocHandler theInstance = new GLXBadAllocHandler(); - public static GLXBadAllocHandler getInstance() { - return theInstance; - } - } } diff --git a/jdk/src/solaris/classes/sun/awt/X11/XErrorHandlerUtil.java b/jdk/src/solaris/classes/sun/awt/X11/XErrorHandlerUtil.java index da12cd9ef89..4bdf0ecb0dc 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XErrorHandlerUtil.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XErrorHandlerUtil.java @@ -42,7 +42,7 @@ public final class XErrorHandlerUtil { private static long display; /** - * Error handler at the moment of XErrorHandlerUtil initialization. + * Error handler at the moment of {@code XErrorHandlerUtil} initialization. */ private static long saved_error_handler; @@ -63,7 +63,7 @@ public final class XErrorHandlerUtil { new GetBooleanAction("sun.awt.noisyerrorhandler")); /** - * The flag indicating that init was called already. + * The flag indicating that {@code init} was called already. */ private static boolean initPassed; @@ -73,9 +73,9 @@ public final class XErrorHandlerUtil { private XErrorHandlerUtil() {} /** - * Sets the toolkit global error handler, stores the connection to X11 server, which - * will be used during an error handling process. This method is called once from - * awt_init_Display function defined in awt_GraphicsEnv.c + * Sets the toolkit global error handler, stores the connection to X11 server, + * which will be used during an error handling process. This method is called + * once from {@code awt_init_Display} function defined in {@code awt_GraphicsEnv.c} * file immediately after the connection to X11 window server is opened. * @param display the connection to X11 server which should be stored */ @@ -109,9 +109,9 @@ public final class XErrorHandlerUtil { } private static void RESTORE_XERROR_HANDLER(boolean doXSync) { - // Wait until all requests are processed by the X server - // and only then uninstall the error handler. if (doXSync) { + // Wait until all requests are processed by the X server + // and only then uninstall the error handler. XSync(); } current_error_handler = null; diff --git a/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c b/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c index 4b6e2c685df..bb042d0648f 100644 --- a/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c +++ b/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c @@ -906,6 +906,20 @@ Java_sun_awt_X11GraphicsDevice_getDisplay(JNIEnv *env, jobject this) static jint canUseShmExt = UNSET_MITSHM; static jint canUseShmExtPixmaps = UNSET_MITSHM; +static jboolean xshmAttachFailed = JNI_FALSE; + +int XShmAttachXErrHandler(Display *display, XErrorEvent *xerr) { + if (xerr->minor_code == X_ShmAttach) { + xshmAttachFailed = JNI_TRUE; + } + return 0; +} +jboolean isXShmAttachFailed() { + return xshmAttachFailed; +} +void resetXShmAttachFailed() { + xshmAttachFailed = JNI_FALSE; +} extern int mitShmPermissionMask; @@ -913,7 +927,6 @@ void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) { XShmSegmentInfo shminfo; int XShmMajor, XShmMinor; int a, b, c; - jboolean xShmAttachResult; AWT_LOCK(); if (canUseShmExt != UNSET_MITSHM) { @@ -957,14 +970,21 @@ void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) { } shminfo.readOnly = True; - xShmAttachResult = TryXShmAttach(env, awt_display, &shminfo); + resetXShmAttachFailed(); + /** + * The J2DXErrHandler handler will set xshmAttachFailed + * to JNI_TRUE if any Shm error has occured. + */ + EXEC_WITH_XERROR_HANDLER(XShmAttachXErrHandler, + XShmAttach(awt_display, &shminfo)); + /** * Get rid of the id now to reduce chances of leaking * system resources. */ shmctl(shminfo.shmid, IPC_RMID, 0); - if (xShmAttachResult == JNI_TRUE) { + if (isXShmAttachFailed() == JNI_FALSE) { canUseShmExt = CAN_USE_MITSHM; /* check if we can use shared pixmaps */ XShmQueryVersion(awt_display, &XShmMajor, &XShmMinor, @@ -979,23 +999,6 @@ void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) { } AWT_UNLOCK(); } - -/* - * Must be called with the acquired AWT lock. - */ -jboolean TryXShmAttach(JNIEnv *env, Display *display, XShmSegmentInfo *shminfo) { - jboolean errorOccurredFlag = JNI_FALSE; - jobject errorHandlerRef; - - /* - * XShmAttachHandler will set its internal flag to JNI_TRUE, if any Shm error occurs. - */ - EXEC_WITH_XERROR_HANDLER(env, "sun/awt/X11/XErrorHandler$XShmAttachHandler", - "()Lsun/awt/X11/XErrorHandler$XShmAttachHandler;", JNI_TRUE, - errorHandlerRef, errorOccurredFlag, - XShmAttach(display, shminfo)); - return errorOccurredFlag == JNI_FALSE ? JNI_TRUE : JNI_FALSE; -} #endif /* MITSHM */ /* diff --git a/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.h b/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.h index 0ca5a329f75..1675c68287b 100644 --- a/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.h +++ b/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.h @@ -53,7 +53,8 @@ extern int XShmQueryExtension(); void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps); -jboolean TryXShmAttach(JNIEnv *env, Display *display, XShmSegmentInfo *shminfo); +void resetXShmAttachFailed(); +jboolean isXShmAttachFailed(); #endif /* MITSHM */ diff --git a/jdk/src/solaris/native/sun/awt/awt_util.c b/jdk/src/solaris/native/sun/awt/awt_util.c index d92c96e5e92..76953f9e973 100644 --- a/jdk/src/solaris/native/sun/awt/awt_util.c +++ b/jdk/src/solaris/native/sun/awt/awt_util.c @@ -41,6 +41,11 @@ #include "java_awt_event_MouseWheelEvent.h" +/* + * Called by "ToolkitErrorHandler" function in "XlibWrapper.c" file. + */ +XErrorHandler current_native_xerror_handler = NULL; + extern jint getModifiers(uint32_t state, jint button, jint keyCode); extern jint getButton(uint32_t button); diff --git a/jdk/src/solaris/native/sun/awt/awt_util.h b/jdk/src/solaris/native/sun/awt/awt_util.h index b93f7744cd6..56781f5ecbd 100644 --- a/jdk/src/solaris/native/sun/awt/awt_util.h +++ b/jdk/src/solaris/native/sun/awt/awt_util.h @@ -29,57 +29,29 @@ #ifndef HEADLESS #include "gdefs.h" -/* - * Expected types of arguments of the macro. - * (JNIEnv*, const char*, const char*, jboolean, jobject) - */ -#define WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, \ - handlerHasFlag, handlerRef) do { \ - handlerRef = JNU_CallStaticMethodByName(env, NULL, handlerClassName, "getInstance", \ - getInstanceSignature).l; \ - if (handlerHasFlag == JNI_TRUE) { \ - JNU_CallMethodByName(env, NULL, handlerRef, "setErrorOccurredFlag", "(Z)V", JNI_FALSE); \ - } \ - JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", "WITH_XERROR_HANDLER", \ - "(Lsun/awt/X11/XErrorHandler;)V", handlerRef); \ +#define WITH_XERROR_HANDLER(f) do { \ + XSync(awt_display, False); \ + current_native_xerror_handler = (f); \ +} while (0) + +#define RESTORE_XERROR_HANDLER do { \ + XSync(awt_display, False); \ + current_native_xerror_handler = NULL; \ +} while (0) + +#define EXEC_WITH_XERROR_HANDLER(f, code) do { \ + WITH_XERROR_HANDLER(f); \ + do { \ + code; \ + } while (0); \ + RESTORE_XERROR_HANDLER; \ } while (0) /* - * Expected types of arguments of the macro. - * (JNIEnv*, jboolean) + * Called by "ToolkitErrorHandler" function in "XlibWrapper.c" file. */ -#define RESTORE_XERROR_HANDLER(env, doXSync) do { \ - JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", \ - "RESTORE_XERROR_HANDLER", "(Z)V", doXSync); \ -} while (0) +extern XErrorHandler current_native_xerror_handler; -/* - * Expected types of arguments of the macro. - * (JNIEnv*, const char*, const char*, jboolean, jobject, jboolean, No type - C expression) - */ -#define EXEC_WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag, \ - handlerRef, errorOccurredFlag, code) do { \ - handlerRef = NULL; \ - WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag, handlerRef); \ - do { \ - code; \ - } while (0); \ - RESTORE_XERROR_HANDLER(env, JNI_TRUE); \ - if (handlerHasFlag == JNI_TRUE) { \ - GET_HANDLER_ERROR_OCCURRED_FLAG(env, handlerRef, errorOccurredFlag); \ - } \ -} while (0) - -/* - * Expected types of arguments of the macro. - * (JNIEnv*, jobject, jboolean) - */ -#define GET_HANDLER_ERROR_OCCURRED_FLAG(env, handlerRef, errorOccurredFlag) do { \ - if (handlerRef != NULL) { \ - errorOccurredFlag = JNU_CallMethodByName(env, NULL, handlerRef, "getErrorOccurredFlag", \ - "()Z").z; \ - } \ -} while (0) #endif /* !HEADLESS */ #ifndef INTERSECTS diff --git a/jdk/src/solaris/native/sun/java2d/opengl/GLXSurfaceData.c b/jdk/src/solaris/native/sun/java2d/opengl/GLXSurfaceData.c index e1cf2c57501..1bdd08827f9 100644 --- a/jdk/src/solaris/native/sun/java2d/opengl/GLXSurfaceData.c +++ b/jdk/src/solaris/native/sun/java2d/opengl/GLXSurfaceData.c @@ -48,6 +48,8 @@ extern DisposeFunc OGLSD_Dispose; extern void OGLSD_SetNativeDimensions(JNIEnv *env, OGLSDOps *oglsdo, jint w, jint h); +jboolean surfaceCreationFailed = JNI_FALSE; + #endif /* !HEADLESS */ JNIEXPORT void JNICALL @@ -347,6 +349,15 @@ OGLSD_InitOGLWindow(JNIEnv *env, OGLSDOps *oglsdo) return JNI_TRUE; } +static int +GLXSD_BadAllocXErrHandler(Display *display, XErrorEvent *xerr) +{ + if (xerr->error_code == BadAlloc) { + surfaceCreationFailed = JNI_TRUE; + } + return 0; +} + JNIEXPORT jboolean JNICALL Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer (JNIEnv *env, jobject glxsd, @@ -362,8 +373,6 @@ Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer int attrlist[] = {GLX_PBUFFER_WIDTH, 0, GLX_PBUFFER_HEIGHT, 0, GLX_PRESERVED_CONTENTS, GL_FALSE, 0}; - jboolean errorOccurredFlag; - jobject errorHandlerRef; J2dTraceLn3(J2D_TRACE_INFO, "GLXSurfaceData_initPbuffer: w=%d h=%d opq=%d", @@ -391,15 +400,12 @@ Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer attrlist[1] = width; attrlist[3] = height; - errorOccurredFlag = JNI_FALSE; - WITH_XERROR_HANDLER(env, "sun/awt/X11/XErrorHandler$GLXBadAllocHandler", - "()Lsun/awt/X11/XErrorHandler$GLXBadAllocHandler;", JNI_TRUE, errorHandlerRef); - pbuffer = j2d_glXCreatePbuffer(awt_display, glxinfo->fbconfig, attrlist); - XSync(awt_display, False); - RESTORE_XERROR_HANDLER(env, JNI_FALSE); - GET_HANDLER_ERROR_OCCURRED_FLAG(env, errorHandlerRef, errorOccurredFlag); - - if ((pbuffer == 0) || errorOccurredFlag) { + surfaceCreationFailed = JNI_FALSE; + EXEC_WITH_XERROR_HANDLER( + GLXSD_BadAllocXErrHandler, + pbuffer = j2d_glXCreatePbuffer(awt_display, + glxinfo->fbconfig, attrlist)); + if ((pbuffer == 0) || surfaceCreationFailed) { J2dRlsTraceLn(J2D_TRACE_ERROR, "GLXSurfaceData_initPbuffer: could not create glx pbuffer"); return JNI_FALSE; diff --git a/jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c b/jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c index a35d6fd3065..79e3be488a6 100644 --- a/jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c +++ b/jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c @@ -65,6 +65,7 @@ static UnlockFunc X11SD_Unlock; static DisposeFunc X11SD_Dispose; static GetPixmapBgFunc X11SD_GetPixmapWithBg; static ReleasePixmapBgFunc X11SD_ReleasePixmapWithBg; +extern int XShmAttachXErrHandler(Display *display, XErrorEvent *xerr); extern AwtGraphicsConfigDataPtr getGraphicsConfigFromComponentPeer(JNIEnv *env, jobject this); extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs; @@ -532,8 +533,6 @@ XImage* X11SD_CreateSharedImage(X11SDOps *xsdo, { XImage *img = NULL; XShmSegmentInfo *shminfo; - JNIEnv* env; - jboolean xShmAttachResult; shminfo = malloc(sizeof(XShmSegmentInfo)); if (shminfo == NULL) { @@ -573,8 +572,9 @@ XImage* X11SD_CreateSharedImage(X11SDOps *xsdo, shminfo->readOnly = False; - env = (JNIEnv*)JNU_GetEnv(jvm, JNI_VERSION_1_2); - xShmAttachResult = TryXShmAttach(env, awt_display, shminfo); + resetXShmAttachFailed(); + EXEC_WITH_XERROR_HANDLER(XShmAttachXErrHandler, + XShmAttach(awt_display, shminfo)); /* * Once the XSync round trip has finished then we @@ -583,7 +583,7 @@ XImage* X11SD_CreateSharedImage(X11SDOps *xsdo, */ shmctl(shminfo->shmid, IPC_RMID, 0); - if (xShmAttachResult == JNI_FALSE) { + if (isXShmAttachFailed() == JNI_TRUE) { J2dRlsTraceLn1(J2D_TRACE_ERROR, "X11SD_SetupSharedSegment XShmAttach has failed: %s", strerror(errno)); diff --git a/jdk/src/solaris/native/sun/xawt/XlibWrapper.c b/jdk/src/solaris/native/sun/xawt/XlibWrapper.c index 3e75f291c94..cf3474d0e5d 100644 --- a/jdk/src/solaris/native/sun/xawt/XlibWrapper.c +++ b/jdk/src/solaris/native/sun/xawt/XlibWrapper.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -1266,6 +1267,10 @@ JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsKanaKeyboard JavaVM* jvm = NULL; static int ToolkitErrorHandler(Display * dpy, XErrorEvent * event) { JNIEnv * env; + // First call the native synthetic error handler declared in "awt_util.h" file. + if (current_native_xerror_handler != NULL) { + current_native_xerror_handler(dpy, event); + } if (jvm != NULL) { env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if (env) { From 64e1aae31aa09b20532fd57f3f79bf8222bd534c Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Wed, 4 Dec 2013 15:41:03 +0400 Subject: [PATCH 8/9] 8028484: [TEST_BUG][macosx] closed/java/awt/MouseInfo/JContainerMousePositionTest fails Reviewed-by: anthony, serb --- .../JContainerMousePositionTest.java | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 jdk/test/java/awt/MouseInfo/JContainerMousePositionTest.java diff --git a/jdk/test/java/awt/MouseInfo/JContainerMousePositionTest.java b/jdk/test/java/awt/MouseInfo/JContainerMousePositionTest.java new file mode 100644 index 00000000000..028d2e180cb --- /dev/null +++ b/jdk/test/java/awt/MouseInfo/JContainerMousePositionTest.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2013, 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 + @summary unit test for a new method in Container class: getMousePosition(boolean) + @author dav@sparc.spb.su: area= + @bug 4009555 + @run main JContainerMousePositionTest +*/ + +import javax.swing.*; +import java.awt.*; +import java.util.concurrent.atomic.AtomicReference; + +// this test looks at mouse pointer when it +// 1 over component +// 2 over Container, but not over one of its child Components. +// out of bounds of Container +// two values of paramater allowChildren are considered. + +public class JContainerMousePositionTest { + //Declare things used in the test, like buttons and labels here + private static JButton jButton1; + private static JButton jButton4; + private static JFrame frame1; + private static Container contentPane; + + public static void main(final String[] args) throws Exception { + Robot robot = new Robot(); + robot.setAutoDelay(200); + robot.setAutoWaitForIdle(true); + + SwingUtilities.invokeAndWait(JContainerMousePositionTest::init); + + robot.delay(500); + robot.waitForIdle(); + + AtomicReference centerC4 = new AtomicReference<>(); + SwingUtilities.invokeAndWait(() -> { + centerC4.set(jButton4.getLocation()); + contentPane.remove(jButton4); + contentPane.validate(); + contentPane.repaint(); + }); + robot.waitForIdle(); + + AtomicReference frameBounds = new AtomicReference<>(); + AtomicReference button1Size = new AtomicReference<>(); + SwingUtilities.invokeAndWait(() -> { + frameBounds.set(frame1.getBounds()); + button1Size.set(jButton1.getSize()); + }); + +//point mouse to center of top-left Component (button1) + robot.mouseMove(frameBounds.get().x + button1Size.get().width / 2, + frameBounds.get().y + button1Size.get().height / 2); + + AtomicReference pFalse = new AtomicReference<>(); + AtomicReference pTrue = new AtomicReference<>(); + SwingUtilities.invokeAndWait(() -> { + pFalse.set(frame1.getMousePosition(false)); + pTrue.set(frame1.getMousePosition(true)); + }); + robot.waitForIdle(); + if (pFalse.get() != null) { + throw new RuntimeException("Test failed: Container.getMousePosition(false) returned non-null over one of children."); + } + System.out.println("Test stage completed: Container.getMousePosition(false) returned null result over child Component. Passed."); + + if (pTrue.get() == null) { + throw new RuntimeException("Test failed: Container.getMousePosition(true) returned null result over child Component"); + } + System.out.println("Test stage compelted: Container.getMousePosition(true) returned non-null result over child Component. Passed."); + +//point mouse out from Container's area + robot.mouseMove(frameBounds.get().x + frameBounds.get().width + 10, + frameBounds.get().y + frameBounds.get().height + 10); + SwingUtilities.invokeAndWait(() -> { + pFalse.set(frame1.getMousePosition(false)); + pTrue.set(frame1.getMousePosition(true)); + }); + robot.waitForIdle(); + if (pFalse.get() != null || pTrue.get() != null) { + throw new RuntimeException("Test failed: Container.getMousePosition(boolean) returned incorrect result outside Container"); + } + System.out.println("Test stage completed: Container.getMousePosition(boolean) returned null result outside Container. Passed."); + +//point mouse in place free from child components (right-botton component) + robot.mouseMove(frameBounds.get().x + centerC4.get().x, + frameBounds.get().y + centerC4.get().y); + + robot.delay(3000); + SwingUtilities.invokeAndWait(() -> { + pFalse.set(contentPane.getMousePosition(false)); + pTrue.set(frame1.getMousePosition(true)); + }); + robot.waitForIdle(); + + if (pFalse.get() == null || pTrue.get() == null) { + throw new RuntimeException("Test failed: Container.getMousePosition(boolean) returned null result inside Container."); + } + System.out.println("Test stage completed: Container.getMousePosition(boolean) returned non-null results inside Container. Passed."); + + if (pTrue.get().x != centerC4.get().x || pTrue.get().y != centerC4.get().y) { + throw new RuntimeException("Test failed: Container.getMousePosition(true) returned incorrect result inside Container."); + } + System.out.println("Test stage completed: Container.getMousePosition(true) returned correct result inside Container. Passed."); + + System.out.println("TEST PASSED"); + } + + private static void init() { + frame1 = new JFrame("Testing getMousePosition() on LWs"); + jButton1 = new JButton("C1"); + jButton4 = new JButton("C4"); + contentPane = frame1.getContentPane(); + contentPane.setLayout(new GridLayout(2, 2, 25, 25)); + contentPane.add(jButton1); + contentPane.add(new JButton("C2")); + contentPane.add(new JButton("C3")); + contentPane.add(jButton4); + frame1.setSize(200, 200); + frame1.setVisible(true); + } +} + + From 6c439131d65997aef263b4e4bf5a4015bb3ff325 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Wed, 4 Dec 2013 15:55:36 +0400 Subject: [PATCH 9/9] 8029382: [macosx] Need test for JDK-7161437 Reviewed-by: pchelko, anthony --- .../FileDialogForDirectories.html | 45 ++++++++++ .../FileDialogForDirectories.java | 82 +++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 jdk/test/java/awt/FileDialog/FileDialogForDirectories/FileDialogForDirectories.html create mode 100644 jdk/test/java/awt/FileDialog/FileDialogForDirectories/FileDialogForDirectories.java diff --git a/jdk/test/java/awt/FileDialog/FileDialogForDirectories/FileDialogForDirectories.html b/jdk/test/java/awt/FileDialog/FileDialogForDirectories/FileDialogForDirectories.html new file mode 100644 index 00000000000..f2179443031 --- /dev/null +++ b/jdk/test/java/awt/FileDialog/FileDialogForDirectories/FileDialogForDirectories.html @@ -0,0 +1,45 @@ + + + + + + FileDialogForDirectories + + + +

FileDialogForDirectories
Bug ID: 7161437

+ +

See the dialog box (usually in upper left corner) for instructions

+ + + + diff --git a/jdk/test/java/awt/FileDialog/FileDialogForDirectories/FileDialogForDirectories.java b/jdk/test/java/awt/FileDialog/FileDialogForDirectories/FileDialogForDirectories.java new file mode 100644 index 00000000000..71dcaea0c79 --- /dev/null +++ b/jdk/test/java/awt/FileDialog/FileDialogForDirectories/FileDialogForDirectories.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2013, 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 sun.awt.OSInfo; +import test.java.awt.regtesthelpers.Sysout; + +import java.applet.Applet; +import java.awt.Button; +import java.awt.FileDialog; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class FileDialogForDirectories extends Applet implements ActionListener { + private volatile Button showBtn; + private volatile FileDialog fd; + + @Override + public void init() { + if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) { + Sysout.createDialogWithInstructions(new String[]{ + "Press PASS, this test is for MacOS X only."}); + return; + } + + System.setProperty("apple.awt.fileDialogForDirectories", "true"); + + setLayout(new GridLayout(1, 1)); + + fd = new FileDialog(new Frame(), "Open"); + + showBtn = new Button("Show File Dialog"); + showBtn.addActionListener(this); + add(showBtn); + String[] instructions = { + "1) Click on 'Show File Dialog' button. A file dialog will come up.", + "2) Check that files can't be selected.", + "3) Check that directories can be selected.", + "4) Repeat steps 1 - 3 a few times for different files and directories.", + "5) If it's true then the test passed, otherwise it failed."}; + Sysout.createDialogWithInstructions(instructions); + }//End init() + + @Override + public void start() { + setSize(200, 200); + show(); + }// start() + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == showBtn) { + fd.setVisible(true); + String output = fd.getFile(); + if (output != null) { + Sysout.println(output + " is selected"); + } + } + } +}// class ManualYesNoTest