Merge
diff --git a/test/java/awt/Choice/ChoiceMouseWheelTest/ChoiceMouseWheelTest.java b/test/java/awt/Choice/ChoiceMouseWheelTest/ChoiceMouseWheelTest.java
index e545b08..a63e6c1 100644
--- a/test/java/awt/Choice/ChoiceMouseWheelTest/ChoiceMouseWheelTest.java
+++ b/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 @@
throw new RuntimeException("Mouse Wheel scroll position error!");
}
- System.exit(0);
-
+ dispose();
} catch (AWTException e) {
throw new RuntimeException("AWTException occurred - problem creating robot!");
}
diff --git a/test/java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Extra.java b/test/java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Extra.java
index 1ef1474..b5d59d0 100644
--- a/test/java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Extra.java
+++ b/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 @@
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 @@
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 @@
checkExtModifiersOnPress(testModifier, paramStringElements, button);
}
- public static void checkExtModifiersOnReleaseClick(int testModifier, HashMap h, int button){
+ public static void checkExtModifiersOnReleaseClick(int testModifier, HashMap<String, String> 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<String, String> 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 static HashMap<String, String> tokenizeParamString(String param){
- HashMap <String, String> params = new HashMap<String, String>();
+ HashMap <String, String> params = new HashMap<>();
StringTokenizer st = new StringTokenizer(param, ",=");
while (st.hasMoreTokens()){
String tmp = st.nextToken();
@@ -167,7 +184,7 @@
}
public static Vector<String> tokenizeModifiers(String modifierList){
- Vector<String> modifiers = new Vector<String>();
+ Vector<String> modifiers = new Vector<>();
StringTokenizer st = new StringTokenizer(modifierList, "+");
while (st.hasMoreTokens()){
String tmp = st.nextToken();
@@ -189,7 +206,8 @@
}
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 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
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);
}
diff --git a/test/java/awt/datatransfer/HTMLDataFlavors/ManualHTMLDataFlavorTest.java b/test/java/awt/datatransfer/HTMLDataFlavors/ManualHTMLDataFlavorTest.java
index 156bbe4..015d46f 100644
--- a/test/java/awt/datatransfer/HTMLDataFlavors/ManualHTMLDataFlavorTest.java
+++ b/test/java/awt/datatransfer/HTMLDataFlavors/ManualHTMLDataFlavorTest.java
@@ -96,9 +96,7 @@
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 @@
" 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",
diff --git a/test/java/awt/event/MouseEvent/DisabledComponents/DisabledComponentsTest.java b/test/java/awt/event/MouseEvent/DisabledComponents/DisabledComponentsTest.java
new file mode 100644
index 0000000..3da25c6
--- /dev/null
+++ b/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();
+ }
+ }
+ }
+}
diff --git a/test/java/awt/event/MouseEvent/EnterAsGrabbedEvent/EnterAsGrabbedEvent.java b/test/java/awt/event/MouseEvent/EnterAsGrabbedEvent/EnterAsGrabbedEvent.java
new file mode 100644
index 0000000..8f62e4f
--- /dev/null
+++ b/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();
+ }
+ }
+ }
+}
diff --git a/test/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java b/test/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java
new file mode 100644
index 0000000..f3dd87c
--- /dev/null
+++ b/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);
+ }
+}