7132383: [macosx] bug6596966.java should be adapted for Mac
authorkshefov
Wed, 13 Feb 2013 19:06:31 +0400
changeset 15636 0eeacbf451a7
parent 15635 1bb3df084c72
child 15637 2c226ebab6a6
7132383: [macosx] bug6596966.java should be adapted for Mac Reviewed-by: serb, alexsch Contributed-by: Vera Akulova <vera.akulova@oracle.com>
jdk/test/javax/swing/JLabel/6596966/bug6596966.java
jdk/test/javax/swing/regtesthelpers/Util.java
--- a/jdk/test/javax/swing/JLabel/6596966/bug6596966.java	Wed Feb 13 18:01:18 2013 +0400
+++ b/jdk/test/javax/swing/JLabel/6596966/bug6596966.java	Wed Feb 13 19:06:31 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -24,16 +24,17 @@
 /* @test
    @bug 6596966
    @summary Some JFileChooser mnemonics do not work with sticky keys
+   @library ../../regtesthelpers
+   @build Util
    @run main bug6596966
    @author Pavel Porvatov
 */
 
-
-import sun.awt.SunToolkit;
-
-import javax.swing.*;
 import java.awt.*;
 import java.awt.event.KeyEvent;
+import java.util.ArrayList;
+import javax.swing.*;
+import sun.awt.SunToolkit;
 
 public class bug6596966 {
     private static JFrame frame;
@@ -71,11 +72,14 @@
 
         toolkit.realSync();
 
-        robot.keyPress(KeyEvent.VK_ALT);
+        ArrayList<Integer> keys = Util.getSystemMnemonicKeyCodes();
+        for (int i = 0; i < keys.size(); ++i) {
+            robot.keyPress(keys.get(i));
+        }
+
         robot.keyPress(KeyEvent.VK_L);
 
         toolkit.realSync();
-
         toolkit.getSystemEventQueue().postEvent(new KeyEvent(label, KeyEvent.KEY_RELEASED,
                 EventQueue.getMostRecentEventTime(), 0, KeyEvent.VK_L, 'L'));
 
@@ -90,7 +94,11 @@
                 }
             });
         } finally {
-            robot.keyRelease(KeyEvent.VK_ALT);
+            robot.keyRelease(KeyEvent.VK_L);
+            for (int i = 0; i < keys.size(); ++i) {
+                robot.keyRelease(keys.get(i));
+            }
+            toolkit.realSync();
         }
     }
 }
--- a/jdk/test/javax/swing/regtesthelpers/Util.java	Wed Feb 13 18:01:18 2013 +0400
+++ b/jdk/test/javax/swing/regtesthelpers/Util.java	Wed Feb 13 19:06:31 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -23,11 +23,13 @@
 
 import javax.swing.*;
 import java.awt.*;
+import java.awt.event.*;
 import java.awt.image.BufferedImage;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.concurrent.Callable;
+import sun.swing.*;
 
 /**
  * <p>This class contains utilities useful for regression testing.
@@ -212,4 +214,33 @@
 
         return result.get(0);
     }
+    /**
+     * Gets key codes from system mnemonic key mask
+     * @return key codes list
+     */
+    public static ArrayList<Integer> getSystemMnemonicKeyCodes() {
+        return Util.getKeyCodesFromKeyMask(SwingUtilities2.getSystemMnemonicKeyMask());
+    }
+
+    /**
+     * Gets the key codes list from modifiers
+     * @param modifiers an integer combination of the modifier constants
+     * @return key codes list
+     */
+    public static ArrayList<Integer> getKeyCodesFromKeyMask(int modifiers) {
+        ArrayList<Integer> result = new ArrayList<>();
+        if ((modifiers & InputEvent.CTRL_MASK) != 0) {
+            result.add(KeyEvent.VK_CONTROL);
+        }
+        if ((modifiers & InputEvent.ALT_MASK) != 0) {
+            result.add(KeyEvent.VK_ALT);
+        }
+        if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
+            result.add(KeyEvent.VK_SHIFT);
+        }
+        if ((modifiers & InputEvent.META_MASK) != 0) {
+            result.add(KeyEvent.VK_META);
+        }
+        return result;
+    }
 }