--- a/jdk/test/java/awt/event/KeyEvent/ExtendedModifiersTest/ExtendedModifiersTest.java Mon Dec 14 14:12:17 2015 -0800
+++ b/jdk/test/java/awt/event/KeyEvent/ExtendedModifiersTest/ExtendedModifiersTest.java Wed Dec 16 17:40:24 2015 +0300
@@ -24,7 +24,7 @@
/*
* @test
- * @bug 8043126
+ * @bug 8043126 8145116
* @summary Check whether
* 1. correct extended modifiers are returned
* by KeyEvent.getModifiersEx()
@@ -38,9 +38,16 @@
* @build ExtendedRobot
* @run main/timeout=600 ExtendedModifiersTest
*/
-
-
-import java.awt.*;
+import java.awt.Button;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.EventQueue;
+import java.awt.Frame;
+import java.awt.GridLayout;
+import java.awt.List;
+import java.awt.Point;
+import java.awt.TextArea;
+import java.awt.TextField;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
@@ -50,33 +57,28 @@
import test.java.awt.event.helpers.lwcomponents.LWButton;
import test.java.awt.event.helpers.lwcomponents.LWList;
-
public class ExtendedModifiersTest implements KeyListener {
Frame frame;
-
- Button button;
- LWButton buttonLW;
+ Button button;
+ LWButton buttonLW;
TextField textField;
- TextArea textArea;
- List list;
- LWList listLW;
+ TextArea textArea;
+ List list;
+ LWList listLW;
private final ExtendedRobot robot;
- private final static int robotDelay = 1000;
- private final static int waitDelay = 5000;
- private final static int keyDelay = 500;
-
+ private static final int WAIT_DELAY = 5000;
+ private static final int KEY_DELAY = 500;
private final Object lock;
- private boolean keyPressedFlag = false;
-
+ private boolean keyPressedFlag;
private int modifiersEx = 0;
private String exText = "";
-
@Override
- public void keyTyped(KeyEvent e) {}
+ public void keyTyped(KeyEvent e) {
+ }
@Override
public void keyPressed(KeyEvent e) {
@@ -84,17 +86,18 @@
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
return;
}
-
modifiersEx = e.getModifiersEx();
exText = InputEvent.getModifiersExText(modifiersEx);
keyPressedFlag = true;
- synchronized (lock) { lock.notifyAll(); }
+ synchronized (lock) {
+ lock.notifyAll();
+ }
}
@Override
- public void keyReleased(KeyEvent e) {}
-
+ public void keyReleased(KeyEvent e) {
+ }
public void createGUI() {
@@ -119,12 +122,16 @@
frame.add(textArea);
list = new List();
- for (int i = 1; i <= 5; ++i) { list.add("item " + i); }
+ for (int i = 1; i <= 5; ++i) {
+ list.add("item " + i);
+ }
list.addKeyListener(this);
frame.add(list);
listLW = new LWList();
- for (int i = 1; i <= 5; ++i) { listLW.add("item " + i); }
+ for (int i = 1; i <= 5; ++i) {
+ listLW.add("item " + i);
+ }
listLW.addKeyListener(this);
frame.add(listLW);
@@ -137,55 +144,56 @@
public ExtendedModifiersTest() throws Exception {
lock = new Object();
robot = new ExtendedRobot();
- EventQueue.invokeAndWait( this::createGUI );
+ EventQueue.invokeAndWait(this::createGUI);
}
-
- private void runScenario(int keys[], int refMask) {
-
- if (keys.length < 1) { return; }
+ private void runScenario(int keys[], int expectedMask) {
+ if (keys.length < 1) {
+ return;
+ }
for (int k = 0; k < keys.length; ++k) {
keyPressedFlag = false;
robot.keyPress(keys[k]);
- robot.delay(keyDelay);
+ robot.delay(KEY_DELAY);
if (!keyPressedFlag) {
synchronized (lock) {
try {
- lock.wait(waitDelay);
- } catch (InterruptedException ex) {}
+ lock.wait(WAIT_DELAY);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
}
}
if (!keyPressedFlag) {
robot.keyRelease(keys[k]);
- robot.delay(keyDelay);
+ robot.delay(KEY_DELAY);
assertTrue(false, "key press event was not received");
}
}
- int modEx = modifiersEx & refMask;
+ int modEx = modifiersEx & expectedMask;
- for (int k = keys.length - 1; k >=0; --k) {
+ for (int k = keys.length - 1; k >= 0; --k) {
robot.keyRelease(keys[k]);
- robot.delay(keyDelay);
+ robot.delay(KEY_DELAY);
}
-
- assertEQ(modifiersEx, modEx, "invalid extended modifiers");
+ assertEQ(expectedMask, modEx, "invalid extended modifiers");
for (int k = 0; k < keys.length; ++k) {
String keyText = KeyEvent.getKeyText(keys[k]).toLowerCase();
- assertTrue(exText.toLowerCase().contains(keyText), "invalid extended modifier keys description");
+ assertTrue(exText.toLowerCase().contains(keyText),
+ "invalid extended modifier keys description");
}
System.out.println(exText + " : passed");
robot.type(KeyEvent.VK_ESCAPE);
-
- robot.delay(robotDelay);
+ robot.waitForIdle();
}
private void doTest() throws Exception {
@@ -201,7 +209,7 @@
String OS = System.getProperty("os.name").toLowerCase();
System.out.println(OS);
- for (Component c: components) {
+ for (Component c : components) {
String className = c.getClass().getName();
System.out.println("component class : " + className);
@@ -211,18 +219,19 @@
int yc = origin.y + c.getHeight() / 2;
Point center = new Point(xc, yc);
- robot.delay(robotDelay);
+ robot.waitForIdle();
robot.glide(origin, center);
robot.click();
- robot.delay(robotDelay);
+ robot.waitForIdle();
// 1. shift + control
runScenario(new int[]{KeyEvent.VK_SHIFT, KeyEvent.VK_CONTROL},
InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK);
// 2. alt + shift + control
- runScenario(new int[]{KeyEvent.VK_ALT, KeyEvent.VK_SHIFT, KeyEvent.VK_CONTROL},
- InputEvent.ALT_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK);
+ runScenario(new int[]{KeyEvent.VK_ALT, KeyEvent.VK_SHIFT,
+ KeyEvent.VK_CONTROL}, InputEvent.ALT_DOWN_MASK
+ | InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK);
// 3. shift
runScenario(new int[]{KeyEvent.VK_SHIFT},
@@ -236,26 +245,31 @@
runScenario(new int[]{KeyEvent.VK_SHIFT, KeyEvent.VK_ALT},
InputEvent.SHIFT_DOWN_MASK | InputEvent.ALT_DOWN_MASK);
-
if (OS.contains("os x") || OS.contains("sunos")) {
// 6. meta
- runScenario(new int[]{KeyEvent.VK_META}, InputEvent.META_DOWN_MASK);
+ runScenario(new int[]{KeyEvent.VK_META},
+ InputEvent.META_DOWN_MASK);
// 7. shift + ctrl + alt + meta
- runScenario(new int[]{KeyEvent.VK_SHIFT, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_META},
- InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK | InputEvent.META_DOWN_MASK);
+ runScenario(new int[]{KeyEvent.VK_SHIFT, KeyEvent.VK_CONTROL,
+ KeyEvent.VK_ALT, KeyEvent.VK_META},
+ InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK
+ | InputEvent.ALT_DOWN_MASK | InputEvent.META_DOWN_MASK);
// 8. meta + shift + ctrl
- runScenario(new int[]{KeyEvent.VK_META, KeyEvent.VK_SHIFT, KeyEvent.VK_CONTROL},
- InputEvent.META_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK);
+ runScenario(new int[]{KeyEvent.VK_META, KeyEvent.VK_SHIFT,
+ KeyEvent.VK_CONTROL}, InputEvent.META_DOWN_MASK
+ | InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK);
// 9. meta + shift + alt
- runScenario(new int[]{KeyEvent.VK_META, KeyEvent.VK_SHIFT, KeyEvent.VK_ALT},
- InputEvent.META_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK | InputEvent.ALT_DOWN_MASK);
+ runScenario(new int[]{KeyEvent.VK_META, KeyEvent.VK_SHIFT,
+ KeyEvent.VK_ALT}, InputEvent.META_DOWN_MASK
+ | InputEvent.SHIFT_DOWN_MASK | InputEvent.ALT_DOWN_MASK);
// 10. meta + ctrl + alt
- runScenario(new int[]{KeyEvent.VK_META, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT},
- InputEvent.META_DOWN_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK);
+ runScenario(new int[]{KeyEvent.VK_META, KeyEvent.VK_CONTROL,
+ KeyEvent.VK_ALT}, InputEvent.META_DOWN_MASK
+ | InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK);
}
}
@@ -267,5 +281,4 @@
ExtendedModifiersTest test = new ExtendedModifiersTest();
test.doTest();
}
-}
-
+}
\ No newline at end of file